forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix implicit input file creation for symbolic macros
Previously we weren't creating input files for labels used in the attribute of a top-level symbolic macro. This meant that if you wrote ``` my_macro( name = "foo", srcs = ["input.txt"], ) ``` you'd get an error message claiming that input.txt is not declared and requires an `exports_files()`. (The usages of input.txt by targets declared inside of foo don't count, because implicit input file creation only works for usages of labels outside of symbolic macro bodies.) This CL fixes this behavior, refactors the relevant logic in Package.java, and adds more test coverage. Package.java: - Factor the big for loop from `beforeBuild()` to `createAssumedInputFiles()`. Leave the original for loop in place for test suite accumulation, and pull the `if (discover...)` out of the new call. - Factor the meat of the logic into a helper, `maybeCreateAssumedInputFile()`, so we can reuse it for both rules and macros (previously there was no loop over references in macros). - Add tedious javadoc to this tedious logic. SymbolicMacroTest.java - Add explanatory comment to `macroCanReferToInputFile()`. - Expand `macroCannotForceCreationOfImplicitInputFileOnItsOwn()` to check that the target is still not created when the inner usage is in an attr of a MacroInstance rather than a Rule. PackageFactoryTest.java - Expand comment in `testSymbolicMacro_macroPreventsImplicitCreationOfInputFilesUnderItsNamespace()`, include coverage for when the reference comes from within a target or submacro inside the symbolic macro itself. - New test case for the behavior of this CL, `..._macroInstantiationCanForceImplicitCreationOfInputFile()`. - Drive-by: Add a test case for when a badly named target in a symbolic macro clashes with an implicitly created input file. This behavior may be affected by lazy macro evaluation in the future. Confirmed that this CL works for the case I originally discovered it on while writing examples documentation. Fixes bazelbuild#24007. PiperOrigin-RevId: 686919555 Change-Id: I6313070f76456c0b0b5d5458ca35c89d1d6da33b
- Loading branch information
1 parent
85edcfe
commit 2b9a2e7
Showing
3 changed files
with
238 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters