| #!/bin/bash | |
| # Copyright (C) 2021 The Android Open Source Project | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| set -eu | |
| ROOT_DIR="$(dirname $(dirname $(cd -P ${BASH_SOURCE[0]%/*}; pwd)))" | |
| if [ "$(uname -s)" == "Darwin" ]; then | |
| readonly NODE_DIR="$ROOT_DIR/buildtools/mac/nodejs" | |
| else | |
| readonly NODE_DIR="$ROOT_DIR/buildtools/linux64/nodejs" | |
| fi | |
| if [ ! -e "$NODE_DIR" ]; then | |
| echo 'Could not find Node.js hermetic installation. Please run:' | |
| echo 'tools/install-build-deps --ui' | |
| exit 1 | |
| fi | |
| # cd into the //infra/perfetto.dev dir, so this works uniformely when invoked by | |
| # other paths. the cd is required for npm install. | |
| cd -P ${BASH_SOURCE[0]%/*} | |
| # Ensure that `pnpm` has been called and is current. Note that the set of | |
| # packages that the docs website requires is != the UI ones. | |
| if ! test node_modules/.stamp -nt pnpm-lock.yaml; then | |
| export PATH="$NODE_DIR/bin:$ROOT_DIR/tools:$PATH" | |
| ../../tools/pnpm install --shamefully-hoist --frozen-lockfile | |
| touch node_modules/.stamp | |
| fi | |
| # Exit code 75 means "sources changed, re-exec me" (see EXIT_RESTART in | |
| # build.mjs). Re-execing from here rather than from node keeps Ctrl-C working | |
| # and avoids stacking up one parent process per edit. | |
| while true; do | |
| set +e | |
| ../../tools/node ./src/build.mjs "$@" | |
| readonly_code=$? | |
| set -e | |
| if [ $readonly_code -ne 75 ]; then | |
| exit $readonly_code | |
| fi | |
| done |