Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate installed emsdk version #2256

Merged
merged 4 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Validate installed emsdk version
  • Loading branch information
tomjakubowski committed Jun 13, 2023
commit 457d65596c9b65f29b38557e3d571b8d869af819
9 changes: 7 additions & 2 deletions scripts/run_emsdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const path = require("path");
try {
const cwd = process.cwd();
const cmd = process.argv.slice(2).join(" ");
const emsdkdir = path.join(__dirname, "..", ".emsdk");
execute_throw`cd ${emsdkdir} && . ./emsdk_env.sh >/dev/null 2>&1 && cd ${cwd} && ${cmd}`;
const scripts = __dirname;
const emsdkdir = path.join(scripts, "..", ".emsdk");
const emversion = require("../package.json").emscripten;
if (!emversion) {
throw new Error("emscripten version not specified in package.json");
}
execute_throw`${scripts}/with_emsdk.sh ${emsdkdir} ${emversion} ${cmd}`;
} catch (e) {
console.log(e.message);
process.exit(1);
Expand Down
40 changes: 40 additions & 0 deletions scripts/with_emsdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# usage: with_emsdk.sh path/to/emsdk <version> [cmd...]

emsdk_path=$1
expected_version=$2
cmd=("${@:3}")

spew_equals_version() {
local spew=$1
local expected=$2
local extracted
extracted=$(echo "$spew" | grep -Eo '\d+\.\d+\.\d+')
[[ "$expected" == "$extracted" ]]
}

selftest() {
local spew="emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.14 (4343cbec72b7db283ea3bda1adc6cb1811ae9a73)"
spew_equals_version "$spew" "3.1.14" || { echo "test failed $LINENO"; exit 1; }
}

if [[ "$1" == "--selftest" ]]
then
selftest
exit
fi

source "$emsdk_path"/emsdk_env.sh >/dev/null 2>&1
version_spew=$(emcc --version 2>&1 | head -n 1)
if spew_equals_version "$version_spew" "$expected_version"
then
"${cmd[@]}"
else
echo "expected emsdk version: $expected_version"
echo "actual emsdk version: $version_spew"
echo "To fix:"
echo " rm -rf .emsdk"
echo " node scripts/install_emsdk.js"
exit 1
fi