blob: cd898e68eb0cfaac297cc62e9d774aa3492107d8 [file] [log] [blame]
Primiano Tucci7e9865c2021-01-10 23:55:15 +01001#!/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
16set -e -u
17
18# Note: this script is both executed standalone via tools/node and
19# sourced by tools/npm.
20
21ROOT_DIR="$(dirname $(cd -P ${BASH_SOURCE[0]%/*}; pwd))"
22
23if [ "$(uname -s)" == "Darwin" ]; then
24readonly NODE_DIR="$ROOT_DIR/buildtools/mac/nodejs"
25else
26readonly NODE_DIR="$ROOT_DIR/buildtools/linux64/nodejs"
27fi
28
29if [ ! -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
33fi
34
35exec_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 Dearmanf451ee62023-08-07 16:56:24 +010041 export NODE_OPTIONS="--max_old_space_size=8192 ${NODE_OPTIONS:-}"
Primiano Tucci7e9865c2021-01-10 23:55:15 +010042 exec node "$@"
43}
44
45# If the script is sourced (from //tools/npm) stop here. Otherwise run node.
46if [ "$0" == "${BASH_SOURCE[0]}" ]; then
47 exec_node "$@"
48fi