[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for force-build-from-source argument #989

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 13 additions & 8 deletions src/module-type/prebuild-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@ export class PrebuildInstall extends NativeModule {
async run(prebuildInstallPath: string): Promise<void> {
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<string[]> {
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<boolean> {
const prebuildInstallPath = await this.locateBinary();
if (prebuildInstallPath) {
Expand Down
3 changes: 3 additions & 0 deletions src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface RebuildOptions {
useElectronClang?: boolean;
cachePath?: string;
prebuildTagPrefix?: string;
forceBuildFromSource?: boolean;
projectRootPath?: string;
forceABI?: number;
disablePreGypCopy?: boolean;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IRebuilder {
msvsVersion?: string;
platform: string;
prebuildTagPrefix: string;
forceBuildFromSource: boolean;
useCache: boolean;
useElectronClang: boolean;
}
11 changes: 11 additions & 0 deletions test/module-type-prebuild-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ 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);
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);
Expand Down