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

bazel: add utility macro for wrapping single-file tools#62930

Merged
Strum355 merged 2 commits into
mainfrom
nsc/bazel-tools
May 27, 2024
Merged

bazel: add utility macro for wrapping single-file tools#62930
Strum355 merged 2 commits into
mainfrom
nsc/bazel-tools

Conversation

@Strum355

Copy link
Copy Markdown
Contributor

Currently, we provide single-file tools such as ctags, gsutil etc via an sh_binary wrapper, to have a single target to reference that automatically does platform selection of the underlying tool.
Due to some unfortunate reason, the underlying srcs (which is a single file) of an sh_binary are also exposed as outputs (rather than just as typical runfiles) alongside the script that wraps. This is sometimes problematic when doing location expansion (e.g. $(location ...)) due to these only allowing a single output (dont ask why this works in some contexts but not others, I dont know).
To address this, we create a wrapper macro + rule to replicate what we want from sh_binary (automatic platform selection + tool naming), while only exposing a singular file.

See example of currently required approach to consuming a tool: BUILD.bazel & main_test.go.

With this change, rlocationpath (singular) can be used instead (or any of the other singular nouns in different contexts), as well as no strings.Split/strings.Fields being required

Test plan

bazel cquery --output=files //dev/tools:dropdb yields 1 vs 2 files.
Also updated the rule behind //internal/database:generate_schemas due to the workaround in it for the fact that the underlying srcs was also exposed. The correctness is verified by running said target (locally + CI)

@Strum355 Strum355 added the bazel label May 27, 2024
@Strum355 Strum355 requested a review from a team May 27, 2024 14:45
@Strum355 Strum355 self-assigned this May 27, 2024
@cla-bot cla-bot Bot added the cla-signed label May 27, 2024
@Strum355 Strum355 marked this pull request as ready for review May 27, 2024 14:45
Comment thread dev/tools/tool.bzl Outdated
@jhchabran

Copy link
Copy Markdown
Contributor

@Strum355 in case you didn't see it, there's a breakage on pgutils.

Comment thread dev/migrations.bzl Outdated
@Strum355 Strum355 enabled auto-merge (squash) May 27, 2024 16:49
@Strum355 Strum355 merged commit 7009f1d into main May 27, 2024
@Strum355 Strum355 deleted the nsc/bazel-tools branch May 27, 2024 16:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants