Skip to content

Commit

Permalink
C++: Remove old params from API
Browse files Browse the repository at this point in the history
    bazelbuild/bazel#4570

    RELNOTES:none
    PiperOrigin-RevId: 227522672
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent aaf5781 commit 68c227c
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import com.google.devtools.build.lib.skylarkbuildapi.SkylarkRuleContextApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcInfoApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcModuleApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcSkylarkInfoApi;
import com.google.devtools.build.lib.skylarkinterface.Param;
Expand Down Expand Up @@ -518,15 +517,77 @@ public CcSkylarkInfo createCcSkylarkInfo(Object skylarkRuleContextObject)
return new CcSkylarkInfo();
}

@Override
public CcInfo mergeCcInfos(SkylarkList<CcInfoApi> ccInfos) throws EvalException {
return CcInfo.merge(ccInfos.getContents(CcInfo.class, /* description= */ null));
@SkylarkCallable(
name = "merge_cc_infos",
documented = false,
parameters = {
@Param(
name = "cc_infos",
doc = "cc_infos to be merged.",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class)
})
public CcInfo mergeCcInfos(SkylarkList<CcInfo> ccInfos) {
return CcInfo.merge(ccInfos);
}

@Override
@SkylarkCallable(
name = "create_compilation_context",
documented = false,
parameters = {
@Param(
name = "headers",
doc = "the set of headers needed to compile this target",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "system_includes",
doc =
"set of search paths for header files referenced by angle brackets, i.e. "
+ "#include <foo/bar/header.h>. They can be either relative to the exec root "
+ "or absolute. Usually passed with -isystem",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "includes",
doc =
"set of search paths for header files referenced both by angle bracket and quotes."
+ "Usually passed with -I",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "quote_includes",
doc =
"set of search paths for header files referenced by quotes, i.e. "
+ "#include \"foo/bar/header.h\". They can be either relative to the exec "
+ "root or absolute. Usually passed with -iquote",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "defines",
doc = "the set of defines needed to compile this target. Each define is a string",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class)
})
public CcCompilationContext createCcCompilationContext(
Object headers, Object systemIncludes, Object includes, Object quoteIncludes, Object defines)
throws EvalException {
Object headers,
Object systemIncludes,
Object includes,
Object quoteIncludes,
Object defines)
throws EvalException, InterruptedException {
CcCompilationContext.Builder ccCompilationContext =
new CcCompilationContext.Builder(/* ruleContext= */ null);
ccCompilationContext.addDeclaredIncludeSrcs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ CcToolchainVariablesT getLinkBuildVariables(

@SkylarkCallable(
name = "create_library_to_link",
doc = "Creates <code>LibraryToLink</code>",
documented = false,
useLocation = true,
useEnvironment = true,
parameters = {
Expand All @@ -476,56 +476,54 @@ CcToolchainVariablesT getLinkBuildVariables(
type = SkylarkActionFactoryApi.class,
positional = false,
named = true,
doc = "<code>actions</code> object."),
doc = "Actions."),
@Param(
name = "feature_configuration",
doc = "<code>feature_configuration</code> to be queried.",
doc = "Feature configuration to be queried.",
positional = false,
named = true,
type = FeatureConfigurationApi.class),
@Param(
name = "cc_toolchain",
doc = "<code>CcToolchainInfo</code> provider to be used.",
doc = "C++ toolchain provider to be used.",
positional = false,
named = true,
type = CcToolchainProviderApi.class),
@Param(
name = "static_library",
doc = "<code>Artifact</code> of static library to be linked.",
doc = "Library to be linked.",
positional = false,
named = true,
noneable = true,
defaultValue = "None",
type = Artifact.class),
@Param(
name = "pic_static_library",
doc = "<code>Artifact</code> of pic static library to be linked.",
doc = "Library to be linked.",
positional = false,
named = true,
noneable = true,
defaultValue = "None",
type = Artifact.class),
@Param(
name = "dynamic_library",
doc =
"<code>Artifact</code> of dynamic library to be linked. Always used for runtime "
+ "and used for linking if <code>interface_library</code> is not passed.",
doc = "Library to be linked.",
positional = false,
named = true,
noneable = true,
defaultValue = "None",
type = Artifact.class),
@Param(
name = "interface_library",
doc = "<code>Artifact</code> of interface library to be linked.",
doc = "Library to be linked.",
positional = false,
named = true,
noneable = true,
defaultValue = "None",
type = Artifact.class),
@Param(
name = "alwayslink",
doc = "Whether to link the static library/objects in the --whole_archive block.",
doc = "Alwayslink.",
positional = false,
named = true,
defaultValue = "False"),
Expand All @@ -545,21 +543,21 @@ Object createLibraryLinkerInput(

@SkylarkCallable(
name = "create_linking_context",
doc = "Creates a <code>LinkingContext</code>.",
documented = false,
useLocation = true,
useEnvironment = true,
parameters = {
@Param(
name = "libraries_to_link",
doc = "List of <code>LibraryToLink</code>.",
doc = "The libraries to link",
positional = false,
named = true,
noneable = true,
defaultValue = "None",
type = SkylarkList.class),
@Param(
name = "user_link_flags",
doc = "List of user link flags passed as strings.",
doc = "User link flags",
positional = false,
named = true,
noneable = true,
Expand Down Expand Up @@ -676,72 +674,6 @@ CcLinkParamsT createCcLinkParams(
CcSkylarkInfoT createCcSkylarkInfo(Object skylarkRuleContextObject)
throws EvalException, InterruptedException;

@SkylarkCallable(
name = "merge_cc_infos",
doc = "Merges a list of <code>CcInfo</code>s into one.",
parameters = {
@Param(
name = "cc_infos",
doc = "List of <code>CcInfo</code>s to be merged.",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class)
})
CcInfoApi mergeCcInfos(SkylarkList<CcInfoApi> ccInfos) throws EvalException;

@SkylarkCallable(
name = "create_compilation_context",
doc = "Creates a <code>CompilationContext</code>.",
parameters = {
@Param(
name = "headers",
doc = "Set of headers needed to compile this target",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "system_includes",
doc =
"Set of search paths for header files referenced by angle brackets, i.e. "
+ "#include <foo/bar/header.h>. They can be either relative to the exec root "
+ "or absolute. Usually passed with -isystem",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "includes",
doc =
"Set of search paths for header files referenced both by angle bracket and quotes."
+ "Usually passed with -I",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "quote_includes",
doc =
"Set of search paths for header files referenced by quotes, i.e. "
+ "#include \"foo/bar/header.h\". They can be either relative to the exec "
+ "root or absolute. Usually passed with -iquote",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class),
@Param(
name = "defines",
doc = "Set of defines needed to compile this target. Each define is a string",
positional = false,
named = true,
defaultValue = "unbound",
type = Object.class)
})
CcCompilationContextApi createCcCompilationContext(
Object headers, Object systemIncludes, Object includes, Object quoteIncludes, Object defines)
throws EvalException;

// TODO(b/65151735): Remove when cc_flags is entirely set from features.
// This should only be called from the cc_flags_supplier rule.
@SkylarkCallable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.skylarkbuildapi.cpp.BazelCcModuleApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcCompilationContextApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcCompilationOutputsApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcInfoApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkParamsApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkingInfoApi;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcModuleApi;
Expand Down Expand Up @@ -158,18 +157,6 @@ public CcSkylarkInfoApi createCcSkylarkInfo(Object skylarkRuleContextObject)
return null;
}

@Override
public CcInfoApi mergeCcInfos(SkylarkList<CcInfoApi> ccInfos) {
return null;
}

@Override
public CcCompilationContextApi createCcCompilationContext(
Object headers, Object systemIncludes, Object includes, Object quoteIncludes, Object defines)
throws EvalException {
return null;
}

@Override
public String legacyCcFlagsMakeVariable(CcToolchainProviderApi ccToolchain) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,52 @@ public void testCcToolchainInfoToProtoBareMinimum() throws Exception {
assertNoEvents();
}

@Test
public void testCcToolchainConfigInfooDynamicLinkingModeEnabledWithFeature() throws Exception {
loadCcToolchainConfigLib();
scratch.file(
"foo/crosstool.bzl",
"load('//tools/cpp:cc_toolchain_config_lib.bzl',",
" 'feature')",
"",
"def _impl(ctx):",
" return cc_common.create_cc_toolchain_config_info(",
" ctx = ctx,",
" toolchain_identifier = 'toolchain',",
" host_system_name = 'host',",
" target_system_name = 'target',",
" target_cpu = 'cpu',",
" target_libc = 'libc',",
" compiler = 'compiler',",
" abi_libc_version = 'abi_libc',",
" abi_version = 'abi',",
" features = [feature(name = 'dynamic_linking_mode')],",
" )",
"cc_toolchain_config_rule = rule(",
" implementation = _impl,",
" attrs = {},",
" provides = [CcToolchainConfigInfo], ",
")");

scratch.file(
"foo/BUILD",
"load(':crosstool.bzl', 'cc_toolchain_config_rule')",
"cc_toolchain_alias(name='alias')",
"cc_toolchain_config_rule(name='r')");

useConfiguration("--experimental_enable_cc_toolchain_config_info");
ConfiguredTarget target = getConfiguredTarget("//foo:r");
assertThat(target).isNotNull();
CcToolchainConfigInfo ccToolchainConfigInfo =
(CcToolchainConfigInfo) target.get(CcToolchainConfigInfo.PROVIDER.getKey());
assertThat(ccToolchainConfigInfo).isNotNull();

// If a feature named 'dynamic_linking_mode' is passed to the create_cc_toolchain_config_info
// method, the corresponding CToolchain should have an entry in its linking_mode_flags list
// that has dynamic linking mode.
assertThat(ccToolchainConfigInfo.hasDynamicLinkingModeFlags()).isTrue();
}

@Test
public void testGetLegacyCcFlagsMakeVariable() throws Exception {
AnalysisMock.get()
Expand Down

0 comments on commit 68c227c

Please sign in to comment.