Update examples collection

This commit is contained in:
github-actions[bot]
2025-08-19 09:15:28 +00:00
parent 8bc9f30d87
commit 87d3066428
130 changed files with 21502 additions and 0 deletions

View File

@ -0,0 +1,7 @@
:: equivalent of test.sh as windows bat file
set PATH=%PATH%;%PYTHON_BIN%
CALL emsdk install latest
CALL emsdk activate latest
CALL emsdk_env.bat
CALL python -c "import sys; print(sys.executable)"
CALL emcc.bat -v

View File

@ -0,0 +1,279 @@
#!/usr/bin/env python3
import json
import os
import platform
import shutil
import subprocess
import sys
import tempfile
import unittest
WINDOWS = sys.platform.startswith('win')
MACOS = sys.platform == 'darwin'
MACOS_ARM64 = MACOS and platform.machine() == 'arm64'
emconfig = os.path.abspath('.emscripten')
assert os.path.exists(emconfig)
upstream_emcc = os.path.join('upstream', 'emscripten', 'emcc')
emsdk = './emsdk'
if WINDOWS:
upstream_emcc += '.bat'
emsdk = 'emsdk.bat'
else:
emsdk = './emsdk'
# Utilities
def listify(x):
if type(x) in {list, tuple}:
return x
return [x]
def check_call(cmd, **args):
if type(cmd) is not list:
cmd = cmd.split()
print('running: %s' % cmd)
args['universal_newlines'] = True
subprocess.check_call(cmd, **args)
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None, env=None):
cmd = cmd.split(' ')
print('running: %s' % cmd)
try:
stdout = subprocess.check_output(cmd, stderr=stderr, universal_newlines=True, env=env)
except subprocess.CalledProcessError as e:
print(e.stderr)
print(e.stdout)
raise e
if expected:
for x in listify(expected):
assert x in stdout, 'expected output missing: ' + stdout + '\n[[[' + x + ']]]'
if unexpected:
for x in listify(unexpected):
assert x not in stdout, 'unexpected output present: ' + stdout + '\n[[[' + x + ']]]'
def failing_call_with_output(cmd, expected, env=None):
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env)
stdout, stderr = proc.communicate()
if WINDOWS:
print('warning: skipping part of failing_call_with_output() due to error codes not being propagated (see #592)')
else:
assert proc.returncode, 'call must have failed: ' + str([stdout, '\n========\n', stderr])
assert expected in stdout or expected in stderr, 'call did not have the expected output: %s: %s' % (expected, str([stdout, '\n========\n', stderr]))
def hack_emsdk(marker, replacement):
with open('emsdk.py') as f:
src = f.read()
assert marker in src
src = src.replace(marker, replacement)
name = '__test_emsdk'
with open(name, 'w') as f:
f.write(src)
return name
# Set up
TAGS = json.loads(open('emscripten-releases-tags.json').read())
# Tests
def do_lib_building(emcc):
cache_building_messages = ['generating system library: ']
def do_build(args, is_expected=None):
unexpected = None
expected = None
if is_expected is True:
expected = cache_building_messages
elif is_expected is False:
unexpected = cache_building_messages
checked_call_with_output(emcc + ' hello_world.c' + args,
expected=expected,
unexpected=unexpected,
stderr=subprocess.STDOUT)
# The emsdk ships all system libraries so we don't expect to see any
# cache population unless we explicly --clear-cache.
do_build('', is_expected=False)
check_call(emcc + ' --clear-cache')
do_build(' -O2', is_expected=True)
# Do another build at -O0. In nwers SDK versions this generates
# different libs, but not in older ones so don't assert here.
do_build('')
# Now verify that libs are *not* build
do_build(' -s WASM=0', is_expected=False)
do_build(' -O2 -s WASM=0', is_expected=False)
def run_emsdk(cmd):
if type(cmd) is not list:
cmd = cmd.split()
check_call([emsdk] + cmd)
class Emsdk(unittest.TestCase):
@classmethod
def setUpClass(cls):
with open('hello_world.c', 'w') as f:
f.write('''\
#include <stdio.h>
int main() {
printf("Hello, world!\\n");
return 0;
}
''')
def setUp(self):
run_emsdk('install latest')
run_emsdk('activate latest')
def test_unknown_arch(self):
env = os.environ.copy()
env['EMSDK_ARCH'] = 'mips'
failing_call_with_output(emsdk + ' install latest',
expected='unknown machine architecture: mips',
env=env)
def test_wrong_bitness(self):
env = os.environ.copy()
env['EMSDK_ARCH'] = 'x86'
failing_call_with_output(emsdk + ' install sdk-latest-64bit',
expected='is only provided for 64-bit OSe',
env=env)
def test_already_installed(self):
# Test we don't re-download unnecessarily
checked_call_with_output(emsdk + ' install latest', expected='already installed', unexpected='Downloading:')
def test_list(self):
# Test we report installed tools properly. The latest version should be
# installed, but not some random old one.
checked_call_with_output(emsdk + ' list', expected=TAGS['aliases']['latest'] + ' INSTALLED', unexpected='1.39.15 INSTALLED:')
def test_config_contents(self):
print('test .emscripten contents')
with open(emconfig) as f:
config = f.read()
assert 'upstream' in config
def test_lib_building(self):
print('building proper system libraries')
do_lib_building(upstream_emcc)
def test_redownload(self):
print('go back to using upstream')
run_emsdk('activate latest')
# Test the normal tools like node don't re-download on re-install
print('another install must re-download')
checked_call_with_output(emsdk + ' uninstall node-22.16.0-64bit')
checked_call_with_output(emsdk + ' install node-22.16.0-64bit', expected='Downloading:', unexpected='already installed')
checked_call_with_output(emsdk + ' install node-22.16.0-64bit', unexpected='Downloading:', expected='already installed')
def test_tot_upstream(self):
print('test update-tags')
run_emsdk('update-tags')
print('test tot-upstream')
run_emsdk('install tot-upstream')
with open(emconfig) as f:
config = f.read()
run_emsdk('activate tot-upstream')
with open(emconfig + '.old') as f:
old_config = f.read()
self.assertEqual(config, old_config)
# TODO; test on latest as well
check_call(upstream_emcc + ' hello_world.c')
def test_closure(self):
# Specifically test with `--closure` so we know that node_modules is working
check_call(upstream_emcc + ' hello_world.c --closure=1')
def test_specific_version(self):
if MACOS_ARM64:
self.skipTest('Old sdk versions do not have ARM64 binaries')
print('test specific release (new, short name)')
run_emsdk('install 1.38.33')
print('another install, but no need for re-download')
checked_call_with_output(emsdk + ' install 1.38.33', expected='Skipped', unexpected='Downloading:')
run_emsdk('activate 1.38.33')
def test_specific_version_full(self):
if MACOS_ARM64:
self.skipTest('Old sdk versions do not have ARM64 binaries')
print('test specific release (new, full name)')
run_emsdk('install sdk-1.38.33-64bit')
run_emsdk('activate sdk-1.38.33-64bit')
print('test specific release (new, tag name)')
run_emsdk('install sdk-tag-1.38.33-64bit')
run_emsdk('activate sdk-tag-1.38.33-64bit')
def test_binaryen_from_source(self):
if MACOS:
self.skipTest("https://github.com/WebAssembly/binaryen/issues/4299")
print('test binaryen source build')
run_emsdk(['install', '--build=Release', '--generator=Unix Makefiles', 'binaryen-main-64bit'])
def test_no_32bit(self):
print('test 32-bit error')
emsdk_hacked = hack_emsdk('not is_os_64bit()', 'True')
failing_call_with_output('%s %s install latest' % (sys.executable, emsdk_hacked),
'this tool is only provided for 64-bit OSes')
os.remove(emsdk_hacked)
def test_update_no_git(self):
print('test non-git update')
temp_dir = tempfile.mkdtemp()
for filename in os.listdir('.'):
if not filename.startswith('.') and not os.path.isdir(filename):
shutil.copy2(filename, os.path.join(temp_dir, filename))
olddir = os.getcwd()
try:
os.chdir(temp_dir)
run_emsdk('update')
print('second time')
run_emsdk('update')
finally:
os.chdir(olddir)
def test_install_arbitrary(self):
# Test that its possible to install arbrary emscripten-releases SDKs
run_emsdk('install 1b7f7bc6002a3ca73647f41fc10e1fac7f06f804')
# Check that its not re-downloaded
checked_call_with_output(emsdk + ' install 1b7f7bc6002a3ca73647f41fc10e1fac7f06f804', expected='Skipped', unexpected='Downloading:')
def test_install_tool(self):
# Test that its possible to install emscripten as tool instead of SDK
checked_call_with_output(emsdk + ' install releases-77b065ace39e6ab21446e13f92897f956c80476a', unexpected='Installing SDK')
def test_activate_missing(self):
run_emsdk('install latest')
failing_call_with_output(emsdk + ' activate 2.0.1', expected="error: tool is not installed and therefore cannot be activated: 'releases-13e29bd55185e3c12802bc090b4507901856b2ba-64bit'")
def test_keep_downloads(self):
env = os.environ.copy()
env['EMSDK_KEEP_DOWNLOADS'] = '1'
# With EMSDK_KEEP_DOWNLOADS the downloading should happen on the first
# install of 2.0.28, and again when we install 2.0.29, but not on the
# second install of 2.0.28 because the zip should already be local.
shutil.rmtree('downloads')
checked_call_with_output(emsdk + ' install 3.1.54', expected='Downloading:', env=env)
checked_call_with_output(emsdk + ' install 3.1.55', expected='Downloading:', env=env)
checked_call_with_output(emsdk + ' install 3.1.54', expected='already downloaded, skipping', unexpected='Downloading:', env=env)
if __name__ == '__main__':
unittest.main(verbosity=2)

View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
echo "test the standard workflow (as close as possible to how a user would do it, in the shell)"
echo "machine: $(uname -m)"
echo "kernel: $(uname -s)"
set -x
set -e
# Test that arbitrary (non-released) versions can be installed and
# activated.
# This test cannot run on linux-arm64 because only certain binaries
# get uploaded for this architecture.
if [[ !($(uname -s) == "Linux" && $(uname -m) == "aarch64") ]]; then
./emsdk install sdk-upstream-1b7f7bc6002a3ca73647f41fc10e1fac7f06f804
./emsdk activate sdk-upstream-1b7f7bc6002a3ca73647f41fc10e1fac7f06f804
source ./emsdk_env.sh
which emcc
emcc -v
fi
# Install an older version of the SDK that requires EM_CACHE to be
# set in the environment, so that we can test it is later removed
# This test only runs on x64 because we didn't build arm binaries
# when this older version of the SDK was built.
if [[ $(uname -m) == "x86_64" ]]; then
./emsdk install sdk-1.39.15
./emsdk activate sdk-1.39.15
source ./emsdk_env.sh
which emcc
emcc -v
test -n "$EM_CACHE"
fi
# Install the latest version of the SDK which is the expected precondition
# of test.py.
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh --build=Release
# Test that EM_CACHE was unset
test -z "$EM_CACHE"
# On mac and windows python3 should be in the path and point to the
# bundled version.
which python3
which emcc
emcc -v

View File

@ -0,0 +1,88 @@
# This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
# and checks if the environment variables and PATH are correctly updated. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
# If no flag is provided the process/shell values are tested. See the CI file for an example.
refreshenv
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
$PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
$PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
$PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
try {
& "$repo_root/emsdk.ps1" install latest
& "$repo_root/emsdk.ps1" activate latest $env:PERMANENT_FLAG $env:SYSTEM_FLAG
if ($env:SYSTEM_FLAG) {
$env_type = "Machine"
}
elseif ($env:PERMANENT_FLAG) {
$env_type = "User"
} else {
$env_type = "Process"
}
$EMSDK = [System.Environment]::GetEnvironmentVariable("EMSDK", $env_type)
$EMSDK_NODE = [System.Environment]::GetEnvironmentVariable("EMSDK_NODE", $env_type)
$EMSDK_PYTHON = [System.Environment]::GetEnvironmentVariable("EMSDK_PYTHON", $env_type)
$PATH = [System.Environment]::GetEnvironmentVariable("PATH", $env_type)
if (!$EMSDK) {
throw "EMSDK is not set for the user"
}
if (!$EMSDK_NODE) {
throw "EMSDK_NODE is not set for the user"
}
if (!$EMSDK_PYTHON) {
throw "EMSDK_PYTHON is not set for the user"
}
$path_split = $PATH.Split(';')
$EMSDK_Path = $path_split | Where-Object { $_ -like "$repo_root*" }
if (!$EMSDK_Path) {
throw "No path is added!"
}
$EMSDK_UPSTREAM_Path = $path_split | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
if (!$EMSDK_UPSTREAM_Path) {
throw "$repo_root\\upstream\emscripten is not added to path."
}
}
finally {
# Recover pre-split PATH
refreshenv
[Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
try {
[Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
}
catch {}
[Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
# Recover pre activation env variables
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
try {
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
} catch {}
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
refreshenv
}

View File

@ -0,0 +1,30 @@
$ErrorActionPreference = 'Stop'
Set-Location bazel
bazel build //hello-world:hello-world-wasm
if (-not $?) { Exit $LastExitCode }
bazel build //hello-world:hello-world-wasm-simd
if (-not $?) { Exit $LastExitCode }
Set-Location test_external
bazel build //:hello-world-wasm
if (-not $?) { Exit $LastExitCode }
bazel build //long_command_line:long_command_line_wasm
if (-not $?) { Exit $LastExitCode }
bazel build //:hello-embind-wasm --compilation_mode dbg # debug
if (-not $?) { Exit $LastExitCode }
# Test use of the closure compiler
bazel build //:hello-embind-wasm --compilation_mode opt # release
if (-not $?) { Exit $LastExitCode }
Set-Location ..\test_secondary_lto_cache
bazel build //:hello-world-wasm
if (-not $?) { Exit $LastExitCode }

View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
echo "test bazel"
set -x
set -e
# Get the latest version number from emscripten-releases-tag.json.
VER=$(scripts/get_release_info.py emscripten-releases-tags.json latest)
# Based on the latest version number, get the commit hash for that version.
HASH=$(scripts/get_release_info.py emscripten-releases-tags.json hash ${VER})
FAILMSG="!!! scripts/update_bazel_workspace.py needs to be run !!!"
# Ensure the WORKSPACE file is up to date with the latest version.
grep ${VER} bazel/revisions.bzl || (echo ${FAILMSG} && false)
grep ${HASH} bazel/revisions.bzl || (echo ${FAILMSG} && false)
grep ${VER} bazel/MODULE.bazel || (echo ${FAILMSG} && false)
cd bazel
bazel build //hello-world:hello-world-wasm
bazel build //hello-world:hello-world-wasm-simd
cd test_external
bazel build //:hello-world-wasm
bazel build //long_command_line:long_command_line_wasm
bazel build //:hello-embind-wasm --compilation_mode dbg # debug
# Test use of the closure compiler
bazel build //:hello-embind-wasm --compilation_mode opt # release
# This function should not be minified if the externs file is loaded correctly.
grep "customJSFunctionToTestClosure" bazel-bin/hello-embind-wasm/hello-embind.js
cd ../test_secondary_lto_cache
bazel build //:hello-world-wasm

View File

@ -0,0 +1,31 @@
#!/usr/bin/env bash
echo "test bazel"
set -x
set -e
# Get the latest version number from emscripten-releases-tag.json.
VER=$(scripts/get_release_info.py emscripten-releases-tags.json latest)
# Based on the latest version number, get the commit hash for that version.
HASH=$(scripts/get_release_info.py emscripten-releases-tags.json hash ${VER})
FAILMSG="!!! scripts/update_bazel_workspace.py needs to be run !!!"
# Ensure the WORKSPACE file is up to date with the latest version.
grep ${VER} bazel/revisions.bzl || (echo ${FAILMSG} && false)
grep ${HASH} bazel/revisions.bzl || (echo ${FAILMSG} && false)
grep ${VER} bazel/MODULE.bazel || (echo ${FAILMSG} && false)
cd bazel
bazel build //hello-world:hello-world-wasm
bazel build //hello-world:hello-world-wasm-simd
cd test_external
bazel build //long_command_line:long_command_line_wasm
bazel build //:hello-world-wasm
cd ../test_secondary_lto_cache
bazel build //:hello-world-wasm

View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
echo "Test that node is added to that PATH if, and only if, it is not one already present".
if [ -n "$EMSDK" ]; then
echo "EMSDK is already defined in this shell. Run tests in a shell without sourcing emsdk_env.sh first"
exit 1
fi
DIR=$(dirname "$BASH_SOURCE")
cd $DIR/..
./emsdk install latest
./emsdk activate latest
if which node; then
echo "Test should be run without node in the path"
exit 1
fi
# Run emsdk_env.sh and confirm that node was added to the PATH
. emsdk_env.sh
if ! which node; then
echo "node not found in path after emsdk_env.sh"
exit 1
fi
# Run emsdk_env.sh again and confirm that node is still in the PATH
. emsdk_env.sh
if ! which node; then
echo "node not found in path after emsdk_env.sh"
exit 1
fi

View File

@ -0,0 +1,142 @@
# This test installs emsdk and activates the latest toolchain using `--system` or `--permanent` flags,
# and checks if parts of PATH are lost or overwritten. Set $env:SYSTEM_FLAG and $env:PERMANENT_FLAG to test each.
# If no flag is provided the process/shell values are tested. See the CI file for an example.
refreshenv
$repo_root = [System.IO.Path]::GetDirectoryName((resolve-path "$PSScriptRoot"))
$PATH_USER_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "User")
$PATH_MACHINE_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
$PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
try {
& "$repo_root/emsdk.ps1" install latest
$esc = '--%'
& "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
$PATH_USER = [System.Environment]::GetEnvironmentVariable("PATH", "User")
$PATH_MACHINE = [System.Environment]::GetEnvironmentVariable("PATH", "Machine")
$PATH_Process = [System.Environment]::GetEnvironmentVariable("PATH", "Process")
if ($env:SYSTEM_FLAG) {
echo "--system test............................."
$path_before_arr = $PATH_MACHINE_BEFORE.Split(';')
$path_arr = $PATH_MACHINE.Split(';')
}
elseif ($env:PERMANENT_FLAG) {
echo "--permanent test.........................."
$path_before_arr = $PATH_USER_BEFORE.Split(';')
$path_arr = $PATH_USER.Split(';')
} else {
echo "no flag test (shell/process).............."
$path_before_arr = $PATH_Process_BEFORE.Split(';')
$path_arr = $PATH_Process.Split(';')
}
$EMSDK_Path = $path_arr | Where-Object { $_ -like "$repo_root*" }
$EMSDK_NODE_Path = $path_arr | Where-Object { $_ -like "$repo_root\node*" }
$EMSDK_PYTHON_Path = $path_arr | Where-Object { $_ -like "$repo_root\python*" }
$EMSDK_JAVA_Path = $path_arr | Where-Object { $_ -like "$repo_root\java*" }
$EMSDK_UPSTREAM_Path = $path_arr | Where-Object { $_ -like "$repo_root\upstream\emscripten*" }
$number_of_items = $path_arr.count
[System.Collections.ArrayList]$rest_of_path = @()
Foreach ($item in $path_arr) {
if (
($item -like "$repo_root*") -or
($item -like "$repo_root\node*") -or
($item -like "$repo_root\python*") -or
($item -like "$repo_root\java*") -or
($item -like "$repo_root\upstream\emscripten*")
) {
echo "$item is on the PATH"
}
else {
$rest_of_path.add($item) | Out-Null
}
}
# compare the PATHs before activation and after activation
if (Compare-Object -ReferenceObject $path_before_arr -DifferenceObject $rest_of_path ) {
echo "Old path is ............................."
echo $path_before_arr
echo "Current rest of path is ................."
echo $rest_of_path
throw "some parts of PATH are removed"
}
# Compare the other untouched PATH
if ($env:SYSTEM_FLAG) {
if (Compare-Object -ReferenceObject $PATH_USER_BEFORE.Split(';') -DifferenceObject $PATH_USER.Split(';') ) {
echo "Old user path is ...................."
echo $PATH_USER_BEFORE
echo "Current user path is ................"
echo $PATH_USER
throw "User PATH are changed while --system had been provided"
}
}
elseif ($env:PERMANENT_FLAG) {
if (Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';') ) {
echo "Old machine path is.................."
echo $PATH_MACHINE_BEFORE
echo "Current machine path is.............."
echo $PATH_MACHINE
throw "MACHINE PATH are changed while --system was not provided"
}
} else {
if (
(Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';')) -or
(Compare-Object -ReferenceObject $PATH_MACHINE_BEFORE.Split(';') -DifferenceObject $PATH_MACHINE.Split(';'))
) {
echo "Old machine path is.................."
echo $PATH_MACHINE_BEFORE
echo "Current machine path is.............."
echo $PATH_MACHINE
echo "Old user path is ...................."
echo $PATH_USER_BEFORE
echo "Current user path is ................"
echo $PATH_USER
throw "MACHINE/USER PATH are changed while no flag was provided"
}
}
}
finally {
# Recover pre-split PATH
refreshenv
[Environment]::SetEnvironmentVariable("Path", $PATH_USER_BEFORE, "User")
try {
[Environment]::SetEnvironmentVariable("Path", $PATH_MACHINE_BEFORE, "Machine")
}
catch {}
[Environment]::SetEnvironmentVariable("Path", $PATH_Process_BEFORE, "Process")
# Recover pre activation env variables
[Environment]::SetEnvironmentVariable("EMSDK", $null, "User")
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "User")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "User")
try {
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Machine")
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Machine")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Machine")
} catch {}
[Environment]::SetEnvironmentVariable("EMSDK", $null, "Process")
[Environment]::SetEnvironmentVariable("EMSDK_NODE", $null, "Process")
[Environment]::SetEnvironmentVariable("EMSDK_PYTHON", $null, "Process")
refreshenv
}

View File

@ -0,0 +1,132 @@
#!/usr/bin/env bash
echo "Test ability to source emsdk_env.sh in different shells"
if [ -n "$EMSDK" ]; then
echo "EMSDK is already defined in this shell. Run tests in a shell without sourcing emsdk_env.sh first"
exit 1
fi
DIR=$(dirname "$BASH_SOURCE")
# setup a symlink relative to the current dir
REL_LINK_DIR="$DIR/tmp"
if [ -d "$REL_LINK_DIR" ]; then
rm -rf "$REL_LINK_DIR"
fi
echo "Creating links in $REL_LINK_DIR"
mkdir -p "$REL_LINK_DIR"
(cd $DIR/.. && ln -s `pwd` "$REL_LINK_DIR/emsdk")
(cd $DIR/.. && ln -s `pwd`/emsdk_env.sh "$REL_LINK_DIR")
# setup a symlink in an absolute directory
ABS_LINK_DIR="/tmp/emsdk_env_test"
if [ -d "$ABS_LINK_DIR" ]; then
rm -rf "$ABS_LINK_DIR"
fi
echo "Creating links in $ABS_LINK_DIR"
mkdir -p "$ABS_LINK_DIR"
(cd $DIR/.. && ln -s `pwd` "$ABS_LINK_DIR/emsdk")
(cd $DIR/.. && ln -s `pwd`/emsdk_env.sh "$ABS_LINK_DIR")
PATH1="$DIR/../emsdk_env.sh"
PATH2="$REL_LINK_DIR/emsdk/emsdk_env.sh"
PATH3="$REL_LINK_DIR/emsdk_env.sh"
PATH4="$ABS_LINK_DIR/emsdk/emsdk_env.sh"
PATH5="$ABS_LINK_DIR/emsdk_env.sh"
assert_emcc() {
current=$1
cmd=$2
value=$3
if [ -z "$value" ] || [ "$value" == "false" ]; then
echo "FAILED: $current"
echo " unable to get EMSDK in $current using '$cmd'"
else
echo "SUCCESS: $current testing $cmd"
echo " -> EMSDK = $value"
fi
}
test_bash() {
value=$(bash --rcfile <(echo $1))
assert_emcc bash "$1" "$value"
}
test_zsh() {
value=$(zsh -d -c "$1")
assert_emcc zsh "$1" "$value"
}
test_ksh() {
value=$(ksh -c "$1")
assert_emcc ksh "$1" "$value"
}
it_tests_direct_path() {
TEST_SCRIPT=". ${PATH1}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
TEST_SCRIPT="source ${PATH1}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
}
it_tests_via_relative_dir_symlink() {
TEST_SCRIPT=". ${PATH2}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
TEST_SCRIPT="source ${PATH2}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
}
it_tests_via_relative_file_symlink() {
TEST_SCRIPT=". ${PATH3}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
TEST_SCRIPT="source ${PATH3}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
}
it_tests_via_absolute_dir_symlink() {
TEST_SCRIPT=". ${PATH4}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
TEST_SCRIPT="source ${PATH4}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
}
it_tests_via_absolute_file_symlink() {
TEST_SCRIPT=". ${PATH5}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
TEST_SCRIPT="source ${PATH5}"' >/dev/null 2>&1; if [ -n "$EMSDK" ]; then echo "$EMSDK"; else echo false; fi ; exit'
test_bash "$TEST_SCRIPT"
test_zsh "$TEST_SCRIPT"
test_ksh "$TEST_SCRIPT"
}
run_bash_tests() {
it_tests_direct_path
it_tests_via_relative_dir_symlink
it_tests_via_relative_file_symlink
it_tests_via_absolute_dir_symlink
it_tests_via_absolute_file_symlink
}
run_bash_tests
rm -rf $REL_LINK_DIR
rm -rf $ABS_LINK_DIR