Skip to content

Commit

Permalink
Determine arch on ARM hosts better
Browse files Browse the repository at this point in the history
Determine which specific ARM version a given host arch is running, so
the appropriate Electron binary is selected. This is particularly
important as of Electron 3, since `-arm` builds are no longer being
created.
  • Loading branch information
malept committed Jul 25, 2018
1 parent bd17ee8 commit 12dadb5
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/arch.js
@@ -0,0 +1,30 @@
'use strict'

const execSync = require('child_process').execSync

module.exports = {
host: function host (quiet) {
const arch = process.arch
if (arch === 'arm') {
switch (process.config.variables.arm_version) {
case '6':
return module.exports.uname()
case '7':
return 'armv7l'
default:
if (!quiet) {
console.warn(`WARNING: Could not determine specific ARM arch. Detected ARM version: ${JSON.stringify(process.config.variables.arm_version)}`)
}
}
}

return arch
},

/**
* Returns the arch name from the `uname` utility.
*/
uname: function uname () {
return execSync('uname -m').toString().trim()
}
}
3 changes: 2 additions & 1 deletion lib/index.js
@@ -1,5 +1,6 @@
'use strict'

const arch = require('./arch')
const debug = require('debug')('electron-download')
const envPaths = require('env-paths')
const fs = require('fs-extra')
Expand Down Expand Up @@ -54,7 +55,7 @@ class ElectronDownloader {
}

get arch () {
return this.opts.arch || os.arch()
return this.opts.arch || arch.host(this.quiet)
}

get cache () {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -39,6 +39,7 @@
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"sinon": "^6.1.4",
"tape": "^4.8.0",
"temp": "^0.8.3"
},
Expand Down
36 changes: 36 additions & 0 deletions test/test_arch.js
@@ -0,0 +1,36 @@
'use strict'

const arch = require('../lib/arch')
const sinon = require('sinon')
const test = require('tape')

test('hostArch detects incorrectly configured armv7l Node', t => {
sinon.stub(arch, 'uname').returns('armv6l')
sinon.stub(process, 'arch').value('arm')
sinon.stub(process, 'config').value({variables: {arm_version: '6'}})

t.is(arch.host(), 'armv6l')

sinon.restore()
t.end()
})

test('hostArch detects correctly configured armv7l Node', t => {
sinon.stub(process, 'arch').value('arm')
sinon.stub(process, 'config').value({variables: {arm_version: '7'}})

t.is(arch.host(), 'armv7l')

sinon.restore()
t.end()
})

test('hostArch cannot determine ARM version', t => {
sinon.stub(process, 'arch').value('arm')
sinon.stub(process, 'config').value({variables: {arm_version: '99'}})

t.is(arch.host(), 'arm')

sinon.restore()
t.end()
})

0 comments on commit 12dadb5

Please sign in to comment.