|
16 | 16 | set -e |
17 | 17 |
|
18 | 18 | # Launcher for NodeJS applications. |
19 | | -# Find our runfiles tree. We need this to launch node with the correct |
| 19 | +# Find our runfiles manifest. We need this to launch node with the correct |
20 | 20 | # entry point. |
21 | 21 | # |
22 | 22 | # Call this program X. X was generated by a genrule and may be invoked |
23 | 23 | # in many ways: |
24 | 24 | # 1a) directly by a user, with $0 in the output tree |
25 | 25 | # 1b) via 'bazel run' (similar to case 1a) |
26 | | -# 2) directly by a user, with $0 in X's runfiles tree |
| 26 | +# 2) directly by a user, with $0 in X's runfiles manifest |
27 | 27 | # 3) by another program Y which has a data dependency on X, with $0 in Y's |
28 | | -# runfiles tree |
| 28 | +# runfiles manifest |
29 | 29 | # 4a) via 'bazel test' |
30 | 30 | # 4b) case 3 in the context of a test |
31 | 31 | # 5a) by a genrule cmd, with $0 in the output tree |
32 | 32 | # 6a) case 3 in the context of a genrule |
33 | 33 | # |
34 | | -# For case 1, $0 will be a regular file, and the runfiles tree will be |
| 34 | +# For case 1, $0 will be a regular file, and the runfiles manifest will be |
35 | 35 | # at $0.runfiles. |
36 | 36 | # For case 2 or 3, $0 will be a symlink to the file seen in case 1. |
37 | | -# For case 4, $TEST_SRCDIR should already be set to the runfiles tree by |
| 37 | +# For case 4, $TEST_SRCDIR should already be set to the runfiles manifest by |
38 | 38 | # blaze. |
39 | 39 | # Case 5a is handled like case 1. |
40 | 40 | # Case 6a is handled like case 3. |
|
46 | 46 |
|
47 | 47 | if [[ -n "$TEST_SRCDIR" ]]; then |
48 | 48 | # Case 4, bazel has identified runfiles for us. |
49 | | - RUNFILES="$TEST_SRCDIR" |
| 49 | + RUNFILES="${TEST_SRCDIR}_manifest" |
50 | 50 | else |
51 | 51 | while true; do |
52 | 52 | if [[ -e "$self.runfiles" ]]; then |
53 | | - RUNFILES="$self.runfiles" |
| 53 | + RUNFILES="$self.runfiles_manifest" |
54 | 54 | break |
55 | 55 | fi |
56 | 56 |
|
57 | 57 | if [[ $self == *.runfiles/* ]]; then |
58 | | - RUNFILES="${self%%.runfiles/*}.runfiles" |
| 58 | + RUNFILES="${self%%.runfiles/*}.runfiles_manifest" |
59 | 59 | # don't break; this is a last resort for case 6b |
60 | 60 | fi |
61 | 61 |
|
|
92 | 92 | # Note: for debugging it is useful to see what files are actually present, eg: |
93 | 93 | # find . -name thingImLookingFor |
94 | 94 |
|
95 | | -exec "${RUNFILES}/TEMPLATED_node" "${NODE_OPTIONS[@]}" "${RUNFILES}/TEMPLATED_script_path" "${ARGS[@]}" |
| 95 | +# Lookup the real paths from the runfiles manifest with no dependency on posix |
| 96 | +while read line; do |
| 97 | + declare -a PARTS=($line) |
| 98 | + if [ "${PARTS[0]}" == "TEMPLATED_node" ]; then |
| 99 | + readonly node="${PARTS[1]}" |
| 100 | + elif [ "${PARTS[0]}" == "TEMPLATED_script_path" ]; then |
| 101 | + readonly script="${PARTS[1]}" |
| 102 | + fi |
| 103 | +done < ${RUNFILES} |
| 104 | +if [ -z "${node}" ]; then |
| 105 | + echo "Failed to find node binary TEMPLATED_node in manifest ${RUNFILES}" |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | +if [ -z "${script}" ]; then |
| 109 | + echo "Failed to find script TEMPLATED_script_path in manifest ${RUNFILES}" |
| 110 | + exit 1 |
| 111 | +fi |
| 112 | +exec "${node}" "${NODE_OPTIONS[@]}" "${script}" "${ARGS[@]}" |
0 commit comments