fix(bazel): Directly spawn native Bazel binary (#30306)

Instead of launching a Node.js process that in turn spawns Bazel binary,
the Builder could now directly spawn the native binary. This makes the
bootup process slightly more efficient, and allows the Builder to
control spawn options. This works with both Bazel and iBazel.

PR Close #30306
This commit is contained in:
Keen Yee Liau 2019-05-07 12:32:49 -07:00 committed by Alex Rickabaugh
parent 392473ec79
commit 2a0f497e94
3 changed files with 8 additions and 6 deletions

View File

@ -8,7 +8,7 @@
/// <reference types='node'/> /// <reference types='node'/>
import {fork} from 'child_process'; import {spawn} from 'child_process';
import {copyFileSync, existsSync, readdirSync, statSync, unlinkSync} from 'fs'; import {copyFileSync, existsSync, readdirSync, statSync, unlinkSync} from 'fs';
import {dirname, join, normalize} from 'path'; import {dirname, join, normalize} from 'path';
@ -24,7 +24,7 @@ export function runBazel(
projectDir = normalize(projectDir); projectDir = normalize(projectDir);
binary = normalize(binary); binary = normalize(binary);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const buildProcess = fork(binary, [command, workspaceTarget, ...flags], { const buildProcess = spawn(binary, [command, workspaceTarget, ...flags], {
cwd: projectDir, cwd: projectDir,
stdio: 'inherit', stdio: 'inherit',
}); });
@ -51,12 +51,12 @@ export function runBazel(
*/ */
export function checkInstallation(name: Executable, projectDir: string): string { export function checkInstallation(name: Executable, projectDir: string): string {
projectDir = normalize(projectDir); projectDir = normalize(projectDir);
const packageName = `@bazel/${name}/package.json`; const packageName = `@bazel/${name}`;
try { try {
const bazelPath = require.resolve(packageName, { const bazelPath = require.resolve(packageName, {
paths: [projectDir], paths: [projectDir],
}); });
return dirname(bazelPath); return require(bazelPath).getNativeBinary();
} catch (error) { } catch (error) {
if (error.code === 'MODULE_NOT_FOUND') { if (error.code === 'MODULE_NOT_FOUND') {
throw new Error( throw new Error(

View File

@ -23,6 +23,8 @@ build --incompatible_strict_action_env
run --incompatible_strict_action_env run --incompatible_strict_action_env
test --incompatible_strict_action_env test --incompatible_strict_action_env
build --incompatible_bzl_disallow_load_after_statement=false
test --test_output=errors test --test_output=errors
# Use the Angular 6 compiler # Use the Angular 6 compiler

View File

@ -48,8 +48,8 @@ function addDevDependenciesToPackageJson(options: Schema) {
const devDependencies: {[k: string]: string} = { const devDependencies: {[k: string]: string} = {
'@angular/bazel': angularCoreVersion, '@angular/bazel': angularCoreVersion,
'@bazel/bazel': '^0.24.0', '@bazel/bazel': '^0.25.1',
'@bazel/ibazel': '^0.10.1', '@bazel/ibazel': '^0.10.2',
'@bazel/karma': '0.27.12', '@bazel/karma': '0.27.12',
'@bazel/typescript': '0.27.12', '@bazel/typescript': '0.27.12',
}; };