Skip to content

Commit

Permalink
feat(CLI): Add --test-dir option to test subcommand
Browse files Browse the repository at this point in the history
Enables running ctest from a subdirectory of the build tree.

Also improve flag documentation.

Remove unused wasmtime-pwd.sh

This is in the dockcross image.
  • Loading branch information
thewtex committed Mar 15, 2023
1 parent 278324c commit 02901c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 0 additions & 4 deletions src/docker/itk-wasm-base/wasmtime-pwd.sh

This file was deleted.

16 changes: 10 additions & 6 deletions src/itk-wasm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ function build(options) {
function test(options) {
const { buildDir, dockcrossScript } = processCommonOptions(true)

const testDir = options.testDir ?? '.'
const ctestTestDir = `${buildDir}/${testDir}`

const hyphenIndex = program.rawArgs.findIndex((arg) => arg === '--')
let ctestArgs = []
if (hyphenIndex !== -1) {
ctestArgs = program.rawArgs.slice(hyphenIndex + 1)
}
if(process.platform === "win32"){
var dockerBuild = spawnSync('"C:\\Program Files\\Git\\bin\\sh.exe"',
["--login", "-i", "-c", `"${buildDir}/itk-wasm-build-env ctest --test-dir ${buildDir} ` + ctestArgs + '"'], {
["--login", "-i", "-c", `"${buildDir}/itk-wasm-build-env ctest --test-dir ${ctestTestDir} ` + ctestArgs + '"'], {
env: process.env,
stdio: 'inherit',
shell: true
Expand All @@ -160,9 +163,9 @@ function test(options) {
}
process.exit(dockerBuild.status);
} else {
const dockerBuild = spawnSync('bash', [dockcrossScript, 'ctest', '--test-dir', buildDir].concat(ctestArgs), {
const dockerBuild = spawnSync('bash', [dockcrossScript, 'ctest', '--test-dir', ctestTestDir].concat(ctestArgs), {
env: process.env,
stdio: 'inherit'
stdio: 'inherit',
})
if (dockerBuild.status !== 0) {
console.error(dockerBuild.error);
Expand Down Expand Up @@ -192,7 +195,7 @@ function run(wasmBinary, options) {
let wasmRuntimeArgs = []
switch (wasmRuntime) {
case 'wasmtime':
wasmRuntimeArgs = ['--args', '-e WasmTIME_BACKTRACE_DETAILS=1', '/wasi-runtimes/wasmtime/bin/wasmtime-pwd.sh',]
wasmRuntimeArgs = ['--args', '-e WASMTIME_BACKTRACE_DETAILS=1', '/wasi-runtimes/wasmtime/bin/wasmtime-pwd.sh',]
break
case 'wasmer':
wasmRuntimeArgs = ['sudo', '/wasi-runtimes/wasmer/bin/wasmer-pwd.sh',]
Expand Down Expand Up @@ -258,16 +261,17 @@ function bindgen(options) {
}

program
.option('-i, --image <image>', 'build environment Docker image, defaults to itkwasm/emscripten')
.option('-i, --image <image>', 'build environment Docker image, defaults to itkwasm/emscripten -- another common image is itkwasm/wasi')
.option('-s, --source-dir <source-directory>', 'path to source directory, defaults to "."')
.option('-b, --build-dir <build-directory>', 'build directory whose path is relative to the source directory, defaults to "emscripten-build"')
.option('-b, --build-dir <build-directory>', 'build directory whose path is relative to the source directory, defaults to "wasi-build" for the "itkwasm/wasi" image and "emscripten-build"i otherwise')
program
.command('build')
.usage('[-- <cmake arguments>]')
.description('build the CMake project found in the source directory')
.action(build)
program
.command('test')
.option('-t, --test-dir <test-dir>', 'Subdirectory to run ctest in relative to the build directory.')
.usage('[-- <ctest arguments>]')
.description('Run the tests for the CMake project found in the build directory')
.action(test)
Expand Down

0 comments on commit 02901c8

Please sign in to comment.