Skip to content

Commit

Permalink
Document cc_common.create_cc_toolchain_config_info()
Browse files Browse the repository at this point in the history
And CcToolchainConfigInfo.proto(), while I'm at it.

Issue bazelbuild#5380

RELNOTES: None.
PiperOrigin-RevId: 232460340
  • Loading branch information
scentini authored and Copybara-Service committed Feb 5, 2019
1 parent 439665c commit 09d50a0
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs;
import com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.LinkingInfo;
import com.google.devtools.build.lib.rules.cpp.CcModule;
import com.google.devtools.build.lib.rules.cpp.CcToolchainConfigInfo;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables;
Expand Down Expand Up @@ -49,7 +50,8 @@ public class BazelCcModule extends CcModule
LinkingInfo,
CcLinkingContext,
LibraryToLinkWrapper,
CcToolchainVariables> {
CcToolchainVariables,
CcToolchainConfigInfo> {

@Override
public CompilationInfo compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.StringValueParser;
import com.google.devtools.build.lib.rules.cpp.CppActionConfigs.CppPlatform;
import com.google.devtools.build.lib.rules.cpp.LibraryToLinkWrapper.CcLinkingContext;
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.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.ParamType;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.StarlarkContext;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
Expand Down Expand Up @@ -91,7 +87,8 @@ public class CcModule
CcLinkingContext,
LibraryToLinkWrapper,
CcToolchainVariables,
SkylarkRuleContext> {
SkylarkRuleContext,
CcToolchainConfigInfo> {

private enum RegisterActions {
ALWAYS,
Expand Down Expand Up @@ -754,79 +751,7 @@ private static <T> NestedSet<T> convertSkylarkListOrNestedSetToNestedSet(
: NestedSetBuilder.wrap(Order.COMPILE_ORDER, (SkylarkList<T>) o);
}

@SkylarkCallable(
name = "create_cc_toolchain_config_info",
documented = false,
parameters = {
@Param(
name = "ctx",
positional = false,
named = true,
type = SkylarkRuleContextApi.class,
doc = "The rule context."),
@Param(
name = "features",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "action_configs",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "artifact_name_patterns",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "cxx_builtin_include_directories",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "toolchain_identifier",
positional = false,
type = String.class,
named = true),
@Param(name = "host_system_name", positional = false, type = String.class, named = true),
@Param(name = "target_system_name", positional = false, type = String.class, named = true),
@Param(name = "target_cpu", positional = false, type = String.class, named = true),
@Param(name = "target_libc", positional = false, type = String.class, named = true),
@Param(name = "compiler", positional = false, type = String.class, named = true),
@Param(name = "abi_version", positional = false, type = String.class, named = true),
@Param(name = "abi_libc_version", positional = false, type = String.class, named = true),
@Param(
name = "tool_paths",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "make_variables",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class),
@Param(
name = "builtin_sysroot",
positional = false,
noneable = true,
defaultValue = "None",
allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)},
named = true),
@Param(
name = "cc_target_os",
positional = false,
noneable = true,
defaultValue = "None",
allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)},
named = true),
})
@Override
public CcToolchainConfigInfo ccToolchainConfigInfoFromSkylark(
SkylarkRuleContext skylarkRuleContext,
SkylarkList<Object> features,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.Expandable;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcToolchainConfigInfoApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
Expand Down Expand Up @@ -724,10 +723,7 @@ public boolean hasDynamicLinkingModeFlags() {
return hasDynamicLinkingModeFlags;
}

@SkylarkCallable(
name = "proto",
doc = "Returns text proto from the CcToolchainConfigInfo data.",
structField = true)
@Override
public String getProto() {
return proto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ public interface BazelCcModuleApi<
LinkingInfoT extends LinkingInfoApi,
LinkingContextT extends CcLinkingContextApi,
LibraryToLinkWrapperT extends LibraryToLinkWrapperApi,
CcToolchainVariablesT extends CcToolchainVariablesApi>
CcToolchainVariablesT extends CcToolchainVariablesApi,
CcToolchainConfigInfoT extends CcToolchainConfigInfoApi>
extends CcModuleApi<
CcToolchainProviderT,
FeatureConfigurationT,
CcCompilationContextT,
LinkingContextT,
LibraryToLinkWrapperT,
CcToolchainVariablesT,
SkylarkRuleContextT> {
SkylarkRuleContextT,
CcToolchainConfigInfoT> {

@SkylarkCallable(
name = "compile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class CcBootstrap implements Bootstrap {
? extends LinkingInfoApi,
? extends CcLinkingContextApi,
? extends LibraryToLinkWrapperApi,
? extends CcToolchainVariablesApi>
? extends CcToolchainVariablesApi,
? extends CcToolchainConfigInfoApi>
ccModule;

public CcBootstrap(
Expand All @@ -50,7 +51,8 @@ public CcBootstrap(
? extends LinkingInfoApi,
? extends CcLinkingContextApi,
? extends LibraryToLinkWrapperApi,
? extends CcToolchainVariablesApi>
? extends CcToolchainVariablesApi,
? extends CcToolchainConfigInfoApi>
ccModule) {
this.ccModule = ccModule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public interface CcModuleApi<
LinkingContextT extends CcLinkingContextApi,
LibraryToLinkWrapperT extends LibraryToLinkWrapperApi,
CcToolchainVariablesT extends CcToolchainVariablesApi,
SkylarkRuleContextT extends SkylarkRuleContextApi> {
SkylarkRuleContextT extends SkylarkRuleContextApi,
CcToolchainConfigInfoT extends CcToolchainConfigInfoApi> {

@SkylarkCallable(
name = "CcToolchainInfo",
Expand Down Expand Up @@ -686,4 +687,166 @@ CompilationContextT createCcCompilationContext(
},
doc = "Returns true if the --incompatible_enable_cc_toolchain_resolution flag is enabled.")
boolean isCcToolchainResolutionEnabled(SkylarkRuleContextT ruleContext);

@SkylarkCallable(
name = "create_cc_toolchain_config_info",
doc = "Creates a <code>CcToolchainConfigInfo</code> provider",
parameters = {
@Param(
name = "ctx",
positional = false,
named = true,
type = SkylarkRuleContextApi.class,
doc = "The rule context."),
@Param(
name = "features",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class,
doc =
"A list of <a href=\"https://github.com/bazelbuild/bazel/blob/master/tools/cpp/"
+ "cc_toolchain_config_lib.bzl#L336\">features</a>."),
@Param(
name = "action_configs",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class,
doc =
"A list of <a href=\"https://github.com/bazelbuild/bazel/blob/master/tools/cpp/"
+ "cc_toolchain_config_lib.bzl#L461\">action_configs</a>."),
@Param(
name = "artifact_name_patterns",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class,
doc =
"A list of <a href=\"https://github.com/bazelbuild/bazel/blob/master/tools/cpp/"
+ "cc_toolchain_config_lib.bzl#L516\">artifact_name_patterns</a>."),
@Param(
name = "cxx_builtin_include_directories",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class,
doc =
"<p>Built-in include directories for C++ compilation. These should be the exact "
+ "paths used by the compiler, and are generally relative to the exec root.</p>"
+ "<p>The paths used by the compiler can be determined by 'gcc -E -xc++ - -v'."
+ "</p><p>We currently use the C++ paths also for C compilation, which is safe "
+ "as long as there are no name clashes between C++ and C header files.</p>"
+ "<p>Relative paths are resolved relative to the configuration file directory."
+ "</p><p>If the compiler has --sysroot support, then these paths should use "
+ "%sysroot% rather than the include path, and specify the sysroot attribute "
+ "in order to give blaze the information necessary to make the correct "
+ "replacements.</p>"),
@Param(
name = "toolchain_identifier",
positional = false,
type = String.class,
named = true,
doc =
"<p>The unique identifier of the toolchain within the crosstool release. It must "
+ "be possible to use this as a directory name in a path.</p>"
+ "<p>It has to match the following regex: [a-zA-Z_][\\.\\- \\w]*</p>"),
@Param(
name = "host_system_name",
positional = false,
type = String.class,
named = true,
doc = "The system name which is required by the toolchain to run."),
@Param(
name = "target_system_name",
positional = false,
type = String.class,
named = true,
doc = "The GNU System Name."),
@Param(
name = "target_cpu",
positional = false,
type = String.class,
named = true,
doc = "The target architecture string."),
@Param(
name = "target_libc",
positional = false,
type = String.class,
named = true,
doc = "The libc version string (e.g. \"glibc-2.2.2\")."),
@Param(
name = "compiler",
positional = false,
type = String.class,
named = true,
doc = "The compiler version string (e.g. \"gcc-4.1.1\")."),
@Param(
name = "abi_version",
positional = false,
type = String.class,
named = true,
doc = "The abi in use, which is a gcc version. E.g.: \"gcc-3.4\""),
@Param(
name = "abi_libc_version",
positional = false,
type = String.class,
named = true,
doc = "The glibc version used by the abi we're using."),
@Param(
name = "tool_paths",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class,
doc =
"A list of <a href=\"https://github.com/bazelbuild/bazel/blob/master/tools/cpp/"
+ "cc_toolchain_config_lib.bzl#L400\">tool_paths</a>."),
@Param(
name = "make_variables",
positional = false,
named = true,
defaultValue = "[]",
type = SkylarkList.class,
doc =
"A list of <a href=\"https://github.com/bazelbuild/bazel/blob/master/tools/cpp/"
+ "cc_toolchain_config_lib.bzl#L86\">make_variables</a>."),
@Param(
name = "builtin_sysroot",
positional = false,
noneable = true,
defaultValue = "None",
allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)},
named = true,
doc =
"The built-in sysroot. If this attribute is not present, Bazel does not "
+ "allow using a different sysroot, i.e. through the --grte_top option."),
@Param(
name = "cc_target_os",
positional = false,
noneable = true,
defaultValue = "None",
allowedTypes = {@ParamType(type = String.class), @ParamType(type = NoneType.class)},
named = true,
doc = "Internal purpose only, do not use."),
})
CcToolchainConfigInfoT ccToolchainConfigInfoFromSkylark(
SkylarkRuleContextT skylarkRuleContext,
SkylarkList<Object> features,
SkylarkList<Object> actionConfigs,
SkylarkList<Object> artifactNamePatterns,
SkylarkList<String> cxxBuiltInIncludeDirectories,
String toolchainIdentifier,
String hostSystemName,
String targetSystemName,
String targetCpu,
String targetLibc,
String compiler,
String abiVersion,
String abiLibcVersion,
SkylarkList<Object> toolPaths,
SkylarkList<Object> makeVariables,
Object builtinSysroot,
Object ccTargetOs)
throws EvalException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.devtools.build.lib.skylarkbuildapi.cpp;

import com.google.devtools.build.lib.skylarkbuildapi.StructApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;

Expand All @@ -28,4 +29,10 @@
+ "specifics of C++ actions through features and action configs. It is used to "
+ "configure the C++ toolchain, and later on for command line construction. "
+ "Replaces the functionality of CROSSTOOL file.")
public interface CcToolchainConfigInfoApi extends StructApi {}
public interface CcToolchainConfigInfoApi extends StructApi {
@SkylarkCallable(
name = "proto",
doc = "Returns CToolchain text proto from the CcToolchainConfigInfo data.",
structField = true)
String getProto();
}
Loading

0 comments on commit 09d50a0

Please sign in to comment.