question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

User-defined build flag bypasses its implementation function when used in transition.

See original GitHub issue

Description of the bug:

User-defined build flag does not execute its implementation function when it is used only in transition.

What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I have compact repro here: https://github.com/Bazel-snippets/multistring

There are two user-defined flags: target_platforms and flavors. Implementation function _multistring_impl validates given value. Command line to try is bazel build transistor --//:flavors=dbg

Observed outcome is the build success, but it is wrong because dbg is not a valid value for this flag (it is commented out) and _multistring_impl supposed to complain about it, but it is never executed!

Now if you uncomment line 50 in transistor.bzl to mention //:flavors flag in the rule then _multistring_impl gets executed and produces expected error message.

Which operating system are you running Bazel on?

Linux, Mac, Windows

What is the output of bazel info release?

5.2.0

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

No response

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?

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
konstecommented, Sep 5, 2022

I understand the reasoning. Speaking of a workaround adding unused private label typed attribute pointing to build_flag to any (?) rule looks like an easier workaround, although it requires extensive comment about why it is there.

To mitigate it for others I would simply add a sentence on this page informing that build_setting implementation function is only invoked when build_setting is used as some rule label attribute value and is not invoked if build_setting is ONLY used in transitions.

0reactions
sdtwiggcommented, Sep 1, 2022

Re-affirming and restating https://github.com/bazelbuild/bazel/issues/15994#issuecomment-1201594481, it is currently by-design that transitions operation on the ‘raw’ values of the configuration before those implementations are run. Changing this is infeasible.

Philosophically, build_setting or build_flag is actually a (slightly special) rule and the implementation function of a build_setting is actually a (slightly special) rule implementation function that takes the raw configuration value and other attributes (which may be Label-type and thus the results of other rule evaluations!) to put the configuration value in a provider suitable for consumption by other rules (like config_setting).

In contrast, transitions are designed to only work on configurations (and not consume rules as metadata), which are essentially just dicts of dicts of text to text at this point. There would be some serious performance concerns if transitions alone could trigger ancillary rule analysis, especially when transitions are composed or chained.

We could probably revamp the documentation on transitions to make it clearer (e.g. notice also how transitions on label-typed settings only see the label as a string, not the transitive provider set). But, in your case, if the transition itself needs to do validation then it should do the validation in the transition. (Perhaps define a helper function in a bzl file that the build_setting implementation and transitions can both call to do the validation uniformly?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configurations | Bazel
User-defined transitions ... A configuration transition maps the transformation from one configured target to another within the build graph.
Read more >
C++ Dialect Options (Using the GNU Compiler Collection ...
This flag attempts to use visibility settings to make GCC's C++ linkage model compatible with that of Microsoft Visual Studio. The flag makes...
Read more >
Xcode 13 Release Notes | Apple Developer Documentation
The compiler supports this flag with deployment targets of macOS 11, iOS and iPadOS 14, tvOS 14, watchOS 7 and later. The flag...
Read more >
MemFuck: Bypassing User-Mode Hooks - Winternl
Preface. Dynamic malware analysis is the preferred way to determine the legitimacy of an application for many AVs/EDRs/MDSs.
Read more >
5 Creating a JD Edwards EnterpriseOne Workflow Process
Section 5.6, "Working with Transitions and Transition Conditions". Section 5.7, "Working with Batch Application Tasks". Section 5.8, "Using Business Function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found