diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcLibraryRule.java index a26da04ec94b9c..242e359c33b57b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcLibraryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcLibraryRule.java @@ -63,6 +63,12 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) attr("implementation_deps", LABEL_LIST) .allowedFileTypes(FileTypeSet.NO_FILE) .mandatoryProviders(CcInfo.PROVIDER.id())) + /* + Any additional files you might want to pass to the compiler command line, such as sanitizer + ignorelists, for example. Files specified here can then be used in copts with the + $(location) function. + */ + .add(attr("additional_compiler_inputs", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE)) .advertiseStarlarkProvider(CcInfo.PROVIDER.id()) .build(); } diff --git a/src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl b/src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl index 33937eba163cac..1c40b6f70285dc 100644 --- a/src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl @@ -706,16 +706,15 @@ def _get_cc_flags_make_variable(ctx, common, cc_toolchain): cc_flags.extend(feature_config_cc_flags) return {"CC_FLAGS": " ".join(cc_flags)} -def _expand_nested_variable(ctx, additional_vars, exp, execpath = True): +def _expand_nested_variable(ctx, additional_vars, exp, execpath = True, targets = []): # If make variable is predefined path variable(like $(location ...)) # we will expand it first. if exp.find(" ") != -1: if not execpath: if exp.startswith("location"): exp = exp.replace("location", "rootpath", 1) - targets = [] if ctx.attr.data != None: - targets = ctx.attr.data + targets.extend(ctx.attr.data) return ctx.expand_location("$({})".format(exp), targets = targets) # Recursively expand nested make variables, but since there is no recursion @@ -739,7 +738,7 @@ def _expand_nested_variable(ctx, additional_vars, exp, execpath = True): fail("potentially unbounded recursion during expansion of {}".format(exp)) return exp -def _expand(ctx, expression, additional_make_variable_substitutions, execpath = True): +def _expand(ctx, expression, additional_make_variable_substitutions, execpath = True, targets = []): idx = 0 last_make_var_end = 0 result = [] @@ -781,7 +780,7 @@ def _expand(ctx, expression, additional_make_variable_substitutions, execpath = # last_make_var_end make_var_start make_var_end result.append(expression[last_make_var_end:make_var_start - 1]) make_var = expression[make_var_start + 1:make_var_end] - exp = _expand_nested_variable(ctx, additional_make_variable_substitutions, make_var, execpath) + exp = _expand_nested_variable(ctx, additional_make_variable_substitutions, make_var, execpath, targets) result.append(exp) # Update indexes. @@ -868,16 +867,19 @@ def _expand_single_make_variable(ctx, token, additional_make_variable_substituti def _expand_make_variables_for_copts(ctx, tokenization, unexpanded_tokens, additional_make_variable_substitutions): tokens = [] + targets = [] + for additional_compiler_input in getattr(ctx.attr, "additional_compiler_inputs", []): + targets.append(additional_compiler_input) for token in unexpanded_tokens: if tokenization: - expanded_token = _expand(ctx, token, additional_make_variable_substitutions) + expanded_token = _expand(ctx, token, additional_make_variable_substitutions, targets = targets) _tokenize(tokens, expanded_token) else: exp = _expand_single_make_variable(ctx, token, additional_make_variable_substitutions) if exp != None: _tokenize(tokens, exp) else: - tokens.append(_expand(ctx, token, additional_make_variable_substitutions)) + tokens.append(_expand(ctx, token, additional_make_variable_substitutions, targets = targets)) return tokens def _get_copts(ctx, common, feature_configuration, additional_make_variable_substitutions): diff --git a/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl b/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl index 5f3ecf7d92dc07..268e7d39e6548e 100755 --- a/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl +++ b/src/main/starlark/builtins_bzl/common/cc/cc_library.bzl @@ -72,6 +72,7 @@ def _cc_library_impl(ctx): textual_hdrs = ctx.files.textual_hdrs, include_prefix = ctx.attr.include_prefix, strip_include_prefix = ctx.attr.strip_include_prefix, + additional_inputs = ctx.files.additional_compiler_inputs, ) precompiled_objects = cc_common.create_compilation_outputs( @@ -600,6 +601,10 @@ attrs = { ), "win_def_file": attr.label(allow_single_file = [".def"]), "licenses": attr.license() if hasattr(attr, "license") else attr.string_list(), + "additional_compiler_inputs": attr.label_list( + allow_files = True, + flags = ["ORDER_INDEPENDENT", "DIRECT_COMPILE_TIME_INPUT"], + ), "_stl": semantics.get_stl(), "_grep_includes": attr.label( allow_files = True, diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index fc06632be7d10c..050f3a8e0f0ac1 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -54,9 +54,7 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * "White-box" unit test of cc_library rule. - */ +/** "White-box" unit test of cc_library rule. */ @RunWith(JUnit4.class) public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { private static final PathFragment STL_CPPMAP = PathFragment.create("stl.cppmap"); @@ -108,9 +106,10 @@ private CppCompileAction getCppCompileAction(String label) throws Exception { private CppCompileAction getCppCompileAction(ConfiguredTarget target) throws Exception { List compilationSteps = - actionsTestUtil().findTransitivePrerequisitesOf( - ActionsTestUtil.getFirstArtifactEndingWith(getFilesToBuild(target), ".a"), - CppCompileAction.class); + actionsTestUtil() + .findTransitivePrerequisitesOf( + ActionsTestUtil.getFirstArtifactEndingWith(getFilesToBuild(target), ".a"), + CppCompileAction.class); return compilationSteps.get(0); } @@ -150,9 +149,12 @@ public void checkWrongExtensionInArtifactNamePattern( @Test public void testDefinesAndMakeVariables() throws Exception { - ConfiguredTarget l = scratchConfiguredTarget("a", "l", - "cc_library(name='l', srcs=['l.cc'], defines=['V=$(FOO)'], toolchains=[':v'])", - "make_variable_tester(name='v', variables={'FOO': 'BAR'})"); + ConfiguredTarget l = + scratchConfiguredTarget( + "a", + "l", + "cc_library(name='l', srcs=['l.cc'], defines=['V=$(FOO)'], toolchains=[':v'])", + "make_variable_tester(name='v', variables={'FOO': 'BAR'})"); assertThat(l.get(CcInfo.PROVIDER).getCcCompilationContext().getDefines()).contains("V=BAR"); } @@ -506,15 +508,13 @@ public void testWindowsFileNamePatternsCanBeSpecifiedInToolchain() throws Except @Test public void testWrongObjectFileArtifactNamePattern() throws Exception { checkWrongExtensionInArtifactNamePattern( - "object_file", - ArtifactCategory.OBJECT_FILE.getAllowedExtensions()); + "object_file", ArtifactCategory.OBJECT_FILE.getAllowedExtensions()); } @Test public void testWrongStaticLibraryArtifactNamePattern() throws Exception { checkWrongExtensionInArtifactNamePattern( - "static_library", - ArtifactCategory.STATIC_LIBRARY.getAllowedExtensions()); + "static_library", ArtifactCategory.STATIC_LIBRARY.getAllowedExtensions()); } @Test @@ -527,22 +527,19 @@ public void testWrongAlwayslinkStaticLibraryArtifactNamePattern() throws Excepti @Test public void testWrongExecutableArtifactNamePattern() throws Exception { checkWrongExtensionInArtifactNamePattern( - "executable", - ArtifactCategory.EXECUTABLE.getAllowedExtensions()); + "executable", ArtifactCategory.EXECUTABLE.getAllowedExtensions()); } @Test public void testWrongDynamicLibraryArtifactNamePattern() throws Exception { checkWrongExtensionInArtifactNamePattern( - "dynamic_library", - ArtifactCategory.DYNAMIC_LIBRARY.getAllowedExtensions()); + "dynamic_library", ArtifactCategory.DYNAMIC_LIBRARY.getAllowedExtensions()); } @Test public void testWrongInterfaceLibraryArtifactNamePattern() throws Exception { checkWrongExtensionInArtifactNamePattern( - "interface_library", - ArtifactCategory.INTERFACE_LIBRARY.getAllowedExtensions()); + "interface_library", ArtifactCategory.INTERFACE_LIBRARY.getAllowedExtensions()); } @Test @@ -593,11 +590,13 @@ public void testTransitiveArtifactsToAlwaysBuildStatic() throws Exception { mockToolsConfig, CcToolchainConfig.builder().withFeatures(CppRuleClasses.SUPPORTS_PIC)); useConfiguration("--cpu=k8"); - ConfiguredTarget x = scratchConfiguredTarget( - "foo", "x", - "cc_library(name = 'x', srcs = ['x.cc'], deps = [':y'], linkstatic = 1)", - "cc_library(name = 'y', srcs = ['y.cc'], deps = [':z'])", - "cc_library(name = 'z', srcs = ['z.cc'])"); + ConfiguredTarget x = + scratchConfiguredTarget( + "foo", + "x", + "cc_library(name = 'x', srcs = ['x.cc'], deps = [':y'], linkstatic = 1)", + "cc_library(name = 'y', srcs = ['y.cc'], deps = [':z'])", + "cc_library(name = 'z', srcs = ['z.cc'])"); assertThat(artifactsToStrings(getOutputGroup(x, OutputGroupInfo.HIDDEN_TOP_LEVEL))) .containsExactly( "bin foo/_objs/x/x.pic.o", "bin foo/_objs/y/y.pic.o", "bin foo/_objs/z/z.pic.o"); @@ -655,13 +654,15 @@ public void testDisablingHeaderModulesWhenDependingOnModuleBuildTransitively() t mockToolsConfig, CcToolchainConfig.builder().withFeatures(MockCcSupport.HEADER_MODULES_FEATURES)); useConfiguration(); - scratch.file("module/BUILD", + scratch.file( + "module/BUILD", "package(features = ['header_modules'])", "cc_library(", " name = 'module',", " srcs = ['a.cc', 'a.h'],", ")"); - scratch.file("nomodule/BUILD", + scratch.file( + "nomodule/BUILD", "package(features = ['-header_modules'])", "cc_library(", " name = 'nomodule',", @@ -692,9 +693,7 @@ private static Iterable getHeaderModules(NestedSet input) { input.toList(), (artifact) -> CppFileTypes.CPP_MODULE.matches(artifact.getExecPath())); } - /** - * Returns the flags in {@code input} that reference a header module. - */ + /** Returns the flags in {@code input} that reference a header module. */ private Iterable getHeaderModuleFlags(Iterable input) { List names = new ArrayList<>(); for (String flag : input) { @@ -728,16 +727,16 @@ public void testCompileHeaderModules() throws Exception { ConfiguredTarget moduleB = getConfiguredTarget("//module:b"); Artifact bModuleArtifact = getBinArtifact("_objs/b/b.pic.pcm", moduleB); CppCompileAction bModuleAction = (CppCompileAction) getGeneratingAction(bModuleArtifact); - assertThat(bModuleAction.getIncludeScannerSources()).containsExactly( - getSourceArtifact("module/b.h"), getSourceArtifact("module/t.h")); + assertThat(bModuleAction.getIncludeScannerSources()) + .containsExactly(getSourceArtifact("module/b.h"), getSourceArtifact("module/t.h")); assertThat(bModuleAction.getInputs().toList()) .contains(getGenfilesArtifact("b.cppmap", moduleB)); ConfiguredTarget moduleA = getConfiguredTarget("//module:a"); Artifact aObjectArtifact = getBinArtifact("_objs/a/a.pic.o", moduleA); CppCompileAction aObjectAction = (CppCompileAction) getGeneratingAction(aObjectArtifact); - assertThat(aObjectAction.getIncludeScannerSources()).containsExactly( - getSourceArtifact("module/a.cc")); + assertThat(aObjectAction.getIncludeScannerSources()) + .containsExactly(getSourceArtifact("module/a.cc")); assertThat(aObjectAction.getCcCompilationContext().getTransitiveModules(true).toList()) .contains(getBinArtifact("_objs/b/b.pic.pcm", moduleB)); assertThat(aObjectAction.getInputs().toList()) @@ -790,7 +789,8 @@ public void testContainingSourcesWithSameBaseName() throws Exception { } private void setupPackagesForModuleTests(boolean useHeaderModules) throws Exception { - scratch.file("module/BUILD", + scratch.file( + "module/BUILD", "package(features = ['header_modules'])", "cc_library(", " name = 'b',", @@ -807,9 +807,11 @@ private void setupPackagesForModuleTests(boolean useHeaderModules) throws Except " srcs = ['j.h', 'j.cc'],", " deps = ['//nomodule:c', '//nomodule:i'],", ")"); - scratch.file("nomodule/BUILD", + scratch.file( + "nomodule/BUILD", "package(features = ['-header_modules'" - + (useHeaderModules ? ", 'use_header_modules'" : "") + "])", + + (useHeaderModules ? ", 'use_header_modules'" : "") + + "])", "cc_library(", " name = 'y',", " srcs = ['y.h'],", @@ -854,7 +856,7 @@ private void setupPackagesForModuleTests(boolean useHeaderModules) throws Except " srcs = ['i.h', 'i.cc'],", " deps = [':h'],", ")"); - } + } @Test public void testCompileHeaderModulesTransitively() throws Exception { @@ -878,8 +880,8 @@ public void testCompileHeaderModulesTransitively() throws Exception { .containsExactly( getGenfilesArtifact("f.cppmap", nomoduleF), getGenfilesArtifact("e.cppmap", nomoduleE)); assertThat(getHeaderModules(fObjectAction.getInputs())).isEmpty(); - assertThat(fObjectAction.getIncludeScannerSources()).containsExactly( - getSourceArtifact("nomodule/f.cc")); + assertThat(fObjectAction.getIncludeScannerSources()) + .containsExactly(getSourceArtifact("nomodule/f.cc")); assertThat(getHeaderModuleFlags(fObjectAction.getCompilerOptions())).isEmpty(); // The //nomodule:c target will get the header module for //module:b, which is a direct @@ -895,10 +897,10 @@ public void testCompileHeaderModulesTransitively() throws Exception { assertThat(getHeaderModules(cObjectAction.getInputs())).isEmpty(); // All headers of transitive dependencies that are built as modules are needed as entry points // for include scanning. - assertThat(cObjectAction.getIncludeScannerSources()).containsExactly( - getSourceArtifact("nomodule/c.cc")); - assertThat(cObjectAction.getMainIncludeScannerSource()).isEqualTo( - getSourceArtifact("nomodule/c.cc")); + assertThat(cObjectAction.getIncludeScannerSources()) + .containsExactly(getSourceArtifact("nomodule/c.cc")); + assertThat(cObjectAction.getMainIncludeScannerSource()) + .isEqualTo(getSourceArtifact("nomodule/c.cc")); assertThat(getHeaderModuleFlags(cObjectAction.getCompilerOptions())).isEmpty(); // The //nomodule:d target depends on //module:b via one indirection (//nomodule:c). @@ -911,12 +913,13 @@ public void testCompileHeaderModulesTransitively() throws Exception { getBinArtifact("_objs/d/d.pic.o", getConfiguredTarget("//nomodule:d")); CppCompileAction dObjectAction = (CppCompileAction) getGeneratingAction(dObjectArtifact); // Module map 'c.cppmap' is needed because it is a direct dependency. - assertThat(getNonSystemModuleMaps(dObjectAction.getInputs())).containsExactly( - getGenfilesArtifact("c.cppmap", "//nomodule:c"), - getGenfilesArtifact("d.cppmap", "//nomodule:d")); + assertThat(getNonSystemModuleMaps(dObjectAction.getInputs())) + .containsExactly( + getGenfilesArtifact("c.cppmap", "//nomodule:c"), + getGenfilesArtifact("d.cppmap", "//nomodule:d")); assertThat(getHeaderModules(dObjectAction.getInputs())).isEmpty(); - assertThat(dObjectAction.getIncludeScannerSources()).containsExactly( - getSourceArtifact("nomodule/d.cc")); + assertThat(dObjectAction.getIncludeScannerSources()) + .containsExactly(getSourceArtifact("nomodule/d.cc")); assertThat(getHeaderModuleFlags(dObjectAction.getCompilerOptions())).isEmpty(); // The //module:j target depends on //module:g via //nomodule:h and on //module:b via @@ -928,10 +931,10 @@ public void testCompileHeaderModulesTransitively() throws Exception { .containsExactly( getBinArtifact("_objs/b/b.pic.pcm", getConfiguredTarget("//module:b")), getBinArtifact("_objs/g/g.pic.pcm", getConfiguredTarget("//module:g"))); - assertThat(jObjectAction.getIncludeScannerSources()).containsExactly( - getSourceArtifact("module/j.cc")); - assertThat(jObjectAction.getMainIncludeScannerSource()).isEqualTo( - getSourceArtifact("module/j.cc")); + assertThat(jObjectAction.getIncludeScannerSources()) + .containsExactly(getSourceArtifact("module/j.cc")); + assertThat(jObjectAction.getMainIncludeScannerSource()) + .isEqualTo(getSourceArtifact("module/j.cc")); assertThat(getHeaderModules(jObjectAction.getCcCompilationContext().getTransitiveModules(true))) .containsExactly( getBinArtifact("_objs/b/b.pic.pcm", getConfiguredTarget("//module:b")), @@ -984,11 +987,8 @@ public void testCompileUsingHeaderModulesTransitively() throws Exception { } private void writeSimpleCcLibrary() throws Exception { - scratch.file("module/BUILD", - "cc_library(", - " name = 'map',", - " srcs = ['a.cc', 'a.h'],", - ")"); + scratch.file( + "module/BUILD", "cc_library(", " name = 'map',", " srcs = ['a.cc', 'a.h'],", ")"); } @Test @@ -1007,7 +1007,9 @@ public void testToolchainWithoutPicForNoPicCompilation() throws Exception { CppActionNames.CPP_LINK_STATIC_LIBRARY, CppActionNames.STRIP)); useConfiguration("--features=-supports_pic"); - scratchConfiguredTarget("a", "a", + scratchConfiguredTarget( + "a", + "a", "cc_binary(name='a', srcs=['a.cc'], deps=[':b'])", "cc_library(name='b', srcs=['b.cc'])"); } @@ -1042,8 +1044,7 @@ public void testCppModuleMap() throws Exception { CppModuleMapAction action = getCppModuleMapAction("//module:map"); assertThat(ActionsTestUtil.baseArtifactNames(action.getDependencyArtifacts())) .contains("crosstool.cppmap"); - assertThat(artifactsToStrings(action.getPrivateHeaders())) - .containsExactly("src module/a.h"); + assertThat(artifactsToStrings(action.getPrivateHeaders())).containsExactly("src module/a.h"); assertThat(action.getPublicHeaders()).isEmpty(); } @@ -1053,9 +1054,12 @@ public void testCppModuleMap() throws Exception { */ @Test public void testFilesToBuildWithPrecompiledStaticLibrary() throws Exception { - ConfiguredTarget hello = scratchConfiguredTarget("precompiled", "library", - "cc_library(name = 'library', ", - " srcs = ['missing.a'])"); + ConfiguredTarget hello = + scratchConfiguredTarget( + "precompiled", + "library", + "cc_library(name = 'library', ", + " srcs = ['missing.a'])"); assertThat(artifactsToStrings(getFilesToBuild(hello))) .doesNotContain("src precompiled/missing.a"); } @@ -1226,7 +1230,8 @@ private CppCompileAction getGeneratingCompileAction( @Test public void testIncludePathOrder() throws Exception { useConfiguration("--incompatible_merge_genfiles_directory=false"); - scratch.file("foo/BUILD", + scratch.file( + "foo/BUILD", "cc_library(", " name = 'bar',", " includes = ['bar'],", @@ -1262,7 +1267,8 @@ public void testIncludePathOrder() throws Exception { @Test public void testDefinesOrder() throws Exception { - scratch.file("foo/BUILD", + scratch.file( + "foo/BUILD", "cc_library(", " name = 'bar',", " defines = ['BAR'],", @@ -1305,7 +1311,9 @@ public void testLocalDefinesNotPassedTransitively() throws Exception { // Regression test - setting "-shared" caused an exception when computing the link command. @Test public void testLinkOptsNotPassedToStaticLink() throws Exception { - scratchConfiguredTarget("foo", "foo", + scratchConfiguredTarget( + "foo", + "foo", "cc_library(", " name = 'foo',", " srcs = ['foo.cc'],", @@ -1354,10 +1362,7 @@ public void testCompilationModeFeatures() throws Exception { @Test public void testIncludePathsOutsideExecutionRoot() throws Exception { - scratchRule( - "root", - "a", - "cc_library(name='a', srcs=['a.cc'], copts=['-Id/../../somewhere'])"); + scratchRule("root", "a", "cc_library(name='a', srcs=['a.cc'], copts=['-Id/../../somewhere'])"); CppCompileAction compileAction = getCppCompileAction("//root:a"); try { compileAction.verifyActionIncludePaths(compileAction.getSystemIncludeDirs(), false); @@ -1371,10 +1376,7 @@ public void testIncludePathsOutsideExecutionRoot() throws Exception { @Test public void testAbsoluteIncludePathsOutsideExecutionRoot() throws Exception { - scratchRule( - "root", - "a", - "cc_library(name='a', srcs=['a.cc'], copts=['-I/somewhere'])"); + scratchRule("root", "a", "cc_library(name='a', srcs=['a.cc'], copts=['-I/somewhere'])"); CppCompileAction compileAction = getCppCompileAction("//root:a"); try { compileAction.verifyActionIncludePaths(compileAction.getSystemIncludeDirs(), false); @@ -1388,10 +1390,7 @@ public void testAbsoluteIncludePathsOutsideExecutionRoot() throws Exception { @Test public void testSystemIncludePathsOutsideExecutionRoot() throws Exception { - scratchRule( - "root", - "a", - "cc_library(name='a', srcs=['a.cc'], copts=['-isystem../system'])"); + scratchRule("root", "a", "cc_library(name='a', srcs=['a.cc'], copts=['-isystem../system'])"); CppCompileAction compileAction = getCppCompileAction("//root:a"); try { compileAction.verifyActionIncludePaths(compileAction.getSystemIncludeDirs(), false); @@ -1405,10 +1404,7 @@ public void testSystemIncludePathsOutsideExecutionRoot() throws Exception { @Test public void testAbsoluteSystemIncludePathsOutsideExecutionRoot() throws Exception { - scratchRule( - "root", - "a", - "cc_library(name='a', srcs=['a.cc'], copts=['-isystem/system'])"); + scratchRule("root", "a", "cc_library(name='a', srcs=['a.cc'], copts=['-isystem/system'])"); CppCompileAction compileAction = getCppCompileAction("//root:a"); try { compileAction.verifyActionIncludePaths(compileAction.getSystemIncludeDirs(), false); @@ -1559,7 +1555,6 @@ public void forbidBuildingAndWrappingSameLibraryIdentifier() throws Exception { "cc_library(name = 'foo', srcs = ['foo.cc', 'libfoo.lo'])"); } - @Test public void testProcessedHeadersWithPicSharedLibsAndNoPicBinaries() throws Exception { AnalysisMock.get() @@ -2375,4 +2370,24 @@ public void testDataDepRunfilesArePropagated() throws Exception { lib.get(DefaultInfo.PROVIDER).getDefaultRunfiles().getAllArtifacts())) .containsExactly("src foo/file.txt"); } + + @Test + public void testAdditionalCompilerInputsArePassedToCompile() throws Exception { + AnalysisMock.get().ccSupport().setupCcToolchainConfig(mockToolsConfig); + scratch.file( + "foo/BUILD", + "cc_library(", + " name = 'foo',", + " srcs = ['hello.cc'],", + " copts = ['$(location compiler_input.txt)'],", + " additional_compiler_inputs = ['compiler_input.txt'],", + ")"); + scratch.file("foo/compiler_input.txt", "hello world!"); + + ConfiguredTarget lib = getConfiguredTarget("//foo:foo"); + Artifact artifact = getBinArtifact("_objs/foo/hello.o", lib); + CppCompileAction action = (CppCompileAction) getGeneratingAction(artifact); + assertThat(action.getInputs().toList()).contains(getSourceArtifact("foo/compiler_input.txt")); + assertThat(action.getArguments()).contains("foo/compiler_input.txt"); + } }