Skip to content

Commit

Permalink
Update query-result normalization logic to support plus repo name del…
Browse files Browse the repository at this point in the history
…imiter

The delimiter used in canonical repo names is changing from `~` to
`+`.[^1] This logic, which tries to normalize query results for the
purposes of diff-testing against golden results, label parsing seems
unavoidable, so we fall back to the non-preferred approach of supporting
both delimiters in our patterns.

Also, refine the patterns to be more exact and better reflect the intent
to only act agaisnt the repo-name part of each label:
  * anchor the patterns to match only at start of each label
  * only operate before the first `/`

[^1]: bazelbuild/bazel#23127
  • Loading branch information
plobsing committed Aug 4, 2024
1 parent 1c5f2eb commit 306b589
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ genrule(
testonly = 1,
srcs = [":testonly-deps"],
outs = ["testonly-deps-sorted.txt"],
cmd = "cat $< | sed -e 's|@@|@|g; s|\r||g' | sed -e 's|@.*~|@|g; s|\r||g' | sort > $@",
cmd = "cat $< | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | sort > $@",
)

diff_test(
Expand All @@ -62,7 +62,7 @@ genrule(
testonly = 1,
srcs = [":version_interval_deps"],
outs = ["version-interval-deps-sorted.txt"],
cmd = "cat $< | sed -e 's|@@|@|g; s|\r||g' | sed -e 's|@.*~|@|g; s|\r||g' | sort > $@",
cmd = "cat $< | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | sort > $@",
)

diff_test(
Expand All @@ -86,7 +86,7 @@ genrule(
testonly = 1,
srcs = [":forced-versions-deps"],
outs = ["forced-versions-deps-sorted.txt"],
cmd = "cat $< | sed -e 's|@@|@|g; s|\r||g' | sed -e 's|@.*~|@|g; s|\r||g' | sort > $@",
cmd = "cat $< | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | sort > $@",
)

diff_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function clean_up_workspace_names() {
local target="$2"
# The first `sed` command replaces `@@` with `@`. The second extracts the visible name
# from the bzlmod mangled workspace name
cat "$file_name" | sed -e 's|@@|@|g; s|\r||g' | sed -e 's|@.*~|@|g; s|\r||g' | grep "$target"
cat "$file_name" | sed -e 's|@@|@|g; s|\r||g' | sed -e 's|@.*~|@|g; s|\r||g' | grep -q "$target"
cat "$file_name" | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | grep "$target"
cat "$file_name" | sed -e 's|^@@|@|g; s|\r||g' | sed -e 's|^@[^/]*[+~]|@|g; s|\r||g' | grep -q "$target"
}

# we should contain the original target
Expand Down

0 comments on commit 306b589

Please sign in to comment.