Skip to content

Commit

Permalink
Allow Starlark to access dynamic_runtime_solib_dir from cc_toolchain
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 384696688
  • Loading branch information
Googler authored and copybara-github committed Jul 14, 2021
1 parent c403305 commit 2da8e84
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,9 @@ public PathFragment getToolPathFragmentOrNull(CppConfiguration.Tool tool) {
return CcToolchainProviderHelper.getToolPathFragment(toolPaths, tool);
}


@Override
public ImmutableList<String> getBuiltInIncludeDirectoriesAsStrings() {
return builtInIncludeDirectories
.stream()
return builtInIncludeDirectories.stream()
.map(PathFragment::getSafePathString)
.collect(ImmutableList.toImmutableList());
}
Expand Down Expand Up @@ -599,8 +597,7 @@ public PathFragment getDynamicRuntimeSolibDir() {
}

@Override
public String getDynamicRuntimeSolibDirForStarlark(StarlarkThread thread) throws EvalException {
CcModule.checkPrivateStarlarkificationAllowlist(thread);
public String getDynamicRuntimeSolibDirForStarlark() {
return getDynamicRuntimeSolibDir().getPathString();
}

Expand All @@ -614,16 +611,12 @@ public CcInfo getCcInfo() {
return ccInfo;
}

/**
* Whether the toolchains supports parameter files.
*/
/** Whether the toolchains supports parameter files. */
public boolean supportsParamFiles() {
return supportsParamFiles;
}

/**
* Returns the configured features of the toolchain.
*/

/** Returns the configured features of the toolchain. */
@Nullable
public CcToolchainFeatures getFeatures() {
return toolchainFeatures;
Expand Down Expand Up @@ -731,9 +724,7 @@ public Artifact getLinkDynamicLibraryTool() {
return linkDynamicLibraryTool;
}

/**
* Returns the tool that builds interface libraries from dynamic libraries.
*/
/** Returns the tool that builds interface libraries from dynamic libraries. */
public Artifact getInterfaceSoBuilder() {
return interfaceSoBuilder;
}
Expand Down Expand Up @@ -946,4 +937,3 @@ public PackageSpecificationProvider getAllowlistForLooseHeaderCheck() {
return allowListForLooseHeaderCheck;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ String getToolPathStringOrNoneForStarlark(String tool, StarlarkThread thread)
@StarlarkMethod(name = "solib_dir", documented = false, useStarlarkThread = true)
String getSolibDirectoryForStarlark(StarlarkThread thread) throws EvalException;

@StarlarkMethod(name = "dynamic_runtime_solib_dir", documented = false, useStarlarkThread = true)
String getDynamicRuntimeSolibDirForStarlark(StarlarkThread thread) throws EvalException;
@StarlarkMethod(name = "dynamic_runtime_solib_dir", documented = false, structField = true)
String getDynamicRuntimeSolibDirForStarlark() throws EvalException;

@StarlarkMethod(name = "linker_files", documented = false, useStarlarkThread = true)
Depset getLinkerFilesForStarlark(StarlarkThread thread) throws EvalException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ public void testRuntimeLib() throws Exception {
.isEqualTo(toolchain.getDynamicRuntimeLibForTesting());
}

@Test
public void testGetDynamicRuntimeSolibDir() throws Exception {
scratch.file(
"a/BUILD",
"load(':rule.bzl', 'crule')",
"cc_toolchain_alias(name='alias')",
"crule(name='r')");

scratch.file(
"a/rule.bzl",
"load('//myinfo:myinfo.bzl', 'MyInfo')",
"def _impl(ctx):",
" toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]",
" return [MyInfo(",
" dynamic_runtime_solib_dir = toolchain.dynamic_runtime_solib_dir,",
" )]",
"crule = rule(",
" _impl,",
" attrs = { ",
" '_cc_toolchain': attr.label(default=Label('//a:alias'))",
" },",
" fragments = ['cpp'],",
");");

ConfiguredTarget r = getConfiguredTarget("//a:r");
String dynamicRuntimeSolibDir =
(String) getMyInfoFromTarget(r).getValue("dynamic_runtime_solib_dir");

RuleContext ruleContext = getRuleContext(r);
CcToolchainProvider toolchain =
CppHelper.getToolchain(ruleContext, ruleContext.getPrerequisite("$cc_toolchain"));

assertThat(dynamicRuntimeSolibDir).isEqualTo(toolchain.getDynamicRuntimeSolibDirForStarlark());
}

@Test
public void testGetToolForAction() throws Exception {
scratch.file(
Expand Down Expand Up @@ -6897,7 +6932,6 @@ public void testExpandedToolchainApiBlocked() throws Exception {
"toolchain.objcopy_files()",
"toolchain.tool_path(tool='ld')",
"toolchain.solib_dir()",
"toolchain.dynamic_runtime_solib_dir()",
"toolchain.linker_files()",
"toolchain.coverage_files()",
"toolchain.strip_files()");
Expand Down

0 comments on commit 2da8e84

Please sign in to comment.