aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar hlopko <hlopko@google.com>2018-08-08 02:31:40 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-08 02:33:11 -0700
commitb9c72697596af9ec650c29513c5057c9314c29f7 (patch)
tree37f0b060885d064b83ff111d0c4cc300a0cb81ec /src/main
parent1056e9451282a5f709d10ce473c817998874af56 (diff)
Expose methods returning bare C++ options in Skylark
This cl exposes getters for flags passed by --copt, --cxxopt, --conlyopt, and --linkopt Bazel options. Fixes #5602. While at it, I deprecated existing methods that are either migrated to the C++ toolchain, or to cc_common. RELNOTES: None. PiperOrigin-RevId: 207854692
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java43
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CppConfigurationApi.java365
2 files changed, 225 insertions, 183 deletions
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 df698edc8f..10b65c1738 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
@@ -216,7 +216,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
private final ImmutableList<String> compilerFlags;
private final ImmutableList<String> cxxFlags;
private final ImmutableList<String> unfilteredCompilerFlags;
- private final ImmutableList<String> cOptions;
+ private final ImmutableList<String> conlyopts;
private final ImmutableList<String> mostlyStaticLinkFlags;
private final ImmutableList<String> mostlyStaticSharedLinkFlags;
@@ -224,7 +224,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
private final ImmutableList<String> copts;
private final ImmutableList<String> cxxopts;
- private final ImmutableList<String> linkOptions;
+ private final ImmutableList<String> linkopts;
private final ImmutableList<String> ltoindexOptions;
private final ImmutableList<String> ltobackendOptions;
@@ -332,13 +332,13 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
ImmutableList<String> compilerFlags,
ImmutableList<String> cxxFlags,
ImmutableList<String> unfilteredCompilerFlags,
- ImmutableList<String> cOptions,
+ ImmutableList<String> conlyopts,
ImmutableList<String> mostlyStaticLinkFlags,
ImmutableList<String> mostlyStaticSharedLinkFlags,
ImmutableList<String> dynamicLinkFlags,
ImmutableList<String> copts,
ImmutableList<String> cxxopts,
- ImmutableList<String> linkOptions,
+ ImmutableList<String> linkopts,
ImmutableList<String> ltoindexOptions,
ImmutableList<String> ltobackendOptions,
CppOptions cppOptions,
@@ -361,13 +361,13 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
this.compilerFlags = compilerFlags;
this.cxxFlags = cxxFlags;
this.unfilteredCompilerFlags = unfilteredCompilerFlags;
- this.cOptions = cOptions;
+ this.conlyopts = conlyopts;
this.mostlyStaticLinkFlags = mostlyStaticLinkFlags;
this.mostlyStaticSharedLinkFlags = mostlyStaticSharedLinkFlags;
this.dynamicLinkFlags = dynamicLinkFlags;
this.copts = copts;
this.cxxopts = cxxopts;
- this.linkOptions = linkOptions;
+ this.linkopts = linkopts;
this.ltoindexOptions = ltoindexOptions;
this.ltobackendOptions = ltobackendOptions;
this.cppOptions = cppOptions;
@@ -602,7 +602,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
}
public ImmutableList<String> getCOptions() {
- return cOptions;
+ return conlyopts;
}
/**
@@ -683,12 +683,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
@Deprecated
ImmutableList<String> getLinkOptionsDoNotUse(@Nullable PathFragment sysroot) {
if (sysroot == null) {
- return linkOptions;
+ return linkopts;
} else {
- return ImmutableList.<String>builder()
- .addAll(linkOptions)
- .add("--sysroot=" + sysroot)
- .build();
+ return ImmutableList.<String>builder().addAll(linkopts).add("--sysroot=" + sysroot).build();
}
}
@@ -696,11 +693,11 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
if (dropFullyStaticLinkingMode()) {
return false;
}
- return linkOptions.contains("-static");
+ return linkopts.contains("-static");
}
public boolean hasSharedLinkOption() {
- return linkOptions.contains("-shared");
+ return linkopts.contains("-shared");
}
/** Returns the set of command-line LTO indexing options. */
@@ -1059,16 +1056,30 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
return cppOptions.experimentalOmitfp;
}
- /** Returns copts given at the Bazel command line. */
+ /** Returns flags passed to Bazel by --copt option. */
+ @Override
public ImmutableList<String> getCopts() {
return copts;
}
- /** Returns copts for c++ given at the Bazel command line. */
+ /** Returns flags passed to Bazel by --cxxopt option. */
+ @Override
public ImmutableList<String> getCxxopts() {
return cxxopts;
}
+ /** Returns flags passed to Bazel by --conlyopt option. */
+ @Override
+ public ImmutableList<String> getConlyopts() {
+ return conlyopts;
+ }
+
+ /** Returns flags passed to Bazel by --linkopt option. */
+ @Override
+ public ImmutableList<String> getLinkopts() {
+ return linkopts;
+ }
+
@Override
public void reportInvalidOptions(EventHandler reporter, BuildOptions buildOptions) {
CppOptions cppOptions = buildOptions.get(CppOptions.class);
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
index f8bcbedf5a..1d45412635 100644
--- 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
@@ -32,52 +32,87 @@ import com.google.devtools.build.lib.syntax.SkylarkList;
)
public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exception> {
- @SkylarkCallable(name = "compiler", structField = true, doc = "C++ compiler.")
+ @SkylarkCallable(
+ name = "copts",
+ structField = true,
+ doc = "Returns flags passed to Bazel by --copt option.")
+ ImmutableList<String> getCopts() throws EvalException;
+
+ @SkylarkCallable(
+ name = "cxxopts",
+ structField = true,
+ doc = "Returns flags passed to Bazel by --cxxopt option.")
+ ImmutableList<String> getCxxopts() throws EvalException;
+
+ @SkylarkCallable(
+ name = "conlyopts",
+ structField = true,
+ doc = "Returns flags passed to Bazel by --conlyopt option.")
+ ImmutableList<String> getConlyopts() throws EvalException;
+
+ @SkylarkCallable(
+ name = "linkopts",
+ structField = true,
+ doc = "Returns flags passed to Bazel by --linkopt option.")
+ ImmutableList<String> getLinkopts() throws EvalException;
+
+ @SkylarkCallable(
+ name = "compiler",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> C++ compiler.")
@Deprecated
String getCompiler() throws EvalException;
- @SkylarkCallable(name = "libc", structField = true, doc = "libc version string.")
+ @SkylarkCallable(
+ name = "libc",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> libc version string.")
@Deprecated
String getTargetLibc() throws EvalException;
- @SkylarkCallable(name = "cpu", structField = true, doc = "Target CPU of the C++ toolchain.")
+ @SkylarkCallable(
+ name = "cpu",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Target CPU of the C++ toolchain.")
@Deprecated
String getTargetCpu() throws EvalException;
@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."
- )
+ name = "built_in_include_directories",
+ structField = true,
+ doc =
+ "<b>Deprecated (use CcToolchainInfo instead).</b> 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.")
+ @Deprecated
ImmutableList<String> getBuiltInIncludeDirectoriesForSkylark()
throws InvalidConfigurationExceptionT, EvalException;
- @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>.")
+ @SkylarkCallable(
+ name = "sysroot",
+ structField = true,
+ doc =
+ "<b>Deprecated (use CcToolchainInfo instead).</b> 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>.")
String getSysroot() throws EvalException;
@SkylarkCallable(
- name = "compiler_options",
- doc =
- "<b>Deprecated.</b> 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",
- parameters = {
- @Param(
- name = "features",
- doc = "Unused.",
- positional = true,
- named = false,
- type = SkylarkList.class
- )
- }
- )
+ name = "compiler_options",
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> 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",
+ parameters = {
+ @Param(
+ name = "features",
+ doc = "Unused.",
+ positional = true,
+ named = false,
+ type = SkylarkList.class)
+ })
@Deprecated
ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore)
throws EvalException;
@@ -86,193 +121,189 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
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>")
+ "<b>Deprecated (use methods in cc_common instead).</b> 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>")
ImmutableList<String> getCOptionsForSkylark() throws EvalException;
@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>",
- parameters = {
- @Param(
- name = "features",
- doc = "Unused.",
- positional = true,
- named = false,
- type = SkylarkList.class
- )
- }
- )
+ name = "cxx_options",
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> 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>",
+ parameters = {
+ @Param(
+ name = "features",
+ doc = "Unused.",
+ positional = true,
+ named = false,
+ type = SkylarkList.class)
+ })
@Deprecated
- ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore)
- throws EvalException;
+ ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore) throws EvalException;
@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.",
- parameters = {
- @Param(
- name = "features",
- doc = "Unused.",
- positional = true,
- named = false,
- type = SkylarkList.class
- )
- }
- )
+ name = "unfiltered_compiler_options",
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> Returns the default list of "
+ + "options which cannot be filtered by BUILD rules. These should be appended to the "
+ + "command line after filtering.",
+ parameters = {
+ @Param(
+ name = "features",
+ doc = "Unused.",
+ positional = true,
+ named = false,
+ type = SkylarkList.class)
+ })
+ @Deprecated
ImmutableList<String> getUnfilteredCompilerOptionsWithLegacySysroot(
Iterable<String> featuresNotUsedAnymore) throws EvalException;
@SkylarkCallable(
- name = "link_options",
- structField = true,
- doc =
- "Returns the set of command-line linker options, including any flags "
- + "inferred from the command-line options."
- )
+ name = "link_options",
+ structField = true,
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> Returns the set of command-line "
+ + "linker options, including any flags inferred from the command-line options.")
ImmutableList<String> getLinkOptionsWithLegacySysroot() throws EvalException;
@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.",
- parameters = {
- @Param(
- name = "features",
- doc = "Unused.",
- positional = true,
- named = false,
- type = SkylarkList.class
- ),
- @Param(
- name = "shared_lib",
- doc = "If true, returns the link options for a shared library.",
- positional = true,
- named = false,
- type = Boolean.class
- )
- }
- )
+ name = "fully_static_link_options",
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> Returns the immutable list of "
+ + "linker options for fully statically linked outputs. Does not include command-line "
+ + "options passed via --linkopt or "
+ + "--linkopts.",
+ parameters = {
+ @Param(
+ name = "features",
+ doc = "Unused.",
+ positional = true,
+ named = false,
+ type = SkylarkList.class),
+ @Param(
+ name = "shared_lib",
+ doc = "If true, returns the link options for a shared library.",
+ positional = true,
+ named = false,
+ type = Boolean.class)
+ })
@Deprecated
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.",
- parameters = {
- @Param(
- name = "features",
- doc = "Unused.",
- positional = true,
- named = false,
- type = SkylarkList.class
- ),
- @Param(
- name = "shared_lib",
- doc = "If true, returns the link options for a shared library.",
- positional = true,
- named = false,
- type = Boolean.class
- )
- }
- )
+ name = "mostly_static_link_options",
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> Returns the immutable list of "
+ + "linker options for mostly statically linked outputs. Does not include "
+ + "command-line options passed via --linkopt or--linkopts.",
+ parameters = {
+ @Param(
+ name = "features",
+ doc = "Unused.",
+ positional = true,
+ named = false,
+ type = SkylarkList.class),
+ @Param(
+ name = "shared_lib",
+ doc = "If true, returns the link options for a shared library.",
+ positional = true,
+ named = false,
+ type = Boolean.class)
+ })
@Deprecated
ImmutableList<String> getMostlyStaticLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException;
@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.",
- parameters = {
- @Param(
- name = "features",
- doc = "Unused.",
- positional = true,
- named = false,
- type = SkylarkList.class
- ),
- @Param(
- name = "shared_lib",
- doc = "If true, returns the link options for a shared library.",
- positional = true,
- named = false,
- type = Boolean.class
- )
- }
- )
+ name = "dynamic_link_options",
+ doc =
+ "<b>Deprecated (use methods in cc_common instead).</b> 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.",
+ parameters = {
+ @Param(
+ name = "features",
+ doc = "Unused.",
+ positional = true,
+ named = false,
+ type = SkylarkList.class),
+ @Param(
+ name = "shared_lib",
+ doc = "If true, returns the link options for a shared library.",
+ positional = true,
+ named = false,
+ type = Boolean.class)
+ })
@Deprecated
ImmutableList<String> getDynamicLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException;
- @SkylarkCallable(name = "ld_executable", structField = true, doc = "Path to the linker binary.")
+ @SkylarkCallable(
+ name = "ld_executable",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Path to the linker binary.")
+ @Deprecated
String getLdExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "objcopy_executable",
- structField = true,
- doc = "Path to GNU binutils 'objcopy' binary."
- )
+ name = "objcopy_executable",
+ structField = true,
+ doc =
+ "<b>Deprecated (use CcToolchainInfo instead).</b> Path to GNU binutils 'objcopy' binary.")
+ @Deprecated
String getObjCopyExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "compiler_executable",
- structField = true,
- doc = "Path to C/C++ compiler binary."
- )
+ name = "compiler_executable",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Path to C/C++ compiler binary.")
+ @Deprecated
String getCppExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "preprocessor_executable",
- structField = true,
- doc = "Path to C/C++ preprocessor binary."
- )
+ name = "preprocessor_executable",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Path to C/C++ preprocessor binary.")
+ @Deprecated
String getCpreprocessorExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "nm_executable",
- structField = true,
- doc = "Path to GNU binutils 'nm' binary."
- )
+ name = "nm_executable",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Path to GNU binutils 'nm' binary.")
+ @Deprecated
String getNmExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "objdump_executable",
- structField = true,
- doc = "Path to GNU binutils 'objdump' binary."
- )
+ name = "objdump_executable",
+ structField = true,
+ doc =
+ "<b>Deprecated (use CcToolchainInfo instead).</b> Path to GNU binutils 'objdump' binary.")
+ @Deprecated
String getObjdumpExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "ar_executable",
- structField = true,
- doc = "Path to GNU binutils 'ar' binary."
- )
+ name = "ar_executable",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Path to GNU binutils 'ar' binary.")
+ @Deprecated
String getArExecutableForSkylark() throws EvalException;
@SkylarkCallable(
- name = "strip_executable",
- structField = true,
- doc = "Path to GNU binutils 'strip' binary."
- )
+ name = "strip_executable",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> Path to GNU binutils 'strip' binary.")
+ @Deprecated
String getStripExecutableForSkylark() throws EvalException;
- @SkylarkCallable(name = "target_gnu_system_name", structField = true,
- doc = "The GNU System Name.")
+ @SkylarkCallable(
+ name = "target_gnu_system_name",
+ structField = true,
+ doc = "<b>Deprecated (use CcToolchainInfo instead).</b> The GNU System Name.")
@Deprecated
String getTargetGnuSystemName() throws EvalException;
}