Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 2e642bc

Browse files
fix(bazel): surface error message when gazelle cant process glob expression (#64214)
Closes DINF-89 Gazelle sometimes have trouble processing glob expressions, and this isn't reported as a failure even though it ultimately results in the `BUILD.bazel` not being correctly updated. ## Test plan * Manual testing In `client/web/BUILD.bazel`, add a new `src` to the `web_lib` ts_project target that includes a glob pattern. ``` ... ts_project( name = "web_lib", srcs = glob(["!src/playwright/*.spec.ts"]) + [ "src/Index.tsx", "src/LegacyLayout.tsx", "src/LegacyRouteContext.tsx", "src/LegacySourcegraphWebApp.tsx", "src/PageError.tsx", "src/SearchQueryStateObserver.tsx", "src/SourcegraphWebApp.tsx", ... ``` When you run `go run ./dev/sg bazel configure`, the command should fail with an error message instead of returning exit 0. ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c --> --------- Co-authored-by: Jean-Hadrien Chabran <[email protected]>
1 parent 4a5e1e4 commit 2e642bc

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

dev/ci/bazel-configure.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@ export PATH
88

99
cd "${BUILD_WORKSPACE_DIRECTORY}"
1010

11-
# This fails using rosetta binary, so we just use our normal bazelrc's
12-
bazel \
13-
--bazelrc=.bazelrc \
14-
--bazelrc=.aspect/bazelrc/ci.bazelrc \
15-
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc \
16-
run //:gazelle
11+
bazelArgs=("--bazelrc=.bazelrc")
12+
13+
if [ "${CI:-}" ]; then
14+
bazelArgs+=("--bazelrc=.aspect/bazelrc/ci.bazelrc")
15+
bazelArgs+=("--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc")
16+
fi
17+
18+
# To enable us access the error message / warning returned by gazelle, we trap stderr in a variable
19+
# so we can check for glob warnings and report accordingly.
20+
stderr_output=$(bazel "${bazelArgs[@]}" run //:gazelle 2>&1 >/dev/null)
21+
22+
# If the messages output to stderr includes `could not merge expression`, then it means gazelle
23+
# encountered an issue while reading a glob expression. We surface that to the user so they can
24+
# fix.
25+
if echo "${stderr_output}" | grep -q "could not merge expression"; then
26+
echo "${stderr_output}"
27+
28+
gazelle_err_line=$(echo "${stderr_output}" | grep -m 1 -o '^gazelle:.*')
29+
echo "gazelle encountered an issue processing glob expression, the BUILD file is not updated. ${gazelle_err_line}"
30+
exit 1
31+
fi
1732

1833
if [ "${CI:-}" ]; then
1934
git ls-files --exclude-standard --others | xargs git add --intent-to-add || true

dev/sg/sg_bazel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var bzlgenTargets = map[string]bzlgenTarget{
4545
"builds": {
4646
order: 1,
4747
cmd: "run",
48-
args: []string{"//:gazelle"},
48+
args: []string{"//:configure"},
4949
},
5050
"godeps": {
5151
cmd: "run",

0 commit comments

Comments
 (0)