From 1ac2e4afdcfc2049ac95261d613bf0b0774da7ed Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Sat, 28 May 2022 15:45:09 +0200 Subject: [PATCH 1/3] feat: Add support for build-from-source argument --- README.md | 2 ++ src/cli.ts | 2 ++ src/module-type/prebuild-install.ts | 21 +++++++++++++-------- src/rebuild.ts | 3 +++ src/types.ts | 1 + test/module-type-prebuild-install.ts | 12 ++++++++++++ 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e8449e64..32aef5d9 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,8 @@ Options: -b, --debug Build debug version of modules --prebuild-tag-prefix GitHub tag prefix passed to prebuild-install. Default is "v" + --force-build-from-source Skip prebuild download and rebuild module from + source. Default is false Copyright 2016 ``` diff --git a/src/cli.ts b/src/cli.ts index 358a10ff..3309dceb 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -28,6 +28,7 @@ const argv = yargs(process.argv.slice(2)).version(false).options({ sequential: { alias: 's', type: 'boolean', description: 'Rebuild modules sequentially, this is enabled by default on Windows' }, debug: { alias: 'b', type: 'boolean', description: 'Build debug version of modules' }, 'prebuild-tag-prefix': { type: 'string', description: 'GitHub tag prefix passed to prebuild-install. Default is "v"' }, + 'force-build-from-source': { type: 'boolean', description: 'Skip prebuild download and rebuild module from source. Default is false' }, 'force-abi': { type: 'number', description: 'Override the ABI version for the version of Electron you are targeting. Only use when targeting Nightly releases.' }, 'use-electron-clang': { type: 'boolean', description: 'Use the clang executable that Electron used when building its binary. This will guarantee compiler compatibility' }, 'disable-pre-gyp-copy': { type: 'boolean', description: 'Disables the pre-gyp copy step' }, @@ -124,6 +125,7 @@ process.on('unhandledRejection', handler); mode: argv.p ? 'parallel' : (argv.s ? 'sequential' : undefined), debug: argv.debug, prebuildTagPrefix: (argv.prebuildTagPrefix as string) || 'v', + forceBuildFromSource: argv.forceBuildFromSource || false, forceABI: argv.forceAbi as number, useElectronClang: !!argv.useElectronClang, disablePreGypCopy: !!argv.disablePreGypCopy, diff --git a/src/module-type/prebuild-install.ts b/src/module-type/prebuild-install.ts index a255bd37..4a333dd4 100644 --- a/src/module-type/prebuild-install.ts +++ b/src/module-type/prebuild-install.ts @@ -20,20 +20,25 @@ export class PrebuildInstall extends NativeModule { async run(prebuildInstallPath: string): Promise { await spawn( process.execPath, - [ - path.resolve(__dirname, '..', `prebuild-shim.js`), - prebuildInstallPath, - `--arch=${this.rebuilder.arch}`, - `--platform=${this.rebuilder.platform}`, - `--tag-prefix=${this.rebuilder.prebuildTagPrefix}`, - ...await this.getPrebuildInstallRuntimeArgs(), - ], + await this.getPrebuildInstallArgs(prebuildInstallPath), { cwd: this.modulePath, } ); } + async getPrebuildInstallArgs(prebuildInstallPath: string): Promise { + return [ + path.resolve(__dirname, '..', `prebuild-shim.js`), + prebuildInstallPath, + `--arch=${this.rebuilder.arch}`, + `--platform=${this.rebuilder.platform}`, + `--tag-prefix=${this.rebuilder.prebuildTagPrefix}`, + this.rebuilder.forceBuildFromSource ? `--build-from-source` : '', + ...(await this.getPrebuildInstallRuntimeArgs()), + ].filter(Boolean); + } + async findPrebuiltModule(): Promise { const prebuildInstallPath = await this.locateBinary(); if (prebuildInstallPath) { diff --git a/src/rebuild.ts b/src/rebuild.ts index 58a54d14..9b938e1e 100644 --- a/src/rebuild.ts +++ b/src/rebuild.ts @@ -25,6 +25,7 @@ export interface RebuildOptions { useElectronClang?: boolean; cachePath?: string; prebuildTagPrefix?: string; + forceBuildFromSource?: boolean; projectRootPath?: string; forceABI?: number; disablePreGypCopy?: boolean; @@ -57,6 +58,7 @@ export class Rebuilder implements IRebuilder { public useCache: boolean; public cachePath: string; public prebuildTagPrefix: string; + public forceBuildFromSource: boolean; public msvsVersion?: string; public useElectronClang: boolean; public disablePreGypCopy: boolean; @@ -74,6 +76,7 @@ export class Rebuilder implements IRebuilder { this.useElectronClang = options.useElectronClang || false; this.cachePath = options.cachePath || path.resolve(os.homedir(), '.electron-rebuild-cache'); this.prebuildTagPrefix = options.prebuildTagPrefix || 'v'; + this.forceBuildFromSource = options.forceBuildFromSource || false; this.msvsVersion = process.env.GYP_MSVS_VERSION; this.disablePreGypCopy = options.disablePreGypCopy || false; diff --git a/src/types.ts b/src/types.ts index 59fa5c92..58347aec 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,6 +23,7 @@ export interface IRebuilder { msvsVersion?: string; platform: string; prebuildTagPrefix: string; + forceBuildFromSource: boolean; useCache: boolean; useElectronClang: boolean; } diff --git a/test/module-type-prebuild-install.ts b/test/module-type-prebuild-install.ts index e812dcc7..84db4c04 100644 --- a/test/module-type-prebuild-install.ts +++ b/test/module-type-prebuild-install.ts @@ -35,6 +35,18 @@ describe('prebuild-install', () => { ]) }); + it('should pass --build-from-source to prebuild-install when forceBuildFromSource is true', async () => { + const rebuilder = new Rebuilder({ + ...rebuilderArgs, + forceBuildFromSource: true, + }); + const prebuildInstall = new PrebuildInstall(rebuilder, modulePath); + console.log(await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path')) + expect( + await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path') + ).to.include('--build-from-source'); + }); + it('should not fail running prebuild-install', async () => { const rebuilder = new Rebuilder(rebuilderArgs); const prebuildInstall = new PrebuildInstall(rebuilder, modulePath); From 96adc8f49b6711711c06fd2e6b4a5cab5559bded Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Sun, 29 May 2022 09:28:43 +0200 Subject: [PATCH 2/3] chore: Remove console.log --- test/module-type-prebuild-install.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/module-type-prebuild-install.ts b/test/module-type-prebuild-install.ts index 84db4c04..1f0280bc 100644 --- a/test/module-type-prebuild-install.ts +++ b/test/module-type-prebuild-install.ts @@ -41,7 +41,6 @@ describe('prebuild-install', () => { forceBuildFromSource: true, }); const prebuildInstall = new PrebuildInstall(rebuilder, modulePath); - console.log(await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path')) expect( await prebuildInstall.getPrebuildInstallArgs('prebuild-install-path') ).to.include('--build-from-source'); From 7af98bb97c47dd18c1b5ce8e597927e28d1ab583 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Mon, 5 Jun 2023 21:46:27 +0200 Subject: [PATCH 3/3] chore: fix help output formatting Co-authored-by: Erick Zhao --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32aef5d9..9389797e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Options: -b, --debug Build debug version of modules --prebuild-tag-prefix GitHub tag prefix passed to prebuild-install. Default is "v" - --force-build-from-source Skip prebuild download and rebuild module from + --force-build-from-source Skip prebuild download and rebuild module from source. Default is false Copyright 2016