From de75b42c9bba23549209197cdfb7db84c6256808 Mon Sep 17 00:00:00 2001 From: plf Date: Mon, 22 Mar 2021 03:35:38 -0700 Subject: [PATCH] Add variables_extension parameter to create_linking_context_from_compilation_output This is needed for objc_proto_library, Swift and other Apple rules. RELNOTES:none PiperOrigin-RevId: 364280322 --- .../devtools/build/lib/rules/cpp/CcModule.java | 4 ++++ .../lib/starlarkbuildapi/cpp/CcModuleApi.java | 8 ++++++++ .../skydoc/fakebuildapi/cpp/FakeCcModule.java | 1 + .../build/lib/rules/cpp/StarlarkCcCommonTest.java | 15 +++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java index f1b6d77550ec50..6bd79bdc4b054d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java @@ -1724,6 +1724,7 @@ public Tuple createLinkingContextFromCompilationOutputs( boolean disallowStaticLibraries, boolean disallowDynamicLibraries, Object grepIncludes, + Object variablesExtension, StarlarkThread thread) throws InterruptedException, EvalException { validateLanguage(language); @@ -1774,6 +1775,9 @@ public Tuple createLinkingContextFromCompilationOutputs( .setStaticLinkType(staticLinkTargetType) .setDynamicLinkType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY) .addLinkopts(Sequence.cast(userLinkFlags, String.class, "user_link_flags")); + if (!asDict(variablesExtension).isEmpty()) { + helper.addVariableExtension(new UserVariablesExtension(asDict(variablesExtension))); + } try { CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY; ImmutableList libraryToLink = ImmutableList.of(); diff --git a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java index bbb072365865df..f03c8be21fd449 100644 --- a/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java +++ b/src/main/java/com/google/devtools/build/lib/starlarkbuildapi/cpp/CcModuleApi.java @@ -1174,6 +1174,13 @@ CcToolchainConfigInfoT ccToolchainConfigInfoFromStarlark( named = true, defaultValue = "None", allowedTypes = {@ParamType(type = FileApi.class), @ParamType(type = NoneType.class)}), + @Param( + name = "variables_extension", + positional = false, + named = true, + documented = false, + allowedTypes = {@ParamType(type = Dict.class)}, + defaultValue = "unbound"), }) Tuple createLinkingContextFromCompilationOutputs( StarlarkActionFactoryT starlarkActionFactoryApi, @@ -1189,6 +1196,7 @@ Tuple createLinkingContextFromCompilationOutputs( boolean disallowStaticLibraries, boolean disallowDynamicLibraries, Object grepIncludes, + Object variablesExtension, StarlarkThread thread) throws InterruptedException, EvalException; diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java index e091d287a1d9e7..5c8d628bd9545f 100644 --- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java +++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/cpp/FakeCcModule.java @@ -316,6 +316,7 @@ public Tuple createLinkingContextFromCompilationOutputs( boolean disallowStaticLibraries, boolean disallowDynamicLibraries, Object grepIncludes, + Object variablesExtension, StarlarkThread thread) throws InterruptedException, EvalException { return null; diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java index f4913e67f6d970..56652986cf46f3 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/StarlarkCcCommonTest.java @@ -6093,6 +6093,8 @@ private static void createFiles( " library_to_link = linking_outputs.library_to_link", " if library_to_link.pic_static_library != None:", " files_to_build.append(library_to_link.pic_static_library)", + " if library_to_link.static_library != None:", + " files_to_build.append(library_to_link.static_library)", " files_to_build.append(library_to_link.dynamic_library)", " return [MyInfo(libraries=[library_to_link]),", " DefaultInfo(files=depset(files_to_build)),", @@ -7371,6 +7373,19 @@ public void testVariableExtensionCompileApi() throws Exception { action.getCompileCommandLine().getVariables().getSequenceVariable("string_depset_variable"); } + @Test + public void testVariableExtensionLinkingContextApi() throws Exception { + createFilesForTestingLinking(scratch, "tools/build_defs/foo", "variables_extension = foo_dict"); + assertThat(getConfiguredTarget("//foo:bin")).isNotNull(); + ConfiguredTarget target = getConfiguredTarget("//foo:starlark_lib"); + CppLinkAction action = + (CppLinkAction) getGeneratingAction(artifactByPath(getFilesToBuild(target), ".a")); + + action.getLinkCommandLine().getBuildVariables().getSequenceVariable("string_sequence_variable"); + action.getLinkCommandLine().getBuildVariables().getStringVariable("string_variable"); + action.getLinkCommandLine().getBuildVariables().getSequenceVariable("string_depset_variable"); + } + @Test public void testVariableExtensionLinkApi() throws Exception { setupTestTransitiveLink(