commit | 2b9a2e79d57fbae57337f2afdabb44bdad7d33f4 | [log] [tgz] |
---|---|---|
author | Googler <brandjon@google.com> | Thu Oct 17 08:13:08 2024 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Thu Oct 17 08:14:14 2024 -0700 |
tree | 07bc627a2ef21dbb83bee4b7557569fe6895d10c | |
parent | 85edcfe2f867cae1539d8f7a967bfde25b5320ff [diff] |
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 #24007. PiperOrigin-RevId: 686919555 Change-Id: I6313070f76456c0b0b5d5458ca35c89d1d6da33b
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.
See CONTRIBUTING.md