Update qemu to v3, and automatically use the correct architecture (arm/aarch64)

When building with emulation mode enabled, this downloads the version of qemu
appropriate to the architecture of the project (either arm or aarch64).

Change-type: minor
This commit is contained in:
Edward Keeble 2018-10-18 10:54:26 -07:00 committed by Tim Perry
parent 69ab9788fc
commit 0b67a40d57
3 changed files with 39 additions and 15 deletions

View File

@ -166,7 +166,7 @@ exports.buildProject = (
renderer = new BuildProgressUI(tty, imageDescriptors) renderer = new BuildProgressUI(tty, imageDescriptors)
renderer.start() renderer.start()
qemu.installQemuIfNeeded(emulated, logger) qemu.installQemuIfNeeded(emulated, logger, arch)
.tap (needsQemu) -> .tap (needsQemu) ->
return if not needsQemu return if not needsQemu
logger.logInfo('Emulation is enabled') logger.logInfo('Emulation is enabled')

View File

@ -1,16 +1,16 @@
Promise = require('bluebird') Promise = require('bluebird')
exports.QEMU_VERSION = QEMU_VERSION = 'v2.5.50-resin-execve' exports.QEMU_VERSION = QEMU_VERSION = 'v3.0.0+resin'
exports.QEMU_BIN_NAME = QEMU_BIN_NAME = 'qemu-execve' exports.QEMU_BIN_NAME = QEMU_BIN_NAME = 'qemu-execve'
exports.installQemuIfNeeded = Promise.method (emulated, logger) -> exports.installQemuIfNeeded = Promise.method (emulated, logger, arch) ->
return false if not (emulated and platformNeedsQemu()) return false if not (emulated and platformNeedsQemu())
hasQemu() hasQemu()
.then (present) -> .then (present) ->
if !present if !present
logger.logInfo('Installing qemu for ARM emulation...') logger.logInfo("Installing qemu for #{arch} emulation...")
installQemu() installQemu(arch)
.return(true) .return(true)
exports.qemuPathInContext = (context) -> exports.qemuPathInContext = (context) ->
@ -67,20 +67,43 @@ platformNeedsQemu = ->
os = require('os') os = require('os')
os.platform() == 'linux' os.platform() == 'linux'
installQemu = -> installQemu = (arch) ->
request = require('request') request = require('request')
fs = require('fs') fs = require('fs')
zlib = require('zlib') zlib = require('zlib')
tar = require('tar')
os = require('os')
path = require('path')
rimraf = require('rimraf')
getQemuPath() getQemuPath()
.then (qemuPath) -> .then (qemuPath) ->
new Promise (resolve, reject) -> new Promise (resolve, reject) ->
installStream = fs.createWriteStream(qemuPath) downloadArchiveName = "qemu-3.0.0+resin-#{arch}.tar.gz"
qemuUrl = "https://github.com/balena-io/qemu/releases/download/#{QEMU_VERSION}/#{QEMU_BIN_NAME}.gz" fs.mkdtemp(path.join(os.tmpdir(), 'balenaqemu-'), (err, folder) ->
if err
reject(err)
qemuUrl = "https://github.com/balena-io/qemu/releases/download/#{QEMU_VERSION}/#{downloadArchiveName}"
request(qemuUrl) request(qemuUrl)
.on('error', reject) .on('error', reject)
.pipe(zlib.createGunzip()) .pipe(zlib.createGunzip())
.on('error', reject) .on('error', reject)
.pipe(installStream) .pipe(tar.extract({
.on('error', reject) C: folder,
.on('finish', resolve) filter: (path, entry) -> return path.includes("qemu-#{arch}-static"),
strip: 1
})).on('finish', ->
# copy qemu binary to intended location then clean up the temp directory
tempFile = path.join(folder, "qemu-#{arch}-static")
fs.copyFile(tempFile, qemuPath, (err) ->
if err
reject(err)
# File moved successfully. Remove temp dir.
rimraf(folder, (err) ->
if err
reject(err)
resolve()
)
)
)
)

View File

@ -168,6 +168,7 @@
"split": "^1.0.1", "split": "^1.0.1",
"string-width": "^2.1.1", "string-width": "^2.1.1",
"strip-ansi-stream": "^1.0.0", "strip-ansi-stream": "^1.0.0",
"tar": "^4.4.6",
"tar-stream": "^1.5.5", "tar-stream": "^1.5.5",
"through2": "^2.0.3", "through2": "^2.0.3",
"tmp": "0.0.31", "tmp": "0.0.31",