enso/tools/run

96 lines
2.6 KiB
Plaintext
Raw Normal View History

2020-07-03 16:42:45 +03:00
#!/usr/bin/env node
const fss = require('fs')
const spawnSync = require('child_process').spawnSync
const spawn = require('child_process').spawn
const path = require('path')
// Versions
2021-05-14 15:08:39 +03:00
const nodeJsVersion = "v14.16.1"
const rustcVersion = "1.54.0-nightly"
2020-07-03 16:42:45 +03:00
// Configuration
const libImplDirName = 'impl'
let args = process.argv.slice(2)
function runRead(cmd, args) {
let out = ''
return new Promise((resolve, reject) => {
let proc = spawn(cmd,args,{shell:true})
proc.stderr.pipe(process.stderr)
proc.stdout.on('data', (data) => { out += data })
proc.on('exit', (code) => {
if (code) process.exit(code);
resolve(out)
})
})
}
async function checkVersion(name, required, cfg) {
if (!cfg) { cfg = {} }
let version = await runRead(name,['--version'])
version = version.trim()
if (cfg.preprocess) { version = cfg.preprocess(version) } if (cfg.silent !== true) {
console.log(`Checking '${name}' version.`)
}
if (version != required) {
throw `[ERROR] The '${name}' version '${version}' does not match the required one '${required}'.`
}
}
function runSync(cmd, args) {
console.log(`Executing '${cmd} ${args.join(' ')}'`)
let proc = spawnSync(cmd, args, {stdio: 'inherit', shell: true})
if (proc.status != 0) {
process.exit(proc.code)
2020-07-03 16:42:45 +03:00
}
}
function testLibrary() {
cwd = process.cwd()
console.log(`In directory ${cwd}`)
if (cwd.endsWith('macros')) {
containedDirs = fss.readdirSync(path.join(cwd, '..'), {withFileTypes: true})
.filter(f => f.isDirectory())
.map(d => d.name)
2020-07-03 16:42:45 +03:00
if (containedDirs.includes(libImplDirName)) return
2020-07-03 16:42:45 +03:00
}
runSync('wasm-pack', ['test', '--node'])
}
async function withCwd(dir, fn) {
let cwd = path.dirname(__filename)
process.chdir(dir)
let out = await fn()
process.chdir(cwd)
return out
}
function testWasm() {
let rootDir = path.join(path.dirname(__filename), '..')
2020-07-03 16:42:45 +03:00
content = fss.readFileSync(path.join(rootDir, 'Cargo.toml'), {encoding: 'utf-8'})
content = content.replace(/\s+|"/g, '')
members = content.split('members')[1].split('[')[1].split(']')[0]
dirs = members.split(',').filter(d => d != '').map(d => path.join(rootDir, d))
2020-07-03 16:42:45 +03:00
dirs.forEach(d => withCwd(d, testLibrary))
}
async function main() {
await checkVersion("node", nodeJsVersion, { silent: true })
await checkVersion('rustc', rustcVersion, {
preprocess:(v) => v.substring(6,20), silent:true
})
if (args.includes('--test-wasm')) {
testWasm()
}
}
main()