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