From a87bfef6e5a8e1da98b392db4e65372c65c1a94a Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 6 Jan 2025 11:44:52 -0800 Subject: [PATCH] Remove unneeded InterruptedException from various types of variable expansion. PiperOrigin-RevId: 712605788 Change-Id: I0c69c9e86c0f170dcc0aa6d7b1115dd5a5c51c78 --- .../ConfigurationMakeVariableContext.java | 5 ++--- .../devtools/build/lib/analysis/Expander.java | 13 +++++-------- .../lib/analysis/LocationTemplateContext.java | 2 +- .../build/lib/analysis/MakeVariableSupplier.java | 5 ++--- .../analysis/starlark/StarlarkRuleContext.java | 12 +++++------- .../analysis/stringtemplate/TemplateContext.java | 2 +- .../analysis/stringtemplate/TemplateExpander.java | 9 ++++----- .../devtools/build/lib/rules/cpp/CcCommon.java | 15 ++++++--------- .../build/lib/rules/genrule/GenRuleBase.java | 6 ++---- 9 files changed, 28 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationMakeVariableContext.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationMakeVariableContext.java index b6ea3760b203b6..80a2c2f3d88ead 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationMakeVariableContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfigurationMakeVariableContext.java @@ -110,7 +110,7 @@ private ConfigurationMakeVariableContext( } @Override - public String lookupVariable(String name) throws ExpansionException, InterruptedException { + public String lookupVariable(String name) throws ExpansionException { for (MakeVariableSupplier supplier : allMakeVariableSuppliers) { String variableValue = supplier.getMakeVariable(name); if (variableValue != null) { @@ -120,8 +120,7 @@ public String lookupVariable(String name) throws ExpansionException, Interrupted throw new ExpansionException(String.format("$(%s) not defined", name)); } - public Dict.Builder collectMakeVariables() - throws ExpansionException, InterruptedException { + public Dict.Builder collectMakeVariables() throws ExpansionException { Dict.Builder map = Dict.builder(); // Collect variables in the reverse order as in lookupMakeVariable // because each update is overwriting. diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Expander.java b/src/main/java/com/google/devtools/build/lib/analysis/Expander.java index c486e4b2a3b3df..3a7650d7ac5b34 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Expander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Expander.java @@ -123,8 +123,7 @@ public void tokenizeAndExpandMakeVars(List result, String attributeName, /** Expands make variables and $(location) tags in value, and optionally tokenizes the result. */ private void expandValue( - List tokens, String attributeName, String value, boolean shouldTokenize) - throws InterruptedException { + List tokens, String attributeName, String value, boolean shouldTokenize) { value = expand(attributeName, value); if (shouldTokenize) { try { @@ -157,8 +156,7 @@ public String expand(String attributeName) throws InterruptedException { * @param expression the string to expand. * @return the expansion of "expression". */ - public String expand(@Nullable String attributeName, String expression) - throws InterruptedException { + public String expand(@Nullable String attributeName, String expression) { try { Expansion expansion = TemplateExpander.expand(expression, templateContext); lookedUpVariables.addAll(expansion.lookedUpVariables()); @@ -178,7 +176,7 @@ public String expand(@Nullable String attributeName, String expression) * attribute name is only used for error reporting. */ private ImmutableList expandAndTokenizeList( - String attrName, List values, boolean shouldTokenize) throws InterruptedException { + String attrName, List values, boolean shouldTokenize) { List variables = new ArrayList<>(); for (String variable : values) { expandValue(variables, attrName, variable, shouldTokenize); @@ -191,15 +189,14 @@ private ImmutableList expandAndTokenizeList( * attribute does not exist or is not of type {@link Types.STRING_LIST}, then this method throws * an error. */ - public ImmutableList list(String attrName) throws InterruptedException { + public ImmutableList list(String attrName) { return list(attrName, ruleContext.attributes().get(attrName, Types.STRING_LIST)); } /** * Expands all the strings in the given list. The attribute name is only used for error reporting. */ - public ImmutableList list(String attrName, List values) - throws InterruptedException { + public ImmutableList list(String attrName, List values) { return expandAndTokenizeList(attrName, values, /* shouldTokenize */ false); } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/LocationTemplateContext.java b/src/main/java/com/google/devtools/build/lib/analysis/LocationTemplateContext.java index b420067a83e86f..0de4a4e498c49b 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/LocationTemplateContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/LocationTemplateContext.java @@ -91,7 +91,7 @@ public LocationTemplateContext( } @Override - public String lookupVariable(String name) throws ExpansionException, InterruptedException { + public String lookupVariable(String name) throws ExpansionException { String val = delegate.lookupVariable(name); if (windowsPath) { val = val.replace('/', '\\'); diff --git a/src/main/java/com/google/devtools/build/lib/analysis/MakeVariableSupplier.java b/src/main/java/com/google/devtools/build/lib/analysis/MakeVariableSupplier.java index 76fa56648a871e..738e767eb6f705 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/MakeVariableSupplier.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/MakeVariableSupplier.java @@ -31,11 +31,10 @@ public interface MakeVariableSupplier { /** Returns Make variable value or null if value is not supplied. */ @Nullable - String getMakeVariable(String variableName) throws ExpansionException, InterruptedException; + String getMakeVariable(String variableName) throws ExpansionException; /** Returns all Make variables that it supplies */ - ImmutableMap getAllMakeVariables() - throws ExpansionException, InterruptedException; + ImmutableMap getAllMakeVariables() throws ExpansionException; /** * {@link MakeVariableSupplier} that reads variables from a list of {@link TemplateVariableInfo} diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java index 3c33af14c90a33..e767cfc40069c0 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java @@ -813,7 +813,7 @@ public ImmutableList aspectIds() throws EvalException { } @Override - public Dict var() throws EvalException, InterruptedException { + public Dict var() throws EvalException { checkMutable("var"); if (cachedMakeVariables == null) { Dict.Builder vars; @@ -933,7 +933,7 @@ public boolean checkPlaceholders(String template, Sequence allowedPlaceholder @Override public String expandMakeVariables( String attributeName, String command, Dict additionalSubstitutions) // - throws EvalException, InterruptedException { + throws EvalException { checkMutable("expand_make_variables"); final Map additionalSubstitutionsMap = Dict.cast(additionalSubstitutions, String.class, String.class, "additional_substitutions"); @@ -941,8 +941,7 @@ public String expandMakeVariables( } private String expandMakeVariables( - String attributeName, String command, Map additionalSubstitutionsMap) - throws InterruptedException { + String attributeName, String command, Map additionalSubstitutionsMap) { ConfigurationMakeVariableContext makeVariableContext = new ConfigurationMakeVariableContext( ruleContext, @@ -950,8 +949,7 @@ private String expandMakeVariables( ruleContext.getConfiguration(), ImmutableList.of()) { @Override - public String lookupVariable(String variableName) - throws ExpansionException, InterruptedException { + public String lookupVariable(String variableName) throws ExpansionException { if (additionalSubstitutionsMap.containsKey(variableName)) { return additionalSubstitutionsMap.get(variableName); } else { @@ -1125,7 +1123,7 @@ public Tuple resolveCommand( Dict labelDictUnchecked, Dict executionRequirementsUnchecked, StarlarkThread thread) - throws EvalException, InterruptedException { + throws EvalException { checkMutable("resolve_command"); Map> labelDict = checkLabelDict(labelDictUnchecked); // The best way to fix this probably is to convert CommandHelper to Starlark. diff --git a/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateContext.java b/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateContext.java index 612986b8eaedd7..dc6d27598daa94 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateContext.java @@ -27,7 +27,7 @@ public interface TemplateContext { * @throws ExpansionException if the given variable was not defined or there was any other error * during expansion */ - String lookupVariable(String name) throws ExpansionException, InterruptedException; + String lookupVariable(String name) throws ExpansionException; /** * Returns the expansion of the specified template function with the given parameter. diff --git a/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateExpander.java b/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateExpander.java index b4d4f3e03aa511..28ccb563d42dad 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateExpander.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/stringtemplate/TemplateExpander.java @@ -38,7 +38,7 @@ private TemplateExpander(String expression) { */ @Nullable public static String expandSingleVariable(String expression, TemplateContext context) - throws ExpansionException, InterruptedException { + throws ExpansionException { String var = new TemplateExpander(expression).getSingleVariable(); return (var != null) ? context.lookupVariable(var) : null; } @@ -53,7 +53,7 @@ public static String expandSingleVariable(String expression, TemplateContext con * @throws ExpansionException if "expr" contained undefined or ill-formed variables references */ public static Expansion expand(String expression, TemplateContext context) - throws ExpansionException, InterruptedException { + throws ExpansionException { if (expression.indexOf('$') < 0) { return Expansion.create(expression, ImmutableSet.of()); } @@ -62,7 +62,7 @@ public static Expansion expand(String expression, TemplateContext context) // Helper method for counting recursion depth. private static Expansion expand(String expression, TemplateContext context, int depth) - throws ExpansionException, InterruptedException { + throws ExpansionException { if (depth > 10) { // plenty! throw new ExpansionException( String.format("potentially unbounded recursion during expansion of '%s'", expression)); @@ -70,8 +70,7 @@ private static Expansion expand(String expression, TemplateContext context, int return new TemplateExpander(expression).expand(context, depth); } - private Expansion expand(TemplateContext context, int depth) - throws ExpansionException, InterruptedException { + private Expansion expand(TemplateContext context, int depth) throws ExpansionException { StringBuilder result = new StringBuilder(); ImmutableSet.Builder lookedUpVariables = ImmutableSet.builder(); while (offset < length) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index c6571b60bb86a3..c4a2d942641b35 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -205,8 +205,7 @@ public CcFlagsSupplier(RuleContext ruleContext) { @Override @Nullable - public String getMakeVariable(String variableName) - throws ExpansionException, InterruptedException { + public String getMakeVariable(String variableName) throws ExpansionException { if (!variableName.equals(CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME)) { return null; } @@ -220,8 +219,7 @@ public String getMakeVariable(String variableName) } @Override - public ImmutableMap getAllMakeVariables() - throws ExpansionException, InterruptedException { + public ImmutableMap getAllMakeVariables() throws ExpansionException { return ImmutableMap.of( CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME, getMakeVariable(CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME)); @@ -271,11 +269,11 @@ public boolean passesFilter(String flag) { * *

But we require that the "defines" attribute consists of a single token. */ - public List getDefines() throws InterruptedException { + public List getDefines() { return getDefinesFromAttribute(DEFINES_ATTRIBUTE); } - private List getDefinesFromAttribute(String attr) throws InterruptedException { + private List getDefinesFromAttribute(String attr) { List defines = new ArrayList<>(); // collect labels that can be substituted in defines @@ -572,7 +570,7 @@ public static FeatureConfiguration configureFeaturesOrThrowEvalException( */ public static String computeCcFlags( RuleContext ruleContext, CcToolchainProvider toolchainProvider) - throws RuleErrorException, InterruptedException, EvalException { + throws RuleErrorException, EvalException { // Determine the original value of CC_FLAGS. String originalCcFlags = toolchainProvider.getLegacyCcFlagsMakeVariable(); @@ -605,8 +603,7 @@ private static boolean containsSysroot(String ccFlags, List moreCcFlags) } private static List computeCcFlagsFromFeatureConfig( - RuleContext ruleContext, CcToolchainProvider toolchainProvider) - throws RuleErrorException, InterruptedException { + RuleContext ruleContext, CcToolchainProvider toolchainProvider) throws RuleErrorException { FeatureConfiguration featureConfiguration = null; CppConfiguration cppConfiguration; cppConfiguration = ruleContext.getFragment(CppConfiguration.class); diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java index 9ed01ef86b6969..e14336f2809105 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java +++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java @@ -322,8 +322,7 @@ private static final class CommandResolverContext extends ConfigurationMakeVaria } @Override - public String lookupVariable(String variableName) - throws ExpansionException, InterruptedException { + public String lookupVariable(String variableName) throws ExpansionException { String val = lookupVariableImpl(variableName); if (windowsPath) { return val.replace('/', '\\'); @@ -331,8 +330,7 @@ public String lookupVariable(String variableName) return val; } - private String lookupVariableImpl(String variableName) - throws ExpansionException, InterruptedException { + private String lookupVariableImpl(String variableName) throws ExpansionException { if (variableName.equals("SRCS")) { return Artifact.joinExecPaths(" ", resolvedSrcs.toList()); }