Skip to content

Commit d70a325

Browse files
authored
Merge pull request #866 from devm33/macos-exec
fix: ensure spawn-helper is executable for macos prebuilds
2 parents 25810ca + 6a7f206 commit d70a325

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ jobs:
5555
- name: Install sysroot
5656
if: runner.os == 'Linux'
5757
run: |
58+
set -eo pipefail
5859
sudo apt-get update -qq
5960
sudo apt-get install -y gcc-10 g++-10
6061
echo "CC=gcc-10" >> $GITHUB_ENV
6162
echo "CXX=g++-10" >> $GITHUB_ENV
6263
SYSROOT_PATH=$(node scripts/linux/install-sysroot.js ${{ steps.arch.outputs.arch }} | grep "SYSROOT_PATH=" | cut -d= -f2)
6364
echo "SYSROOT_PATH=$SYSROOT_PATH" >> $GITHUB_ENV
6465
echo "Sysroot path set to: $SYSROOT_PATH"
66+
env:
67+
# Set github token for authenticated sysroot download
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6569

6670
- name: Install dependencies and build
6771
run: npm ci

publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ extends:
5252
- pwsh: |
5353
Get-ChildItem -Path . -Recurse -Directory -Name "_manifest" | Remove-Item -Recurse -Force
5454
displayName: 'Delete _manifest folders'
55+
- bash: chmod +x prebuilds/darwin-*/spawn-helper
56+
displayName: 'Ensure spawn-helper is executable'
5557
- script: npm ci
5658
displayName: 'Install dependencies and build'
5759
# The following script leaves the version unchanged for
@@ -70,6 +72,8 @@ extends:
7072
branchName: 'refs/heads/main'
7173
artifactName: 'prebuilds'
7274
targetPath: 'prebuilds'
75+
- bash: chmod +x prebuilds/darwin-*/spawn-helper
76+
displayName: 'Ensure spawn-helper is executable'
7377
- script: npm ci
7478
displayName: 'Install dependencies and build'
7579
- script: npm test

scripts/linux/install-sysroot.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const ghApiHeaders = {
1818

1919
if (process.env.GITHUB_TOKEN) {
2020
ghApiHeaders.Authorization = 'Basic ' + Buffer.from(process.env.GITHUB_TOKEN).toString('base64');
21+
console.error('Using GITHUB_TOKEN for authenticated requests to GitHub API.');
2122
}
2223

2324
const ghDownloadHeaders = {
@@ -48,29 +49,29 @@ async function fetchUrl(options, retries = 10, retryDelay = 1000) {
4849
signal: controller.signal
4950
});
5051
if (response.ok && (response.status >= 200 && response.status < 300)) {
51-
console.log(`Fetch completed: Status ${response.status}.`);
52+
console.error(`Fetch completed: Status ${response.status}.`);
5253
const contents = Buffer.from(await response.arrayBuffer());
5354
const asset = JSON.parse(contents.toString()).assets.find((a) => a.name === options.assetName);
5455
if (!asset) {
5556
throw new Error(`Could not find asset in release of Microsoft/vscode-linux-build-agent @ ${version}`);
5657
}
57-
console.log(`Found asset ${options.assetName} @ ${asset.url}.`);
58+
console.error(`Found asset ${options.assetName} @ ${asset.url}.`);
5859
const assetResponse = await fetch(asset.url, {
5960
headers: ghDownloadHeaders
6061
});
6162
if (assetResponse.ok && (assetResponse.status >= 200 && assetResponse.status < 300)) {
6263
const assetContents = Buffer.from(await assetResponse.arrayBuffer());
63-
console.log(`Fetched response body buffer: ${assetContents.byteLength} bytes`);
64+
console.error(`Fetched response body buffer: ${assetContents.byteLength} bytes`);
6465
if (options.checksumSha256) {
6566
const actualSHA256Checksum = createHash('sha256').update(assetContents).digest('hex');
6667
if (actualSHA256Checksum !== options.checksumSha256) {
6768
throw new Error(`Checksum mismatch for ${asset.url} (expected ${options.checksumSha256}, actual ${actualSHA256Checksum})`);
6869
}
6970
}
70-
console.log(`Verified SHA256 checksums match for ${asset.url}`);
71+
console.error(`Verified SHA256 checksums match for ${asset.url}`);
7172
const tarCommand = `tar -xz -C ${options.dest}`;
7273
execSync(tarCommand, { input: assetContents });
73-
console.log(`Fetch complete!`);
74+
console.error(`Fetch complete!`);
7475
return;
7576
}
7677
throw new Error(`Request ${asset.url} failed with status code: ${assetResponse.status}`);
@@ -81,7 +82,7 @@ async function fetchUrl(options, retries = 10, retryDelay = 1000) {
8182
}
8283
} catch (e) {
8384
if (retries > 0) {
84-
console.log(`Fetching failed: ${e}`);
85+
console.error(`Fetching failed: ${e}`);
8586
await new Promise(resolve => setTimeout(resolve, retryDelay));
8687
return fetchUrl(options, retries - 1, retryDelay);
8788
}
@@ -122,7 +123,7 @@ async function getSysroot(arch) {
122123
return result;
123124
}
124125

125-
console.log(`Installing ${arch} root image: ${sysroot}`);
126+
console.error(`Installing ${arch} root image: ${sysroot}`);
126127
fs.rmSync(sysroot, { recursive: true, force: true });
127128
fs.mkdirSync(sysroot, { recursive: true });
128129

@@ -139,7 +140,7 @@ async function getSysroot(arch) {
139140

140141
async function main() {
141142
const arch = process.argv[2] || process.env.ARCH || 'x64';
142-
console.log(`Installing sysroot for architecture: ${arch}`);
143+
console.error(`Installing sysroot for architecture: ${arch}`);
143144

144145
try {
145146
const sysrootPath = await getSysroot(arch);

scripts/prebuild.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,4 @@ if (!fs.existsSync(PREBUILD_DIR)) {
3131
process.exit(1);
3232
}
3333

34-
// Ensure spawn-helper has execute permission (may be stripped by npm pack)
35-
if (process.platform === 'darwin') {
36-
const spawnHelper = path.join(PREBUILD_DIR, 'spawn-helper');
37-
if (fs.existsSync(spawnHelper)) {
38-
fs.chmodSync(spawnHelper, 0o755);
39-
}
40-
}
41-
4234
process.exit(0);

src/unixTerminal.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,15 @@ if (process.platform !== 'win32') {
280280
let sub = '';
281281
let pid = '';
282282
p.stdout.on('data', (data) => {
283-
if (!data.toString().indexOf('title')) {
284-
sub = data.toString().split(' ')[1].slice(0, -1);
285-
} else if (!data.toString().indexOf('ready')) {
286-
pid = data.toString().split(' ')[1].slice(0, -1);
287-
process.kill(parseInt(pid), 'SIGINT');
288-
p.kill('SIGINT');
283+
const lines = data.toString().split('\n');
284+
for (const line of lines) {
285+
if (line.startsWith('title ')) {
286+
sub = line.split(' ')[1];
287+
} else if (line.startsWith('ready ')) {
288+
pid = line.split(' ')[1];
289+
process.kill(parseInt(pid), 'SIGINT');
290+
p.kill('SIGINT');
291+
}
289292
}
290293
});
291294
p.on('exit', () => {

0 commit comments

Comments
 (0)