Skip to content

Commit

Permalink
Automated rollback of commit 2398d85.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Breaks skylib :(
https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/861#8e4e9bc5-ea99-4036-9fc9-867a90e708a3

*** Original change description ***

Pass repoMapping through toolchain functions

Closes #7718.
Fixes #7654.

PiperOrigin-RevId: 238606863
  • Loading branch information
hlopko authored and copybara-github committed Mar 15, 2019
1 parent a6d773e commit 7988d78
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
import static java.util.stream.Collectors.joining;

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.platform.PlatformInfo;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.analysis.platform.ToolchainTypeInfo;
import com.google.devtools.build.lib.analysis.skylark.BazelStarlarkContext;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
Expand Down Expand Up @@ -135,8 +133,7 @@ public void repr(SkylarkPrinter printer) {
printer.append(">");
}

private Label transformKey(Object key, Location loc, BazelStarlarkContext context)
throws EvalException {
private Label transformKey(Object key, Location loc) throws EvalException {
if (key instanceof Label) {
return (Label) key;
} else if (key instanceof ToolchainTypeInfo) {
Expand All @@ -145,7 +142,7 @@ private Label transformKey(Object key, Location loc, BazelStarlarkContext contex
Label toolchainType;
String rawLabel = (String) key;
try {
toolchainType = Label.parseAbsolute(rawLabel, context.getRepoMapping());
toolchainType = Label.parseAbsolute(rawLabel, ImmutableMap.of());
} catch (LabelSyntaxException e) {
throw new EvalException(
loc, String.format("Unable to parse toolchain %s: %s", rawLabel, e.getMessage()), e);
Expand All @@ -163,8 +160,7 @@ private Label transformKey(Object key, Location loc, BazelStarlarkContext contex
@Override
public ToolchainInfo getIndex(Object key, Location loc, StarlarkContext context)
throws EvalException {
Preconditions.checkArgument(context instanceof BazelStarlarkContext);
Label toolchainTypeLabel = transformKey(key, loc, (BazelStarlarkContext) context);
Label toolchainTypeLabel = transformKey(key, loc);

if (!containsKey(key, loc, context)) {
throw new EvalException(
Expand All @@ -184,8 +180,7 @@ public ToolchainInfo getIndex(Object key, Location loc, StarlarkContext context)
@Override
public boolean containsKey(Object key, Location loc, StarlarkContext context)
throws EvalException {
Preconditions.checkArgument(context instanceof BazelStarlarkContext);
Label toolchainTypeLabel = transformKey(key, loc, (BazelStarlarkContext) context);
Label toolchainTypeLabel = transformKey(key, loc);
Optional<Label> matching =
toolchains().keySet().stream()
.map(ToolchainTypeInfo::typeLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.cmdline.LabelValidator;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeMap;
Expand Down Expand Up @@ -290,7 +289,6 @@ public BaseFunction rule(
throws EvalException, ConversionException {
SkylarkUtils.checkLoadingOrWorkspacePhase(funcallEnv, "rule", ast.getLocation());

Preconditions.checkArgument(context instanceof BazelStarlarkContext);
BazelStarlarkContext bazelContext = (BazelStarlarkContext) context;
// analysis_test=true implies test=true.
test |= Boolean.TRUE.equals(analysisTest);
Expand Down Expand Up @@ -357,9 +355,7 @@ public BaseFunction rule(
funcallEnv.getGlobals().getLabel(), funcallEnv.getTransitiveContentHashCode());
builder.addRequiredToolchains(
collectToolchainLabels(
toolchains.getContents(String.class, "toolchains"),
bazelContext.getRepoMapping(),
ast.getLocation()));
toolchains.getContents(String.class, "toolchains"), ast.getLocation()));

if (!buildSetting.equals(Runtime.NONE) && !cfg.equals(Runtime.NONE)) {
throw new EvalException(
Expand Down Expand Up @@ -435,14 +431,11 @@ private static void addAttribute(
}

private static ImmutableList<Label> collectToolchainLabels(
Iterable<String> rawLabels,
ImmutableMap<RepositoryName, RepositoryName> repoMapping,
Location loc)
throws EvalException {
Iterable<String> rawLabels, Location loc) throws EvalException {
ImmutableList.Builder<Label> requiredToolchains = new ImmutableList.Builder<>();
for (String rawLabel : rawLabels) {
try {
Label toolchainLabel = Label.parseAbsolute(rawLabel, repoMapping);
Label toolchainLabel = Label.parseAbsolute(rawLabel, ImmutableMap.of());
requiredToolchains.add(toolchainLabel);
} catch (LabelSyntaxException e) {
throw new EvalException(
Expand Down Expand Up @@ -481,10 +474,8 @@ public SkylarkAspect aspect(
SkylarkList<?> toolchains,
String doc,
FuncallExpression ast,
Environment funcallEnv,
StarlarkContext context)
Environment funcallEnv)
throws EvalException {
Preconditions.checkArgument(context instanceof BazelStarlarkContext);
Location location = ast.getLocation();
ImmutableList.Builder<String> attrAspects = ImmutableList.builder();
for (Object attributeAspect : attributeAspects) {
Expand Down Expand Up @@ -572,9 +563,7 @@ public SkylarkAspect aspect(
HostTransition.INSTANCE,
ImmutableSet.copyOf(hostFragments.getContents(String.class, "host_fragments")),
collectToolchainLabels(
toolchains.getContents(String.class, "toolchains"),
((BazelStarlarkContext) context).getRepoMapping(),
ast.getLocation()));
toolchains.getContents(String.class, "toolchains"), ast.getLocation()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,104 +374,110 @@ public BaseFunction rule(
+ "Please see the <a href=\"../aspects.md\">introduction to Aspects</a> for more "
+ "details.",
parameters = {
@Param(
name = "implementation",
type = BaseFunction.class,
legacyNamed = true,
doc =
"the function implementing this aspect. Must have two parameters: "
+ "<a href=\"Target.html\">Target</a> (the target to which the aspect is "
+ "applied) and <a href=\"ctx.html\">ctx</a>. Attributes of the target are "
+ "available via ctx.rule field. The function is called during the analysis "
+ "phase for each application of an aspect to a target."),
@Param(
name = "attr_aspects",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"List of attribute names. The aspect propagates along dependencies specified by"
+ " attributes of a target with this name. The list can also contain a single "
+ "string '*': in that case aspect propagates along all dependencies of a"
+ " target."),
@Param(
name = "attrs",
type = SkylarkDict.class,
legacyNamed = true,
noneable = true,
defaultValue = "None",
doc =
"dictionary to declare all the attributes of the aspect. It maps from an"
+ " attribute name to an attribute object (see <a href=\"attr.html\">attr</a>"
+ " module). Aspect attributes are available to implementation function as"
+ " fields of ctx parameter. Implicit attributes starting with <code>_</code>"
+ " must have default values, and have type <code>label</code> or"
+ " <code>label_list</code>. Explicit attributes must have type"
+ " <code>string</code>, and must use the <code>values</code> restriction. If"
+ " explicit attributes are present, the aspect can only be used with rules"
+ " that have attributes of the same name and type, with valid values."),
@Param(
name = "required_aspect_providers",
type = SkylarkList.class,
legacyNamed = true,
defaultValue = "[]",
doc =
"Allow the aspect to inspect other aspects. If the aspect propagates along a"
+ " dependency, and the underlying rule sends a different aspect along that "
+ "dependency, and that aspect provides one of the providers listed here, this"
+ " aspect will see the providers provided by that aspect. <p>The value should"
+ " be either a list of providers, or a list of lists of providers. This"
+ " aspect will 'see' the underlying aspects that provide ALL providers from"
+ " at least ONE of these lists. A single list of providers will be"
+ " automatically converted to a list containing one list of providers."),
@Param(
name = "provides",
type = SkylarkList.class,
legacyNamed = true,
defaultValue = "[]",
doc = PROVIDES_DOC),
@Param(
name = "fragments",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"List of names of configuration fragments that the aspect requires "
+ "in target configuration."),
@Param(
name = "host_fragments",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"List of names of configuration fragments that the aspect requires "
+ "in host configuration."),
@Param(
name = "toolchains",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"<i>(Experimental)</i><br/><br/>"
+ "If set, the set of toolchains this rule requires. Toolchains will be "
+ "found by checking the current platform, and provided to the rule "
+ "implementation via <code>ctx.toolchain</code>."),
@Param(
name = "doc",
type = String.class,
legacyNamed = true,
defaultValue = "''",
doc =
"A description of the aspect that can be extracted by documentation generating "
+ "tools.")
@Param(
name = "implementation",
type = BaseFunction.class,
legacyNamed = true,
doc =
"the function implementing this aspect. Must have two parameters: "
+ "<a href=\"Target.html\">Target</a> (the target to which the aspect is "
+ "applied) and <a href=\"ctx.html\">ctx</a>. Attributes of the target are "
+ "available via ctx.rule field. The function is called during the analysis "
+ "phase for each application of an aspect to a target."
),
@Param(
name = "attr_aspects",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc = "List of attribute names. The aspect propagates along dependencies specified "
+ "by attributes of a target with this name. The list can also contain a single "
+ "string '*': in that case aspect propagates along all dependencies of a target."
),
@Param(
name = "attrs",
type = SkylarkDict.class,
legacyNamed = true,
noneable = true,
defaultValue = "None",
doc = "dictionary to declare all the attributes of the aspect. "
+ "It maps from an attribute name to an attribute object "
+ "(see <a href=\"attr.html\">attr</a> module). "
+ "Aspect attributes are available to implementation function as fields of ctx "
+ "parameter. Implicit attributes starting with <code>_</code> must have default "
+ "values, and have type <code>label</code> or <code>label_list</code>. "
+ "Explicit attributes must have type <code>string</code>, and must use the "
+ "<code>values</code> restriction. If explicit attributes are present, the "
+ "aspect can only be used with rules that have attributes of the same name and "
+ "type, with valid values."
),
@Param(
name = "required_aspect_providers",
type = SkylarkList.class,
legacyNamed = true,
defaultValue = "[]",
doc = "Allow the aspect to inspect other aspects. If the aspect propagates along "
+ "a dependency, and the underlying rule sends a different aspect along that "
+ "dependency, and that aspect provides one of the providers listed here, this "
+ "aspect will see the providers provided by that aspect. "
+ "<p>The value should be either a list of providers, or a "
+ "list of lists of providers. This aspect will 'see' the underlying aspects "
+ "that provide ALL providers from at least ONE of these lists. A single list "
+ "of providers will be automatically converted to a list containing one list of "
+ "providers."
),
@Param(
name = "provides",
type = SkylarkList.class,
legacyNamed = true,
defaultValue = "[]",
doc = PROVIDES_DOC
),
@Param(
name = "fragments",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"List of names of configuration fragments that the aspect requires "
+ "in target configuration."
),
@Param(
name = "host_fragments",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"List of names of configuration fragments that the aspect requires "
+ "in host configuration."
),
@Param(
name = "toolchains",
type = SkylarkList.class,
legacyNamed = true,
generic1 = String.class,
defaultValue = "[]",
doc =
"<i>(Experimental)</i><br/><br/>"
+ "If set, the set of toolchains this rule requires. Toolchains will be "
+ "found by checking the current platform, and provided to the rule "
+ "implementation via <code>ctx.toolchain</code>."
),
@Param(
name = "doc",
type = String.class,
legacyNamed = true,
defaultValue = "''",
doc = "A description of the aspect that can be extracted by documentation generating "
+ "tools."
)
},
useEnvironment = true,
useAst = true,
useContext = true)
useAst = true
)
public SkylarkAspectApi aspect(
BaseFunction implementation,
SkylarkList<?> attributeAspects,
Expand All @@ -483,8 +489,7 @@ public SkylarkAspectApi aspect(
SkylarkList<?> toolchains,
String doc,
FuncallExpression ast,
Environment funcallEnv,
StarlarkContext context)
Environment funcallEnv)
throws EvalException;

@SkylarkCallable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,10 @@ public FileTypeApi<FileApi> fileType(SkylarkList<?> types, Location loc, Environ
}

@Override
public SkylarkAspectApi aspect(
BaseFunction implementation,
SkylarkList<?> attributeAspects,
Object attrs,
SkylarkList<?> requiredAspectProvidersArg,
SkylarkList<?> providesArg,
SkylarkList<?> fragments,
SkylarkList<?> hostFragments,
SkylarkList<?> toolchains,
String doc,
FuncallExpression ast,
Environment funcallEnv,
StarlarkContext context)
throws EvalException {
public SkylarkAspectApi aspect(BaseFunction implementation, SkylarkList<?> attributeAspects,
Object attrs, SkylarkList<?> requiredAspectProvidersArg, SkylarkList<?> providesArg,
SkylarkList<?> fragments, SkylarkList<?> hostFragments, SkylarkList<?> toolchains, String doc,
FuncallExpression ast, Environment funcallEnv) throws EvalException {
return new FakeSkylarkAspect();
}

Expand Down
Loading

0 comments on commit 7988d78

Please sign in to comment.