Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias() doesn't support surfacing a *_flag to the command line #20582

Closed
afq984 opened this issue Dec 18, 2023 · 4 comments
Closed

alias() doesn't support surfacing a *_flag to the command line #20582

afq984 opened this issue Dec 18, 2023 · 4 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request

Comments

@afq984
Copy link

afq984 commented Dec 18, 2023

Description of the feature request:

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

config_setting(
    name = "my_flag_enabled",
    flag_values = {
        ":my_flag": "true",
    },
)

bool_flag(
    name = "my_flag",
    build_setting_default = False,
)

alias(
    name = "my_flag_alias",
    actual = ":my_flag",
)
bazelisk build --//:my_flag_alias //:my_flag_enabled
INFO: Invocation ID: 4dda7f49-80a0-4ae1-be58-37d1ebd1876d
ERROR: //:my_flag_alias :: Unrecognized option: //:my_flag_alias

Which category does this issue belong to?

Configurability

What underlying problem are you trying to solve with this feature?

We were trying to expose user-friendly flags aliases to generated repositories, so users don't have to type the full path of packages.

E.g. people can use --@portage//target/sys-apps/attr:2.5.1_incremental instead of --@portage//internal/packages/stage2/target/board/portage-stable/sys-apps/attr:2.5.1_incremental

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

development version

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

cat .bazelversion 
bbc4b12eb562de5e5daeec9700fa258dfdc5a51b

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

For our use case, we also need the alias's actual to be in a select.

e.g. something like alias(name = "incremental", actual = select({"//bazel/stage1": "//internal/stage1/pkg/incremental", "//bazel/stage2": "//internal/stage2/pkg/incremental"})

Not sure if it is something possible to support.

@afq984
Copy link
Author

afq984 commented Dec 18, 2023

I initially confused this with #13463, which was aliasing on the config_setting instead of the bool_flag.

@gregestren
Copy link
Contributor

Can https://bazel.build/reference/command-line-reference#flag--flag_alias work for you?

I thought we had some support for what you describe, but I guess not?

@gregestren gregestren added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Jan 4, 2024
@afq984
Copy link
Author

afq984 commented Jan 4, 2024

Our build targets are, generated from a repository rule which inspects local build manifests (which we are slowly migrating away from).

As the targets are dynamic, we cannot use a static bazelrc with --flag_alias for that.

I think if we write a bazelrc file to be imported by the main file, in the tools/bazel wrapper, then we can get dynamically generated aliases.

It might be hard to pull off though. The build manifest analysis is expensive and lives inside a Bazel invocation already.

bazel-io pushed a commit to bazel-io/bazel that referenced this issue May 1, 2024
Fixes bazelbuild#20582

RELNOTES: Starlark command-line flags can now be referred to through `alias` targets.

Closes bazelbuild#22192.

PiperOrigin-RevId: 629865954
Change-Id: I6215c8484ddc08e75507191bfa1eb5bc709c5fc6
github-merge-queue bot pushed a commit that referenced this issue May 2, 2024
Fixes #20582

RELNOTES: Starlark command-line flags can now be referred to through
`alias` targets.

Closes #22192.

PiperOrigin-RevId: 629865954
Change-Id: I6215c8484ddc08e75507191bfa1eb5bc709c5fc6

Commit
43fdcd3

Co-authored-by: Fabian Meumertzheim <[email protected]>
Kila2 pushed a commit to Kila2/bazel that referenced this issue May 13, 2024
Fixes bazelbuild#20582

RELNOTES: Starlark command-line flags can now be referred to through `alias` targets.

Closes bazelbuild#22192.

PiperOrigin-RevId: 629865954
Change-Id: I6215c8484ddc08e75507191bfa1eb5bc709c5fc6
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.2.0 RC1. Please test out the release candidate and report any issues as soon as possible.
If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.2.0rc1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants