From e810ae5118f19d118260165608c1e840ccbe3f26 Mon Sep 17 00:00:00 2001 From: lberki Date: Mon, 2 Jul 2018 00:11:48 -0700 Subject: 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 --- .../build/lib/rules/cpp/CppConfiguration.java | 104 ++++++++++++++------- .../devtools/build/lib/rules/cpp/CppOptions.java | 11 +++ .../skylarkbuildapi/cpp/CppConfigurationApi.java | 54 +++++------ 3 files changed, 111 insertions(+), 58 deletions(-) (limited to 'src/main') 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 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 null. */ @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 getCompilerOptions(Iterable featuresNotUsedAnymore) { + public ImmutableList getCompilerOptions(Iterable 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 getCOptionsForSkylark() throws EvalException { + checkForToolchainSkylarkApiAvailability(); + return getCOptions(); + } + public ImmutableList 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 getCxxOptions(Iterable featuresNotUsedAnymore) { + public ImmutableList getCxxOptions(Iterable featuresNotUsedAnymore) + throws EvalException { + checkForToolchainSkylarkApiAvailability(); return cxxFlags; } @@ -584,7 +601,8 @@ public final class CppConfiguration extends BuildConfiguration.Fragment @Deprecated @Override public ImmutableList getUnfilteredCompilerOptionsWithLegacySysroot( - Iterable featuresNotUsedAnymore) { + Iterable 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 getUnfilteredCompilerOptionsDoNotUse(@Nullable PathFragment sysroot) { + ImmutableList 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 getLinkOptionsWithLegacySysroot() { + public ImmutableList getLinkOptionsWithLegacySysroot() throws EvalException { + checkForToolchainSkylarkApiAvailability(); return getLinkOptionsDoNotUse(nonConfiguredSysroot); } @@ -672,6 +693,7 @@ public final class CppConfiguration extends BuildConfiguration.Fragment @Deprecated public ImmutableList getFullyStaticLinkOptions( Iterable 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 getMostlyStaticLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) { + Iterable 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 getDynamicLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) { + Iterable 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.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 @@ -787,6 +787,17 @@ public class CppOptions extends FragmentOptions { help = "If true, entries in linkopts that are not preceded by - or $ will be expanded.") 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", 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 getBuiltInIncludeDirectoriesForSkylark() - throws InvalidConfigurationExceptionT; + ImmutableList 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 None.") - public String getSysroot(); + String getSysroot() throws EvalException; @SkylarkCallable( name = "compiler_options", @@ -79,7 +79,8 @@ public interface CppConfigurationApi getCompilerOptions(Iterable featuresNotUsedAnymore); + ImmutableList getCompilerOptions(Iterable featuresNotUsedAnymore) + throws EvalException; @SkylarkCallable( name = "c_options", @@ -88,7 +89,7 @@ public interface CppConfigurationApi compiler_options") - public ImmutableList getCOptions(); + ImmutableList getCOptionsForSkylark() throws EvalException; @SkylarkCallable( name = "cxx_options", @@ -107,7 +108,8 @@ public interface CppConfigurationApi getCxxOptions(Iterable featuresNotUsedAnymore); + ImmutableList getCxxOptions(Iterable featuresNotUsedAnymore) + throws EvalException; @SkylarkCallable( name = "unfiltered_compiler_options", @@ -124,8 +126,8 @@ public interface CppConfigurationApi getUnfilteredCompilerOptionsWithLegacySysroot( - Iterable featuresNotUsedAnymore); + ImmutableList getUnfilteredCompilerOptionsWithLegacySysroot( + Iterable featuresNotUsedAnymore) throws EvalException; @SkylarkCallable( name = "link_options", @@ -134,7 +136,7 @@ public interface CppConfigurationApi getLinkOptionsWithLegacySysroot(); + ImmutableList getLinkOptionsWithLegacySysroot() throws EvalException; @SkylarkCallable( name = "fully_static_link_options", @@ -160,7 +162,7 @@ public interface CppConfigurationApi getFullyStaticLinkOptions( + ImmutableList getFullyStaticLinkOptions( Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException; @SkylarkCallable( @@ -187,8 +189,8 @@ public interface CppConfigurationApi getMostlyStaticLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib); + ImmutableList getMostlyStaticLinkOptions( + Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException; @SkylarkCallable( name = "dynamic_link_options", @@ -214,63 +216,63 @@ public interface CppConfigurationApi getDynamicLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib); + ImmutableList getDynamicLinkOptions( + Iterable 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; } -- cgit v1.2.3