From 8cb1d2fb460a9caf47df58d7ff051d31080a77cb Mon Sep 17 00:00:00 2001 From: ulfjack Date: Thu, 26 Oct 2017 10:27:00 +0200 Subject: Automated rollback of commit ca77f608e486bf7aa762565d25bf7b9e30f2268c. This also rolls back unknown commit. *** Reason for rollback *** Affected expand_location Skylark API semantics - it no longer accepts ${abc} or plain dollar signs, but complains. *** Original change description *** Extend TemplateExpander to handle $(func param) expansion Rewrite the Expander to use the new functionality; also rewrite the Skylark expand_location function to use it. PiperOrigin-RevId: 173508888 --- .../SkylarkRuleImplementationFunctions.java | 31 +++++----------------- 1 file changed, 6 insertions(+), 25 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleImplementationFunctions.java') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleImplementationFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleImplementationFunctions.java index 53aaf47e79..f71730b10a 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleImplementationFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleImplementationFunctions.java @@ -20,12 +20,11 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.AliasProvider; import com.google.devtools.build.lib.analysis.CommandHelper; import com.google.devtools.build.lib.analysis.FileProvider; +import com.google.devtools.build.lib.analysis.LocationExpander; import com.google.devtools.build.lib.analysis.Runfiles; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.configuredtargets.AbstractConfiguredTarget; -import com.google.devtools.build.lib.analysis.stringtemplate.ExpansionException; -import com.google.devtools.build.lib.analysis.stringtemplate.TemplateContext; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.skylarkinterface.Param; @@ -319,35 +318,17 @@ public class SkylarkRuleImplementationFunctions { throws EvalException { ctx.checkMutable("expand_location"); try { - return ctx - .getRuleContext() - .getExpander(new FakeTemplateContext()) - .withExecLocations( - makeLabelMap(targets.getContents(TransitiveInfoCollection.class, "targets"))) - .expand(/*attributeName=*/null, input); + return new LocationExpander( + ctx.getRuleContext(), + makeLabelMap(targets.getContents(TransitiveInfoCollection.class, "targets")), + LocationExpander.Options.EXEC_PATHS) + .expand(input); } catch (IllegalStateException ise) { throw new EvalException(loc, ise); } } }; - /** - * This class only exists for backwards compatibility. Previously, we were using LocationExpander - * directly, which passes through all unrecognized $() expressions. - */ - private static final class FakeTemplateContext implements TemplateContext { - @Override - public String lookupVariable(String name) throws ExpansionException { - return String.format("$$(%s)", name); - } - - @Override - public String lookupFunction(String name, String param) throws ExpansionException { - // Variables get recursively expanded, functions don't. - return String.format("$(%s %s)", name, param); - } - } - /** * Builds a map: Label -> List of files from the given labels * -- cgit v1.2.3