| #!/bin/bash |
| # Copyright 2024 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This script generates the ctf_releases.gni file. It is intended to be |
| # called by a git-hook after prebuilts are downloaded. |
| # |
| # The ctf_releases.gni file is used by the build to determine which |
| # CTF releases were downloaded from CIPD as prebuilts so that they can |
| # be run as tests against the current platform image. |
| |
| set -e |
| |
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" |
| FUCHSIA_DIR="$(dirname $(dirname $(dirname $(dirname "${script_dir}"))))" |
| |
| # The CTF manifest file could be in //integration/fuchsia/ctf/all, |
| # //integration/platform/fuchsia/ctf/all or //integration/ctf/all |
| # depending on the integration repository the user uses. |
| if [[ -f "${FUCHSIA_DIR}/integration/platform/fuchsia/ctf/all" ]]; then |
| CTF_MANIFEST="${FUCHSIA_DIR}/integration/platform/fuchsia/ctf/all" |
| elif [[ -f "${FUCHSIA_DIR}/integration/fuchsia/ctf/all" ]]; then |
| CTF_MANIFEST="${FUCHSIA_DIR}/integration/fuchsia/ctf/all" |
| elif [[ -f "${FUCHSIA_DIR}/integration/ctf/all" ]]; then |
| CTF_MANIFEST="${FUCHSIA_DIR}/integration/ctf/all" |
| else |
| echo "Error: Failed to find CTF manifest file." 1>&2 |
| exit 1 |
| fi |
| |
| DESTINATION="${FUCHSIA_DIR}/sdk/ctf/build/internal/ctf_releases.gni" |
| |
| YEAR=$(date +%Y) |
| |
| echo \ |
| "# Copyright ${YEAR} The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This file is autogenerated by create_ctf_releases_gni.sh |
| # Do not edit manually |
| |
| ctf_releases = [" \ |
| > "${DESTINATION}" |
| |
| echo "Finding CTF releases..." |
| |
| # The CTF integration manifest has one <localimport> tag for each version: |
| # <localimport file="f16"/> |
| # This script looks for all the localimport tags in the file and extracts the |
| # "file" field. |
| # |
| # TODO(liyl): Technically we shouldn't use regex to parse XML. Consider rewriting |
| # it with more robust XML parsing logic. |
| IFS=$'\n' |
| for release in $(grep -Po '(?<=localimport file=").*?(?=")' ${CTF_MANIFEST}); do |
| echo " Have release for ${release}... adding" |
| echo " \"${release}\"," >> "${DESTINATION}" |
| done |
| |
| echo "]" >> "${DESTINATION}" |
| |
| echo "Wrote output to ${DESTINATION}" |