Skip to content

Commit c88612d

Browse files
authored
Fix activated_path_skip on repeated running of emsdk_env.sh (#1250)
The first time around `node` was being correctly added to the PATH, but the second time around this code was observing the emsdk copy of node in the PATH and assuming it could be skipped. Fixes: #1240
1 parent 098a3ff commit c88612d

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
- run:
8181
name: Install debian packages
8282
command: apt-get update -q && apt-get install -q -y cmake build-essential openjdk-8-jre-headless ksh zsh
83+
- run: test/test_node_path.sh
8384
- run: test/test.sh
8485
- run: test/test_source_env.sh
8586
- run:

emsdk.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,9 +1438,18 @@ def get_required_path(active_tools):
14381438
path_add = [to_native_path(EMSDK_PATH)]
14391439
for tool in active_tools:
14401440
if hasattr(tool, 'activated_path'):
1441-
if hasattr(tool, 'activated_path_skip') and which(tool.activated_path_skip):
1442-
continue
14431441
path = to_native_path(tool.expand_vars(tool.activated_path))
1442+
# If the tool has an activated_path_skip attribute then we don't add
1443+
# the tools path to the users path if a program by that name is found
1444+
# in the existing PATH. This allows us to, for example, add our version
1445+
# node to the users PATH if, and only if, they don't already have a
1446+
# another version of node in thier PATH.
1447+
if hasattr(tool, 'activated_path_skip'):
1448+
current_path = which(tool.activated_path_skip)
1449+
# We found an executable by this name in the current PATH, but we
1450+
# ignore our own version for this purpose.
1451+
if current_path and os.path.dirname(current_path) != path:
1452+
continue
14441453
path_add.append(path)
14451454
return path_add
14461455

test/test_node_path.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Test that node is added to that PATH if, and only if, it is not one already present".
4+
5+
if [ -n "$EMSDK" ]; then
6+
echo "EMSDK is already defined in this shell. Run tests in a shell without sourcing emsdk_env.sh first"
7+
exit 1
8+
fi
9+
10+
DIR=$(dirname "$BASH_SOURCE")
11+
cd $DIR/..
12+
13+
./emsdk install latest
14+
./emsdk activate latest
15+
16+
if which node; then
17+
echo "Test should be run without node in the path"
18+
exit 1
19+
fi
20+
21+
# Run emsdk_env.sh and confirm that node was added to the PATH
22+
. emsdk_env.sh
23+
24+
if ! which node; then
25+
echo "node not found in path after emsdk_env.sh"
26+
exit 1
27+
fi
28+
29+
# Run emsdk_env.sh again and confirm that node is still in the PATH
30+
. emsdk_env.sh
31+
32+
if ! which node; then
33+
echo "node not found in path after emsdk_env.sh"
34+
exit 1
35+
fi

0 commit comments

Comments
 (0)