Use new C++ toolchain API in internal Go rules

This cl makes sure go rules use the supported API to get information about C++
toolchain. Hopefully this cl is practically noop, but it can happen that more
flags are now passed to the C++ compiler and linker than before. It also makes
go rules aware of C++ features enabled/disabled by `--features` option.

RELNOTES: None.
PiperOrigin-RevId: 210533647
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index b525c95..0d00e1e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -567,7 +567,7 @@
       CcLinkParams linkParams,
       boolean linkCompileOutputSeparately,
       CppSemantics cppSemantics)
-      throws InterruptedException {
+      throws InterruptedException, RuleErrorException {
     CppLinkActionBuilder builder =
         new CppLinkActionBuilder(
                 context, binary, toolchain, fdoProvider, featureConfiguration, cppSemantics)
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
index 5fca15a..14925a6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
@@ -1239,7 +1239,7 @@
       return envBuilder.build();
     }
 
-    String getToolPathForAction(String actionName) {
+    public String getToolPathForAction(String actionName) {
       Preconditions.checkArgument(
           actionConfigByActionName.containsKey(actionName),
           "Action %s does not have an enabled configuration in the toolchain.",
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 f0627c0..67a937a 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
@@ -39,6 +39,7 @@
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
 import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
 import com.google.devtools.build.lib.collect.nestedset.Order;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
 import com.google.devtools.build.lib.packages.RuleErrorConsumer;
 import com.google.devtools.build.lib.rules.cpp.CcLinkParams.Linkstamp;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
@@ -1490,7 +1491,8 @@
    * #addLibraries}, and {@link #addLinkstamps}.
    */
   public CppLinkActionBuilder addLinkParams(
-      CcLinkParams linkParams, RuleErrorConsumer errorListener) throws InterruptedException {
+      CcLinkParams linkParams, RuleErrorConsumer errorListener)
+      throws InterruptedException, RuleErrorException {
     addLinkopts(linkParams.flattenedLinkopts());
     addLibraries(linkParams.getLibraries());
     ExtraLinkTimeLibraries extraLinkTimeLibraries = linkParams.getExtraLinkTimeLibraries();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibrary.java
index 9c04dc9..fa98dcc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/ExtraLinkTimeLibrary.java
@@ -16,6 +16,7 @@
 
 import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
 import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
 
 /**
@@ -30,7 +31,8 @@
  */
 public interface ExtraLinkTimeLibrary {
   /** Build the LibraryToLink inputs to pass to the C++ linker. */
-  NestedSet<LibraryToLink> buildLibraries(RuleContext context) throws InterruptedException;
+  NestedSet<LibraryToLink> buildLibraries(RuleContext context)
+      throws InterruptedException, RuleErrorException;
 
   /**
    * Get a new Builder for this ExtraLinkTimeLibrary class.  This acts
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java
index 2d5e1c7..44539bc 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java
@@ -38,6 +38,7 @@
 import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
 import com.google.devtools.build.lib.packages.Attribute.LabelListLateBoundDefault;
 import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
 import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder.Compression;
 import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType;
 import com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaOptimizationMode;
@@ -462,7 +463,7 @@
       List<String> jvmFlags,
       JavaTargetAttributes.Builder attributesBuilder,
       boolean shouldStrip)
-      throws InterruptedException;
+      throws InterruptedException, RuleErrorException;
 
   /**
    * Add a source artifact to a {@link JavaTargetAttributes.Builder}. It is called when a source
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
index 70a1613..aa6376b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
@@ -54,8 +54,9 @@
     return builder.build();
   }
 
-  static RuleConfiguredTargetBuilder init(RuleContext ruleContext, PythonSemantics semantics,
-      PyCommon common) throws InterruptedException {
+  static RuleConfiguredTargetBuilder init(
+      RuleContext ruleContext, PythonSemantics semantics, PyCommon common)
+      throws InterruptedException, RuleErrorException {
     ruleContext.initConfigurationMakeVariableContext(new CcFlagsSupplier(ruleContext));
 
     List<Artifact> srcs = common.validateSrcs();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java
index 2ca0bc2..fb53beb 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java
@@ -20,6 +20,7 @@
 import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
 import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec;
 import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
 import com.google.devtools.build.lib.rules.cpp.CcLinkingInfo;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import java.util.Collection;
@@ -78,7 +79,7 @@
       PyCommon common,
       CcLinkingInfo ccLinkingInfo,
       NestedSet<PathFragment> imports)
-      throws InterruptedException;
+      throws InterruptedException, RuleErrorException;
 
   /**
    * Called at the end of the analysis of {@code py_binary} rules.