blob: 3806b51f6fbaff7011936ad43f7d05253b7d1d64 [file] [log] [blame]
#!/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.
#### CATEGORY=Build
### add a GN label to args.gn and regen
## usage: fx add-test //foo/bar //foo/baz
##
## Adds the labels to `developer_test_labels` and regen.
## This is useful when `fx test` tells you to add a target to the build,
## but you have some custom args set in `args.gn`, so do not want to run
## `fx set` to overwrite those args.
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
source "$SCRIPT_DIR/../lib/vars.sh" || exit $?
fx-config-read
set -e
# Cache args in case of typos, bad paths, etc.
args_gn="${FUCHSIA_BUILD_DIR}/args.gn"
backup_args_gn="$(mktemp --suffix=.args.gn)"
cp "${args_gn}" "${backup_args_gn}"
echo "Adding test labels to ${args_gn}"
for arg in "$@"; do
if [ "$arg" == "--with" ]; then
# Skip the '--with' argument, which is included in some error messages
continue
fi
# Append the formatted string to args.gn
echo "developer_test_labels += [\"$arg\"]" >> "$args_gn"
done
echo "Generating Ninja outputs file"
if ! fx-gen; then
echo "fx gen failed, restoring original args.gn and re-running 'fx gen'"
cp "${backup_args_gn}" "${args_gn}"
fx-gen
fi
rm -f "${backup_args_gn}"