Skip to content

Commit e8d13d5

Browse files
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 <[email protected]>
1 parent 1e829d4 commit e8d13d5

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ Default: `undefined`
275275

276276
Machine architecture the package is targeted to, used to set the `--target` option.
277277

278+
#### options.os
279+
Type: `String`
280+
Default: Operating system platform of the host machine
281+
282+
Operating system platform the package is targeted to, used to set the `--target` option.
283+
278284
#### options.requires
279285
Type: `Array[String]`
280286
Default: The minimum list of packages needed for Electron to run

src/installer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RedhatInstaller extends common.ElectronInstaller {
5959
async createPackage () {
6060
this.options.logger(`Creating package at ${this.stagingDir}`)
6161

62-
const output = await spawn('rpmbuild', ['-bb', this.specPath, '--target', this.options.arch, '--define', `_topdir ${this.stagingDir}`], this.options.logger)
62+
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)
6363
this.options.logger(`rpmbuild output: ${output}`)
6464
}
6565

@@ -126,6 +126,9 @@ class RedhatInstaller extends common.ElectronInstaller {
126126
this.options.requires = common.mergeUserSpecified(this.userSupplied, 'requires', this.defaults)
127127

128128
this.normalizeVersion()
129+
130+
this.options.vendor = 'none'
131+
this.options.os = this.options.os || process.platform
129132
}
130133

131134
/**

test/installer.js

+39
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,43 @@ describe('module', function () {
144144
}
145145
}
146146
)
147+
148+
describeInstaller(
149+
'with an app with default %_target_os',
150+
{
151+
src: 'test/fixtures/app-with-asar/',
152+
options: {
153+
arch: 'x86'
154+
}
155+
},
156+
'generates a `.rpm` package with default %_target_os',
157+
async outputDir => {
158+
await assertASARRpmExists(outputDir)
159+
const stdout = await spawn('rpm', ['-qp', '--qf', '%{OS}', 'footest.x86.rpm'], { cwd: outputDir })
160+
if (stdout !== process.platform) {
161+
throw new Error(`RPM built with wrong platform: ${stdout}`)
162+
}
163+
}
164+
)
165+
166+
if (process.platform === 'darwin') {
167+
describeInstaller(
168+
'with an app with %_target_os linux',
169+
{
170+
src: 'test/fixtures/app-with-asar/',
171+
options: {
172+
arch: 'x86',
173+
os: 'linux'
174+
}
175+
},
176+
'generates a `.rpm` package with linux %_target_os',
177+
async outputDir => {
178+
await assertASARRpmExists(outputDir)
179+
const stdout = await spawn('rpm', ['-qp', '--qf', '%{OS}', 'footest.x86.rpm'], { cwd: outputDir })
180+
if (stdout !== 'linux') {
181+
throw new Error(`RPM was not built for linux: ${stdout}`)
182+
}
183+
}
184+
)
185+
}
147186
})

0 commit comments

Comments
 (0)