diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java index 2fba9e6c0036df..a21a79450a7d0b 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java @@ -40,6 +40,47 @@ public class BazelRulesModule extends BlazeModule { /** This is where deprecated options go to die. */ public static class GraveyardOptions extends OptionsBase { + @Option( + name = "incompatible_disable_legacy_flags_cc_toolchain_api", + defaultValue = "true", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, + metadataTags = { + OptionMetadataTag.INCOMPATIBLE_CHANGE, + OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES, + OptionMetadataTag.DEPRECATED + }, + help = + "Flag for disabling the legacy cc_toolchain Skylark API for accessing legacy " + + "CROSSTOOL fields.") + public boolean disableLegacyFlagsCcToolchainApi; + + @Option( + name = "incompatible_enable_legacy_cpp_toolchain_skylark_api", + defaultValue = "true", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.UNKNOWN}, + metadataTags = { + OptionMetadataTag.INCOMPATIBLE_CHANGE, + OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES, + OptionMetadataTag.DEPRECATED + }, + help = "Obsolete, no effect.") + public boolean enableLegacyToolchainSkylarkApi; + + @Option( + name = "incompatible_disable_legacy_cpp_toolchain_skylark_api", + defaultValue = "true", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.UNKNOWN}, + metadataTags = { + OptionMetadataTag.INCOMPATIBLE_CHANGE, + OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES, + OptionMetadataTag.DEPRECATED + }, + help = "Obsolete, no effect.") + public boolean disableLegacyToolchainSkylarkApi; + @Deprecated @Option( name = "direct_run", diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java index fdc7f0d6dfe281..4f46a4d7f1e9a5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java @@ -1503,7 +1503,7 @@ public static ImmutableList getCoptsFromOptions( flagsBuilder.addAll(config.getCopts()); if (CppFileTypes.C_SOURCE.matches(sourceFilename)) { - flagsBuilder.addAll(config.getCOptions()); + flagsBuilder.addAll(config.getConlyopts()); } if (CppFileTypes.CPP_SOURCE.matches(sourceFilename) 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 08619fad15342b..f2d991c27c467f 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 @@ -35,7 +35,6 @@ 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.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; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; @@ -745,14 +744,6 @@ public boolean supportsFission() { return toolchainInfo.supportsFission(); } - @Override - // TODO(b/24373706): Remove this method once new C++ toolchain API is available - public ImmutableList getUnfilteredCompilerOptionsWithSysroot( - Iterable featuresNotUsedAnymore) throws EvalException { - cppConfiguration.checkForLegacyCompilationApiAvailability(); - return toolchainInfo.getUnfilteredCompilerOptions(sysroot); - } - public ImmutableList getUnfilteredCompilerOptions() { return toolchainInfo.getUnfilteredCompilerOptions(/* sysroot= */ null); } @@ -767,19 +758,6 @@ public String getTargetOS() { return toolchainInfo.getTargetOS(); } - @Override - public ImmutableList getLinkOptionsWithSysroot() throws EvalException { - if (cppConfiguration == null) { - return ImmutableList.of(); - } - cppConfiguration.checkForLegacyLinkingApiAvailability(); - return cppConfiguration.getLinkOptionsDoNotUse(sysroot); - } - - public ImmutableList getLinkOptions() { - return cppConfiguration.getLinkOptionsDoNotUse(/* sysroot= */ null); - } - /** * Returns test-only link options such that certain test-specific features can be configured * separately (e.g. lazy binding). @@ -925,47 +903,6 @@ public FdoMode getFdoMode() { return fdoMode; } - /** - * 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. - */ - @Override - public ImmutableList getCompilerOptions() throws EvalException { - cppConfiguration.checkForLegacyCompilationApiAvailability(); - return getLegacyCompileOptionsWithCopts(); - } - - /** - * 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. - * - *

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 {@link - * CcToolchainProvider#getLegacyCompileOptionsWithCopts()}. - */ - @Override - public ImmutableList getCOptions() throws EvalException { - cppConfiguration.checkForLegacyCompilationApiAvailability(); - return cppConfiguration.getCOptions(); - } - - /** - * 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. - * - *

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}. - */ - @Override - @Deprecated - public ImmutableList getCxxOptionsWithCopts() throws EvalException { - cppConfiguration.checkForLegacyCompilationApiAvailability(); - return ImmutableList.builder() - .addAll(getLegacyCxxOptions()) - .addAll(cppConfiguration.getCxxopts()) - .build(); - } - public ImmutableList getLegacyCxxOptions() { return ImmutableList.builder() .addAll(getToolchainCxxFlags()) @@ -973,59 +910,6 @@ public ImmutableList getLegacyCxxOptions() { .build(); } - /** - * 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. - * - *

Returns the immutable list of linker options for fully statically linked outputs. Does not - * include command-line options passed via --linkopt or --linkopts. - * - * @param sharedLib true if the output is a shared lib, false if it's an executable - */ - @Override - @Deprecated - public ImmutableList getFullyStaticLinkOptions(Boolean sharedLib) throws EvalException { - cppConfiguration.checkForLegacyLinkingApiAvailability(); - if (!sharedLib) { - throw new EvalException( - Location.BUILTIN, "fully_static_link_options is deprecated, new uses are not allowed."); - } - return CppHelper.getFullyStaticLinkOptions(cppConfiguration, this, sharedLib); - } - - /** - * 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. - * - *

Returns the immutable list of linker options for mostly statically linked outputs. Does not - * include command-line options passed via --linkopt or --linkopts. - * - * @param sharedLib true if the output is a shared lib, false if it's an executable - */ - @Override - @Deprecated - public ImmutableList getMostlyStaticLinkOptions(Boolean sharedLib) throws EvalException { - cppConfiguration.checkForLegacyLinkingApiAvailability(); - return CppHelper.getMostlyStaticLinkOptions( - cppConfiguration, this, sharedLib, /* shouldStaticallyLinkCppRuntimes= */ true); - } - - /** - * 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. - * - *

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. - * - * @param sharedLib true if the output is a shared lib, false if it's an executable - */ - @Override - @Deprecated - public ImmutableList getDynamicLinkOptions(Boolean sharedLib) throws EvalException { - cppConfiguration.checkForLegacyLinkingApiAvailability(); - return CppHelper.getDynamicLinkOptions(cppConfiguration, this, sharedLib); - } - /** * 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. 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 f993a598d296fd..e716dd6a7ec522 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 @@ -32,12 +32,10 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; -import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.rules.cpp.CppConfigurationLoader.CppConfigurationParameters; import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode; import com.google.devtools.build.lib.skylarkbuildapi.cpp.CppConfigurationApi; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -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; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease; @@ -196,19 +194,9 @@ public String toString() { // TODO(b/113849758): Remove once it's not needed for toolchain selection in CppConfiguration. private final Label ccToolchainLabel; - - // TODO(kmensah): This is temporary until all the Skylark functions that need this can be removed. - private final PathFragment nonConfiguredSysroot; private final Label sysrootLabel; - - private final ImmutableList compilerFlags; - private final ImmutableList cxxFlags; - private final ImmutableList unfilteredCompilerFlags; private final ImmutableList conlyopts; - private final ImmutableList mostlyStaticLinkFlags; - private final ImmutableList mostlyStaticSharedLinkFlags; - private final ImmutableList dynamicLinkFlags; private final ImmutableList copts; private final ImmutableList cxxopts; @@ -242,24 +230,6 @@ static CppConfiguration create(CppConfigurationParameters params) CompilationMode compilationMode = params.commonOptions.compilationMode; - ImmutableList.Builder coptsBuilder = - ImmutableList.builder() - .addAll(cppToolchainInfo.getCompilerFlags()) - .addAll(cppToolchainInfo.getCFlagsByCompilationMode().get(compilationMode)); - if (cppOptions.experimentalOmitfp) { - coptsBuilder.add("-fomit-frame-pointer"); - coptsBuilder.add("-fasynchronous-unwind-tables"); - coptsBuilder.add("-DNO_FRAME_POINTER"); - } - coptsBuilder.addAll(cppOptions.coptList); - - ImmutableList cxxOpts = - ImmutableList.builder() - .addAll(cppToolchainInfo.getCxxFlags()) - .addAll(cppToolchainInfo.getCxxFlagsByCompilationMode().get(compilationMode)) - .addAll(cppOptions.cxxoptList) - .build(); - ImmutableList.Builder linkoptsBuilder = ImmutableList.builder(); linkoptsBuilder.addAll(cppOptions.linkoptList); if (cppOptions.experimentalOmitfp) { @@ -276,18 +246,8 @@ static CppConfiguration create(CppConfigurationParameters params) params.fdoPath, params.fdoOptimizeLabel, params.ccToolchainLabel, - params.sysrootLabel == null - ? cppToolchainInfo.getDefaultSysroot() - : params.sysrootLabel.getPackageFragment(), params.sysrootLabel, - coptsBuilder.build(), - cxxOpts, - cppToolchainInfo.getUnfilteredCompilerOptions(/* sysroot= */ null), ImmutableList.copyOf(cppOptions.conlyoptList), - cppToolchainInfo.configureAllLegacyLinkOptions(compilationMode, LinkingMode.STATIC), - cppToolchainInfo.configureAllLegacyLinkOptions( - compilationMode, LinkingMode.LEGACY_MOSTLY_STATIC_LIBRARIES), - cppToolchainInfo.configureAllLegacyLinkOptions(compilationMode, LinkingMode.DYNAMIC), ImmutableList.copyOf(cppOptions.coptList), ImmutableList.copyOf(cppOptions.cxxoptList), linkoptsBuilder.build(), @@ -312,15 +272,8 @@ private CppConfiguration( PathFragment fdoPath, Label fdoOptimizeLabel, Label ccToolchainLabel, - PathFragment nonConfiguredSysroot, Label sysrootLabel, - ImmutableList compilerFlags, - ImmutableList cxxFlags, - ImmutableList unfilteredCompilerFlags, ImmutableList conlyopts, - ImmutableList mostlyStaticLinkFlags, - ImmutableList mostlyStaticSharedLinkFlags, - ImmutableList dynamicLinkFlags, ImmutableList copts, ImmutableList cxxopts, ImmutableList linkopts, @@ -340,15 +293,8 @@ private CppConfiguration( this.fdoPath = fdoPath; this.fdoOptimizeLabel = fdoOptimizeLabel; this.ccToolchainLabel = ccToolchainLabel; - this.nonConfiguredSysroot = nonConfiguredSysroot; this.sysrootLabel = sysrootLabel; - this.compilerFlags = compilerFlags; - this.cxxFlags = cxxFlags; - this.unfilteredCompilerFlags = unfilteredCompilerFlags; this.conlyopts = conlyopts; - this.mostlyStaticLinkFlags = mostlyStaticLinkFlags; - this.mostlyStaticSharedLinkFlags = mostlyStaticSharedLinkFlags; - this.dynamicLinkFlags = dynamicLinkFlags; this.copts = copts; this.cxxopts = cxxopts; this.linkopts = linkopts; @@ -408,45 +354,6 @@ public String toString() { return cppToolchainInfo.toString(); } - /** - * Returns the compiler version string (e.g. "gcc-4.1.1"). - * - *

Deprecated: Use {@link CcToolchainProvider#getCompiler()} - */ - // TODO(b/68038647): Remove once make variables are no longer derived from CppConfiguration. - @Override - @Deprecated - public String getCompiler() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - return cppToolchainInfo.getCompiler(); - } - - /** - * Returns the libc version string (e.g. "glibc-2.2.2"). - * - *

Deprecated: Use {@link CcToolchainProvider#getTargetLibc()} - */ - // TODO(b/68038647): Remove once make variables are no longer derived from CppConfiguration. - @Override - @Deprecated - public String getTargetLibc() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - return cppToolchainInfo.getTargetLibc(); - } - - /** - * Returns the target architecture using blaze-specific constants (e.g. "piii"). - * - *

Deprecated: Use {@link CcToolchainProvider#getTargetCpu()} - */ - // TODO(b/68038647): Remove once skylark callers are migrated. - @Override - @Deprecated - public String getTargetCpu() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - return cppToolchainInfo.getTargetCpu(); - } - /** * Returns the path fragment that is either absolute or relative to the execution root that can be * used to execute the given tool. @@ -488,168 +395,10 @@ public CompilationMode getCompilationMode() { return compilationMode; } - @Override - @Deprecated - public ImmutableList getBuiltInIncludeDirectoriesForSkylark() - throws InvalidConfigurationException, EvalException { - checkForToolchainSkylarkApiAvailability(); - return getBuiltInIncludeDirectories(nonConfiguredSysroot) - .stream() - .map(PathFragment::getPathString) - .collect(ImmutableList.toImmutableList()); - } - - /** - * Returns the built-in list of 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. - * - *

TODO(b/64384912): Migrate skylark callers to - * CcToolchainProvider#getBuiltinIncludeDirectories and delete this method. - */ - private ImmutableList getBuiltInIncludeDirectories(PathFragment sysroot) - throws InvalidConfigurationException { - ImmutableList.Builder builtInIncludeDirectoriesBuilder = ImmutableList.builder(); - for (String s : cppToolchainInfo.getRawBuiltInIncludeDirectories()) { - builtInIncludeDirectoriesBuilder.add( - CcToolchainProviderHelper.resolveIncludeDir(s, sysroot, crosstoolTopPathFragment)); - } - return builtInIncludeDirectoriesBuilder.build(); - } - - /** - * 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 null. - */ - @Override - @Deprecated - public String getSysroot() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - return nonConfiguredSysroot.getPathString(); - } - public Label getSysrootLabel() { return sysrootLabel; } - /** - * 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: Use {@link CcToolchainProvider#getLegacyCompileOptionsWithCopts()} - */ - // TODO(b/64384912): Migrate skylark callers and remove. - @Override - @Deprecated - public ImmutableList getCompilerOptions(Iterable featuresNotUsedAnymore) - throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyCompilationApiAvailability(); - return compilerFlags; - } - - /** - * 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 {@link #getCompilerOptions}. - */ - // TODO(b/64384912): Migrate skylark callers and remove. - @Override - @Deprecated - public ImmutableList getCOptionsForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyCompilationApiAvailability(); - return getCOptions(); - } - - public ImmutableList getCOptions() { - return conlyopts; - } - - /** - * 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}. - * - *

Deprecated: Use {@link CcToolchainProvider#getCxxOptionsWithCopts} - */ - // TODO(b/64384912): Migrate skylark callers and remove. - @Override - @Deprecated - public ImmutableList getCxxOptions(Iterable featuresNotUsedAnymore) - throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyCompilationApiAvailability(); - return cxxFlags; - } - - /** - * Returns the default list of options which cannot be filtered by BUILD rules. These should be - * appended to the command line after filtering. - * - * @deprecated since it uses nonconfigured sysroot. Use {@link - * CcToolchainProvider#getUnfilteredCompilerOptionsWithSysroot(Iterable)} if you *really* need - * to. - */ - // TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here. - @Deprecated - @Override - public ImmutableList getUnfilteredCompilerOptionsWithLegacySysroot( - Iterable featuresNotUsedAnymore) throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyCompilationApiAvailability(); - return getUnfilteredCompilerOptionsDoNotUse(nonConfiguredSysroot); - } - - /** - * @deprecated since it hardcodes --sysroot flag. Use {@link - * com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration} instead. - */ - // TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here. - @Deprecated - ImmutableList getUnfilteredCompilerOptionsDoNotUse(@Nullable PathFragment sysroot) - throws EvalException { - checkForToolchainSkylarkApiAvailability(); - if (sysroot == null) { - return unfilteredCompilerFlags; - } - return ImmutableList.builder() - .add("--sysroot=" + sysroot) - .addAll(unfilteredCompilerFlags) - .build(); - } - - /** - * Returns the set of command-line linker options, including any flags inferred from the - * command-line options. - * - * @see Link - * @deprecated since it uses nonconfigured sysroot. Use - * {@link CcToolchainProvider#getLinkOptionsWithSysroot()} if you *really* need to. - */ - // TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here. - @Deprecated - @Override - public ImmutableList getLinkOptionsWithLegacySysroot() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyLinkingApiAvailability(); - return getLinkOptionsDoNotUse(nonConfiguredSysroot); - } - - /** - * @deprecated since it hardcodes --sysroot flag. Use - * {@link com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration} - * instead. - */ - // TODO(b/65401585): Migrate existing uses to cc_toolchain and cleanup here. - @Deprecated - ImmutableList getLinkOptionsDoNotUse(@Nullable PathFragment sysroot) { - if (sysroot == null) { - return linkopts; - } else { - return ImmutableList.builder().addAll(linkopts).add("--sysroot=" + sysroot).build(); - } - } public boolean hasSharedLinkOption() { return linkopts.contains("-shared"); @@ -665,89 +414,6 @@ public ImmutableList getLtoBackendOptions() { return ltobackendOptions; } - /** - * Returns the immutable list of linker options for fully statically linked outputs. Does not - * include command-line options passed via --linkopt or --linkopts. - * - * @param featuresNotUsedAnymore - * @param sharedLib true if the output is a shared lib, false if it's an executable - *

Deprecated: Use {@link CppHelper#getFullyStaticLinkOptions(CppConfiguration, - * CcToolchainProvider, boolean)} - */ - // TODO(b/64384912): Migrate skylark users to cc_common and remove. - @Override - @Deprecated - public ImmutableList getFullyStaticLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyLinkingApiAvailability(); - if (!sharedLib) { - throw new EvalException( - Location.BUILTIN, "fully_static_link_options is deprecated, new uses are not allowed."); - } - return getSharedLibraryLinkOptions(mostlyStaticLinkFlags); - } - - /** - * Returns the immutable list of linker options for mostly statically linked outputs. Does not - * include command-line options passed via --linkopt or --linkopts. - * - * @param featuresNotUsedAnymore - * @param sharedLib true if the output is a shared lib, false if it's an executable - *

Deprecated: Use {@link CppHelper#getMostlyStaticLinkOptions( CppConfiguration, - * CcToolchainProvider, boolean, boolean)} - */ - // TODO(b/64384912): Migrate skylark users to cc_common and remove. - @Override - @Deprecated - public ImmutableList getMostlyStaticLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyLinkingApiAvailability(); - if (sharedLib) { - return getSharedLibraryLinkOptions( - cppToolchainInfo.supportsEmbeddedRuntimes() - ? mostlyStaticSharedLinkFlags - : dynamicLinkFlags); - } else { - return mostlyStaticLinkFlags; - } - } - - /** - * 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. - * - * @param featuresNotUsedAnymore - * @param sharedLib true if the output is a shared lib, false if it's an executable - *

Deprecated: Use {@link CppHelper#getDynamicLinkOptions(CppConfiguration, - * CcToolchainProvider, Boolean)} - */ - // TODO(b/64384912): Migrate skylark users to cc_common and remove. - @Override - @Deprecated - public ImmutableList getDynamicLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException { - checkForToolchainSkylarkApiAvailability(); - checkForLegacyLinkingApiAvailability(); - if (sharedLib) { - return getSharedLibraryLinkOptions(dynamicLinkFlags); - } else { - return dynamicLinkFlags; - } - } - - /** - * Returns link options for the specified flag list, combined with universal options for all - * shared libraries (regardless of link staticness). - * - *

Deprecated: Use {@link CcToolchainProvider#getSharedLibraryLinkOptions} - */ - // TODO(b/64384912): Migrate skylark dependants and delete. - private ImmutableList getSharedLibraryLinkOptions(ImmutableList flags) { - return cppToolchainInfo.getSharedLibraryLinkOptions(flags); - } - /** * Returns a map of additional make variables for use by {@link * BuildConfiguration}. These are to used to allow some build rules to @@ -760,18 +426,6 @@ public ImmutableMap getAdditionalMakeVariables() { return cppToolchainInfo.getAdditionalMakeVariables(); } - /** - * Returns the execution path to the linker binary to use for this build. Relative paths are - * relative to the execution root. - */ - @Override - @Deprecated - public String getLdExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment ldExecutable = getToolPathFragment(CppConfiguration.Tool.LD); - return ldExecutable != null ? ldExecutable.getPathString() : ""; - } - @SkylarkCallable( name = "minimum_os_version", doc = "The minimum OS version for C/C++ compilation.") @@ -917,78 +571,6 @@ public boolean getUseInterfaceSharedObjects() { return cppOptions.useInterfaceSharedObjects; } - /** - * 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. - */ - @Override - @Deprecated - public String getObjCopyExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment objCopyExecutable = getToolPathFragment(Tool.OBJCOPY); - return objCopyExecutable != null ? objCopyExecutable.getPathString() : ""; - } - - @Override - @Deprecated - public String getCppExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment cppExecutable = getToolPathFragment(Tool.GCC); - return cppExecutable != null ? cppExecutable.getPathString() : ""; - } - - @Override - @Deprecated - public String getCpreprocessorExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment cpreprocessorExecutable = getToolPathFragment(Tool.CPP); - return cpreprocessorExecutable != null ? cpreprocessorExecutable.getPathString() : ""; - } - - @Override - @Deprecated - public String getNmExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment nmExecutable = getToolPathFragment(Tool.NM); - return nmExecutable != null ? nmExecutable.getPathString() : ""; - } - - @Override - @Deprecated - public String getObjdumpExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment objdumpExecutable = getToolPathFragment(Tool.OBJDUMP); - return objdumpExecutable != null ? objdumpExecutable.getPathString() : ""; - } - - @Override - @Deprecated - public String getArExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment arExecutable = getToolPathFragment(Tool.AR); - return arExecutable != null ? arExecutable.getPathString() : ""; - } - - @Override - @Deprecated - public String getStripExecutableForSkylark() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - PathFragment stripExecutable = getToolPathFragment(Tool.STRIP); - return stripExecutable != null ? stripExecutable.getPathString() : ""; - } - - /** - * Returns the GNU System Name - * - */ - //TODO(b/70225490): Migrate skylark dependants to CcToolchainProvider and delete. - @Override - @Deprecated - public String getTargetGnuSystemName() throws EvalException { - checkForToolchainSkylarkApiAvailability(); - return cppToolchainInfo.getTargetGnuSystemName(); - } - /** Returns whether this configuration will use libunwind for stack unwinding. */ public boolean isOmitfp() { return cppOptions.experimentalOmitfp; @@ -1173,44 +755,6 @@ public boolean disableDepsetInUserFlags() { return cppOptions.disableDepsetInUserFlags; } - private void checkForToolchainSkylarkApiAvailability() throws EvalException { - if (cppOptions.disableLegacyToolchainSkylarkApi - || !cppOptions.enableLegacyToolchainSkylarkApi) { - throw new EvalException( - null, - "Information about the C++ toolchain API is not accessible " - + "anymore through ctx.fragments.cpp " - + "(see --incompatible_disable_legacy_cpp_toolchain_skylark_api on " - + "http://docs.bazel.build/versions/master/skylark/backward-compatibility.html" - + "#disable-legacy-c-configuration-api for migration notes). " - + "Use CcToolchainInfo instead."); - } - } - - public void checkForLegacyCompilationApiAvailability() throws EvalException { - if (cppOptions.disableLegacyCompilationApi || cppOptions.disableLegacyFlagsCcToolchainApi) { - throw new EvalException( - null, - "Starlark APIs accessing compilation flags has been removed. " - + "Use the new API on cc_common (see " - + "--incompatible_disable_legacy_flags_cc_toolchain_api on" - + "https://docs.bazel.build/versions/master/skylark/backward-compatibility.html" - + "#disable-legacy-c-toolchain-api for migration notes)."); - } - } - - public void checkForLegacyLinkingApiAvailability() throws EvalException { - if (cppOptions.disableLegacyLinkingApi || cppOptions.disableLegacyFlagsCcToolchainApi) { - throw new EvalException( - null, - "Starlark APIs accessing linking flags has been removed. " - + "Use the new API on cc_common (see " - + "--incompatible_disable_legacy_flags_cc_toolchain_api on" - + "https://docs.bazel.build/versions/master/skylark/backward-compatibility.html" - + "#disable-legacy-c-toolchain-api for migration notes)."); - } - } - public static PathFragment computeDefaultSysroot(String builtInSysroot) { if (builtInSysroot.isEmpty()) { return null; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index 9e6e422634c73e..ddf02fe088d057 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -420,7 +420,7 @@ private ImmutableList collectPerFileLtoBackendOpts(Artifact objectFile) private List getLtoBackendCommandLineOptions() { List argv = new ArrayList<>(); - argv.addAll(toolchain.getLinkOptions()); + argv.addAll(cppConfiguration.getLinkopts()); argv.addAll(toolchain.getLegacyCompileOptionsWithCopts()); argv.addAll(cppConfiguration.getLtoBackendOptions()); return argv; @@ -839,7 +839,7 @@ public CppLinkAction build() throws InterruptedException { userLinkFlags = ImmutableList.builder() .addAll(linkopts) - .addAll(toolchain.getLinkOptions()) + .addAll(cppConfiguration.getLinkopts()) .build(); } else { userLinkFlags = ImmutableList.copyOf(linkopts); 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 87e36059878578..6e7844c70ecd28 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 @@ -709,64 +709,6 @@ public Label getFdoPrefetchHintsLabel() { ) public boolean useLLVMCoverageMapFormat; - @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 = - "Do not use this flag. Use --incompatible_disable_legacy_cpp_toolchain_skylark_api " - + "instead.") - public boolean enableLegacyToolchainSkylarkApi; - - @Option( - name = "incompatible_disable_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 disableLegacyToolchainSkylarkApi; - - @Option( - name = "experimental_disable_legacy_cc_linking_api", - defaultValue = "false", - documentationCategory = OptionDocumentationCategory.TOOLCHAIN, - effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, - metadataTags = {OptionMetadataTag.EXPERIMENTAL}, - help = "If true, C++ Starlark API exposing linking flags will be disabled.") - public boolean disableLegacyLinkingApi; - - @Option( - name = "experimental_disable_legacy_cc_compilation_api", - defaultValue = "false", - documentationCategory = OptionDocumentationCategory.TOOLCHAIN, - effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, - metadataTags = {OptionMetadataTag.EXPERIMENTAL}, - help = "If true, C++ Starlark API exposing compilation flags will be disabled.") - public boolean disableLegacyCompilationApi; - - @Option( - name = "incompatible_disable_legacy_flags_cc_toolchain_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 the legacy cc_toolchain Starlark API for accessing legacy " - + "CROSSTOOL fields.") - public boolean disableLegacyFlagsCcToolchainApi; - @Option( name = "experimental_disable_linking_mode_flags", defaultValue = "false", @@ -938,7 +880,6 @@ public FragmentOptions getHost() { host.fdoProfileLabel = null; host.inmemoryDotdFiles = inmemoryDotdFiles; - host.disableLegacyToolchainSkylarkApi = disableLegacyToolchainSkylarkApi; host.disableSysrootFromConfiguration = disableSysrootFromConfiguration; return host; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java index 4eea6c8e621b1e..292ad3c898b91c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java @@ -324,7 +324,7 @@ private static ImmutableList getToolchainFlags( } if (!cppConfiguration.enableLinkoptsInUserLinkFlags()) { - result.addAll(ccToolchainProvider.getLinkOptions()); + result.addAll(cppConfiguration.getLinkopts()); } // -pie is not compatible with shared and should be 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 index 7bcdbd637ab873..4c45a9c75d6ac8 100644 --- 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 @@ -16,11 +16,8 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.skylarkbuildapi.platform.ToolchainInfoApi; -import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; -import com.google.devtools.build.lib.syntax.EvalException; -import com.google.devtools.build.lib.syntax.SkylarkList; /** Information about the C++ toolchain. */ @SkylarkModule(name = "CcToolchainInfo", doc = "Information about the C++ compiler being used.") @@ -66,31 +63,6 @@ public interface CcToolchainProviderApi extends ToolchainInfoApi { allowReturnNones = true) public String getTargetCpu(); - @SkylarkCallable( - name = "unfiltered_compiler_options", - doc = - "Deprecated. 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) - }) - // TODO(b/24373706): Remove this method once new C++ toolchain API is available - public ImmutableList getUnfilteredCompilerOptionsWithSysroot( - Iterable featuresNotUsedAnymore) throws EvalException; - - @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 getLinkOptionsWithSysroot() throws EvalException; - @SkylarkCallable( name = "target_gnu_system_name", structField = true, @@ -99,85 +71,6 @@ public ImmutableList getUnfilteredCompilerOptionsWithSysroot( ) 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 getCompilerOptions() throws EvalException; - - @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 " - + "compiler_options") - public ImmutableList getCOptions() 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 " - + "compiler_options") - @Deprecated - public ImmutableList getCxxOptionsWithCopts() 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 = "shared_lib", - doc = "If true, returns the link options for a shared library.", - positional = true, - named = false, - type = Boolean.class - ) - } - ) - @Deprecated - public ImmutableList 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.", - parameters = { - @Param( - name = "shared_lib", - doc = "If true, returns the link options for a shared library.", - positional = true, - named = false, - type = Boolean.class) - }) - @Deprecated - public ImmutableList getMostlyStaticLinkOptions(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 = "shared_lib", - doc = "If true, returns the link options for a shared library.", - positional = true, - named = false, - type = Boolean.class) - }) - @Deprecated - public ImmutableList getDynamicLinkOptions(Boolean sharedLib) throws EvalException; - @SkylarkCallable( name = "ld_executable", doc = 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 1d45412635af33..55f2d43d153501 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 @@ -15,12 +15,10 @@ package com.google.devtools.build.lib.skylarkbuildapi.cpp; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.skylarkinterface.Param; 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; -import com.google.devtools.build.lib.syntax.SkylarkList; /** * The C++ configuration fragment. @@ -55,255 +53,4 @@ public interface CppConfigurationApi getLinkopts() throws EvalException; - - @SkylarkCallable( - name = "compiler", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). C++ compiler.") - @Deprecated - String getCompiler() throws EvalException; - - @SkylarkCallable( - name = "libc", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). libc version string.") - @Deprecated - String getTargetLibc() throws EvalException; - - @SkylarkCallable( - name = "cpu", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Target CPU of the C++ toolchain.") - @Deprecated - String getTargetCpu() throws EvalException; - - @SkylarkCallable( - name = "built_in_include_directories", - structField = true, - doc = - "Deprecated (use CcToolchainInfo instead). 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 getBuiltInIncludeDirectoriesForSkylark() - throws InvalidConfigurationExceptionT, EvalException; - - @SkylarkCallable( - name = "sysroot", - structField = true, - doc = - "Deprecated (use CcToolchainInfo instead). 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.") - String getSysroot() throws EvalException; - - @SkylarkCallable( - name = "compiler_options", - doc = - "Deprecated (use methods in cc_common instead). 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 getCompilerOptions(Iterable featuresNotUsedAnymore) - throws EvalException; - - @SkylarkCallable( - name = "c_options", - structField = true, - doc = - "Deprecated (use methods in cc_common instead). 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 compiler_options") - ImmutableList getCOptionsForSkylark() throws EvalException; - - @SkylarkCallable( - name = "cxx_options", - doc = - "Deprecated (use methods in cc_common instead). 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 compiler_options", - parameters = { - @Param( - name = "features", - doc = "Unused.", - positional = true, - named = false, - type = SkylarkList.class) - }) - @Deprecated - ImmutableList getCxxOptions(Iterable featuresNotUsedAnymore) throws EvalException; - - @SkylarkCallable( - name = "unfiltered_compiler_options", - doc = - "Deprecated (use methods in cc_common instead). 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 getUnfilteredCompilerOptionsWithLegacySysroot( - Iterable featuresNotUsedAnymore) throws EvalException; - - @SkylarkCallable( - name = "link_options", - structField = true, - doc = - "Deprecated (use methods in cc_common instead). Returns the set of command-line " - + "linker options, including any flags inferred from the command-line options.") - ImmutableList getLinkOptionsWithLegacySysroot() throws EvalException; - - @SkylarkCallable( - name = "fully_static_link_options", - doc = - "Deprecated (use methods in cc_common instead). 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 getFullyStaticLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException; - - @SkylarkCallable( - name = "mostly_static_link_options", - doc = - "Deprecated (use methods in cc_common instead). 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 getMostlyStaticLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException; - - @SkylarkCallable( - name = "dynamic_link_options", - doc = - "Deprecated (use methods in cc_common instead). 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 getDynamicLinkOptions( - Iterable featuresNotUsedAnymore, Boolean sharedLib) throws EvalException; - - @SkylarkCallable( - name = "ld_executable", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Path to the linker binary.") - @Deprecated - String getLdExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "objcopy_executable", - structField = true, - doc = - "Deprecated (use CcToolchainInfo instead). Path to GNU binutils 'objcopy' binary.") - @Deprecated - String getObjCopyExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "compiler_executable", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Path to C/C++ compiler binary.") - @Deprecated - String getCppExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "preprocessor_executable", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Path to C/C++ preprocessor binary.") - @Deprecated - String getCpreprocessorExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "nm_executable", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Path to GNU binutils 'nm' binary.") - @Deprecated - String getNmExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "objdump_executable", - structField = true, - doc = - "Deprecated (use CcToolchainInfo instead). Path to GNU binutils 'objdump' binary.") - @Deprecated - String getObjdumpExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "ar_executable", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Path to GNU binutils 'ar' binary.") - @Deprecated - String getArExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "strip_executable", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). Path to GNU binutils 'strip' binary.") - @Deprecated - String getStripExecutableForSkylark() throws EvalException; - - @SkylarkCallable( - name = "target_gnu_system_name", - structField = true, - doc = "Deprecated (use CcToolchainInfo instead). The GNU System Name.") - @Deprecated - String getTargetGnuSystemName() throws EvalException; } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java index 69471cc2c489f2..bd0ef1686ad935 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProviderTest.java @@ -26,7 +26,6 @@ import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.ToolPath; -import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -43,25 +42,18 @@ public void testSkylarkCallables() throws Exception { .setupCrosstool( mockToolsConfig, CrosstoolConfig.CToolchain.newBuilder() - .addCompilerFlag("-foo_compiler") - .addCxxFlag("-foo_cxx") .setBuiltinSysroot("/usr/local/custom-sysroot") .addToolPath(ToolPath.newBuilder().setName("ar").setPath("foo/ar/path").build()) .buildPartial()); - useConfiguration( - "--cpu=k8", "--force_pic", "--noincompatible_disable_legacy_flags_cc_toolchain_api"); + useConfiguration("--cpu=k8", "--force_pic"); scratch.file( "test/rule.bzl", "def _impl(ctx):", " provider = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", " return struct(", " dirs = provider.built_in_include_directories,", - " link_options = provider.link_options_do_not_use,", - " unfiltered_compiler_options = provider.unfiltered_compiler_options([]),", " sysroot = provider.sysroot,", " cpu = provider.cpu,", - " compiler_options = provider.compiler_options(),", - " cxx_options = provider.cxx_options(),", " ar_executable = provider.ar_executable,", " use_pic_for_dynamic_libraries = provider.use_pic_for_dynamic_libraries,", " )", @@ -78,136 +70,17 @@ public void testSkylarkCallables() throws Exception { ConfiguredTarget ct = getConfiguredTarget("//test:target"); - @SuppressWarnings("unchecked") - List compilerOptions = (List) ct.get("compiler_options"); - assertThat(compilerOptions).contains("-foo_compiler"); - - @SuppressWarnings("unchecked") - List cxxOptions = (List) ct.get("cxx_options"); - assertThat(cxxOptions).contains("-foo_cxx"); - assertThat((String) ct.get("ar_executable")).endsWith("foo/ar/path"); assertThat(ct.get("cpu")).isEqualTo("k8"); assertThat(ct.get("sysroot")).isEqualTo("/usr/local/custom-sysroot"); - @SuppressWarnings("unchecked") - List linkOptions = (List) ct.get("link_options"); - assertThat(linkOptions).contains("--sysroot=/usr/local/custom-sysroot"); - - @SuppressWarnings("unchecked") - List unfilteredCompilerOptions = (List) ct.get("unfiltered_compiler_options"); - assertThat(unfilteredCompilerOptions).contains("--sysroot=/usr/local/custom-sysroot"); - @SuppressWarnings("unchecked") boolean usePicForDynamicLibraries = (boolean) ct.get("use_pic_for_dynamic_libraries"); assertThat(usePicForDynamicLibraries).isTrue(); } - @Test - public void testDisablingMostlyStaticLinkOptions() throws Exception { - testDisablingLinkingApiMethod("provider.mostly_static_link_options(False)"); - } - - @Test - public void testDisablingFullyStaticLinkOptions() throws Exception { - testDisablingLinkingApiMethod("provider.fully_static_link_options(True)"); - } - - @Test - public void testDisablingDynamicLinkOptions() throws Exception { - testDisablingLinkingApiMethod("provider.dynamic_link_options(False)"); - } - - @Test - public void testDisablingLinkOptions() throws Exception { - testDisablingLinkingApiMethod("provider.link_options_do_not_use"); - } - - private void testDisablingLinkingApiMethod(String method) throws Exception { - useConfiguration("--experimental_disable_legacy_cc_linking_api"); - testDisablingLinkingApiMethodWithConfiguration(method); - useConfiguration("--incompatible_disable_legacy_flags_cc_toolchain_api"); - testDisablingLinkingApiMethodWithConfiguration(method); - } - - private void testDisablingLinkingApiMethodWithConfiguration(String method) throws Exception { - scratch.overwriteFile( - "test/rule.bzl", - "def _impl(ctx):", - " provider = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", - " return struct(", - " link_options = " + method + ",", - " )", - "", - "my_rule = rule(", - " _impl,", - " fragments = [ 'cpp' ],", - " attrs = {'_cc_toolchain': attr.label(default=Label('//test:toolchain')) }", - ")"); - scratch.overwriteFile( - "test/BUILD", - "load(':rule.bzl', 'my_rule')", - "cc_toolchain_alias(name = 'toolchain')", - "my_rule(name = 'target')"); - invalidatePackages(); - reporter.removeHandler(failFastHandler); - getConfiguredTarget("//test:target"); - assertContainsEvent("Starlark APIs accessing linking flags has been removed."); - } - - @Test - public void testDisablingCompilerOptions() throws Exception { - testDisablingCompilationApiMethod("provider.compiler_options()"); - } - - @Test - public void testDisablingCxxOptions() throws Exception { - testDisablingCompilationApiMethod("provider.cxx_options()"); - } - - @Test - public void testDisablingCOptions() throws Exception { - testDisablingCompilationApiMethod("provider.c_options()"); - } - - @Test - public void testDisablingUnfilteredOptions() throws Exception { - testDisablingCompilationApiMethod("provider.unfiltered_compiler_options([])"); - } - private void testDisablingCompilationApiMethod(String method) throws Exception { - useConfiguration("--experimental_disable_legacy_cc_compilation_api"); - testDisablingCompilationApiMethodWithConfiguration(method); - useConfiguration("--incompatible_disable_legacy_flags_cc_toolchain_api"); - testDisablingCompilationApiMethodWithConfiguration(method); - } - - private void testDisablingCompilationApiMethodWithConfiguration(String method) throws Exception { - scratch.overwriteFile( - "test/rule.bzl", - "def _impl(ctx):", - " provider = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]", - " return struct(", - " compile_options = " + method + ",", - " )", - "", - "my_rule = rule(", - " _impl,", - " fragments = [ 'cpp' ],", - " attrs = {'_cc_toolchain': attr.label(default=Label('//test:toolchain')) }", - ")"); - scratch.overwriteFile( - "test/BUILD", - "load(':rule.bzl', 'my_rule')", - "cc_toolchain_alias(name = 'toolchain')", - "my_rule(name = 'target')"); - invalidatePackages(); - reporter.removeHandler(failFastHandler); - getConfiguredTarget("//test:target"); - assertContainsEvent("Starlark APIs accessing compilation flags has been removed."); - } - @Test public void testDisablingCompilationModeFlags() throws Exception { AnalysisMock.get() @@ -219,21 +92,16 @@ public void testDisablingCompilationModeFlags() throws Exception { "compilation_mode_flags { mode: OPT linker_flag: '-baz_from_compilation_mode' }"); scratch.file("a/BUILD", "cc_library(name='a', srcs=['a.cc'])"); - useConfiguration("-c", "opt", "--noincompatible_disable_legacy_flags_cc_toolchain_api"); + useConfiguration("-c", "opt"); CcToolchainProvider ccToolchainProvider = getCcToolchainProvider(); - assertThat(ccToolchainProvider.getCompilerOptions()).contains("-foo_from_compilation_mode"); + assertThat(ccToolchainProvider.getLegacyCompileOptionsWithCopts()) + .contains("-foo_from_compilation_mode"); assertThat(ccToolchainProvider.getLegacyCxxOptions()).contains("-bar_from_compilation_mode"); assertThat(ccToolchainProvider.getLegacyMostlyStaticLinkFlags(CompilationMode.OPT)) .contains("-baz_from_compilation_mode"); - useConfiguration( - "-c", - "opt", - "--experimental_disable_compilation_mode_flags", - "--noincompatible_disable_legacy_flags_cc_toolchain_api"); + useConfiguration("-c", "opt", "--experimental_disable_compilation_mode_flags"); ccToolchainProvider = getCcToolchainProvider(); - assertThat(ccToolchainProvider.getCompilerOptions()) - .doesNotContain("-foo_from_compilation_mode"); assertThat(ccToolchainProvider.getLegacyCxxOptions()) .doesNotContain("-bar_from_compilation_mode"); assertThat(ccToolchainProvider.getLegacyMostlyStaticLinkFlags(CompilationMode.OPT)) diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java index 2c4958ee42e2e0..56e335a8893919 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CrosstoolConfigurationLoaderTest.java @@ -167,13 +167,7 @@ public void testSimpleCompleteConfiguration() throws Exception { // Need to clear out the android cpu options to avoid this split transition in Bazel. CppConfiguration toolchain = - create( - loader, - "--cpu=k8", - "--host_cpu=k8", - "--android_cpu=", - "--fat_apk_cpu=", - "--noincompatible_disable_legacy_flags_cc_toolchain_api"); + create(loader, "--cpu=k8", "--host_cpu=k8", "--android_cpu=", "--fat_apk_cpu="); CcToolchainProvider ccProvider = getCcToolchainProvider(toolchain); assertThat(toolchain.getToolchainIdentifier()).isEqualTo("toolchain-identifier"); @@ -202,13 +196,8 @@ public void testSimpleCompleteConfiguration() throws Exception { assertThat(ccProvider.getLegacyCompileOptionsWithCopts()) .containsExactly("c", "fastbuild") .inOrder(); - assertThat(toolchain.getCOptions()).isEmpty(); - assertThat(ccProvider.getCxxOptionsWithCopts()) - .containsExactly("cxx", "cxx-fastbuild") - .inOrder(); assertThat(ccProvider.getUnfilteredCompilerOptions()).containsExactly("unfiltered").inOrder(); - assertThat(ccProvider.getLinkOptions()).isEmpty(); assertThat(CppHelper.getFullyStaticLinkOptions(toolchain, ccProvider, false)) .containsExactly("linker", "linker-fastbuild", "fully static") .inOrder(); @@ -447,13 +436,7 @@ public void testComprehensiveCompleteConfiguration() throws Exception { // Need to clear out the android cpu options to avoid this split transition in Bazel. CppConfiguration toolchainA = - create( - loader, - "--cpu=k8", - "--host_cpu=k8", - "--android_cpu=", - "--fat_apk_cpu=", - "--noincompatible_disable_legacy_flags_cc_toolchain_api"); + create(loader, "--cpu=k8", "--host_cpu=k8", "--android_cpu=", "--fat_apk_cpu="); ConfiguredTarget ccToolchainA = getCcToolchainTarget(toolchainA); CcToolchainProvider ccProviderA = (CcToolchainProvider) ccToolchainA.get(ToolchainInfo.PROVIDER); @@ -487,10 +470,6 @@ public void testComprehensiveCompleteConfiguration() throws Exception { .containsExactly( "compiler-flag-A-1", "compiler-flag-A-2", "fastbuild-flag-A-1", "fastbuild-flag-A-2") .inOrder(); - assertThat(ccProviderA.getCxxOptionsWithCopts()) - .containsExactly( - "cxx-flag-A-1", "cxx-flag-A-2", "cxx-fastbuild-flag-A-1", "cxx-fastbuild-flag-A-2") - .inOrder(); assertThat(ccProviderA.getUnfilteredCompilerOptions()) .containsExactly("unfiltered-flag-A-1", "unfiltered-flag-A-2") .inOrder(); @@ -572,8 +551,7 @@ public void testComprehensiveCompleteConfiguration() throws Exception { "--cpu=k8", "--host_cpu=k8", "--android_cpu=", - "--fat_apk_cpu=", - "--noincompatible_disable_legacy_flags_cc_toolchain_api"); + "--fat_apk_cpu="); CcToolchainProvider ccProviderC = getCcToolchainProvider(toolchainC); assertThat(toolchainC.getToolchainIdentifier()).isEqualTo("toolchain-identifier-C"); assertThat(ccProviderC.getHostSystemName()).isEqualTo("host-system-name-C"); @@ -592,8 +570,6 @@ public void testComprehensiveCompleteConfiguration() throws Exception { assertThat(ccProviderC.supportsFission()).isFalse(); assertThat(ccProviderC.getLegacyCompileOptionsWithCopts()).isEmpty(); - assertThat(toolchainC.getCOptions()).isEmpty(); - assertThat(ccProviderC.getCxxOptionsWithCopts()).isEmpty(); assertThat(ccProviderC.getUnfilteredCompilerOptions()).isEmpty(); assertThat(CppHelper.getDynamicLinkOptions(toolchainC, ccProviderC, true)).isEmpty(); assertThat(