diff options
author | 2018-05-25 13:31:09 -0700 | |
---|---|---|
committer | 2018-05-25 13:32:51 -0700 | |
commit | 9b5d886524cd0a65b27079ca76299403a18d2bb7 (patch) | |
tree | f89f9a9f439b622f0378b77db9a58c29157c18fb /src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp | |
parent | 10a6130dbafdf4e5f61198bec08b88fe6d6381fe (diff) |
Migrate cpp rules skylark objects to skylarkbuildapi
RELNOTES: None.
PiperOrigin-RevId: 198094324
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp')
7 files changed, 554 insertions, 0 deletions
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(); +} |