Skip to content

Commit

Permalink
feat: add options.os to set %_target_os (#175)
Browse files Browse the repository at this point in the history
* Add option to set %_target_os

* test: correctly assert target_os

* fix: use process.platform instead of OS module

Co-authored-by: Felipe Castillo <fcastillo.ec@gmail.com>
  • Loading branch information
hicom150 and fcastilloec committed May 5, 2021
1 parent 1e829d4 commit e8d13d5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}

Expand Down Expand Up @@ -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
}

/**
Expand Down
39 changes: 39 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}
)
}
})

0 comments on commit e8d13d5

Please sign in to comment.