From e8d13d570f1743b0757be6d8d6af78a58d3963ac Mon Sep 17 00:00:00 2001 From: Julen Garcia Leunda Date: Wed, 5 May 2021 22:27:53 +0200 Subject: [PATCH] feat: add options.os to set %_target_os (#175) * Add option to set %_target_os * test: correctly assert target_os * fix: use process.platform instead of OS module Co-authored-by: Felipe Castillo --- README.md | 6 ++++++ src/installer.js | 5 ++++- test/installer.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad0d4ff..56d95c2 100644 --- a/README.md +++ b/README.md @@ -275,6 +275,12 @@ Default: `undefined` Machine architecture the package is targeted to, used to set the `--target` option. +#### options.os +Type: `String` +Default: Operating system platform of the host machine + +Operating system platform the package is targeted to, used to set the `--target` option. + #### options.requires Type: `Array[String]` Default: The minimum list of packages needed for Electron to run diff --git a/src/installer.js b/src/installer.js index 663c92d..b371130 100644 --- a/src/installer.js +++ b/src/installer.js @@ -59,7 +59,7 @@ class RedhatInstaller extends common.ElectronInstaller { async createPackage () { this.options.logger(`Creating package at ${this.stagingDir}`) - const output = await spawn('rpmbuild', ['-bb', this.specPath, '--target', this.options.arch, '--define', `_topdir ${this.stagingDir}`], this.options.logger) + const output = await spawn('rpmbuild', ['-bb', this.specPath, '--target', `${this.options.arch}-${this.options.vendor}-${this.options.os}`, '--define', `_topdir ${this.stagingDir}`], this.options.logger) this.options.logger(`rpmbuild output: ${output}`) } @@ -126,6 +126,9 @@ class RedhatInstaller extends common.ElectronInstaller { this.options.requires = common.mergeUserSpecified(this.userSupplied, 'requires', this.defaults) this.normalizeVersion() + + this.options.vendor = 'none' + this.options.os = this.options.os || process.platform } /** diff --git a/test/installer.js b/test/installer.js index 8e9aa24..fa37444 100644 --- a/test/installer.js +++ b/test/installer.js @@ -144,4 +144,43 @@ describe('module', function () { } } ) + + describeInstaller( + 'with an app with default %_target_os', + { + src: 'test/fixtures/app-with-asar/', + options: { + arch: 'x86' + } + }, + 'generates a `.rpm` package with default %_target_os', + async outputDir => { + await assertASARRpmExists(outputDir) + const stdout = await spawn('rpm', ['-qp', '--qf', '%{OS}', 'footest.x86.rpm'], { cwd: outputDir }) + if (stdout !== process.platform) { + throw new Error(`RPM built with wrong platform: ${stdout}`) + } + } + ) + + if (process.platform === 'darwin') { + describeInstaller( + 'with an app with %_target_os linux', + { + src: 'test/fixtures/app-with-asar/', + options: { + arch: 'x86', + os: 'linux' + } + }, + 'generates a `.rpm` package with linux %_target_os', + async outputDir => { + await assertASARRpmExists(outputDir) + const stdout = await spawn('rpm', ['-qp', '--qf', '%{OS}', 'footest.x86.rpm'], { cwd: outputDir }) + if (stdout !== 'linux') { + throw new Error(`RPM was not built for linux: ${stdout}`) + } + } + ) + } })