Skip to content

Commit

Permalink
Proper support for platform specific extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek committed May 23, 2024
1 parent 5bb239f commit bc9c943
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 22 deletions.
6 changes: 2 additions & 4 deletions extensions-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
36 changes: 23 additions & 13 deletions extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion publish-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ openGalleryApi.post = (url, data, additionalHeaders) =>
{ cwd: path.join(context.repo, extension.location ?? "."), quiet: false },
);
}
} catch { }
} catch {}

if (extension.custom) {
try {
Expand Down
16 changes: 13 additions & 3 deletions publish-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,21 @@ 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,
["publish-extension.js", JSON.stringify({ extension, context, extensions })],
{
stdio: ["ignore", "inherit", "inherit"],
cwd: process.cwd(),
env: process.env,
env,
},
);
p.on("error", reject);
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -124,6 +130,8 @@ export interface PublishContext {
file?: string;
repo?: string;
ref?: string;

environmentVariables?: { [key: string]: string };
}

interface IRawGalleryExtensionProperty {
Expand Down

0 comments on commit bc9c943

Please sign in to comment.