aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2018-07-02 00:11:48 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-02 00:14:31 -0700
commite810ae5118f19d118260165608c1e840ccbe3f26 (patch)
tree3b071e27b5b07c9fbbd10afca3edba45c08e0600 /src/main
parenta5e2f1b3d0679ef82d658a7e02bffa8d515faf8d (diff)
Add a flag to disable the parts of the Skylark API of the C++ configuration that depend on BUILD/CROSSTOOL files.
Also add @Deprecated tags for these methods and extract CppConfigurationSkylarkTest in a separate class so that it actually gets run (followup change with the explanation a-coming) RELNOTES: None. PiperOrigin-RevId: 202903559
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java104
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CppConfigurationApi.java54
3 files changed, 111 insertions, 58 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 965317c0fe..523b8fecbf 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
@@ -415,7 +415,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// TODO(b/68038647): Remove once make variables are no longer derived from CppConfiguration.
@Override
@Deprecated
- public String getCompiler() {
+ public String getCompiler() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return cppToolchainInfo.getCompiler();
}
@@ -427,7 +428,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// TODO(b/68038647): Remove once make variables are no longer derived from CppConfiguration.
@Override
@Deprecated
- public String getTargetLibc() {
+ public String getTargetLibc() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return cppToolchainInfo.getTargetLibc();
}
@@ -439,7 +441,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// TODO(b/68038647): Remove once skylark callers are migrated.
@Override
@Deprecated
- public String getTargetCpu() {
+ public String getTargetCpu() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return cppToolchainInfo.getTargetCpu();
}
@@ -495,8 +498,10 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
}
@Override
+ @Deprecated
public ImmutableList<String> getBuiltInIncludeDirectoriesForSkylark()
- throws InvalidConfigurationException {
+ throws InvalidConfigurationException, EvalException {
+ checkForToolchainSkylarkApiAvailability();
return getBuiltInIncludeDirectories(nonConfiguredSysroot)
.stream()
.map(PathFragment::getPathString)
@@ -527,7 +532,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
* this method returns <code>null</code>.
*/
@Override
- public String getSysroot() {
+ @Deprecated
+ public String getSysroot() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return nonConfiguredSysroot.getPathString();
}
@@ -545,7 +552,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// TODO(b/64384912): Migrate skylark callers and remove.
@Override
@Deprecated
- public ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore) {
+ public ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore)
+ throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return compilerFlags;
}
@@ -555,6 +564,12 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
*/
// TODO(b/64384912): Migrate skylark callers and remove.
@Override
+ @Deprecated
+ public ImmutableList<String> getCOptionsForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
+ return getCOptions();
+ }
+
public ImmutableList<String> getCOptions() {
return cOptions;
}
@@ -568,7 +583,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// TODO(b/64384912): Migrate skylark callers and remove.
@Override
@Deprecated
- public ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore) {
+ public ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore)
+ throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return cxxFlags;
}
@@ -584,7 +601,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
@Deprecated
@Override
public ImmutableList<String> getUnfilteredCompilerOptionsWithLegacySysroot(
- Iterable<String> featuresNotUsedAnymore) {
+ Iterable<String> featuresNotUsedAnymore) throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return getUnfilteredCompilerOptionsDoNotUse(nonConfiguredSysroot);
}
@@ -594,7 +612,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
*/
// TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here.
@Deprecated
- ImmutableList<String> getUnfilteredCompilerOptionsDoNotUse(@Nullable PathFragment sysroot) {
+ ImmutableList<String> getUnfilteredCompilerOptionsDoNotUse(@Nullable PathFragment sysroot)
+ throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
if (sysroot == null) {
return unfilteredCompilerFlags;
}
@@ -615,7 +635,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here.
@Deprecated
@Override
- public ImmutableList<String> getLinkOptionsWithLegacySysroot() {
+ public ImmutableList<String> getLinkOptionsWithLegacySysroot() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return getLinkOptionsDoNotUse(nonConfiguredSysroot);
}
@@ -672,6 +693,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
@Deprecated
public ImmutableList<String> getFullyStaticLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
if (!sharedLib) {
throw new EvalException(
Location.BUILTIN, "fully_static_link_options is deprecated, new uses are not allowed.");
@@ -692,7 +714,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
@Override
@Deprecated
public ImmutableList<String> getMostlyStaticLinkOptions(
- Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) {
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
if (sharedLib) {
return getSharedLibraryLinkOptions(
cppToolchainInfo.supportsEmbeddedRuntimes()
@@ -716,7 +739,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
@Override
@Deprecated
public ImmutableList<String> getDynamicLinkOptions(
- Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) {
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
if (sharedLib) {
return getSharedLibraryLinkOptions(dynamicLinkFlags);
} else {
@@ -752,7 +776,9 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
* relative to the execution root.
*/
@Override
- public String getLdExecutableForSkylark() {
+ @Deprecated
+ public String getLdExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment ldExecutable = getToolPathFragment(CppConfiguration.Tool.LD);
return ldExecutable != null ? ldExecutable.getPathString() : "";
}
@@ -932,51 +958,57 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
* $(OBJCOPY) in make-dbg.) Relative paths are relative to the execution root.
*/
@Override
- public String getObjCopyExecutableForSkylark() {
+ @Deprecated
+ public String getObjCopyExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment objCopyExecutable = getToolPathFragment(Tool.OBJCOPY);
return objCopyExecutable != null ? objCopyExecutable.getPathString() : "";
}
@Override
- public String getCppExecutableForSkylark() {
+ @Deprecated
+ public String getCppExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment cppExecutable = getToolPathFragment(Tool.GCC);
return cppExecutable != null ? cppExecutable.getPathString() : "";
}
@Override
- public String getCpreprocessorExecutableForSkylark() {
+ @Deprecated
+ public String getCpreprocessorExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment cpreprocessorExecutable = getToolPathFragment(Tool.CPP);
return cpreprocessorExecutable != null ? cpreprocessorExecutable.getPathString() : "";
}
- /**
- * Returns the path to the 'gcov-tool' executable that should be used
- * by this build. Relative paths are relative to the execution root.
- */
- public PathFragment getGcovToolExecutable() {
- return getToolPathFragment(CppConfiguration.Tool.GCOVTOOL);
- }
-
@Override
- public String getNmExecutableForSkylark() {
+ @Deprecated
+ public String getNmExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment nmExecutable = getToolPathFragment(Tool.NM);
return nmExecutable != null ? nmExecutable.getPathString() : "";
}
@Override
- public String getObjdumpExecutableForSkylark() {
+ @Deprecated
+ public String getObjdumpExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment objdumpExecutable = getToolPathFragment(Tool.OBJDUMP);
return objdumpExecutable != null ? objdumpExecutable.getPathString() : "";
}
@Override
- public String getArExecutableForSkylark() {
+ @Deprecated
+ public String getArExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment arExecutable = getToolPathFragment(Tool.AR);
return arExecutable != null ? arExecutable.getPathString() : "";
}
@Override
- public String getStripExecutableForSkylark() {
+ @Deprecated
+ public String getStripExecutableForSkylark() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
PathFragment stripExecutable = getToolPathFragment(Tool.STRIP);
return stripExecutable != null ? stripExecutable.getPathString() : "";
}
@@ -988,7 +1020,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
//TODO(b/70225490): Migrate skylark dependants to CcToolchainProvider and delete.
@Override
@Deprecated
- public String getTargetGnuSystemName() {
+ public String getTargetGnuSystemName() throws EvalException {
+ checkForToolchainSkylarkApiAvailability();
return cppToolchainInfo.getTargetGnuSystemName();
}
@@ -1062,8 +1095,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
globalMakeEnvBuilder.putAll(
CcToolchainProvider.getCppBuildVariables(
this::getToolPathFragment,
- getTargetLibc(),
- getCompiler(),
+ cppToolchainInfo.getTargetLibc(),
+ cppToolchainInfo.getCompiler(),
desiredCpu,
crosstoolTopPathFragment,
cppToolchainInfo.getAbiGlibcVersion(),
@@ -1097,7 +1130,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
// --compiler initially defaults to null because its *actual* default isn't known
// until it's read from the CROSSTOOL. Feed the CROSSTOOL defaults in here.
return ImmutableMap.<String, Object>of(
- "compiler", getCompiler());
+ "compiler", cppToolchainInfo.getCompiler());
}
public String getFdoInstrument() {
@@ -1128,6 +1161,13 @@ public final class CppConfiguration extends BuildConfiguration.Fragment
return cppOptions.useLLVMCoverageMapFormat;
}
+ private void checkForToolchainSkylarkApiAvailability() throws EvalException {
+ if (!cppOptions.enableLegacyToolchainSkylarkApi) {
+ throw new EvalException(null, "Information about the C++ toolchain API is not accessible "
+ + "anymore through ctx.fragments.cpp . Use CcToolchainInfo instead.");
+ }
+ }
+
public static PathFragment computeDefaultSysroot(String builtInSysroot) {
if (builtInSysroot.isEmpty()) {
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
index 98d7573aac..8ce5b3cd3e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
@@ -788,6 +788,17 @@ public class CppOptions extends FragmentOptions {
public boolean expandLinkoptsLabels;
@Option(
+ name = "incompatible_enable_legacy_cpp_toolchain_skylark_api",
+ defaultValue = "true",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
+ metadataTags = {
+ OptionMetadataTag.INCOMPATIBLE_CHANGE,
+ OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES},
+ help = "Flag for disabling access to the C++ toolchain API through the ctx.fragments.cpp .")
+ public boolean enableLegacyToolchainSkylarkApi;
+
+ @Option(
name = "experimental_enable_cc_skylark_api",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
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 3e85affcf6..f8bcbedf5a 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
@@ -34,15 +34,15 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
@SkylarkCallable(name = "compiler", structField = true, doc = "C++ compiler.")
@Deprecated
- public String getCompiler();
+ String getCompiler() throws EvalException;
@SkylarkCallable(name = "libc", structField = true, doc = "libc version string.")
@Deprecated
- public String getTargetLibc();
+ String getTargetLibc() throws EvalException;
@SkylarkCallable(name = "cpu", structField = true, doc = "Target CPU of the C++ toolchain.")
@Deprecated
- public String getTargetCpu();
+ String getTargetCpu() throws EvalException;
@SkylarkCallable(
name = "built_in_include_directories",
@@ -52,14 +52,14 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
+ " 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;
+ 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>.")
- public String getSysroot();
+ String getSysroot() throws EvalException;
@SkylarkCallable(
name = "compiler_options",
@@ -79,7 +79,8 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
}
)
@Deprecated
- public ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore);
+ ImmutableList<String> getCompilerOptions(Iterable<String> featuresNotUsedAnymore)
+ throws EvalException;
@SkylarkCallable(
name = "c_options",
@@ -88,7 +89,7 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
"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();
+ ImmutableList<String> getCOptionsForSkylark() throws EvalException;
@SkylarkCallable(
name = "cxx_options",
@@ -107,7 +108,8 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
}
)
@Deprecated
- public ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore);
+ ImmutableList<String> getCxxOptions(Iterable<String> featuresNotUsedAnymore)
+ throws EvalException;
@SkylarkCallable(
name = "unfiltered_compiler_options",
@@ -124,8 +126,8 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
)
}
)
- public ImmutableList<String> getUnfilteredCompilerOptionsWithLegacySysroot(
- Iterable<String> featuresNotUsedAnymore);
+ ImmutableList<String> getUnfilteredCompilerOptionsWithLegacySysroot(
+ Iterable<String> featuresNotUsedAnymore) throws EvalException;
@SkylarkCallable(
name = "link_options",
@@ -134,7 +136,7 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
"Returns the set of command-line linker options, including any flags "
+ "inferred from the command-line options."
)
- public ImmutableList<String> getLinkOptionsWithLegacySysroot();
+ ImmutableList<String> getLinkOptionsWithLegacySysroot() throws EvalException;
@SkylarkCallable(
name = "fully_static_link_options",
@@ -160,7 +162,7 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
}
)
@Deprecated
- public ImmutableList<String> getFullyStaticLinkOptions(
+ ImmutableList<String> getFullyStaticLinkOptions(
Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException;
@SkylarkCallable(
@@ -187,8 +189,8 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
}
)
@Deprecated
- public ImmutableList<String> getMostlyStaticLinkOptions(
- Iterable<String> featuresNotUsedAnymore, Boolean sharedLib);
+ ImmutableList<String> getMostlyStaticLinkOptions(
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException;
@SkylarkCallable(
name = "dynamic_link_options",
@@ -214,63 +216,63 @@ public interface CppConfigurationApi <InvalidConfigurationExceptionT extends Exc
}
)
@Deprecated
- public ImmutableList<String> getDynamicLinkOptions(
- Iterable<String> featuresNotUsedAnymore, Boolean sharedLib);
+ ImmutableList<String> getDynamicLinkOptions(
+ Iterable<String> featuresNotUsedAnymore, Boolean sharedLib) throws EvalException;
@SkylarkCallable(name = "ld_executable", structField = true, doc = "Path to the linker binary.")
- public String getLdExecutableForSkylark();
+ String getLdExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "objcopy_executable",
structField = true,
doc = "Path to GNU binutils 'objcopy' binary."
)
- public String getObjCopyExecutableForSkylark();
+ String getObjCopyExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "compiler_executable",
structField = true,
doc = "Path to C/C++ compiler binary."
)
- public String getCppExecutableForSkylark();
+ String getCppExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "preprocessor_executable",
structField = true,
doc = "Path to C/C++ preprocessor binary."
)
- public String getCpreprocessorExecutableForSkylark();
+ String getCpreprocessorExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "nm_executable",
structField = true,
doc = "Path to GNU binutils 'nm' binary."
)
- public String getNmExecutableForSkylark();
+ String getNmExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "objdump_executable",
structField = true,
doc = "Path to GNU binutils 'objdump' binary."
)
- public String getObjdumpExecutableForSkylark();
+ String getObjdumpExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "ar_executable",
structField = true,
doc = "Path to GNU binutils 'ar' binary."
)
- public String getArExecutableForSkylark();
+ String getArExecutableForSkylark() throws EvalException;
@SkylarkCallable(
name = "strip_executable",
structField = true,
doc = "Path to GNU binutils 'strip' binary."
)
- public String getStripExecutableForSkylark();
+ String getStripExecutableForSkylark() throws EvalException;
@SkylarkCallable(name = "target_gnu_system_name", structField = true,
doc = "The GNU System Name.")
@Deprecated
- public String getTargetGnuSystemName();
+ String getTargetGnuSystemName() throws EvalException;
}