Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for VSCode in distribution directory #383

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app-editors/vscode/Manifest
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ DIST @types-vscode-webview-1.57.0.tgz 2037 BLAKE2B b2f60239ef705d012d6420b85a135
DIST @types-webpack-5.28.5.tgz 2380 BLAKE2B 1773db03a3168bbb60706a81a4b50be97e83b15250df56abe7256551bee9d8ff11f3634ca2b2270ef5a9eb96121dd594e43fc5718a274de2264f08a72d3ad849 SHA512 c11f3b720bf18f7a7a0f40abb75af96afc2a7dfa8f5d490d9674359a353ddc6ee00ae163b9f651e08ea3f1ccf9835175b536297ce385be5cbe726210c0bf70bf
DIST @types-which-2.0.0.tgz 2163 BLAKE2B 309af4f35b39275dbe9f9f7759f5b7d46d879ded47e42edeb9995646328ccf2cda7e3d5809bc31e7ef9da0daf8768c08b278f60f70cd1f49747d772addc2c209 SHA512 2474cd384a599c009076c4e88d68209fe490f08b9c7ea121b73ee0f19d06ebb59d4a3e31dc5d17e48d9cfc255c97ccff42e906ac81de43f378f6fd5abbbe1715
DIST @types-which-3.0.0.tgz 2154 BLAKE2B fbda2c12dee2a829054c0e2219e5575639d22917881455eec3553be5540e310a115297297dba78daa6c4b6edc3aa2dd351b19ecee9aff1720350af21c5ab2aac SHA512 0120b175bb2bc0d7d231700b942dc379c89ff6bc0332efbcd0a1a9e7323644b468b5f32c4efedf1cbf16f150e9db8c329b30f2205b9d8547920ae82b81115f1d
DIST @types-which-3.0.4.tgz 2242 BLAKE2B 4025116ebea23ab93bd5dc8a01ce8469e078c85cb4417e0a8681e504c11ef48a9c5e8756c12ece3c777f923c3229c029a7ea1117e64885c67e28a9297acb699f SHA512 962c9fba8ff5d3a25d96049c849cd711009502b9340af7afa8fa2d7bc17c1e05a027775109c4c780922c2c3b9e7b493193f9a16c89f321993741649927c47edb
DIST @types-wicg-file-system-access-2020.9.6.tgz 3345 BLAKE2B 5ec47d62292f2071e2f636f92fbe20e62d09b37085824da30b00604a5447ef4fcb94a71f28fe74a2c742bd8f2e3022037732186b926bce2126a52d8c03e4a6ac SHA512 ea1a2013be479763affe3829f1984368698817fab7274ec6b577fc9c2242c0a4c7abbf7bd69a39f8321dee0adfb74f731bba65070a45e99534cb1f43bb8fded4
DIST @types-windows-foreground-love-0.3.0.tgz 1526 BLAKE2B 444fe789b620fe8a358dfdd311f14f27c9a44ee4e06830b36318ed7fee0f63ba3cbc95e6be8381daf8a248f6b7c2e896d79f71c4393acdabb99bc0b024f9732f SHA512 b4551503f7e2a1f36a3a1ea5665ca6bd089060f63e7195d93d1f669fdc0debf292f2ec31d33807e088ff8e6172458afec7e0c66561087a49d2d81322ec564901
DIST @types-winreg-1.2.30.tgz 2847 BLAKE2B 4f5bdb826a0349b72b4e131bbda1d82283c3fdb7a2d535691c812fa7b69b3c34115f33083c719b0c5405da46a50e2e510af647cfbcec75adbfe78d5a028de171 SHA512 7389bf867388d63df88bc8579646737a513a4977cea9a4d6841a7452006ec26a6269f876d8ea6c136eb546583ffda819b501c863970c81b917f1b9ed85416b98
Expand Down Expand Up @@ -1959,6 +1960,7 @@ DIST whatwg-url-5.0.0.tgz 11073 BLAKE2B 18f88e3d75a7c99c3f6487955363170f3f465844
DIST which-1.3.1.tgz 4174 BLAKE2B 9e1a011f4a786c323a2e7245979f30fa4f70af39db69913d60a32d3402a3fa3a47b80e9dc64256bf814277c262a6e2b57c664fd01b99e2b1f0b3314ee41b2715 SHA512 1f125d616ab53132106c9de7c3472ab2c1e84cd536ebb2a5ac3b866755989710d2b54b4a52139a266875d76fd36661f1c547ee26a3d748e9bbb43c9ab3439221
DIST which-2.0.2.tgz 4496 BLAKE2B d3a7efcfb97c5f7a5cd50907eb9535fef5e6c2c69f6810c230ad1b26fc8f2ad5d6921136fce9274805a060b67a7a29c0248bd0eb5b9412da1991c2e09610fcbe SHA512 04b2374e5d535b73ef97bd25df2ab763ae22f9ac29c17aac181616924a8cb676d782b303fb28fbae15b492e103c7325a6171a3116e6881aa4a34c10a34c8e26c
DIST which-4.0.0.tgz 3322 BLAKE2B bf37a2e24ae9b3d9f80cc7d2efd7089d2851cfe605488c5b64557224ad3778c11dc5c1906cead9c38492b4a8a409e4a40a6c26b69c9f13d61b9e653b8e6bb348 SHA512 1a5698c846f4ec33f16022a12b3a65096049b6fc5971932b2fee1492b4d22471cfc99538998613bf7a9a39eefb1fb10e0cb492a2901414073a5bc538caabec72
DIST which-5.0.0.tgz 3346 BLAKE2B 0cf8a23f884ebfb9c3c8fe1a14357856a87f539645ad231b2cd3dc34fe8dcc18ea06c565a14fe627670a42e0b1395cae06a26a11633bd5e326379cc430d6ebd1 SHA512 244746cc7c3092b6d6a063a5207a90e60b69aca18e7a7a431e9c44f73551d5b59b3ad611c8f3c731ef4568feb1eb50a635a4d385291bd03009b5ee630fe0e6cd
DIST which-module-1.0.0.tgz 2088 BLAKE2B bd811b7b604e2a2864d71ac4546ab7371d63ef76dcb02315fe6af0f22c25b2e3299f1ff4599fae01a0553a8db7ab5f97ad8b6dca13e90b553b1fedf94259245f SHA512 17af968277198bf9890eb6a699b4ee1ded6ad11e61397bff9816a2340d9308d4ff2d31eeb17d15f822678fd5d3f248b9967d94672c9d7438077c2cf2ace1fb31
DIST which-module-2.0.0.tgz 2232 BLAKE2B f577fba8e685beed06cfa0a793f015ca3c73b252e02d74ae0ed3b6a05681ae923807960160c2ff4f17251c1bf639195fbd337c1f468b53d98c8d9bec00def057 SHA512 07e7a75a19b0e9c8df542ee44bc3e3f690ab292739b7102b47269819ed3cf2c86ffc51961fed118f1ff13e0b6c59fb14b52dbb1643faf7b1380c3860ae0a1cd1
DIST which-pm-2.1.1.tgz 2126 BLAKE2B 0d6f81c83d71eb4b43b76bed7196f9755bdd28da44946949c3442dc2b7f2c74839125c462d8e7875c0295d64c70916525e5baf630df169024def1214dcf34702 SHA512 c73cf1370db031aa0259788613c209f70b8f314f84621164b231f1ad14fc90c4f94a7a1c04f460ebd60032dc95e03d767cfe7cd9103e9373fc1fd27910c748c5
Expand Down
185 changes: 185 additions & 0 deletions app-editors/vscode/files/add-distribution-dir-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -111,6 +111,7 @@
"vscode-oniguruma": "1.7.0",
"vscode-regexpp": "^3.1.0",
"vscode-textmate": "9.1.0",
+ "which": "^5.0.0",
"yauzl": "^3.0.0",
"yazl": "^2.4.3"
},
@@ -130,6 +131,7 @@
"@types/trusted-types": "^1.0.6",
"@types/vscode-notebook-renderer": "^1.72.0",
"@types/webpack": "^5.28.5",
+ "@types/which": "^3.0.4",
"@types/wicg-file-system-access": "^2020.9.6",
"@types/windows-foreground-love": "^0.3.0",
"@types/winreg": "^1.2.30",
diff --git a/src/vs/platform/native/electron-main/nativeHostMainService.ts b/src/vs/platform/native/electron-main/nativeHostMainService.ts
--- a/src/vs/platform/native/electron-main/nativeHostMainService.ts
+++ b/src/vs/platform/native/electron-main/nativeHostMainService.ts
@@ -5,0 +5,2 @@
+import { tmpdir } from "os"
+import { sync as whichSync } from "which"
@@ -609,31 +610,69 @@ export class NativeHostMainService extends Disposable implements INativeHostMain

@memoize
private get cliPath(): string {
+ const stdCliPath = (() => {
+ // Windows
+ if (isWindows) {
+ if (this.environmentMainService.isBuilt) {
+ return join(dirname(process.execPath), 'bin', `${this.productService.applicationName}.cmd`);
+ }

- // Windows
- if (isWindows) {
- if (this.environmentMainService.isBuilt) {
- return join(dirname(process.execPath), 'bin', `${this.productService.applicationName}.cmd`);
+ return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.bat');
}

- return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.bat');
- }
+ // Linux
+ if (isLinux) {
+ if (this.environmentMainService.isBuilt) {
+ return join(dirname(process.execPath), 'bin', `${this.productService.applicationName}`);
+ }

- // Linux
- if (isLinux) {
+ return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.sh');
+ }
+
+ // macOS
if (this.environmentMainService.isBuilt) {
- return join(dirname(process.execPath), 'bin', `${this.productService.applicationName}`);
+ return join(this.environmentMainService.appRoot, 'bin', 'code');
}

return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.sh');
- }
+ })()

- // macOS
- if (this.environmentMainService.isBuilt) {
- return join(this.environmentMainService.appRoot, 'bin', 'code');
- }
+ const isStdCliAccessible = (() => {
+ try {
+ fs.statSync(stdCliPath, { throwIfNoEntry: true })
+ fs.accessSync(stdCliPath, fs.constants.R_OK | fs.constants.X_OK)
+ return true
+ } catch (err) {
+ return false
+ }
+ })()
+
+ if (isStdCliAccessible)
+ return stdCliPath
+
+ const systemCliBin = whichSync(this.productService.applicationName, { all: false, nothrow: true })
+
+ if (systemCliBin)
+ return systemCliBin
+
+ const redirector = process.platform !== "win32" ? "$@" : "%*"
+
+ return this.createTmpScript("code-argv", `${process.argv.join(" ")} ${redirector}`)
+ }
+
+ private createTmpScript(name: string, command: string): string {
+ const sanitizedName = name.replace(/[^a-zA-Z0-9]/g, '_');
+ const isUnix = process.platform !== "win32"
+ const extension = isUnix ? "sh" : "cmd"
+ const tmpScript = join(tmpdir(), `${sanitizedName}-${process.pid}.${extension}`)
+ const header = isUnix ? "#!/bin/sh" : "@echo off"
+
+ fs.writeFileSync(tmpScript, `${header}\n` + `${command}\n`, {
+ flag: "a+",
+ mode: fs.constants.S_IXUSR | fs.constants.S_IRUSR | fs.constants.S_IWUSR
+ })

- return join(this.environmentMainService.appRoot, 'scripts', 'code-cli.sh');
+ return tmpScript
}

async getOSStatistics(): Promise<IOSStatistics> {
diff --git a/yarn.lock b/yarn.lock
--- a/yarn.lock
+++ b/yarn.lock
@@ -1335,1 +1300,18 @@

+"@types/which@^3.0.4":
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/@types/which/-/which-3.0.4.tgz#2c3a89be70c56a84a6957a7264639f39ae4340a1"
+ integrity sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w==
+
+isexe@^3.1.1:
+ version "3.1.1"
+ resolved "https://registry.yarnpkg.com/isexe/-/isexe-3.1.1.tgz#4a407e2bd78ddfb14bea0c27c6f7072dde775f0d"
+ integrity sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==
+
+which@^5.0.0:
+ version "5.0.0"
+ resolved "https://registry.yarnpkg.com/which/-/which-5.0.0.tgz#d93f2d93f79834d4363c7d0c23e00d07c466c8d6"
+ integrity sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==
+ dependencies:
+ isexe "^3.1.1"
+
diff --git a/src/bootstrap-node.js b/src/bootstrap-node.js
--- a/src/bootstrap-node.js
+++ b/src/bootstrap-node.js
@@ -149,7 +149,7 @@ module.exports.configurePortable = function (product) {
* @param {import('path')} path
*/
function getApplicationPath(path) {
- if (process.env['VSCODE_DEV']) {
+ if (process.env['VSCODE_DEV'] || process.env['VSCODE_DISTDIR']) {
return appRoot;
}

diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js
--- a/src/bootstrap-window.js
+++ b/src/bootstrap-window.js
@@ -66,6 +66,7 @@
removeDeveloperKeybindingsAfterLoad: false
};
const isDev = !!safeProcess.env['VSCODE_DEV'];
+ const isDistDir = isDev || !!process.env['VSCODE_DISTDIR'];
const enableDeveloperKeybindings = isDev || forceEnableDeveloperKeybindings;
/**
* @type {() => void | undefined}
@@ -178,7 +179,7 @@
// Teach the loader the location of the node modules we use in renderers
// This will enable to load these modules via <script> tags instead of
// using a fallback such as node.js require which does not exist in sandbox
- const baseNodeModulesPath = isDev ? '../node_modules' : '../node_modules.asar';
+ const baseNodeModulesPath = isDistDir ? '../node_modules' : '../node_modules.asar';
loaderConfig.paths = {
'@vscode/tree-sitter-wasm': `${baseNodeModulesPath}/@vscode/tree-sitter-wasm/wasm/tree-sitter.js`,
'vscode-textmate': `${baseNodeModulesPath}/vscode-textmate/release/main.js`,
diff --git a/src/vs/platform/environment/node/argvHelper.ts b/src/vs/platform/environment/node/argvHelper.ts
--- a/src/vs/platform/environment/node/argvHelper.ts
+++ b/src/vs/platform/environment/node/argvHelper.ts
@@ -64,7 +64,7 @@ export function parseMainProcessArgv(processArgv: string[]): NativeParsedArgs {
let [, ...args] = processArgv;

// If dev, remove the first non-option argument: it's the app location
- if (process.env['VSCODE_DEV']) {
+ if (process.env['VSCODE_DEV'] || process.env['VSCODE_DISTDIR']) {
args = stripAppPath(args) || [];
}

@@ -80,7 +80,7 @@ export function parseCLIProcessArgv(processArgv: string[]): NativeParsedArgs {
let [, , ...args] = processArgv; // remove the first non-option argument: it's always the app location

// If dev, remove the first non-option argument: it's the app location
- if (process.env['VSCODE_DEV']) {
+ if (process.env['VSCODE_DEV'] || process.env['VSCODE_DISTDIR']) {
args = stripAppPath(args) || [];
}

9 changes: 7 additions & 2 deletions app-editors/vscode/vscode-1.93.1.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ SRC_URI="!build-online? (
https://registry.yarnpkg.com/@types/webpack/-/webpack-5.28.5.tgz -> @types-webpack-5.28.5.tgz
https://registry.yarnpkg.com/@types/which/-/which-2.0.0.tgz -> @types-which-2.0.0.tgz
https://registry.yarnpkg.com/@types/which/-/which-3.0.0.tgz -> @types-which-3.0.0.tgz
https://registry.yarnpkg.com/@types/which/-/which-3.0.4.tgz -> @types-which-3.0.4.tgz
https://registry.yarnpkg.com/@types/wicg-file-system-access/-/wicg-file-system-access-2020.9.6.tgz -> @types-wicg-file-system-access-2020.9.6.tgz
https://registry.yarnpkg.com/@types/windows-foreground-love/-/windows-foreground-love-0.3.0.tgz -> @types-windows-foreground-love-0.3.0.tgz
https://registry.yarnpkg.com/@types/winreg/-/winreg-1.2.30.tgz -> @types-winreg-1.2.30.tgz
Expand Down Expand Up @@ -1956,6 +1957,7 @@ SRC_URI="!build-online? (
https://registry.yarnpkg.com/which/-/which-1.3.1.tgz
https://registry.yarnpkg.com/which/-/which-2.0.2.tgz
https://registry.yarnpkg.com/which/-/which-4.0.0.tgz
https://registry.yarnpkg.com/which/-/which-5.0.0.tgz
https://registry.yarnpkg.com/wildcard/-/wildcard-2.0.0.tgz
https://registry.yarnpkg.com/windows-foreground-love/-/windows-foreground-love-0.5.0.tgz
https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz
Expand Down Expand Up @@ -2118,6 +2120,9 @@ src_prepare() {
einfo "Add PPC target to package build scripts"
patch -p1 -i "${FILESDIR}/ppc64le/add-ppc-target.patch" || die

einfo "Add support for launching from a distribution directory"
patch -p1 -i "${FILESDIR}/add-distribution-dir-support.patch" || die

einfo "Removing vscode-ripgrep and other dependencies"
sed -i '/ripgrep"/d' package.json || die
sed -i '/telemetry-extractor"/d' package.json || die
Expand Down Expand Up @@ -2381,10 +2386,10 @@ src_install() {
sed -i "s|@ELECTRON@|code-oss|" "${WORKDIR}"/V*/bin/code-oss

echo "VSCODE_PATH=\"/usr/$(get_libdir)/vscode\"
VSCODE_DISTDIR=1
ELECTRON_PATH=\"/usr/$(get_libdir)/electron-${ELECTRON_SLOT}\"
CLI=\"\${VSCODE_PATH}/out/cli.js\"
exec /usr/bin/env ELECTRON_RUN_AS_NODE=1 \
NPM_CONFIG_NODEDIR=\"\${ELECTRON_PATH}/node/\" \
exec /usr/bin/env \
\"\${ELECTRON_PATH}/electron\" \"\${CLI}\" --app=\"\${VSCODE_PATH}\" \"\${flags[@]}\" \"\$@\"" >> "${WORKDIR}"/V*/bin/code-oss
doexe "${WORKDIR}"/VSCode-linux-${VSCODE_ARCH}/bin/code-oss
dosym "${VSCODE_HOME}/code-oss" /usr/bin/code-oss
Expand Down
6 changes: 4 additions & 2 deletions app-editors/vscode/vscode-9999.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ src_prepare() {
einfo "Add PPC target to package build scripts"
patch -p1 -i "${FILESDIR}/ppc64le/add-ppc-target.patch" || die

# einfo "Add support for launching from a distribution directory" # TODO: npm with package-lock?
# patch -p1 -i "${FILESDIR}/add-distribution-dir-support.patch" || die

einfo "Removing vscode-ripgrep and other dependencies"
sed -i '/ripgrep"/d' package.json || die
sed -i '/telemetry-extractor"/d' package.json || die
Expand Down Expand Up @@ -388,8 +391,7 @@ src_install() {
echo "VSCODE_PATH=\"/usr/$(get_libdir)/vscode\"
ELECTRON_PATH=\"/usr/$(get_libdir)/electron-${ELECTRON_SLOT}\"
CLI=\"\${VSCODE_PATH}/out/cli.js\"
exec /usr/bin/env ELECTRON_RUN_AS_NODE=1 \
NPM_CONFIG_NODEDIR=\"\${ELECTRON_PATH}/node/\" \
exec /usr/bin/env \
\"\${ELECTRON_PATH}/electron\" \"\${CLI}\" --app=\"\${VSCODE_PATH}\" \"\${flags[@]}\" \"\$@\"" >> "${WORKDIR}"/V*/bin/code-oss
doexe "${WORKDIR}"/VSCode-linux-${VSCODE_ARCH}/bin/code-oss
dosym "${VSCODE_HOME}/code-oss" /usr/bin/code-oss
Expand Down
Loading