aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar cparsons <cparsons@google.com>2018-05-25 13:31:09 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-25 13:32:51 -0700
commit9b5d886524cd0a65b27079ca76299403a18d2bb7 (patch)
treef89f9a9f439b622f0378b77db9a58c29157c18fb /src/main/java/com/google
parent10a6130dbafdf4e5f61198bec08b88fe6d6381fe (diff)
Migrate cpp rules skylark objects to skylarkbuildapi
RELNOTES: None. PiperOrigin-RevId: 198094324
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfiles.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java76
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java97
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java143
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BUILD4
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingInfoApi.java39
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java35
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkApiProviderApi.java105
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcToolchainProviderApi.java138
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CppConfigurationApi.java199
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java34
14 files changed, 616 insertions, 308 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
index b2294e45f6..e6767975bc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
@@ -49,9 +49,7 @@ import com.google.devtools.build.lib.rules.cpp.Link.LinkerOrArchiver;
import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode;
import com.google.devtools.build.lib.rules.cpp.Link.Picness;
import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.LinkingInfoApi;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -79,13 +77,7 @@ public final class CcLinkingHelper {
public static final String DYNAMIC_LIBRARY_OUTPUT_GROUP_NAME = "dynamic_library";
/** Contains the providers as well as the linking outputs. */
- @SkylarkModule(
- name = "linking_info",
- documented = false,
- category = SkylarkModuleCategory.BUILTIN,
- doc = "Helper class containing CC linking providers."
- )
- public static final class LinkingInfo {
+ public static final class LinkingInfo implements LinkingInfoApi {
private final TransitiveInfoProviderMap providers;
private final Map<String, NestedSet<Artifact>> outputGroups;
private final CcLinkingOutputs linkingOutputs;
@@ -107,7 +99,7 @@ public final class CcLinkingHelper {
return providers;
}
- @SkylarkCallable(name = "cc_linking_info", documented = false)
+ @Override
public CcLinkingInfo getCcLinkParamsInfo() {
return (CcLinkingInfo) providers.getProvider(CcLinkingInfo.PROVIDER.getKey());
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java
index b42eaa13f2..1157301846 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingInfo.java
@@ -22,9 +22,7 @@ import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
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.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcLinkingInfoApi;
import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.FunctionSignature;
@@ -33,13 +31,7 @@ import com.google.devtools.build.lib.syntax.SkylarkType;
/** Wrapper for every C++ linking provider. */
@Immutable
@AutoCodec
-@SkylarkModule(
- name = "cc_linking_info",
- documented = false,
- category = SkylarkModuleCategory.PROVIDER,
- doc = "Wrapper for every C++ linking provider"
-)
-public final class CcLinkingInfo extends NativeInfo {
+public final class CcLinkingInfo extends NativeInfo implements CcLinkingInfoApi {
private static final FunctionSignature.WithValues<Object, SkylarkType> SIGNATURE =
FunctionSignature.WithValues.create(
@@ -86,11 +78,7 @@ public final class CcLinkingInfo extends NativeInfo {
return ccLinkParamsStore;
}
- @SkylarkCallable(
- name = "cc_runfiles",
- documented = false,
- allowReturnNones = true,
- structField = true)
+ @Override
public CcRunfiles getCcRunfiles() {
return ccRunfiles;
}
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 f540cf11e6..3971d9766f 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
@@ -16,21 +16,13 @@ package com.google.devtools.build.lib.rules.cpp;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.packages.Provider;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcModuleApi;
/** A module that contains Skylark utilities for C++ support. */
-@SkylarkModule(name = "cc_common", doc = "Utilities related to C++ support.")
-public class CcModule {
+public class CcModule implements CcModuleApi {
public static final CcModule INSTANCE = new CcModule();
- @SkylarkCallable(
- name = CcToolchainProvider.SKYLARK_NAME,
- doc =
- "The key used to retrieve the provider that contains information about the C++ "
- + "toolchain being used",
- structField = true
- )
+ @Override
public Provider getCcToolchainProvider() {
return ToolchainInfo.PROVIDER;
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfiles.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfiles.java
index 67e17c841f..d2b7a490fa 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcRunfiles.java
@@ -20,8 +20,6 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcRunfilesApi;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
/**
* Runfiles for C++ targets.
@@ -32,12 +30,6 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
*/
@Immutable
@AutoCodec
-@SkylarkModule(
- name = "cc_runfiles",
- category = SkylarkModuleCategory.NONE,
- doc =
- "CC runfiles. Separated into files needed for linking statically and files needed for "
- + "linking dynamically.")
public final class CcRunfiles implements CcRunfilesApi {
private final Runfiles runfilesForLinkingStatically;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java
index 7a0aa93363..eeec948aa2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcSkylarkApiProvider.java
@@ -20,49 +20,27 @@ import com.google.devtools.build.lib.analysis.skylark.SkylarkApiProvider;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcSkylarkApiProviderApi;
import com.google.devtools.build.lib.vfs.PathFragment;
/**
* A class that exposes the C++ providers to Skylark. It is intended to provide a simple and stable
* interface for Skylark users.
*/
-@SkylarkModule(
- name = "CcSkylarkApiProvider",
- category = SkylarkModuleCategory.PROVIDER,
- doc =
- "Provides access to information about C++ rules. "
- + "Every C++-related target provides this struct, accessible as a <code>cc</code> field "
- + "on <a href=\"Target.html\">target</a>."
-)
@AutoCodec
-public final class CcSkylarkApiProvider extends SkylarkApiProvider {
+public final class CcSkylarkApiProvider extends SkylarkApiProvider
+ implements CcSkylarkApiProviderApi<Artifact> {
/** The name of the field in Skylark used to access this class. */
public static final String NAME = "cc";
- @SkylarkCallable(
- name = "transitive_headers",
- structField = true,
- doc =
- "Returns a <a href=\"depset.html\">depset</a> of headers that have been declared in the "
- + " <code>src</code> or <code>headers</code> attribute"
- + "(possibly empty but never <code>None</code>).")
+ @Override
public NestedSet<Artifact> getTransitiveHeaders() {
CcCompilationContext ccCompilationContext =
getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext();
return ccCompilationContext.getDeclaredIncludeSrcs();
}
- @SkylarkCallable(
- name = "libs",
- structField = true,
- doc =
- "Returns the <a href=\"depset.html\">depset</a> of libraries for either "
- + "<code>FULLY STATIC</code> mode (<code>linkopts=[\"-static\"]</code>) or "
- + "<code>MOSTLY STATIC</code> mode (<code>linkstatic=1</code>) "
- + "(possibly empty but never <code>None</code>)")
+ @Override
public NestedSet<Artifact> getLibraries() {
NestedSetBuilder<Artifact> libs = NestedSetBuilder.linkOrder();
CcLinkingInfo ccLinkingInfo = getInfo().get(CcLinkingInfo.PROVIDER);
@@ -77,14 +55,7 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider {
return libs.build();
}
- @SkylarkCallable(
- name = "link_flags",
- structField = true,
- doc =
- "Returns the list of flags given to the C++ linker command for either "
- + "<code>FULLY STATIC</code> mode (<code>linkopts=[\"-static\"]</code>) or "
- + "<code>MOSTLY STATIC</code> mode (<code>linkstatic=1</code>) "
- + "(possibly empty but never <code>None</code>)")
+ @Override
public ImmutableList<String> getLinkopts() {
CcLinkingInfo ccLinkingInfo = getInfo().get(CcLinkingInfo.PROVIDER);
CcLinkParamsStore ccLinkParams =
@@ -95,12 +66,7 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider {
return ccLinkParams.getCcLinkParams(true, false).flattenedLinkopts();
}
- @SkylarkCallable(
- name = "defines",
- structField = true,
- doc =
- "Returns the list of defines used to compile this target "
- + "(possibly empty but never <code>None</code>).")
+ @Override
public ImmutableList<String> getDefines() {
CcCompilationContext ccCompilationContext =
getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext();
@@ -109,12 +75,7 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider {
: ccCompilationContext.getDefines();
}
- @SkylarkCallable(
- name = "system_include_directories",
- structField = true,
- doc =
- "Returns the list of system include directories used to compile this target "
- + "(possibly empty but never <code>None</code>).")
+ @Override
public ImmutableList<String> getSystemIncludeDirs() {
CcCompilationContext ccCompilationContext =
getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext();
@@ -128,12 +89,7 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider {
return builder.build();
}
- @SkylarkCallable(
- name = "include_directories",
- structField = true,
- doc =
- "Returns the list of include directories used to compile this target "
- + "(possibly empty but never <code>None</code>).")
+ @Override
public ImmutableList<String> getIncludeDirs() {
CcCompilationContext ccCompilationContext =
getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext();
@@ -147,12 +103,7 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider {
return builder.build();
}
- @SkylarkCallable(
- name = "quote_include_directories",
- structField = true,
- doc =
- "Returns the list of quote include directories used to compile this target "
- + "(possibly empty but never <code>None</code>).")
+ @Override
public ImmutableList<String> getQuoteIncludeDirs() {
CcCompilationContext ccCompilationContext =
getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext();
@@ -166,12 +117,7 @@ public final class CcSkylarkApiProvider extends SkylarkApiProvider {
return builder.build();
}
- @SkylarkCallable(
- name = "compile_flags",
- structField = true,
- doc =
- "Returns the list of flags used to compile this target "
- + "(possibly empty but never <code>None</code>).")
+ @Override
public ImmutableList<String> getCcFlags() {
CcCompilationContext ccCompilationContext =
getInfo().get(CcCompilationInfo.PROVIDER).getCcCompilationContext();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
index f11e80ae0b..43fc27630d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java
@@ -33,8 +33,7 @@ import com.google.devtools.build.lib.rules.cpp.CppConfiguration.Tool;
import com.google.devtools.build.lib.rules.cpp.FdoSupport.FdoMode;
import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.CcToolchainProviderApi;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -44,10 +43,10 @@ import java.util.Map;
import javax.annotation.Nullable;
/** Information about a C++ compiler used by the <code>cc_*</code> rules. */
-@SkylarkModule(name = "CcToolchainInfo", doc = "Information about the C++ compiler being used.")
@Immutable
@AutoCodec
-public final class CcToolchainProvider extends ToolchainInfo {
+public final class CcToolchainProvider extends ToolchainInfo
+ implements CcToolchainProviderApi<PathFragment> {
public static final String SKYLARK_NAME = "CcToolchainInfo";
/** An empty toolchain to be returned in the error case (instead of null). */
@@ -289,11 +288,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
getAdditionalMakeVariables()));
}
- @SkylarkCallable(
- name = "built_in_include_directories",
- doc = "Returns the list of built-in directories of the compiler.",
- structField = true
- )
+ @Override
public ImmutableList<PathFragment> getBuiltInIncludeDirectories() {
return builtInIncludeDirectories;
}
@@ -581,14 +576,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
return interfaceSoBuilder;
}
- @SkylarkCallable(
- name = "sysroot",
- structField = true,
- doc =
- "Returns the sysroot to be used. If the toolchain compiler does not support "
- + "different sysroots, or the sysroot is the same as the default sysroot, then "
- + "this method returns <code>None</code>."
- )
+ @Override
public PathFragment getSysroot() {
return sysroot;
}
@@ -641,22 +629,19 @@ public final class CcToolchainProvider extends ToolchainInfo {
}
/** Returns the compiler version string (e.g. "gcc-4.1.1"). */
- @SkylarkCallable(name = "compiler", structField = true, doc = "C++ compiler.",
- allowReturnNones = true)
+ @Override
public String getCompiler() {
return toolchainInfo == null ? null : toolchainInfo.getCompiler();
}
/** Returns the libc version string (e.g. "glibc-2.2.2"). */
- @SkylarkCallable(name = "libc", structField = true, doc = "libc version string.",
- allowReturnNones = true)
+ @Override
public String getTargetLibc() {
return toolchainInfo == null ? null : toolchainInfo.getTargetLibc();
}
/** Returns the target architecture using blaze-specific constants (e.g. "piii"). */
- @SkylarkCallable(name = "cpu", structField = true, doc = "Target CPU of the C++ toolchain.",
- allowReturnNones = true)
+ @Override
public String getTargetCpu() {
return toolchainInfo == null ? null : toolchainInfo.getTargetCpu();
}
@@ -681,11 +666,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
return toolchainInfo.supportsFission();
}
- @SkylarkCallable(
- name = "unfiltered_compiler_options",
- doc =
- "Returns the default list of options which cannot be filtered by BUILD "
- + "rules. These should be appended to the command line after filtering.")
+ @Override
// TODO(b/24373706): Remove this method once new C++ toolchain API is available
public ImmutableList<String> getUnfilteredCompilerOptionsWithSysroot(
Iterable<String> featuresNotUsedAnymore) {
@@ -706,13 +687,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
return toolchainInfo.getTargetOS();
}
- @SkylarkCallable(
- name = "link_options_do_not_use",
- structField = true,
- doc =
- "Returns the set of command-line linker options, including any flags "
- + "inferred from the command-line options."
- )
+ @Override
public ImmutableList<String> getLinkOptionsWithSysroot() {
return cppConfiguration == null
? ImmutableList.of()
@@ -868,12 +843,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
}
/** Returns the GNU System Name */
- @SkylarkCallable(
- name = "target_gnu_system_name",
- structField = true,
- doc = "The GNU System Name.",
- allowReturnNones = true
- )
+ @Override
public String getTargetGnuSystemName() {
return toolchainInfo == null ? null : toolchainInfo.getTargetGnuSystemName();
}
@@ -895,14 +865,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
* WARNING: This method is only added to allow incremental migration of existing users. Please do
* not use in new code. Will be removed soon as part of the new Skylark API to the C++ toolchain.
*/
- @SkylarkCallable(
- name = "compiler_options",
- doc =
- "Returns the default options to use for compiling C, C++, and assembler. "
- + "This is just the options that should be used for all three languages. "
- + "There may be additional C-specific or C++-specific options that should be used, "
- + "in addition to the ones returned by this method"
- )
+ @Override
public ImmutableList<String> getCompilerOptions() {
return getLegacyCompileOptionsWithCopts();
}
@@ -915,12 +878,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
* on the command line after the common options returned by {@link
* CcToolchainProvider#getLegacyCompileOptionsWithCopts()}.
*/
- @SkylarkCallable(
- name = "c_options",
- doc =
- "Returns the list of additional C-specific options to use for compiling C. "
- + "These should be go on the command line after the common options returned by "
- + "<code>compiler_options</code>")
+ @Override
public ImmutableList<String> getCOptions() {
return cppConfiguration.getCOptions();
}
@@ -932,12 +890,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
* <p>Returns the list of additional C++-specific options to use for compiling C++. These should
* be on the command line after the common options returned by {@link #getCompilerOptions}.
*/
- @SkylarkCallable(
- name = "cxx_options",
- doc =
- "Returns the list of additional C++-specific options to use for compiling C++. "
- + "These should be go on the command line after the common options returned by "
- + "<code>compiler_options</code>")
+ @Override
@Deprecated
public ImmutableList<String> getCxxOptionsWithCopts() {
return ImmutableList.<String>builder()
@@ -963,12 +916,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
*
* @param sharedLib true if the output is a shared lib, false if it's an executable
*/
- @SkylarkCallable(
- name = "fully_static_link_options",
- doc =
- "Returns the immutable list of linker options for fully statically linked "
- + "outputs. Does not include command-line options passed via --linkopt or "
- + "--linkopts.")
+ @Override
@Deprecated
public ImmutableList<String> getFullyStaticLinkOptions(Boolean sharedLib) throws EvalException {
if (!sharedLib) {
@@ -987,12 +935,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
*
* @param sharedLib true if the output is a shared lib, false if it's an executable
*/
- @SkylarkCallable(
- name = "mostly_static_link_options",
- doc =
- "Returns the immutable list of linker options for mostly statically linked "
- + "outputs. Does not include command-line options passed via --linkopt or "
- + "--linkopts.")
+ @Override
@Deprecated
public ImmutableList<String> getMostlyStaticLinkOptions(Boolean sharedLib) {
return CppHelper.getMostlyStaticLinkOptions(
@@ -1008,13 +951,7 @@ public final class CcToolchainProvider extends ToolchainInfo {
*
* @param sharedLib true if the output is a shared lib, false if it's an executable
*/
- @SkylarkCallable(
- name = "dynamic_link_options",
- doc =
- "Returns the immutable list of linker options for artifacts that are not "
- + "fully or mostly statically linked. Does not include command-line options "
- + "passed via --linkopt or --linkopts."
- )
+ @Override
@Deprecated
public ImmutableList<String> getDynamicLinkOptions(Boolean sharedLib) {
return CppHelper.getDynamicLinkOptions(cppConfiguration, this, sharedLib);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index a1721ca642..0b705aae49 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -42,9 +42,7 @@ import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode;
import com.google.devtools.build.lib.rules.cpp.transitions.ContextCollectorOwnerTransition;
import com.google.devtools.build.lib.rules.cpp.transitions.DisableLipoTransition;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
-import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.skylarkbuildapi.cpp.CppConfigurationApi;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
@@ -59,13 +57,9 @@ import javax.annotation.Nullable;
* information about the tools locations and the flags required for compiling.
*/
@AutoCodec
-@SkylarkModule(
- name = "cpp",
- doc = "A configuration fragment for C++.",
- category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT
-)
@Immutable
-public final class CppConfiguration extends BuildConfiguration.Fragment {
+public final class CppConfiguration extends BuildConfiguration.Fragment
+ implements CppConfigurationApi<InvalidConfigurationException> {
/**
* String indicating a Mac system, for example when used in a crosstool configuration's host or
* target system name.
@@ -419,7 +413,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* <p>Deprecated: Use {@link CcToolchainProvider#getCompiler()}
*/
// TODO(b/68038647): Remove once make variables are no longer derived from CppConfiguration.
- @SkylarkCallable(name = "compiler", structField = true, doc = "C++ compiler.")
+ @Override
@Deprecated
public String getCompiler() {
return cppToolchainInfo.getCompiler();
@@ -431,7 +425,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* <p>Deprecated: Use {@link CcToolchainProvider#getTargetLibc()}
*/
// TODO(b/68038647): Remove once make variables are no longer derived from CppConfiguration.
- @SkylarkCallable(name = "libc", structField = true, doc = "libc version string.")
+ @Override
@Deprecated
public String getTargetLibc() {
return cppToolchainInfo.getTargetLibc();
@@ -443,7 +437,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* <p>Deprecated: Use {@link CcToolchainProvider#getTargetCpu()}
*/
// TODO(b/68038647): Remove once skylark callers are migrated.
- @SkylarkCallable(name = "cpu", structField = true, doc = "Target CPU of the C++ toolchain.")
+ @Override
@Deprecated
public String getTargetCpu() {
return cppToolchainInfo.getTargetCpu();
@@ -500,14 +494,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
return compilationMode;
}
- @SkylarkCallable(
- name = "built_in_include_directories",
- structField = true,
- doc =
- "Built-in system include paths for the toolchain compiler. All paths in this list"
- + " should be relative to the exec directory. They may be absolute if they are also"
- + " installed on the remote build nodes or for local compilation."
- )
+ @Override
public ImmutableList<String> getBuiltInIncludeDirectoriesForSkylark()
throws InvalidConfigurationException {
return getBuiltInIncludeDirectories(nonConfiguredSysroot)
@@ -539,10 +526,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* different sysroots, or the sysroot is the same as the default sysroot, then
* this method returns <code>null</code>.
*/
- @SkylarkCallable(name = "sysroot", structField = true,
- doc = "Returns the sysroot to be used. If the toolchain compiler does not support "
- + "different sysroots, or the sysroot is the same as the default sysroot, then "
- + "this method returns <code>None</code>.")
+ @Override
public String getSysroot() {
return nonConfiguredSysroot.getPathString();
}
@@ -559,14 +543,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* <p>Deprecated: Use {@link CcToolchainProvider#getLegacyCompileOptionsWithCopts()}
*/
// TODO(b/64384912): Migrate skylark callers and remove.
- @SkylarkCallable(
- name = "compiler_options",
- doc =
- "Returns the default options to use for compiling C, C++, and assembler. "
- + "This is just the options that should be used for all three languages. "
- + "There may be additional C-specific or C++-specific options that should be used, "
- + "in addition to the ones returned by this method"
- )
+ @Override
@Deprecated
public ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore) {
return compilerFlags;
@@ -577,13 +554,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* the command line after the common options returned by {@link #getCompilerOptions}.
*/
// TODO(b/64384912): Migrate skylark callers and remove.
- @SkylarkCallable(
- name = "c_options",
- structField = true,
- doc =
- "Returns the list of additional C-specific options to use for compiling C. "
- + "These should be go on the command line after the common options returned by "
- + "<code>compiler_options</code>")
+ @Override
public ImmutableList<String> getCOptions() {
return cOptions;
}
@@ -595,13 +566,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* <p>Deprecated: Use {@link CcToolchainProvider#getCxxOptionsWithCopts}
*/
// TODO(b/64384912): Migrate skylark callers and remove.
- @SkylarkCallable(
- name = "cxx_options",
- doc =
- "Returns the list of additional C++-specific options to use for compiling C++. "
- + "These should be go on the command line after the common options returned by "
- + "<code>compiler_options</code>"
- )
+ @Override
@Deprecated
public ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore) {
return cxxFlags;
@@ -617,12 +582,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
*/
// TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here.
@Deprecated
- @SkylarkCallable(
- name = "unfiltered_compiler_options",
- doc =
- "Returns the default list of options which cannot be filtered by BUILD "
- + "rules. These should be appended to the command line after filtering."
- )
+ @Override
public ImmutableList<String> getUnfilteredCompilerOptionsWithLegacySysroot(
Iterable<String> featuresNotUsedAnymore) {
return getUnfilteredCompilerOptionsDoNotUse(nonConfiguredSysroot);
@@ -654,13 +614,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
*/
// TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here.
@Deprecated
- @SkylarkCallable(
- name = "link_options",
- structField = true,
- doc =
- "Returns the set of command-line linker options, including any flags "
- + "inferred from the command-line options."
- )
+ @Override
public ImmutableList<String> getLinkOptionsWithLegacySysroot() {
return getLinkOptionsDoNotUse(nonConfiguredSysroot);
}
@@ -714,13 +668,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* CcToolchainProvider, Boolean)}
*/
// TODO(b/64384912): Migrate skylark users to cc_common and remove.
- @SkylarkCallable(
- name = "fully_static_link_options",
- doc =
- "Returns the immutable list of linker options for fully statically linked "
- + "outputs. Does not include command-line options passed via --linkopt or "
- + "--linkopts."
- )
+ @Override
@Deprecated
public ImmutableList<String> getFullyStaticLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException {
@@ -741,13 +689,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* CcToolchainProvider, boolean, boolean)}
*/
// TODO(b/64384912): Migrate skylark users to cc_common and remove.
- @SkylarkCallable(
- name = "mostly_static_link_options",
- doc =
- "Returns the immutable list of linker options for mostly statically linked "
- + "outputs. Does not include command-line options passed via --linkopt or "
- + "--linkopts."
- )
+ @Override
@Deprecated
public ImmutableList<String> getMostlyStaticLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) {
@@ -771,13 +713,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* CcToolchainProvider, Boolean)}
*/
// TODO(b/64384912): Migrate skylark users to cc_common and remove.
- @SkylarkCallable(
- name = "dynamic_link_options",
- doc =
- "Returns the immutable list of linker options for artifacts that are not "
- + "fully or mostly statically linked. Does not include command-line options "
- + "passed via --linkopt or --linkopts."
- )
+ @Override
@Deprecated
public ImmutableList<String> getDynamicLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) {
@@ -815,7 +751,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* Returns the execution path to the linker binary to use for this build. Relative paths are
* relative to the execution root.
*/
- @SkylarkCallable(name = "ld_executable", structField = true, doc = "Path to the linker binary.")
+ @Override
public String getLdExecutableForSkylark() {
PathFragment ldExecutable = getToolPathFragment(CppConfiguration.Tool.LD);
return ldExecutable != null ? ldExecutable.getPathString() : "";
@@ -1059,31 +995,19 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
* Returns the path to the GNU binutils 'objcopy' binary to use for this build. (Corresponds to
* $(OBJCOPY) in make-dbg.) Relative paths are relative to the execution root.
*/
- @SkylarkCallable(
- name = "objcopy_executable",
- structField = true,
- doc = "Path to GNU binutils 'objcopy' binary."
- )
+ @Override
public String getObjCopyExecutableForSkylark() {
PathFragment objCopyExecutable = getToolPathFragment(Tool.OBJCOPY);
return objCopyExecutable != null ? objCopyExecutable.getPathString() : "";
}
- @SkylarkCallable(
- name = "compiler_executable",
- structField = true,
- doc = "Path to C/C++ compiler binary."
- )
+ @Override
public String getCppExecutableForSkylark() {
PathFragment cppExecutable = getToolPathFragment(Tool.GCC);
return cppExecutable != null ? cppExecutable.getPathString() : "";
}
- @SkylarkCallable(
- name = "preprocessor_executable",
- structField = true,
- doc = "Path to C/C++ preprocessor binary."
- )
+ @Override
public String getCpreprocessorExecutableForSkylark() {
PathFragment cpreprocessorExecutable = getToolPathFragment(Tool.CPP);
return cpreprocessorExecutable != null ? cpreprocessorExecutable.getPathString() : "";
@@ -1097,41 +1021,25 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
return getToolPathFragment(CppConfiguration.Tool.GCOVTOOL);
}
- @SkylarkCallable(
- name = "nm_executable",
- structField = true,
- doc = "Path to GNU binutils 'nm' binary."
- )
+ @Override
public String getNmExecutableForSkylark() {
PathFragment nmExecutable = getToolPathFragment(Tool.NM);
return nmExecutable != null ? nmExecutable.getPathString() : "";
}
- @SkylarkCallable(
- name = "objdump_executable",
- structField = true,
- doc = "Path to GNU binutils 'objdump' binary."
- )
+ @Override
public String getObjdumpExecutableForSkylark() {
PathFragment objdumpExecutable = getToolPathFragment(Tool.OBJDUMP);
return objdumpExecutable != null ? objdumpExecutable.getPathString() : "";
}
- @SkylarkCallable(
- name = "ar_executable",
- structField = true,
- doc = "Path to GNU binutils 'ar' binary."
- )
+ @Override
public String getArExecutableForSkylark() {
PathFragment arExecutable = getToolPathFragment(Tool.AR);
return arExecutable != null ? arExecutable.getPathString() : "";
}
- @SkylarkCallable(
- name = "strip_executable",
- structField = true,
- doc = "Path to GNU binutils 'strip' binary."
- )
+ @Override
public String getStripExecutableForSkylark() {
PathFragment stripExecutable = getToolPathFragment(Tool.STRIP);
return stripExecutable != null ? stripExecutable.getPathString() : "";
@@ -1142,8 +1050,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment {
*
*/
//TODO(b/70225490): Migrate skylark dependants to CcToolchainProvider and delete.
- @SkylarkCallable(name = "target_gnu_system_name", structField = true,
- doc = "The GNU System Name.")
+ @Override
@Deprecated
public String getTargetGnuSystemName() {
return cppToolchainInfo.getTargetGnuSystemName();
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BUILD b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BUILD
index 811d5cb72b..0b19d2d178 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/BUILD
@@ -23,6 +23,10 @@ java_library(
"//src/main/java/com/google/devtools/build/lib:skylarkinterface",
"//src/main/java/com/google/devtools/build/lib:syntax",
"//src/main/java/com/google/devtools/build/lib/actions",
+ "//src/main/java/com/google/devtools/build/lib/cmdline",
+ "//src/main/java/com/google/devtools/build/lib/collect/nestedset",
+ "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi",
+ "//src/main/java/com/google/devtools/build/lib/skylarkbuildapi/platform",
"//third_party:guava",
"//third_party:jsr305",
],
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingInfoApi.java
new file mode 100644
index 0000000000..12bc9368d0
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcLinkingInfoApi.java
@@ -0,0 +1,39 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+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;
+
+/**
+ * Wrapper for every C++ linking provider.
+ */
+@SkylarkModule(
+ name = "cc_linking_info",
+ documented = false,
+ category = SkylarkModuleCategory.PROVIDER,
+ doc = "Wrapper for every C++ linking provider"
+)
+public interface CcLinkingInfoApi extends StructApi {
+
+ @SkylarkCallable(
+ name = "cc_runfiles",
+ documented = false,
+ allowReturnNones = true,
+ structField = true)
+ public CcRunfilesApi getCcRunfiles();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java
new file mode 100644
index 0000000000..0a8fba160c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java
@@ -0,0 +1,35 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi.cpp;
+
+import com.google.devtools.build.lib.skylarkbuildapi.ProviderApi;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+
+/**
+ * Utilies related to C++ support.
+ */
+@SkylarkModule(name = "cc_common", doc = "Utilities related to C++ support.")
+public interface CcModuleApi {
+
+ @SkylarkCallable(
+ name = "CcToolchainInfo",
+ doc =
+ "The key used to retrieve the provider that contains information about the C++ "
+ + "toolchain being usCced",
+ structField = true
+ )
+ public ProviderApi getCcToolchainProvider();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkApiProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkApiProviderApi.java
new file mode 100644
index 0000000000..79fe8a1d8c
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcSkylarkApiProviderApi.java
@@ -0,0 +1,105 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi.cpp;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.skylarkbuildapi.FileApi;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+
+/**
+ * Object with information about C++ rules. Every C++-related target should provide this.
+ */
+@SkylarkModule(
+ name = "CcSkylarkApiProvider",
+ category = SkylarkModuleCategory.PROVIDER,
+ doc =
+ "Provides access to information about C++ rules. "
+ + "Every C++-related target provides this struct, accessible as a <code>cc</code> field "
+ + "on <a href=\"Target.html\">target</a>."
+)
+public interface CcSkylarkApiProviderApi<FileT extends FileApi> {
+
+ @SkylarkCallable(
+ name = "transitive_headers",
+ structField = true,
+ doc =
+ "Returns a <a href=\"depset.html\">depset</a> of headers that have been declared in the "
+ + " <code>src</code> or <code>headers</code> attribute"
+ + "(possibly empty but never <code>None</code>).")
+ public NestedSet<FileT> getTransitiveHeaders();
+
+ @SkylarkCallable(
+ name = "libs",
+ structField = true,
+ doc =
+ "Returns the <a href=\"depset.html\">depset</a> of libraries for either "
+ + "<code>FULLY STATIC</code> mode (<code>linkopts=[\"-static\"]</code>) or "
+ + "<code>MOSTLY STATIC</code> mode (<code>linkstatic=1</code>) "
+ + "(possibly empty but never <code>None</code>)")
+ public NestedSet<FileT> getLibraries();
+
+ @SkylarkCallable(
+ name = "link_flags",
+ structField = true,
+ doc =
+ "Returns the list of flags given to the C++ linker command for either "
+ + "<code>FULLY STATIC</code> mode (<code>linkopts=[\"-static\"]</code>) or "
+ + "<code>MOSTLY STATIC</code> mode (<code>linkstatic=1</code>) "
+ + "(possibly empty but never <code>None</code>)")
+ public ImmutableList<String> getLinkopts();
+
+ @SkylarkCallable(
+ name = "defines",
+ structField = true,
+ doc =
+ "Returns the list of defines used to compile this target "
+ + "(possibly empty but never <code>None</code>).")
+ public ImmutableList<String> getDefines();
+
+ @SkylarkCallable(
+ name = "system_include_directories",
+ structField = true,
+ doc =
+ "Returns the list of system include directories used to compile this target "
+ + "(possibly empty but never <code>None</code>).")
+ public ImmutableList<String> getSystemIncludeDirs();
+
+ @SkylarkCallable(
+ name = "include_directories",
+ structField = true,
+ doc =
+ "Returns the list of include directories used to compile this target "
+ + "(possibly empty but never <code>None</code>).")
+ public ImmutableList<String> getIncludeDirs();
+
+ @SkylarkCallable(
+ name = "quote_include_directories",
+ structField = true,
+ doc =
+ "Returns the list of quote include directories used to compile this target "
+ + "(possibly empty but never <code>None</code>).")
+ public ImmutableList<String> getQuoteIncludeDirs();
+
+ @SkylarkCallable(
+ name = "compile_flags",
+ structField = true,
+ doc =
+ "Returns the list of flags used to compile this target "
+ + "(possibly empty but never <code>None</code>).")
+ public ImmutableList<String> getCcFlags();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcToolchainProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcToolchainProviderApi.java
new file mode 100644
index 0000000000..fefb424a57
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcToolchainProviderApi.java
@@ -0,0 +1,138 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi.cpp;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.skylarkbuildapi.platform.ToolchainInfoApi;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.syntax.EvalException;
+
+/**
+ * Information about the C++ toolchain.
+ */
+@SkylarkModule(name = "CcToolchainInfo", doc = "Information about the C++ compiler being used.")
+public interface CcToolchainProviderApi<PathFragmentT> extends ToolchainInfoApi {
+
+ @SkylarkCallable(
+ name = "built_in_include_directories",
+ doc = "Returns the list of built-in directories of the compiler.",
+ structField = true
+ )
+ public ImmutableList<PathFragmentT> getBuiltInIncludeDirectories();
+
+ @SkylarkCallable(
+ name = "sysroot",
+ structField = true,
+ doc =
+ "Returns the sysroot to be used. If the toolchain compiler does not support "
+ + "different sysroots, or the sysroot is the same as the default sysroot, then "
+ + "this method returns <code>None</code>."
+ )
+ public PathFragmentT getSysroot();
+
+ @SkylarkCallable(name = "compiler", structField = true, doc = "C++ compiler.",
+ allowReturnNones = true)
+ public String getCompiler();
+
+ @SkylarkCallable(name = "libc", structField = true, doc = "libc version string.",
+ allowReturnNones = true)
+ public String getTargetLibc();
+
+ @SkylarkCallable(name = "cpu", structField = true, doc = "Target CPU of the C++ toolchain.",
+ allowReturnNones = true)
+ public String getTargetCpu();
+
+ @SkylarkCallable(
+ name = "unfiltered_compiler_options",
+ doc =
+ "Returns the default list of options which cannot be filtered by BUILD "
+ + "rules. These should be appended to the command line after filtering.")
+ // TODO(b/24373706): Remove this method once new C++ toolchain API is available
+ public ImmutableList<String> getUnfilteredCompilerOptionsWithSysroot(
+ Iterable<String> featuresNotUsedAnymore);
+
+ @SkylarkCallable(
+ name = "link_options_do_not_use",
+ structField = true,
+ doc =
+ "Returns the set of command-line linker options, including any flags "
+ + "inferred from the command-line options."
+ )
+ public ImmutableList<String> getLinkOptionsWithSysroot();
+
+ @SkylarkCallable(
+ name = "target_gnu_system_name",
+ structField = true,
+ doc = "The GNU System Name.",
+ allowReturnNones = true
+ )
+ public String getTargetGnuSystemName();
+
+ @SkylarkCallable(
+ name = "compiler_options",
+ doc =
+ "Returns the default options to use for compiling C, C++, and assembler. "
+ + "This is just the options that should be used for all three languages. "
+ + "There may be additional C-specific or C++-specific options that should be used, "
+ + "in addition to the ones returned by this method"
+ )
+ public ImmutableList<String> getCompilerOptions();
+
+ @SkylarkCallable(
+ name = "c_options",
+ doc =
+ "Returns the list of additional C-specific options to use for compiling C. "
+ + "These should be go on the command line after the common options returned by "
+ + "<code>compiler_options</code>")
+ public ImmutableList<String> getCOptions();
+
+ @SkylarkCallable(
+ name = "cxx_options",
+ doc =
+ "Returns the list of additional C++-specific options to use for compiling C++. "
+ + "These should be go on the command line after the common options returned by "
+ + "<code>compiler_options</code>")
+ @Deprecated
+ public ImmutableList<String> getCxxOptionsWithCopts();
+
+ @SkylarkCallable(
+ name = "fully_static_link_options",
+ doc =
+ "Returns the immutable list of linker options for fully statically linked "
+ + "outputs. Does not include command-line options passed via --linkopt or "
+ + "--linkopts.")
+ @Deprecated
+ public ImmutableList<String> getFullyStaticLinkOptions(Boolean sharedLib) throws EvalException;
+
+ @SkylarkCallable(
+ name = "mostly_static_link_options",
+ doc =
+ "Returns the immutable list of linker options for mostly statically linked "
+ + "outputs. Does not include command-line options passed via --linkopt or "
+ + "--linkopts.")
+ @Deprecated
+ public ImmutableList<String> getMostlyStaticLinkOptions(Boolean sharedLib);
+
+ @SkylarkCallable(
+ name = "dynamic_link_options",
+ doc =
+ "Returns the immutable list of linker options for artifacts that are not "
+ + "fully or mostly statically linked. Does not include command-line options "
+ + "passed via --linkopt or --linkopts."
+ )
+ @Deprecated
+ public ImmutableList<String> getDynamicLinkOptions(Boolean sharedLib);
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CppConfigurationApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CppConfigurationApi.java
new file mode 100644
index 0000000000..0b2e406fd5
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CppConfigurationApi.java
@@ -0,0 +1,199 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi.cpp;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+import com.google.devtools.build.lib.syntax.EvalException;
+
+/**
+ * The C++ configuration fragment.
+ */
+@SkylarkModule(
+ name = "cpp",
+ doc = "A configuration fragment for C++.",
+ category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT
+)
+public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exception> {
+
+ @SkylarkCallable(name = "compiler", structField = true, doc = "C++ compiler.")
+ @Deprecated
+ public String getCompiler();
+
+ @SkylarkCallable(name = "libc", structField = true, doc = "libc version string.")
+ @Deprecated
+ public String getTargetLibc();
+
+ @SkylarkCallable(name = "cpu", structField = true, doc = "Target CPU of the C++ toolchain.")
+ @Deprecated
+ public String getTargetCpu();
+
+ @SkylarkCallable(
+ name = "built_in_include_directories",
+ structField = true,
+ doc =
+ "Built-in system include paths for the toolchain compiler. All paths in this list"
+ + " should be relative to the exec directory. They may be absolute if they are also"
+ + " installed on the remote build nodes or for local compilation."
+ )
+ public ImmutableList<String> getBuiltInIncludeDirectoriesForSkylark()
+ throws InvalidConfigurationExceptionT;
+
+ @SkylarkCallable(name = "sysroot", structField = true,
+ doc = "Returns the sysroot to be used. If the toolchain compiler does not support "
+ + "different sysroots, or the sysroot is the same as the default sysroot, then "
+ + "this method returns <code>None</code>.")
+ public String getSysroot();
+
+ @SkylarkCallable(
+ name = "compiler_options",
+ doc =
+ "Returns the default options to use for compiling C, C++, and assembler. "
+ + "This is just the options that should be used for all three languages. "
+ + "There may be additional C-specific or C++-specific options that should be used, "
+ + "in addition to the ones returned by this method"
+ )
+ @Deprecated
+ public ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore);
+
+ @SkylarkCallable(
+ name = "c_options",
+ structField = true,
+ doc =
+ "Returns the list of additional C-specific options to use for compiling C. "
+ + "These should be go on the command line after the common options returned by "
+ + "<code>compiler_options</code>")
+ public ImmutableList<String> getCOptions();
+
+ @SkylarkCallable(
+ name = "cxx_options",
+ doc =
+ "Returns the list of additional C++-specific options to use for compiling C++. "
+ + "These should be go on the command line after the common options returned by "
+ + "<code>compiler_options</code>"
+ )
+ @Deprecated
+ public ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore);
+
+ @SkylarkCallable(
+ name = "unfiltered_compiler_options",
+ doc =
+ "Returns the default list of options which cannot be filtered by BUILD "
+ + "rules. These should be appended to the command line after filtering."
+ )
+ public ImmutableList<String> getUnfilteredCompilerOptionsWithLegacySysroot(
+ Iterable<String> featuresNotUsedAnymore);
+
+ @SkylarkCallable(
+ name = "link_options",
+ structField = true,
+ doc =
+ "Returns the set of command-line linker options, including any flags "
+ + "inferred from the command-line options."
+ )
+ public ImmutableList<String> getLinkOptionsWithLegacySysroot();
+
+ @SkylarkCallable(
+ name = "fully_static_link_options",
+ doc =
+ "Returns the immutable list of linker options for fully statically linked "
+ + "outputs. Does not include command-line options passed via --linkopt or "
+ + "--linkopts."
+ )
+ @Deprecated
+ public ImmutableList<String> getFullyStaticLinkOptions(
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException;
+
+ @SkylarkCallable(
+ name = "mostly_static_link_options",
+ doc =
+ "Returns the immutable list of linker options for mostly statically linked "
+ + "outputs. Does not include command-line options passed via --linkopt or "
+ + "--linkopts."
+ )
+ @Deprecated
+ public ImmutableList<String> getMostlyStaticLinkOptions(
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib);
+
+ @SkylarkCallable(
+ name = "dynamic_link_options",
+ doc =
+ "Returns the immutable list of linker options for artifacts that are not "
+ + "fully or mostly statically linked. Does not include command-line options "
+ + "passed via --linkopt or --linkopts."
+ )
+ @Deprecated
+ public ImmutableList<String> getDynamicLinkOptions(
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib);
+
+ @SkylarkCallable(name = "ld_executable", structField = true, doc = "Path to the linker binary.")
+ public String getLdExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "objcopy_executable",
+ structField = true,
+ doc = "Path to GNU binutils 'objcopy' binary."
+ )
+ public String getObjCopyExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "compiler_executable",
+ structField = true,
+ doc = "Path to C/C++ compiler binary."
+ )
+ public String getCppExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "preprocessor_executable",
+ structField = true,
+ doc = "Path to C/C++ preprocessor binary."
+ )
+ public String getCpreprocessorExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "nm_executable",
+ structField = true,
+ doc = "Path to GNU binutils 'nm' binary."
+ )
+ public String getNmExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "objdump_executable",
+ structField = true,
+ doc = "Path to GNU binutils 'objdump' binary."
+ )
+ public String getObjdumpExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "ar_executable",
+ structField = true,
+ doc = "Path to GNU binutils 'ar' binary."
+ )
+ public String getArExecutableForSkylark();
+
+ @SkylarkCallable(
+ name = "strip_executable",
+ structField = true,
+ doc = "Path to GNU binutils 'strip' binary."
+ )
+ public String getStripExecutableForSkylark();
+
+ @SkylarkCallable(name = "target_gnu_system_name", structField = true,
+ doc = "The GNU System Name.")
+ @Deprecated
+ public String getTargetGnuSystemName();
+}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java
new file mode 100644
index 0000000000..cf708412cc
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/LinkingInfoApi.java
@@ -0,0 +1,34 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi.cpp;
+
+import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+
+/**
+ * Helper object containing CC linking info objects.
+ */
+@SkylarkModule(
+ name = "linking_info",
+ documented = false,
+ category = SkylarkModuleCategory.BUILTIN,
+ doc = "Helper class containing CC linking providers."
+)
+public interface LinkingInfoApi {
+
+ @SkylarkCallable(name = "cc_linking_info", documented = false)
+ public CcLinkingInfoApi getCcLinkParamsInfo();
+}