Skip to content

Commit

Permalink
Remove unneeded InterruptedException from various types of variable e…
Browse files Browse the repository at this point in the history
…xpansion.

PiperOrigin-RevId: 712605788
Change-Id: I0c69c9e86c0f170dcc0aa6d7b1115dd5a5c51c78
  • Loading branch information
katre authored and copybara-github committed Jan 6, 2025
1 parent ee07e26 commit a87bfef
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -120,8 +120,7 @@ public String lookupVariable(String name) throws ExpansionException, Interrupted
throw new ExpansionException(String.format("$(%s) not defined", name));
}

public Dict.Builder<String, String> collectMakeVariables()
throws ExpansionException, InterruptedException {
public Dict.Builder<String, String> collectMakeVariables() throws ExpansionException {
Dict.Builder<String, String> map = Dict.builder();
// Collect variables in the reverse order as in lookupMakeVariable
// because each update is overwriting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public void tokenizeAndExpandMakeVars(List<String> result, String attributeName,

/** Expands make variables and $(location) tags in value, and optionally tokenizes the result. */
private void expandValue(
List<String> tokens, String attributeName, String value, boolean shouldTokenize)
throws InterruptedException {
List<String> tokens, String attributeName, String value, boolean shouldTokenize) {
value = expand(attributeName, value);
if (shouldTokenize) {
try {
Expand Down Expand Up @@ -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());
Expand All @@ -178,7 +176,7 @@ public String expand(@Nullable String attributeName, String expression)
* attribute name is only used for error reporting.
*/
private ImmutableList<String> expandAndTokenizeList(
String attrName, List<String> values, boolean shouldTokenize) throws InterruptedException {
String attrName, List<String> values, boolean shouldTokenize) {
List<String> variables = new ArrayList<>();
for (String variable : values) {
expandValue(variables, attrName, variable, shouldTokenize);
Expand All @@ -191,15 +189,14 @@ private ImmutableList<String> expandAndTokenizeList(
* attribute does not exist or is not of type {@link Types.STRING_LIST}, then this method throws
* an error.
*/
public ImmutableList<String> list(String attrName) throws InterruptedException {
public ImmutableList<String> 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<String> list(String attrName, List<String> values)
throws InterruptedException {
public ImmutableList<String> list(String attrName, List<String> values) {
return expandAndTokenizeList(attrName, values, /* shouldTokenize */ false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('/', '\\');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> getAllMakeVariables()
throws ExpansionException, InterruptedException;
ImmutableMap<String, String> getAllMakeVariables() throws ExpansionException;

/**
* {@link MakeVariableSupplier} that reads variables from a list of {@link TemplateVariableInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ public ImmutableList<String> aspectIds() throws EvalException {
}

@Override
public Dict<String, String> var() throws EvalException, InterruptedException {
public Dict<String, String> var() throws EvalException {
checkMutable("var");
if (cachedMakeVariables == null) {
Dict.Builder<String, String> vars;
Expand Down Expand Up @@ -933,25 +933,23 @@ public boolean checkPlaceholders(String template, Sequence<?> allowedPlaceholder
@Override
public String expandMakeVariables(
String attributeName, String command, Dict<?, ?> additionalSubstitutions) // <String, String>
throws EvalException, InterruptedException {
throws EvalException {
checkMutable("expand_make_variables");
final Map<String, String> additionalSubstitutionsMap =
Dict.cast(additionalSubstitutions, String.class, String.class, "additional_substitutions");
return expandMakeVariables(attributeName, command, additionalSubstitutionsMap);
}

private String expandMakeVariables(
String attributeName, String command, Map<String, String> additionalSubstitutionsMap)
throws InterruptedException {
String attributeName, String command, Map<String, String> additionalSubstitutionsMap) {
ConfigurationMakeVariableContext makeVariableContext =
new ConfigurationMakeVariableContext(
ruleContext,
ruleContext.getRule().getPackage(),
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 {
Expand Down Expand Up @@ -1125,7 +1123,7 @@ public Tuple resolveCommand(
Dict<?, ?> labelDictUnchecked,
Dict<?, ?> executionRequirementsUnchecked,
StarlarkThread thread)
throws EvalException, InterruptedException {
throws EvalException {
checkMutable("resolve_command");
Map<Label, Iterable<Artifact>> labelDict = checkLabelDict(labelDictUnchecked);
// The best way to fix this probably is to convert CommandHelper to Starlark.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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());
}
Expand All @@ -62,16 +62,15 @@ 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));
}
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<String> lookedUpVariables = ImmutableSet.builder();
while (offset < length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -220,8 +219,7 @@ public String getMakeVariable(String variableName)
}

@Override
public ImmutableMap<String, String> getAllMakeVariables()
throws ExpansionException, InterruptedException {
public ImmutableMap<String, String> getAllMakeVariables() throws ExpansionException {
return ImmutableMap.of(
CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME,
getMakeVariable(CppConfiguration.CC_FLAGS_MAKE_VARIABLE_NAME));
Expand Down Expand Up @@ -271,11 +269,11 @@ public boolean passesFilter(String flag) {
*
* <p>But we require that the "defines" attribute consists of a single token.
*/
public List<String> getDefines() throws InterruptedException {
public List<String> getDefines() {
return getDefinesFromAttribute(DEFINES_ATTRIBUTE);
}

private List<String> getDefinesFromAttribute(String attr) throws InterruptedException {
private List<String> getDefinesFromAttribute(String attr) {
List<String> defines = new ArrayList<>();

// collect labels that can be substituted in defines
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -605,8 +603,7 @@ private static boolean containsSysroot(String ccFlags, List<String> moreCcFlags)
}

private static List<String> computeCcFlagsFromFeatureConfig(
RuleContext ruleContext, CcToolchainProvider toolchainProvider)
throws RuleErrorException, InterruptedException {
RuleContext ruleContext, CcToolchainProvider toolchainProvider) throws RuleErrorException {
FeatureConfiguration featureConfiguration = null;
CppConfiguration cppConfiguration;
cppConfiguration = ruleContext.getFragment(CppConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,15 @@ 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('/', '\\');
}
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());
}
Expand Down

0 comments on commit a87bfef

Please sign in to comment.