Primiano Tucci | 7e9865c | 2021-01-10 23:55:15 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2021 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -e -u |
| 17 | |
| 18 | # Note: this script is both executed standalone via tools/node and |
| 19 | # sourced by tools/npm. |
| 20 | |
| 21 | ROOT_DIR="$(dirname $(cd -P ${BASH_SOURCE[0]%/*}; pwd))" |
| 22 | |
| 23 | if [ "$(uname -s)" == "Darwin" ]; then |
| 24 | readonly NODE_DIR="$ROOT_DIR/buildtools/mac/nodejs" |
| 25 | else |
| 26 | readonly NODE_DIR="$ROOT_DIR/buildtools/linux64/nodejs" |
| 27 | fi |
| 28 | |
| 29 | if [ ! -e "$NODE_DIR" ]; then |
| 30 | echo 'Could not find Node.js hermetic installation. Please run:' |
| 31 | echo 'tools/install-build-deps --ui' |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | exec_node() { |
| 36 | # Rationale for adding $ROOT_DIR/tools: some packages (notably protobufjs) |
| 37 | # have the bad habit of executing "npm install ..." at runtime on the first |
| 38 | # run. That will pick whatever "npm" is in the PATH which might be strongly |
| 39 | # different than ours in /buildtools. |
| 40 | export PATH="$NODE_DIR/bin:$ROOT_DIR/tools:$PATH" |
Hector Dearman | f451ee6 | 2023-08-07 16:56:24 +0100 | [diff] [blame] | 41 | export NODE_OPTIONS="--max_old_space_size=8192 ${NODE_OPTIONS:-}" |
Primiano Tucci | 7e9865c | 2021-01-10 23:55:15 +0100 | [diff] [blame] | 42 | exec node "$@" |
| 43 | } |
| 44 | |
| 45 | # If the script is sourced (from //tools/npm) stop here. Otherwise run node. |
| 46 | if [ "$0" == "${BASH_SOURCE[0]}" ]; then |
| 47 | exec_node "$@" |
| 48 | fi |