blob: ca9a7f7f49c432d62096e901967d56b3ebf72c5a [file] [log] [blame]
c-parsons166ff5e2019-09-11 12:04:15 -04001#!/usr/bin/env bash
2# Copyright 2019 The Bazel Authors. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Renerates most Stardoc golden files for Stardoc golden tests.
17#
18# When run, every golden file which is changed as a result of this script should
19# be manually examined and *heavily* scrutinized, as this usually indicates a large
20# in-place change of core rendering functionality of Stardoc.
21
22set -eu
23
Alexandre Rostovtsevf8fab822023-07-24 21:43:33 -040024function run_buildozer () {
25 # buildozer uses return code 3 to signal a no-op, so we can't use "set -e"
26 set +e
27 buildozer "$@"
28 ret=$?
29 set -e
30 if [[ $ret != 0 && $ret != 3 ]]; then
31 return $ret
32 fi
33}
34
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040035function update_non_manual_tests () {
36 echo "** Querying for non-manual tests..."
37 regenerate $(${BAZEL} query "kind(sh_binary, //test:all) - attr(tags, manual, //test:all)" | grep _regenerate)
38}
39
40function update_manual_tests_with_tag () {
41 local manual_tag="$1"; shift
Fabian Meumertzheim018dee52024-06-18 22:34:12 +020042 echo "** Querying for tests tagged \"${manual_tag}\", \"manual\" using 'USE_BAZEL_VERSION=${USE_BAZEL_VERSION:-} ${BAZEL}' $@ ..."
43 BUILD_FLAGS="$@" regenerate $(${BAZEL} query "attr(tags, ${manual_tag}, attr(tags, manual, kind(sh_binary, //test:all)))" | grep _regenerate)
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040044}
45
46function regenerate () {
47 echo "** Regenerating and copying goldens..."
Fabian Meumertzheim018dee52024-06-18 22:34:12 +020048 local run_cmd="run ${BUILD_FLAGS:-}"
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040049 for regen_target in $@; do
Fabian Meumertzheim018dee52024-06-18 22:34:12 +020050 if [[ -z ${USE_BAZEL_VERSION:-} ]]; then
51 echo "** Running '${BAZEL} ${run_cmd} ${regen_target}' ..."
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040052 else
Fabian Meumertzheim018dee52024-06-18 22:34:12 +020053 echo "** Running 'USE_BAZEL_VERSION=${USE_BAZEL_VERSION} ${BAZEL} ${run_cmd} ${regen_target}' BAZEL_BUILD_FLAGS ..."
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040054 fi
Fabian Meumertzheim018dee52024-06-18 22:34:12 +020055 ${BAZEL} ${run_cmd} "${regen_target}"
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040056 done
57}
58
Alexandre Rostovtsevf8fab822023-07-24 21:43:33 -040059# Allow users to override the bazel command with e.g. bazelisk.
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040060: "${BAZEL:=bazelisk}"
Alexandre Rostovtsevf8fab822023-07-24 21:43:33 -040061
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040062update_non_manual_tests
Fabian Meumertzheim018dee52024-06-18 22:34:12 +020063update_manual_tests_with_tag "noenable_bzlmod" --noenable_bzlmod
Alexandre Rostovtsevaba1a012024-06-18 14:40:59 -040064USE_BAZEL_VERSION="7.2.0" update_manual_tests_with_tag "bazel_7_2"
65USE_BAZEL_VERSION="8.0.0-pre.20240603.2" update_manual_tests_with_tag "bazel_8"
Alexandre Rostovtsevf8fab822023-07-24 21:43:33 -040066
c-parsons166ff5e2019-09-11 12:04:15 -040067echo "** Files copied."
68echo "Please note that not all golden files are correctly copied by this script."
69echo "You may want to manually run:"
70echo ""
Alexandre Rostovtsevf8fab822023-07-24 21:43:33 -040071echo "${BAZEL} test //test:all"
c-parsons166ff5e2019-09-11 12:04:15 -040072echo ""
73echo "...and manually update tests which are still broken."