Skip to content

Commit

Permalink
Add option to set %_target_os
Browse files Browse the repository at this point in the history
  • Loading branch information
hicom150 authored and fcastilloec committed May 5, 2021
1 parent 1e829d4 commit e21b5ab
Show file tree
Hide file tree
Showing 3 changed files with 45 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
6 changes: 5 additions & 1 deletion src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const debug = require('debug')
const fs = require('fs-extra')
const path = require('path')
const wrap = require('word-wrap')
const os = require('os')

const redhatDependencies = require('./dependencies')
const spawn = require('./spawn')
Expand Down Expand Up @@ -59,7 +60,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 +127,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 || os.platform()
}

/**
Expand Down
34 changes: 34 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const fs = require('fs-extra')
const installer = require('..')
const path = require('path')
const { spawn } = require('@malept/cross-spawn-promise')
const os = require('os')

const assertASARRpmExists = outputDir =>
access(path.join(outputDir, 'footest.x86.rpm'))
Expand Down Expand Up @@ -144,4 +145,37 @@ 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 })
return stdout === os.platform()
}
)

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 })
return stdout === 'linux'
}
)
})

0 comments on commit e21b5ab

Please sign in to comment.