Skip to content

Commit

Permalink
Merge pull request #727 from electron-userland/target-arch-api
Browse files Browse the repository at this point in the history
Add target arch API
  • Loading branch information
malept committed Sep 14, 2017
2 parents 27f4f73 + 43397e8 commit ab0419f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
30 changes: 28 additions & 2 deletions targets.js
Expand Up @@ -72,8 +72,26 @@ function warnIfAllNotSpecified (opts, message) {
}
}

function hostArch () {
/* istanbul ignore if */
if (process.arch === 'arm' && process.config.variables.arm_version === '7') {
return 'armv7l'
}

return process.arch
}

module.exports = {
allOfficialArchsForPlatformAndVersion: function allOfficialArchsForPlatformAndVersion (platform, electronVersion) {
const archs = officialPlatformArchCombos[platform]
if (platform === 'linux' && !officialLinuxARM64BuildExists({electronVersion: electronVersion})) {
return archs.filter((arch) => arch !== 'arm64')
}

return archs
},
createPlatformArchPairs: createPlatformArchPairs,
hostArch: hostArch,
officialArchs: officialArchs,
officialPlatformArchCombos: officialPlatformArchCombos,
officialPlatforms: officialPlatforms,
Expand All @@ -84,8 +102,16 @@ module.exports = {
validateListFromOptions: function validateListFromOptions (opts, name) {
if (opts.all) return Array.from(supported[name].values())

let list = opts[name] || process[name]
if (list === 'all') return Array.from(supported[name].values())
let list = opts[name]
if (!list) {
if (name === 'arch') {
list = hostArch()
} else {
list = process[name]
}
} else if (list === 'all') {
return Array.from(supported[name].values())
}

if (!Array.isArray(list)) {
if (typeof list === 'string') {
Expand Down
18 changes: 18 additions & 0 deletions test/targets.js
Expand Up @@ -30,6 +30,24 @@ function testCombinations (testcaseDescription, arch, platform) {
'Packages should be generated for all combinations of specified archs and platforms')
}

test('allOfficialArchsForPlatformAndVersion is undefined for unknown platforms', (t) => {
t.equal(targets.allOfficialArchsForPlatformAndVersion('unknown', '1.0.0'), undefined)
t.end()
})

test('allOfficialArchsForPlatformAndVersion returns the correct arches for a known platform', (t) => {
t.deepEqual(targets.allOfficialArchsForPlatformAndVersion('darwin', '1.0.0'), ['x64'])
t.end()
})

test('allOfficialArchsForPlatformAndVersion returns arm64 when the correct version is specified', (t) => {
t.notEqual(targets.allOfficialArchsForPlatformAndVersion('linux', '1.8.0').indexOf('arm64'), -1,
'should be found when version is >= 1.8.0')
t.equal(targets.allOfficialArchsForPlatformAndVersion('linux', '1.7.0').indexOf('arm64'), -1,
'should not be found when version is < 1.8.0')
t.end()
})

test('validateListFromOptions does not take non-Array/String values', (t) => {
targets.supported.digits = new Set(['64', '65'])
t.notOk(targets.validateListFromOptions({digits: 64}, 'digits') instanceof Array,
Expand Down

0 comments on commit ab0419f

Please sign in to comment.