2016-04-12 02:20:18 +00:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
2022-05-12 07:16:03 +00:00
|
|
|
|
2023-04-02 07:35:39 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const os = require('os');
|
2016-04-21 14:01:37 +00:00
|
|
|
const cp = require('child_process');
|
2020-12-23 10:28:32 +00:00
|
|
|
const { dirs } = require('./dirs');
|
2022-05-12 07:16:03 +00:00
|
|
|
const { setupBuildYarnrc } = require('./setupBuildYarnrc');
|
2017-11-13 21:36:57 +00:00
|
|
|
const yarn = process.platform === 'win32' ? 'yarn.cmd' : 'yarn';
|
2023-04-02 07:35:39 +00:00
|
|
|
const root = path.dirname(path.dirname(__dirname));
|
|
|
|
|
|
|
|
function run(command, args, opts) {
|
|
|
|
console.log('$ ' + command + ' ' + args.join(' '));
|
|
|
|
|
|
|
|
const result = cp.spawnSync(command, args, opts);
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
console.error(`ERR Failed to spawn process: ${result.error}`);
|
|
|
|
process.exit(1);
|
|
|
|
} else if (result.status !== 0) {
|
|
|
|
console.error(`ERR Process exited with code: ${result.status}`);
|
|
|
|
process.exit(result.status);
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 02:20:18 +00:00
|
|
|
|
2018-10-16 00:24:11 +00:00
|
|
|
/**
|
2023-04-02 07:35:39 +00:00
|
|
|
* @param {string} dir
|
2018-10-16 00:24:11 +00:00
|
|
|
* @param {*} [opts]
|
|
|
|
*/
|
2023-04-02 07:35:39 +00:00
|
|
|
function yarnInstall(dir, opts) {
|
|
|
|
opts = {
|
|
|
|
env: { ...process.env },
|
|
|
|
...(opts ?? {}),
|
|
|
|
cwd: dir,
|
|
|
|
stdio: 'inherit',
|
|
|
|
};
|
2017-06-26 13:15:54 +00:00
|
|
|
|
2019-03-19 15:52:13 +00:00
|
|
|
const raw = process.env['npm_config_argv'] || '{}';
|
|
|
|
const argv = JSON.parse(raw);
|
|
|
|
const original = argv.original || [];
|
2022-03-18 12:54:01 +00:00
|
|
|
const args = original.filter(arg => arg === '--ignore-optional' || arg === '--frozen-lockfile' || arg === '--check-files');
|
2023-04-02 07:35:39 +00:00
|
|
|
|
2020-12-18 09:14:08 +00:00
|
|
|
if (opts.ignoreEngines) {
|
|
|
|
args.push('--ignore-engines');
|
|
|
|
delete opts.ignoreEngines;
|
|
|
|
}
|
2019-03-19 15:52:13 +00:00
|
|
|
|
2023-04-02 07:35:39 +00:00
|
|
|
if (process.env['VSCODE_REMOTE_DEPENDENCIES_CONTAINER_NAME'] && /^(.build\/distro\/npm\/)?remote$/.test(dir)) {
|
|
|
|
const userinfo = os.userInfo();
|
|
|
|
console.log(`Installing dependencies in ${dir} inside container ${process.env['VSCODE_REMOTE_DEPENDENCIES_CONTAINER_NAME']}...`);
|
2016-11-23 15:09:58 +00:00
|
|
|
|
2023-04-02 07:35:39 +00:00
|
|
|
opts.cwd = root;
|
2024-02-06 10:25:58 +00:00
|
|
|
if (process.env['npm_config_arch'] === 'arm64' || process.env['npm_config_arch'] === 'arm') {
|
2023-07-21 04:02:56 +00:00
|
|
|
run('sudo', ['docker', 'run', '--rm', '--privileged', 'multiarch/qemu-user-static', '--reset', '-p', 'yes'], opts);
|
|
|
|
}
|
2024-02-06 10:25:58 +00:00
|
|
|
if (process.env['npm_config_arch'] === 'arm') {
|
|
|
|
run('sudo', ['docker', 'run', '-e', 'GITHUB_TOKEN', '-e', 'npm_config_arch', '-v', `${process.env['VSCODE_HOST_MOUNT']}:/home/builduser`, '-v', `${process.env['VSCODE_HOST_MOUNT']}/.build/.netrc:/home/builduser/.netrc`, process.env['VSCODE_REMOTE_DEPENDENCIES_CONTAINER_NAME'], 'yarn', '--cwd', dir, ...args], opts);
|
|
|
|
} else {
|
|
|
|
run('sudo', ['docker', 'run', '-e', 'GITHUB_TOKEN', '-e', 'npm_config_arch', '-v', `${process.env['VSCODE_HOST_MOUNT']}:/root/vscode`, '-v', `${process.env['VSCODE_HOST_MOUNT']}/.build/.netrc:/root/.netrc`, process.env['VSCODE_REMOTE_DEPENDENCIES_CONTAINER_NAME'], 'yarn', '--cwd', dir, ...args], opts);
|
|
|
|
}
|
2023-04-02 07:35:39 +00:00
|
|
|
run('sudo', ['chown', '-R', `${userinfo.uid}:${userinfo.gid}`, `${dir}/node_modules`], opts);
|
|
|
|
} else {
|
|
|
|
console.log(`Installing dependencies in ${dir}...`);
|
|
|
|
run(yarn, args, opts);
|
2016-11-23 15:09:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 10:28:32 +00:00
|
|
|
for (let dir of dirs) {
|
2016-11-23 15:09:58 +00:00
|
|
|
|
2020-12-23 10:28:32 +00:00
|
|
|
if (dir === '') {
|
|
|
|
// `yarn` already executed in root
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-17 10:16:32 +00:00
|
|
|
|
2023-04-02 07:35:39 +00:00
|
|
|
if (/^.build\/distro\/npm(\/?)/.test(dir)) {
|
|
|
|
const ossPath = path.relative('.build/distro/npm', dir);
|
|
|
|
const ossYarnRc = path.join(ossPath, '.yarnrc');
|
|
|
|
|
|
|
|
if (fs.existsSync(ossYarnRc)) {
|
|
|
|
fs.cpSync(ossYarnRc, path.join(dir, '.yarnrc'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/^(.build\/distro\/npm\/)?remote/.test(dir) && process.platform === 'win32' && (process.arch === 'arm64' || process.env['npm_config_arch'] === 'arm64')) {
|
2020-12-23 10:28:32 +00:00
|
|
|
// windows arm: do not execute `yarn` on remote folder
|
|
|
|
continue;
|
|
|
|
}
|
2019-07-14 11:12:54 +00:00
|
|
|
|
2023-12-12 10:39:00 +00:00
|
|
|
let opts;
|
|
|
|
|
2022-05-12 07:16:03 +00:00
|
|
|
if (dir === 'build') {
|
2023-12-12 10:39:00 +00:00
|
|
|
const env = { ...process.env };
|
2022-05-12 07:16:03 +00:00
|
|
|
setupBuildYarnrc();
|
2023-12-12 10:39:00 +00:00
|
|
|
opts = { env };
|
|
|
|
if (process.env['CC']) { env['CC'] = 'gcc'; }
|
|
|
|
if (process.env['CXX']) { env['CXX'] = 'g++'; }
|
|
|
|
if (process.env['CXXFLAGS']) { env['CXXFLAGS'] = ''; }
|
|
|
|
if (process.env['LDFLAGS']) { env['LDFLAGS'] = ''; }
|
|
|
|
yarnInstall('build', opts);
|
2020-12-23 10:28:32 +00:00
|
|
|
continue;
|
2018-03-18 16:29:53 +00:00
|
|
|
}
|
2016-04-12 02:20:18 +00:00
|
|
|
|
2023-04-02 07:35:39 +00:00
|
|
|
if (/^(.build\/distro\/npm\/)?remote$/.test(dir)) {
|
2020-12-23 10:28:32 +00:00
|
|
|
// node modules used by vscode server
|
|
|
|
const env = { ...process.env };
|
2024-02-06 10:25:58 +00:00
|
|
|
if (process.env['VSCODE_REMOTE_CC']) {
|
|
|
|
env['CC'] = process.env['VSCODE_REMOTE_CC'];
|
|
|
|
} else {
|
|
|
|
delete env['CC'];
|
|
|
|
}
|
|
|
|
if (process.env['VSCODE_REMOTE_CXX']) {
|
|
|
|
env['CXX'] = process.env['VSCODE_REMOTE_CXX'];
|
|
|
|
} else {
|
|
|
|
delete env['CXX'];
|
|
|
|
}
|
|
|
|
if (process.env['CXXFLAGS']) { delete env['CXXFLAGS']; }
|
|
|
|
if (process.env['CFLAGS']) { delete env['CFLAGS']; }
|
|
|
|
if (process.env['LDFLAGS']) { delete env['LDFLAGS']; }
|
2023-12-12 10:39:00 +00:00
|
|
|
if (process.env['VSCODE_REMOTE_CXXFLAGS']) { env['CXXFLAGS'] = process.env['VSCODE_REMOTE_CXXFLAGS']; }
|
|
|
|
if (process.env['VSCODE_REMOTE_LDFLAGS']) { env['LDFLAGS'] = process.env['VSCODE_REMOTE_LDFLAGS']; }
|
2020-12-23 10:28:32 +00:00
|
|
|
if (process.env['VSCODE_REMOTE_NODE_GYP']) { env['npm_config_node_gyp'] = process.env['VSCODE_REMOTE_NODE_GYP']; }
|
2022-02-28 17:11:40 +00:00
|
|
|
|
2020-12-23 10:28:32 +00:00
|
|
|
opts = { env };
|
|
|
|
} else if (/^extensions\//.test(dir)) {
|
|
|
|
opts = { ignoreEngines: true };
|
|
|
|
}
|
|
|
|
|
|
|
|
yarnInstall(dir, opts);
|
|
|
|
}
|
2017-04-05 10:22:25 +00:00
|
|
|
|
2021-06-22 17:55:07 +00:00
|
|
|
cp.execSync('git config pull.rebase merges');
|
2023-10-27 10:34:22 +00:00
|
|
|
cp.execSync('git config blame.ignoreRevsFile .git-blame-ignore-revs');
|