Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
fix(build): catch spawn err (#193)
Browse files Browse the repository at this point in the history
* fix(build): catch spawn err

* fix

* fix

* fix
  • Loading branch information
JonasBa authored Aug 30, 2023
1 parent 890a40c commit 1dcdff6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
43 changes: 34 additions & 9 deletions scripts/check-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,57 @@ import cp from 'child_process';
import { existsSync } from 'fs';
import process from 'process';
import { target } from './binaries.mjs';
import { log } from 'console';

import { createRequire } from 'module';
const require = createRequire(import.meta.url);

function clean(err) {
return err.toString().trim();
}

function recompileFromSource() {
console.log('@sentry/profiling-node: Compiling from source...');
cp.spawnSync('npm', ['run', 'build:configure'], { env: process.env });
cp.spawnSync('npm', ['run', 'build:bindings'], { env: process.env });
cp.spawnSync('node', ['scripts/copy-target.mjs'], { env: process.env });
log('@sentry/profiling-node: Compiling from source...');
let spawn = cp.spawnSync('npm', ['run', 'build:configure'], {
stdio: ['inherit', 'inherit', 'pipe'],
env: process.env,
shell: true
});

if (spawn.status !== 0) {
log('@sentry/profiling-node: Failed to configure gyp');
log('@sentry/profiling-node:', clean(spawn.stderr));
return;
}

spawn = cp.spawnSync('npm', ['run', 'build:bindings'], {
stdio: ['inherit', 'inherit', 'pipe'],
env: process.env,
shell: true
});
if (spawn.status !== 0) {
log('@sentry/profiling-node: Failed to build bindings');
log('@sentry/profiling-node:', clean(spawn.stderr));
return;
}
}

if (existsSync(target)) {
try {
console.log(`@sentry/profiling-node: Precompiled binary found, attempting to load ${target}`);
log(`@sentry/profiling-node: Precompiled binary found, attempting to load ${target}`);
require(target);
console.log('@sentry/profiling-node: Precompiled binary found, skipping build from source.');
log('@sentry/profiling-node: Precompiled binary found, skipping build from source.');
} catch (e) {
console.log('@sentry/profiling-node: Precompiled binary found but failed loading');
log('@sentry/profiling-node: Precompiled binary found but failed loading');
log('@sentry/profiling-node:', e);
try {
recompileFromSource();
} catch (e) {
console.log('@sentry/profiling-node: Failed to compile from source');
log('@sentry/profiling-node: Failed to compile from source');
throw e;
}
}
} else {
console.log('@sentry/profiling-node: No precompiled binary found');
log('@sentry/profiling-node: No precompiled binary found');
recompileFromSource();
}
8 changes: 4 additions & 4 deletions scripts/copy-target.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { existsSync, mkdirSync, renameSync } from 'fs';
import path from 'path';
import { fileURLToPath, URL } from 'url';
import { exit } from 'process';

import { getModuleName } from './binaries.mjs';
import { log } from 'console';

const __dirname = fileURLToPath(new URL('.', import.meta.url));
const lib = path.resolve(__dirname, '..', 'lib');
Expand All @@ -16,12 +16,12 @@ const source = path.join(__dirname, '..', 'build', 'Release', 'sentry_cpu_profil
const target = path.join(__dirname, '..', 'lib', getModuleName());

if (!existsSync(source)) {
console.log('Source file does not exist:', source);
log('Source file does not exist:', source);
exit(1);
} else {
if (existsSync(target)) {
console.log('Target file already exists, overwriting it');
log('Target file already exists, overwriting it');
}
console.log('Renaming', source, 'to', target);
log('Renaming', source, 'to', target);
renameSync(source, target);
}

0 comments on commit 1dcdff6

Please sign in to comment.