Skip to content

Commit

Permalink
Add variables_extension parameter to create_linking_context_from_comp…
Browse files Browse the repository at this point in the history
…ilation_output

This is needed for objc_proto_library, Swift and other Apple rules.

RELNOTES:none
PiperOrigin-RevId: 364280322
  • Loading branch information
oquenchil authored and copybara-github committed Mar 22, 2021
1 parent ac7fc7c commit de75b42
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,7 @@ public Tuple createLinkingContextFromCompilationOutputs(
boolean disallowStaticLibraries,
boolean disallowDynamicLibraries,
Object grepIncludes,
Object variablesExtension,
StarlarkThread thread)
throws InterruptedException, EvalException {
validateLanguage(language);
Expand Down Expand Up @@ -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> libraryToLink = ImmutableList.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1189,6 +1196,7 @@ Tuple createLinkingContextFromCompilationOutputs(
boolean disallowStaticLibraries,
boolean disallowDynamicLibraries,
Object grepIncludes,
Object variablesExtension,
StarlarkThread thread)
throws InterruptedException, EvalException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public Tuple createLinkingContextFromCompilationOutputs(
boolean disallowStaticLibraries,
boolean disallowDynamicLibraries,
Object grepIncludes,
Object variablesExtension,
StarlarkThread thread)
throws InterruptedException, EvalException {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),",
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit de75b42

Please sign in to comment.