From bc9c9437af959e9ae1ebc784e053aec9bf54a2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 23 May 2024 17:07:32 +0000 Subject: [PATCH] Proper support for platform specific extensions --- extensions-schema.json | 6 ++---- extensions.json | 36 +++++++++++++++++++++++------------- publish-extension.js | 2 +- publish-extensions.js | 16 +++++++++++++--- types.d.ts | 10 +++++++++- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/extensions-schema.json b/extensions-schema.json index df03fee26..79de2fe17 100644 --- a/extensions-schema.json +++ b/extensions-schema.json @@ -41,10 +41,8 @@ "description": "A property to set a different lookup ID when querying the Microsoft Marketplace. Please do not ever use if not absolutely necessary." }, "target": { - "type": "array", - "description": "A list of platforms to target. If unspecified, a universal extension will be published in case of building from source and if the vsix is resolved from GitHub Releases, all of the attached platform-specific assets will be published.", - "uniqueItems": true, - "minItems": 1 + "type": "object", + "description": "An object containing the ids of platforms to target while publishing. If unspecified, a universal extension will be published in case of building from source and if the vsix is resolved from GitHub Releases, all of the attached platform-specific assets will be published. The value of the key should be either `true` or an object specifying environment variables to be applied while packaging inside of `env`." } }, "required": ["repository"], diff --git a/extensions.json b/extensions.json index cfc78f70e..55b942262 100644 --- a/extensions.json +++ b/extensions.json @@ -805,19 +805,29 @@ }, "ms-python.debugpy": { "repository": "https://github.com/microsoft/vscode-python-debugger", - "custom": [ - "python -m pip install -U pip pipx wheel", - "npm ci --prefer-offline", - "VSCETARGET=linux-x64 python -m pipx run nox --session install_bundled_libs", - "vsce package --target=linux-x64", - "VSCETARGET=linux-arm64 python -m pipx run nox --session install_bundled_libs", - "vsce package --target=linux-arm64", - "VSCETARGET=darwin-arm64 python -m pipx run nox --session install_bundled_libs", - "vsce package --target=darwin-arm64", - "VSCETARGET=win32-x64 python -m pipx run nox --session install_bundled_libs", - "vsce package --target=win32-x64" - ], - "target": ["linux-x64", "linux-arm64", "darwin-arm64", "win32-x64"] + "prepublish": "python -m pip install -U pip pipx wheel && npm ci --prefer-offline && python -m pipx run nox --session install_bundled_libs", + "target": { + "linux-x64": { + "env": { + "VSCETARGET": "linux-x64" + } + }, + "linux-arm64": { + "env": { + "VSCETARGET": "linux-arm64" + } + }, + "darwin-arm64": { + "env": { + "VSCETARGET": "darwin-arm64" + } + }, + "win32-x64": { + "env": { + "VSCETARGET": "win32-x64" + } + } + } }, "ms-python.flake8": { "repository": "https://github.com/microsoft/vscode-flake8", diff --git a/publish-extension.js b/publish-extension.js index 94daab29b..3dbe5bcb9 100644 --- a/publish-extension.js +++ b/publish-extension.js @@ -82,7 +82,7 @@ openGalleryApi.post = (url, data, additionalHeaders) => { cwd: path.join(context.repo, extension.location ?? "."), quiet: false }, ); } - } catch { } + } catch {} if (extension.custom) { try { diff --git a/publish-extensions.js b/publish-extensions.js index 6a4d0b37b..1169c3c01 100644 --- a/publish-extensions.js +++ b/publish-extensions.js @@ -291,6 +291,13 @@ const ensureBuildPrerequisites = async () => { let timeout; const publishVersion = async (extension, context) => { + const env = { + ...process.env, + ...context.environmentVariables, + }; + + console.debug(`Publishing ${extension.id} for ${context.target || "universal"}...`); + await new Promise((resolve, reject) => { const p = cp.spawn( process.execPath, @@ -298,7 +305,7 @@ const ensureBuildPrerequisites = async () => { { stdio: ["ignore", "inherit", "inherit"], cwd: process.cwd(), - env: process.env, + env, }, ); p.on("error", reject); @@ -326,7 +333,7 @@ const ensureBuildPrerequisites = async () => { if (context.files) { // Publish all targets of extension from GitHub Release assets for (const [target, file] of Object.entries(context.files)) { - if (!extension.target || extension.target.includes(target)) { + if (!extension.target || Object.keys(extension.target).includes(target)) { context.file = file; context.target = target; await publishVersion(extension, context); @@ -336,8 +343,11 @@ const ensureBuildPrerequisites = async () => { } } else if (extension.target) { // Publish all specified targets of extension from sources - for (const target of extension.target) { + for (const [target, targetData] of Object.entries(extension.target)) { context.target = target; + if (targetData !== true) { + context.environmentVariables = targetData.env; + } await publishVersion(extension, context); } } else { diff --git a/types.d.ts b/types.d.ts index b4c13755b..e3a6bd3c6 100644 --- a/types.d.ts +++ b/types.d.ts @@ -88,7 +88,13 @@ export interface Extension { extensionFile?: string; custom?: string[]; timeout?: number; - target?: string[]; + target?: { + [key: string]: + | true + | { + env: { [key: string]: string }; + }; + }; msMarketplaceIdOverride?: string; pythonVersion?: string; } @@ -124,6 +130,8 @@ export interface PublishContext { file?: string; repo?: string; ref?: string; + + environmentVariables?: { [key: string]: string }; } interface IRawGalleryExtensionProperty {