| #!/bin/bash |
| |
| # Copyright 2022 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 is used to output the global test manifest which can be consumed |
| # by infra for CI/CQ. |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/common.sh || exit $? |
| |
| help() { |
| echo |
| echo "Script used to output a generated test manifest for a given fuchsia_tests target." |
| echo |
| echo "Usage:" |
| echo " $(basename "$0") fuchsia_tests_target [<options>]" |
| echo |
| echo "Options:" |
| echo |
| echo " fuchsia_test_target" |
| echo " A mandatory label of the fuchsia_tests target to emit the manifest of." |
| echo " --help, -h" |
| echo " Prints this help message" |
| echo " --output-base, -o <output_base>" |
| echo " This is a bazel parameter. More about it can be found in" |
| echo " https://docs.bazel.build/versions/main/command-line-reference.html#flag--output_base" |
| echo |
| } |
| |
| emit_test_manifest() { |
| MANIFEST=$(run_bazel cquery --output starlark --starlark:expr "target.files.to_list()[0].path" $1 2>/dev/null) |
| if [ ! -f "$MANIFEST" ]; then |
| echo "Unable to read $MANIFEST" |
| echo "Did you build that target yet?" |
| exit 1 |
| fi |
| cat $MANIFEST |
| } |
| |
| main() { |
| for arg in "$@"; do |
| if [[ "$#" > 0 ]]; then |
| case $1 in |
| -h|--help) |
| help |
| exit 1 |
| ;; |
| --output_base|-o) |
| OUTPUT_BASE="${2}" |
| shift |
| ;; |
| *) |
| if [ -n "${TEST_TARGET}" ]; then |
| echo "Error: Exactly 1 fuchsia_tests_target can be specified." |
| help |
| exit 1 |
| fi |
| TEST_TARGET="${arg}" |
| ;; |
| esac |
| shift |
| fi |
| done |
| if [ -z "${TEST_TARGET}" ]; then |
| echo "Error: No fuchsia_tests_target specified." |
| help |
| exit 1 |
| fi |
| |
| emit_test_manifest $TEST_TARGET |
| } |
| |
| main "$@" |