| #!/bin/bash |
| # Copyright 2026 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. |
| |
| readonly GIT_CITC_PATH="$(which git-citc)" |
| readonly COG_FUCHSIA_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/../..")" |
| readonly CARTFS_FUCHSIA_DIR="${COG_FUCHSIA_DIR}/cartfs-dir/fuchsia" |
| |
| set -e |
| |
| if [[ ! -e "${CARTFS_FUCHSIA_DIR}" ]]; then |
| echo "Error: unable to find the cartfs symlink. Run the setup script to fix this." |
| exit 1 |
| fi |
| |
| # Compute the base commit hash |
| base_commit_hash=$("${GIT_CITC_PATH}" api.get-repo-states fuchsia | grep base_commit_hash | awk '{print $2}' | tr -d '"') |
| base_commit_hash_in_cartfs=$(cd "${CARTFS_FUCHSIA_DIR}" && git rev-parse HEAD) |
| |
| # if the base commit hash is different from the one in CartFS, then we need to |
| # update the CartFS. |
| if [[ "${base_commit_hash}" != "${base_commit_hash_in_cartfs}" ]]; then |
| echo "Updating CartFS to base commit hash ${base_commit_hash}..." |
| "${COG_FUCHSIA_DIR}/scripts/cog/setup_cog_workspace.py" |
| fi |
| |
| diff_output=$("${GIT_CITC_PATH}" cli.diff "${base_commit_hash}" @) |
| |
| # Copy over any added or modified files to the CartFS. |
| added_or_modified_files=$(echo "${diff_output}" | grep '^\[[AM]\]' | awk '{print $2}') |
| for file in ${added_or_modified_files[@]}; do |
| sha256_cog=$(sha256sum "${COG_FUCHSIA_DIR}/${file}" | awk '{print $1}') |
| sha256_cartfs="" |
| if [[ -f "${CARTFS_FUCHSIA_DIR}/${file}" ]]; then |
| sha256_cartfs=$(sha256sum "${CARTFS_FUCHSIA_DIR}/${file}" | awk '{print $1}') |
| fi |
| if [[ "${sha256_cog}" != "${sha256_cartfs}" ]]; then |
| cp "${COG_FUCHSIA_DIR}/${file}" "${CARTFS_FUCHSIA_DIR}/${file}" |
| fi |
| done |
| |
| # Delete files in CartFS |
| deleted_files=$(echo "${diff_output}" | grep '^\[D\]' | awk '{print $2}') |
| for file in ${deleted_files[@]}; do |
| if [[ -f "${CARTFS_FUCHSIA_DIR}/${file}" ]]; then |
| rm "${CARTFS_FUCHSIA_DIR}/${file}" |
| fi |
| done |
| |
| command="$1" |
| if [[ "$command" =~ ^(set|build|test|add-test|add-host-test|set-main-pb|args)$ ]]; then |
| # We need to run this here to make sure that the PATH is updated with the |
| # prebuilts in the CartFS. If we do not do this then we will pick up the wrong |
| # hermetic-env. |
| source "${CARTFS_FUCHSIA_DIR}/scripts/fx-env.sh" && fx-update-path |
| ( |
| cd "${CARTFS_FUCHSIA_DIR}" |
| exec "${CARTFS_FUCHSIA_DIR}/scripts/fx" "$@" |
| ) |
| else |
| exec "${COG_FUCHSIA_DIR}/scripts/fx" "$@" |
| fi |