refactor: use sysroots on linux prod pipeline (#192513)

* ci: use sysroots on linux prod pipeline to build native modules

* ci: rebuild after electron update
This commit is contained in:
Robo
2023-12-12 19:39:00 +09:00
committed by GitHub
parent 9c679f1e07
commit e7b5076dd7
19 changed files with 597 additions and 170 deletions

View File

@@ -11,15 +11,15 @@ const os_1 = require("os");
const path = require("path");
const manifests = require("../../../cgmanifest.json");
const dep_lists_1 = require("./dep-lists");
function generatePackageDeps(files, arch, sysroot) {
const dependencies = files.map(file => calculatePackageDeps(file, arch, sysroot));
function generatePackageDeps(files, arch, chromiumSysroot, vscodeSysroot) {
const dependencies = files.map(file => calculatePackageDeps(file, arch, chromiumSysroot, vscodeSysroot));
const additionalDepsSet = new Set(dep_lists_1.additionalDeps);
dependencies.push(additionalDepsSet);
return dependencies;
}
exports.generatePackageDeps = generatePackageDeps;
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/debian/calculate_package_deps.py.
function calculatePackageDeps(binaryPath, arch, sysroot) {
function calculatePackageDeps(binaryPath, arch, chromiumSysroot, vscodeSysroot) {
try {
if (!((0, fs_1.statSync)(binaryPath).mode & fs_1.constants.S_IXUSR)) {
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
@@ -42,18 +42,19 @@ function calculatePackageDeps(binaryPath, arch, sysroot) {
const cmd = [dpkgShlibdepsScriptLocation, '--ignore-weak-undefined'];
switch (arch) {
case 'amd64':
cmd.push(`-l${sysroot}/usr/lib/x86_64-linux-gnu`, `-l${sysroot}/lib/x86_64-linux-gnu`);
cmd.push(`-l${chromiumSysroot}/usr/lib/x86_64-linux-gnu`, `-l${chromiumSysroot}/lib/x86_64-linux-gnu`, `-l${vscodeSysroot}/usr/lib/x86_64-linux-gnu`, `-l${vscodeSysroot}/lib/x86_64-linux-gnu`);
break;
case 'armhf':
cmd.push(`-l${sysroot}/usr/lib/arm-linux-gnueabihf`, `-l${sysroot}/lib/arm-linux-gnueabihf`);
cmd.push(`-l${chromiumSysroot}/usr/lib/arm-linux-gnueabihf`, `-l${chromiumSysroot}/lib/arm-linux-gnueabihf`, `-l${vscodeSysroot}/usr/lib/arm-linux-gnueabihf`, `-l${vscodeSysroot}/lib/arm-linux-gnueabihf`);
break;
case 'arm64':
cmd.push(`-l${sysroot}/usr/lib/aarch64-linux-gnu`, `-l${sysroot}/lib/aarch64-linux-gnu`);
cmd.push(`-l${chromiumSysroot}/usr/lib/aarch64-linux-gnu`, `-l${chromiumSysroot}/lib/aarch64-linux-gnu`, `-l${vscodeSysroot}/usr/lib/aarch64-linux-gnu`, `-l${vscodeSysroot}/lib/aarch64-linux-gnu`);
break;
}
cmd.push(`-l${sysroot}/usr/lib`);
cmd.push(`-l${chromiumSysroot}/usr/lib`);
cmd.push(`-L${vscodeSysroot}/debian/libxkbfile1/DEBIAN/shlibs`);
cmd.push('-O', '-e', path.resolve(binaryPath));
const dpkgShlibdepsResult = (0, child_process_1.spawnSync)('perl', cmd, { cwd: sysroot });
const dpkgShlibdepsResult = (0, child_process_1.spawnSync)('perl', cmd, { cwd: chromiumSysroot });
if (dpkgShlibdepsResult.status !== 0) {
throw new Error(`dpkg-shlibdeps failed with exit code ${dpkgShlibdepsResult.status}. stderr:\n${dpkgShlibdepsResult.stderr} `);
}
@@ -78,9 +79,7 @@ function calculatePackageDeps(binaryPath, arch, sysroot) {
// TODO(deepak1556): remove this workaround in favor of computing the
// versions from build container for native modules.
const filteredDeps = depsStr.split(', ').filter(dependency => {
return !dependency.startsWith('libgcc-s1') &&
!dependency.startsWith('libgssapi-krb5-2') &&
!dependency.startsWith('libkrb5-3');
return !dependency.startsWith('libgcc-s1');
}).sort();
const requires = new Set(filteredDeps);
return requires;

View File

@@ -11,15 +11,15 @@ import * as manifests from '../../../cgmanifest.json';
import { additionalDeps } from './dep-lists';
import { DebianArchString } from './types';
export function generatePackageDeps(files: string[], arch: DebianArchString, sysroot: string): Set<string>[] {
const dependencies: Set<string>[] = files.map(file => calculatePackageDeps(file, arch, sysroot));
export function generatePackageDeps(files: string[], arch: DebianArchString, chromiumSysroot: string, vscodeSysroot: string): Set<string>[] {
const dependencies: Set<string>[] = files.map(file => calculatePackageDeps(file, arch, chromiumSysroot, vscodeSysroot));
const additionalDepsSet = new Set(additionalDeps);
dependencies.push(additionalDepsSet);
return dependencies;
}
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/debian/calculate_package_deps.py.
function calculatePackageDeps(binaryPath: string, arch: DebianArchString, sysroot: string): Set<string> {
function calculatePackageDeps(binaryPath: string, arch: DebianArchString, chromiumSysroot: string, vscodeSysroot: string): Set<string> {
try {
if (!(statSync(binaryPath).mode & constants.S_IXUSR)) {
throw new Error(`Binary ${binaryPath} needs to have an executable bit set.`);
@@ -42,22 +42,29 @@ function calculatePackageDeps(binaryPath: string, arch: DebianArchString, sysroo
const cmd = [dpkgShlibdepsScriptLocation, '--ignore-weak-undefined'];
switch (arch) {
case 'amd64':
cmd.push(`-l${sysroot}/usr/lib/x86_64-linux-gnu`,
`-l${sysroot}/lib/x86_64-linux-gnu`);
cmd.push(`-l${chromiumSysroot}/usr/lib/x86_64-linux-gnu`,
`-l${chromiumSysroot}/lib/x86_64-linux-gnu`,
`-l${vscodeSysroot}/usr/lib/x86_64-linux-gnu`,
`-l${vscodeSysroot}/lib/x86_64-linux-gnu`);
break;
case 'armhf':
cmd.push(`-l${sysroot}/usr/lib/arm-linux-gnueabihf`,
`-l${sysroot}/lib/arm-linux-gnueabihf`);
cmd.push(`-l${chromiumSysroot}/usr/lib/arm-linux-gnueabihf`,
`-l${chromiumSysroot}/lib/arm-linux-gnueabihf`,
`-l${vscodeSysroot}/usr/lib/arm-linux-gnueabihf`,
`-l${vscodeSysroot}/lib/arm-linux-gnueabihf`);
break;
case 'arm64':
cmd.push(`-l${sysroot}/usr/lib/aarch64-linux-gnu`,
`-l${sysroot}/lib/aarch64-linux-gnu`);
cmd.push(`-l${chromiumSysroot}/usr/lib/aarch64-linux-gnu`,
`-l${chromiumSysroot}/lib/aarch64-linux-gnu`,
`-l${vscodeSysroot}/usr/lib/aarch64-linux-gnu`,
`-l${vscodeSysroot}/lib/aarch64-linux-gnu`);
break;
}
cmd.push(`-l${sysroot}/usr/lib`);
cmd.push(`-l${chromiumSysroot}/usr/lib`);
cmd.push(`-L${vscodeSysroot}/debian/libxkbfile1/DEBIAN/shlibs`);
cmd.push('-O', '-e', path.resolve(binaryPath));
const dpkgShlibdepsResult = spawnSync('perl', cmd, { cwd: sysroot });
const dpkgShlibdepsResult = spawnSync('perl', cmd, { cwd: chromiumSysroot });
if (dpkgShlibdepsResult.status !== 0) {
throw new Error(`dpkg-shlibdeps failed with exit code ${dpkgShlibdepsResult.status}. stderr:\n${dpkgShlibdepsResult.stderr} `);
}
@@ -83,9 +90,7 @@ function calculatePackageDeps(binaryPath: string, arch: DebianArchString, sysroo
// TODO(deepak1556): remove this workaround in favor of computing the
// versions from build container for native modules.
const filteredDeps = depsStr.split(', ').filter(dependency => {
return !dependency.startsWith('libgcc-s1') &&
!dependency.startsWith('libgssapi-krb5-2') &&
!dependency.startsWith('libkrb5-3');
return !dependency.startsWith('libgcc-s1');
}).sort();
const requires = new Set(filteredDeps);
return requires;

View File

@@ -13,8 +13,6 @@ exports.additionalDeps = [
'libnss3 (>= 3.26)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3', // For Breakpad crash reports.
'xdg-utils (>= 1.0.2)', // OS integration
'libgssapi-krb5-2',
'libkrb5-3',
];
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/debian/manual_recommends
// Dependencies that we can only recommend
@@ -33,6 +31,7 @@ exports.referenceGeneratedDepsByArch = {
'libc6 (>= 2.16)',
'libc6 (>= 2.17)',
'libc6 (>= 2.2.5)',
'libc6 (>= 2.28)',
'libcairo2 (>= 1.6.0)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3',
'libdbus-1-3 (>= 1.9.14)',
@@ -40,10 +39,10 @@ exports.referenceGeneratedDepsByArch = {
'libexpat1 (>= 2.1~beta3)',
'libgbm1 (>= 17.1.0~rc2)',
'libglib2.0-0 (>= 2.37.3)',
'libgssapi-krb5-2',
'libgssapi-krb5-2 (>= 1.17)',
'libgtk-3-0 (>= 3.9.10)',
'libgtk-3-0 (>= 3.9.10) | libgtk-4-1',
'libkrb5-3',
'libkrb5-3 (>= 1.6.dfsg.2)',
'libnspr4 (>= 2:4.9-2~)',
'libnss3 (>= 2:3.30)',
'libnss3 (>= 3.26)',
@@ -56,9 +55,10 @@ exports.referenceGeneratedDepsByArch = {
'libxext6',
'libxfixes3',
'libxkbcommon0 (>= 0.5.0)',
'libxkbfile1',
'libxkbfile1 (>= 1:1.1.0)',
'libxrandr2',
'xdg-utils (>= 1.0.2)'
'xdg-utils (>= 1.0.2)',
'zlib1g (>= 1:1.2.3.4)'
],
'armhf': [
'ca-certificates',
@@ -66,11 +66,10 @@ exports.referenceGeneratedDepsByArch = {
'libatk-bridge2.0-0 (>= 2.5.3)',
'libatk1.0-0 (>= 2.2.0)',
'libatspi2.0-0 (>= 2.9.90)',
'libc6 (>= 2.15)',
'libc6 (>= 2.16)',
'libc6 (>= 2.17)',
'libc6 (>= 2.28)',
'libc6 (>= 2.4)',
'libc6 (>= 2.8)',
'libc6 (>= 2.9)',
'libcairo2 (>= 1.6.0)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3',
@@ -79,14 +78,15 @@ exports.referenceGeneratedDepsByArch = {
'libexpat1 (>= 2.1~beta3)',
'libgbm1 (>= 17.1.0~rc2)',
'libglib2.0-0 (>= 2.37.3)',
'libgssapi-krb5-2',
'libgssapi-krb5-2 (>= 1.17)',
'libgtk-3-0 (>= 3.9.10)',
'libgtk-3-0 (>= 3.9.10) | libgtk-4-1',
'libkrb5-3',
'libkrb5-3 (>= 1.6.dfsg.2)',
'libnspr4 (>= 2:4.9-2~)',
'libnss3 (>= 2:3.30)',
'libnss3 (>= 3.26)',
'libpango-1.0-0 (>= 1.14.0)',
'libstdc++6 (>= 4.1.1)',
'libstdc++6 (>= 5)',
'libstdc++6 (>= 5.2)',
'libstdc++6 (>= 6)',
@@ -98,7 +98,7 @@ exports.referenceGeneratedDepsByArch = {
'libxext6',
'libxfixes3',
'libxkbcommon0 (>= 0.5.0)',
'libxkbfile1',
'libxkbfile1 (>= 1:1.1.0)',
'libxrandr2',
'xdg-utils (>= 1.0.2)'
],
@@ -109,6 +109,7 @@ exports.referenceGeneratedDepsByArch = {
'libatk1.0-0 (>= 2.2.0)',
'libatspi2.0-0 (>= 2.9.90)',
'libc6 (>= 2.17)',
'libc6 (>= 2.28)',
'libcairo2 (>= 1.6.0)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3',
'libdbus-1-3 (>= 1.9.14)',
@@ -116,14 +117,15 @@ exports.referenceGeneratedDepsByArch = {
'libexpat1 (>= 2.1~beta3)',
'libgbm1 (>= 17.1.0~rc2)',
'libglib2.0-0 (>= 2.37.3)',
'libgssapi-krb5-2',
'libgssapi-krb5-2 (>= 1.17)',
'libgtk-3-0 (>= 3.9.10)',
'libgtk-3-0 (>= 3.9.10) | libgtk-4-1',
'libkrb5-3',
'libkrb5-3 (>= 1.6.dfsg.2)',
'libnspr4 (>= 2:4.9-2~)',
'libnss3 (>= 2:3.30)',
'libnss3 (>= 3.26)',
'libpango-1.0-0 (>= 1.14.0)',
'libstdc++6 (>= 4.1.1)',
'libstdc++6 (>= 5)',
'libstdc++6 (>= 5.2)',
'libstdc++6 (>= 6)',
@@ -135,7 +137,7 @@ exports.referenceGeneratedDepsByArch = {
'libxext6',
'libxfixes3',
'libxkbcommon0 (>= 0.5.0)',
'libxkbfile1',
'libxkbfile1 (>= 1:1.1.0)',
'libxrandr2',
'xdg-utils (>= 1.0.2)'
]

View File

@@ -11,8 +11,6 @@ export const additionalDeps = [
'libnss3 (>= 3.26)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3', // For Breakpad crash reports.
'xdg-utils (>= 1.0.2)', // OS integration
'libgssapi-krb5-2',
'libkrb5-3',
];
// Based on https://source.chromium.org/chromium/chromium/src/+/main:chrome/installer/linux/debian/manual_recommends
@@ -33,6 +31,7 @@ export const referenceGeneratedDepsByArch = {
'libc6 (>= 2.16)',
'libc6 (>= 2.17)',
'libc6 (>= 2.2.5)',
'libc6 (>= 2.28)',
'libcairo2 (>= 1.6.0)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3',
'libdbus-1-3 (>= 1.9.14)',
@@ -40,10 +39,10 @@ export const referenceGeneratedDepsByArch = {
'libexpat1 (>= 2.1~beta3)',
'libgbm1 (>= 17.1.0~rc2)',
'libglib2.0-0 (>= 2.37.3)',
'libgssapi-krb5-2',
'libgssapi-krb5-2 (>= 1.17)',
'libgtk-3-0 (>= 3.9.10)',
'libgtk-3-0 (>= 3.9.10) | libgtk-4-1',
'libkrb5-3',
'libkrb5-3 (>= 1.6.dfsg.2)',
'libnspr4 (>= 2:4.9-2~)',
'libnss3 (>= 2:3.30)',
'libnss3 (>= 3.26)',
@@ -56,9 +55,10 @@ export const referenceGeneratedDepsByArch = {
'libxext6',
'libxfixes3',
'libxkbcommon0 (>= 0.5.0)',
'libxkbfile1',
'libxkbfile1 (>= 1:1.1.0)',
'libxrandr2',
'xdg-utils (>= 1.0.2)'
'xdg-utils (>= 1.0.2)',
'zlib1g (>= 1:1.2.3.4)'
],
'armhf': [
'ca-certificates',
@@ -66,11 +66,10 @@ export const referenceGeneratedDepsByArch = {
'libatk-bridge2.0-0 (>= 2.5.3)',
'libatk1.0-0 (>= 2.2.0)',
'libatspi2.0-0 (>= 2.9.90)',
'libc6 (>= 2.15)',
'libc6 (>= 2.16)',
'libc6 (>= 2.17)',
'libc6 (>= 2.28)',
'libc6 (>= 2.4)',
'libc6 (>= 2.8)',
'libc6 (>= 2.9)',
'libcairo2 (>= 1.6.0)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3',
@@ -79,14 +78,15 @@ export const referenceGeneratedDepsByArch = {
'libexpat1 (>= 2.1~beta3)',
'libgbm1 (>= 17.1.0~rc2)',
'libglib2.0-0 (>= 2.37.3)',
'libgssapi-krb5-2',
'libgssapi-krb5-2 (>= 1.17)',
'libgtk-3-0 (>= 3.9.10)',
'libgtk-3-0 (>= 3.9.10) | libgtk-4-1',
'libkrb5-3',
'libkrb5-3 (>= 1.6.dfsg.2)',
'libnspr4 (>= 2:4.9-2~)',
'libnss3 (>= 2:3.30)',
'libnss3 (>= 3.26)',
'libpango-1.0-0 (>= 1.14.0)',
'libstdc++6 (>= 4.1.1)',
'libstdc++6 (>= 5)',
'libstdc++6 (>= 5.2)',
'libstdc++6 (>= 6)',
@@ -98,7 +98,7 @@ export const referenceGeneratedDepsByArch = {
'libxext6',
'libxfixes3',
'libxkbcommon0 (>= 0.5.0)',
'libxkbfile1',
'libxkbfile1 (>= 1:1.1.0)',
'libxrandr2',
'xdg-utils (>= 1.0.2)'
],
@@ -109,6 +109,7 @@ export const referenceGeneratedDepsByArch = {
'libatk1.0-0 (>= 2.2.0)',
'libatspi2.0-0 (>= 2.9.90)',
'libc6 (>= 2.17)',
'libc6 (>= 2.28)',
'libcairo2 (>= 1.6.0)',
'libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3',
'libdbus-1-3 (>= 1.9.14)',
@@ -116,14 +117,15 @@ export const referenceGeneratedDepsByArch = {
'libexpat1 (>= 2.1~beta3)',
'libgbm1 (>= 17.1.0~rc2)',
'libglib2.0-0 (>= 2.37.3)',
'libgssapi-krb5-2',
'libgssapi-krb5-2 (>= 1.17)',
'libgtk-3-0 (>= 3.9.10)',
'libgtk-3-0 (>= 3.9.10) | libgtk-4-1',
'libkrb5-3',
'libkrb5-3 (>= 1.6.dfsg.2)',
'libnspr4 (>= 2:4.9-2~)',
'libnss3 (>= 2:3.30)',
'libnss3 (>= 3.26)',
'libpango-1.0-0 (>= 1.14.0)',
'libstdc++6 (>= 4.1.1)',
'libstdc++6 (>= 5)',
'libstdc++6 (>= 5.2)',
'libstdc++6 (>= 6)',
@@ -135,7 +137,7 @@ export const referenceGeneratedDepsByArch = {
'libxext6',
'libxfixes3',
'libxkbcommon0 (>= 0.5.0)',
'libxkbfile1',
'libxkbfile1 (>= 1:1.1.0)',
'libxrandr2',
'xdg-utils (>= 1.0.2)'
]

View File

@@ -4,17 +4,35 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSysroot = void 0;
exports.getChromiumSysroot = exports.getVSCodeSysroot = void 0;
const child_process_1 = require("child_process");
const crypto_1 = require("crypto");
const os_1 = require("os");
const fs = require("fs");
const https = require("https");
const path = require("path");
const util = require("../../lib/util");
const crypto_1 = require("crypto");
const ansiColors = require("ansi-colors");
// Based on https://source.chromium.org/chromium/chromium/src/+/main:build/linux/sysroot_scripts/install-sysroot.py.
const URL_PREFIX = 'https://msftelectron.blob.core.windows.net';
const URL_PATH = 'sysroots/toolchain';
const REPO_ROOT = path.dirname(path.dirname(path.dirname(__dirname)));
const ghApiHeaders = {
Accept: 'application/vnd.github.v3+json',
'User-Agent': 'VSCode Build',
};
if (process.env.GITHUB_TOKEN) {
ghApiHeaders.Authorization = 'Basic ' + Buffer.from(process.env.GITHUB_TOKEN).toString('base64');
}
const ghDownloadHeaders = {
...ghApiHeaders,
Accept: 'application/octet-stream',
};
function getElectronVersion() {
const yarnrc = fs.readFileSync(path.join(REPO_ROOT, '.yarnrc'), 'utf8');
const electronVersion = /^target "(.*)"$/m.exec(yarnrc)[1];
const msBuildId = /^ms_build_id "(.*)"$/m.exec(yarnrc)[1];
return { electronVersion, msBuildId };
}
function getSha(filename) {
const hash = (0, crypto_1.createHash)('sha1');
// Read file 1 MB at a time
@@ -29,8 +47,115 @@ function getSha(filename) {
hash.update(buffer.slice(0, bytesRead));
return hash.digest('hex');
}
async function getSysroot(arch) {
const sysrootJSONUrl = `https://raw.githubusercontent.com/electron/electron/v${util.getElectronVersion().electronVersion}/script/sysroots.json`;
function getVSCodeSysrootChecksum(expectedName) {
const checksums = fs.readFileSync(path.join(REPO_ROOT, 'build', 'checksums', 'vscode-sysroot.txt'), 'utf8');
for (const line of checksums.split('\n')) {
const [checksum, name] = line.split(/\s+/);
if (name === expectedName) {
return checksum;
}
}
return undefined;
}
/*
* Do not use the fetch implementation from build/lib/fetch as it relies on vinyl streams
* and vinyl-fs breaks the symlinks in the compiler toolchain sysroot. We use the native
* tar implementation for that reason.
*/
async function fetchUrl(options, retries = 10, retryDelay = 1000) {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 30 * 1000);
const version = '20231122-245579';
try {
const response = await fetch(`https://api.github.com/repos/Microsoft/vscode-linux-build-agent/releases/tags/v${version}`, {
headers: ghApiHeaders,
signal: controller.signal /* Typings issue with lib.dom.d.ts */
});
if (response.ok && (response.status >= 200 && response.status < 300)) {
console.log(`Fetch completed: Status ${response.status}.`);
const contents = Buffer.from(await response.arrayBuffer());
const asset = JSON.parse(contents.toString()).assets.find((a) => a.name === options.assetName);
if (!asset) {
throw new Error(`Could not find asset in release of Microsoft/vscode-linux-build-agent @ ${version}`);
}
console.log(`Found asset ${options.assetName} @ ${asset.url}.`);
const assetResponse = await fetch(asset.url, {
headers: ghDownloadHeaders
});
if (assetResponse.ok && (assetResponse.status >= 200 && assetResponse.status < 300)) {
const assetContents = Buffer.from(await assetResponse.arrayBuffer());
console.log(`Fetched response body buffer: ${ansiColors.magenta(`${assetContents.byteLength} bytes`)}`);
if (options.checksumSha256) {
const actualSHA256Checksum = (0, crypto_1.createHash)('sha256').update(assetContents).digest('hex');
if (actualSHA256Checksum !== options.checksumSha256) {
throw new Error(`Checksum mismatch for ${ansiColors.cyan(asset.url)} (expected ${options.checksumSha256}, actual ${actualSHA256Checksum}))`);
}
}
console.log(`Verified SHA256 checksums match for ${ansiColors.cyan(asset.url)}`);
const tarCommand = `tar -xz -C ${options.dest}`;
(0, child_process_1.execSync)(tarCommand, { input: assetContents });
console.log(`Fetch complete!`);
return;
}
throw new Error(`Request ${ansiColors.magenta(asset.url)} failed with status code: ${assetResponse.status}`);
}
throw new Error(`Request ${ansiColors.magenta('https://api.github.com')} failed with status code: ${response.status}`);
}
finally {
clearTimeout(timeout);
}
}
catch (e) {
if (retries > 0) {
console.log(`Fetching failed: ${e}`);
await new Promise(resolve => setTimeout(resolve, retryDelay));
return fetchUrl(options, retries - 1, retryDelay);
}
throw e;
}
}
async function getVSCodeSysroot(arch) {
let expectedName;
let triple;
switch (arch) {
case 'amd64':
expectedName = `x86_64-linux-gnu.tar.gz`;
triple = 'x86_64-linux-gnu';
break;
case 'arm64':
expectedName = `aarch64-linux-gnu.tar.gz`;
triple = 'aarch64-linux-gnu';
break;
case 'armhf':
expectedName = `arm-rpi-linux-gnueabihf.tar.gz`;
triple = 'arm-rpi-linux-gnueabihf';
break;
}
const checksumSha256 = getVSCodeSysrootChecksum(expectedName);
if (!checksumSha256) {
throw new Error(`Could not find checksum for ${expectedName}`);
}
const sysroot = process.env['VSCODE_SYSROOT_DIR'] ?? path.join((0, os_1.tmpdir)(), `vscode-${arch}-sysroot`);
const stamp = path.join(sysroot, '.stamp');
const result = `${sysroot}/${triple}/${triple}/sysroot`;
if (fs.existsSync(stamp) && fs.readFileSync(stamp).toString() === expectedName) {
return result;
}
console.log(`Installing ${arch} root image: ${sysroot}`);
fs.rmSync(sysroot, { recursive: true, force: true });
fs.mkdirSync(sysroot);
await fetchUrl({
checksumSha256,
assetName: expectedName,
dest: sysroot
});
fs.writeFileSync(stamp, expectedName);
return result;
}
exports.getVSCodeSysroot = getVSCodeSysroot;
async function getChromiumSysroot(arch) {
const sysrootJSONUrl = `https://raw.githubusercontent.com/electron/electron/v${getElectronVersion().electronVersion}/script/sysroots.json`;
const sysrootDictLocation = `${(0, os_1.tmpdir)()}/sysroots.json`;
const result = (0, child_process_1.spawnSync)('curl', [sysrootJSONUrl, '-o', sysrootDictLocation]);
if (result.status !== 0) {
@@ -86,5 +211,5 @@ async function getSysroot(arch) {
fs.writeFileSync(stamp, url);
return sysroot;
}
exports.getSysroot = getSysroot;
exports.getChromiumSysroot = getChromiumSysroot;
//# sourceMappingURL=install-sysroot.js.map

View File

@@ -3,18 +3,46 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { spawnSync } from 'child_process';
import { createHash } from 'crypto';
import { spawnSync, execSync } from 'child_process';
import { tmpdir } from 'os';
import * as fs from 'fs';
import * as https from 'https';
import * as path from 'path';
import { createHash } from 'crypto';
import { DebianArchString } from './types';
import * as util from '../../lib/util';
import * as ansiColors from 'ansi-colors';
// Based on https://source.chromium.org/chromium/chromium/src/+/main:build/linux/sysroot_scripts/install-sysroot.py.
const URL_PREFIX = 'https://msftelectron.blob.core.windows.net';
const URL_PATH = 'sysroots/toolchain';
const REPO_ROOT = path.dirname(path.dirname(path.dirname(__dirname)));
const ghApiHeaders: Record<string, string> = {
Accept: 'application/vnd.github.v3+json',
'User-Agent': 'VSCode Build',
};
if (process.env.GITHUB_TOKEN) {
ghApiHeaders.Authorization = 'Basic ' + Buffer.from(process.env.GITHUB_TOKEN).toString('base64');
}
const ghDownloadHeaders = {
...ghApiHeaders,
Accept: 'application/octet-stream',
};
interface IFetchOptions {
assetName: string;
checksumSha256?: string;
dest: string;
}
function getElectronVersion(): Record<string, string> {
const yarnrc = fs.readFileSync(path.join(REPO_ROOT, '.yarnrc'), 'utf8');
const electronVersion = /^target "(.*)"$/m.exec(yarnrc)![1];
const msBuildId = /^ms_build_id "(.*)"$/m.exec(yarnrc)![1];
return { electronVersion, msBuildId };
}
function getSha(filename: fs.PathLike): string {
const hash = createHash('sha1');
@@ -31,14 +59,121 @@ function getSha(filename: fs.PathLike): string {
return hash.digest('hex');
}
function getVSCodeSysrootChecksum(expectedName: string) {
const checksums = fs.readFileSync(path.join(REPO_ROOT, 'build', 'checksums', 'vscode-sysroot.txt'), 'utf8');
for (const line of checksums.split('\n')) {
const [checksum, name] = line.split(/\s+/);
if (name === expectedName) {
return checksum;
}
}
return undefined;
}
/*
* Do not use the fetch implementation from build/lib/fetch as it relies on vinyl streams
* and vinyl-fs breaks the symlinks in the compiler toolchain sysroot. We use the native
* tar implementation for that reason.
*/
async function fetchUrl(options: IFetchOptions, retries = 10, retryDelay = 1000): Promise<undefined> {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 30 * 1000);
const version = '20231122-245579';
try {
const response = await fetch(`https://api.github.com/repos/Microsoft/vscode-linux-build-agent/releases/tags/v${version}`, {
headers: ghApiHeaders,
signal: controller.signal as any /* Typings issue with lib.dom.d.ts */
});
if (response.ok && (response.status >= 200 && response.status < 300)) {
console.log(`Fetch completed: Status ${response.status}.`);
const contents = Buffer.from(await response.arrayBuffer());
const asset = JSON.parse(contents.toString()).assets.find((a: { name: string }) => a.name === options.assetName);
if (!asset) {
throw new Error(`Could not find asset in release of Microsoft/vscode-linux-build-agent @ ${version}`);
}
console.log(`Found asset ${options.assetName} @ ${asset.url}.`);
const assetResponse = await fetch(asset.url, {
headers: ghDownloadHeaders
});
if (assetResponse.ok && (assetResponse.status >= 200 && assetResponse.status < 300)) {
const assetContents = Buffer.from(await assetResponse.arrayBuffer());
console.log(`Fetched response body buffer: ${ansiColors.magenta(`${(assetContents as Buffer).byteLength} bytes`)}`);
if (options.checksumSha256) {
const actualSHA256Checksum = createHash('sha256').update(assetContents).digest('hex');
if (actualSHA256Checksum !== options.checksumSha256) {
throw new Error(`Checksum mismatch for ${ansiColors.cyan(asset.url)} (expected ${options.checksumSha256}, actual ${actualSHA256Checksum}))`);
}
}
console.log(`Verified SHA256 checksums match for ${ansiColors.cyan(asset.url)}`);
const tarCommand = `tar -xz -C ${options.dest}`;
execSync(tarCommand, { input: assetContents });
console.log(`Fetch complete!`);
return;
}
throw new Error(`Request ${ansiColors.magenta(asset.url)} failed with status code: ${assetResponse.status}`);
}
throw new Error(`Request ${ansiColors.magenta('https://api.github.com')} failed with status code: ${response.status}`);
} finally {
clearTimeout(timeout);
}
} catch (e) {
if (retries > 0) {
console.log(`Fetching failed: ${e}`);
await new Promise(resolve => setTimeout(resolve, retryDelay));
return fetchUrl(options, retries - 1, retryDelay);
}
throw e;
}
}
type SysrootDictEntry = {
Sha1Sum: string;
SysrootDir: string;
Tarball: string;
};
export async function getSysroot(arch: DebianArchString): Promise<string> {
const sysrootJSONUrl = `https://raw.githubusercontent.com/electron/electron/v${util.getElectronVersion().electronVersion}/script/sysroots.json`;
export async function getVSCodeSysroot(arch: DebianArchString): Promise<string> {
let expectedName: string;
let triple: string;
switch (arch) {
case 'amd64':
expectedName = `x86_64-linux-gnu.tar.gz`;
triple = 'x86_64-linux-gnu';
break;
case 'arm64':
expectedName = `aarch64-linux-gnu.tar.gz`;
triple = 'aarch64-linux-gnu';
break;
case 'armhf':
expectedName = `arm-rpi-linux-gnueabihf.tar.gz`;
triple = 'arm-rpi-linux-gnueabihf';
break;
}
const checksumSha256 = getVSCodeSysrootChecksum(expectedName);
if (!checksumSha256) {
throw new Error(`Could not find checksum for ${expectedName}`);
}
const sysroot = process.env['VSCODE_SYSROOT_DIR'] ?? path.join(tmpdir(), `vscode-${arch}-sysroot`);
const stamp = path.join(sysroot, '.stamp');
const result = `${sysroot}/${triple}/${triple}/sysroot`;
if (fs.existsSync(stamp) && fs.readFileSync(stamp).toString() === expectedName) {
return result;
}
console.log(`Installing ${arch} root image: ${sysroot}`);
fs.rmSync(sysroot, { recursive: true, force: true });
fs.mkdirSync(sysroot);
await fetchUrl({
checksumSha256,
assetName: expectedName,
dest: sysroot
});
fs.writeFileSync(stamp, expectedName);
return result;
}
export async function getChromiumSysroot(arch: DebianArchString): Promise<string> {
const sysrootJSONUrl = `https://raw.githubusercontent.com/electron/electron/v${getElectronVersion().electronVersion}/script/sysroots.json`;
const sysrootDictLocation = `${tmpdir()}/sysroots.json`;
const result = spawnSync('curl', [sysrootJSONUrl, '-o', sysrootDictLocation]);
if (result.status !== 0) {