|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | +# Shell script to update perfetto in the source tree to specific version |
| 4 | + |
| 5 | +BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) |
| 6 | +DEPS_DIR="$BASE_DIR/deps" |
| 7 | + |
| 8 | +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" |
| 9 | +[ -x "$NODE" ] || NODE=$(command -v node) |
| 10 | + |
| 11 | +# shellcheck disable=SC1091 |
| 12 | +. "$BASE_DIR/tools/dep_updaters/utils.sh" |
| 13 | + |
| 14 | +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' |
| 15 | +const res = await fetch('https://api.github.com/repos/google/perfetto/releases/latest', |
| 16 | + process.env.GITHUB_TOKEN && { |
| 17 | + headers: { |
| 18 | + "Authorization": `Bearer ${process.env.GITHUB_TOKEN}` |
| 19 | + }, |
| 20 | + }); |
| 21 | +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); |
| 22 | +const { tag_name } = await res.json(); |
| 23 | +console.log(tag_name.replace('v', '')); |
| 24 | +EOF |
| 25 | +)" |
| 26 | + |
| 27 | +CURRENT_VERSION=$(cat ./deps/perfetto/VERSION) |
| 28 | + |
| 29 | +# This function exit with 0 if new version and current version are the same |
| 30 | +compare_dependency_version "perfetto" "$NEW_VERSION" "$CURRENT_VERSION" |
| 31 | + |
| 32 | +echo "Making temporary workspace" |
| 33 | + |
| 34 | +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') |
| 35 | + |
| 36 | +cleanup () { |
| 37 | + EXIT_CODE=$? |
| 38 | + [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" |
| 39 | + exit $EXIT_CODE |
| 40 | +} |
| 41 | + |
| 42 | +trap cleanup INT TERM EXIT |
| 43 | + |
| 44 | +PERFETTO_REF="v$NEW_VERSION" |
| 45 | +PERFETTO_SDK_ZIP="perfetto-cpp-sdk-src.zip" |
| 46 | + |
| 47 | +cd "$WORKSPACE" |
| 48 | + |
| 49 | +echo "Fetching perfetto sdk archive" |
| 50 | +curl -sL -o "$PERFETTO_SDK_ZIP" "https://github.com/google/perfetto/releases/download/$PERFETTO_REF/$PERFETTO_SDK_ZIP" |
| 51 | + |
| 52 | +echo "Unpacking archive" |
| 53 | +mkdir -p perfetto/sdk |
| 54 | +unzip -d perfetto/sdk "$PERFETTO_SDK_ZIP" |
| 55 | +rm "$PERFETTO_SDK_ZIP" |
| 56 | +echo "$NEW_VERSION" > perfetto/VERSION |
| 57 | +curl -sL -o "perfetto/LICENSE" "https://raw.githubusercontent.com/google/perfetto/refs/tags/$PERFETTO_REF/LICENSE" |
| 58 | + |
| 59 | +# Remove C API headers. Only keep C++ API headers. |
| 60 | +rm perfetto/sdk/perfetto_c.h perfetto/sdk/perfetto_c.cc |
| 61 | + |
| 62 | +echo "Copying existing gyp files" |
| 63 | +cp "$DEPS_DIR/perfetto/perfetto.gyp" "$WORKSPACE/perfetto" |
| 64 | + |
| 65 | +echo "Copying existing GN files" |
| 66 | +cp "$DEPS_DIR/perfetto/"*.gn "$DEPS_DIR/perfetto/"*.gni "$WORKSPACE/perfetto" |
| 67 | + |
| 68 | +echo "Replacing existing perfetto" |
| 69 | +rm -rf "$DEPS_DIR/perfetto" |
| 70 | +mv "$WORKSPACE/perfetto" "$DEPS_DIR/" |
| 71 | + |
| 72 | +# Update the version number on maintaining-dependencies.md |
| 73 | +# and print the new version as the last line of the script as we need |
| 74 | +# to add it to $GITHUB_ENV variable |
| 75 | +finalize_version_update "perfetto" "$NEW_VERSION" |
0 commit comments