Skip to content

Commit abbb900

Browse files
c-parsonsCopybara-Service
authored andcommitted
Migrate SkylarkRuleContext (and a few dependencies) to the build API
RELNOTES: None. PiperOrigin-RevId: 196287081
1 parent 0565a93 commit abbb900

10 files changed

Lines changed: 1198 additions & 827 deletions

src/main/java/com/google/devtools/build/lib/analysis/TransitiveInfoCollection.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
import com.google.devtools.build.lib.collect.nestedset.Order;
2525
import com.google.devtools.build.lib.packages.RequiredProviders;
2626
import com.google.devtools.build.lib.skyframe.BuildConfigurationValue;
27-
import com.google.devtools.build.lib.skylarkinterface.Param;
28-
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
29-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
30-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
27+
import com.google.devtools.build.lib.skylarkbuildapi.TransitiveInfoCollectionApi;
3128
import com.google.devtools.build.lib.syntax.SkylarkIndexable;
3229
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
3330
import javax.annotation.Nullable;
@@ -47,37 +44,10 @@
4744
* @see com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory
4845
* @see TransitiveInfoProvider
4946
*/
50-
@SkylarkModule(
51-
name = "Target",
52-
category = SkylarkModuleCategory.BUILTIN,
53-
doc =
54-
"A BUILD target. It is essentially a <code>struct</code> with the following fields:"
55-
+ "<ul>"
56-
+ "<li><h3 id=\"modules.Target.label\">label</h3><code><a class=\"anchor\" "
57-
+ "href=\"Label.html\">Label</a> Target.label</code><br>The identifier of the "
58-
+ "target.</li>"
59-
+ "<li><h3 id=\"modules.Target.files\">files</h3><code><a class=\"anchor\" "
60-
+ "href=\"depset.html\">depset</a> Target.files </code><br>The set of "
61-
+ "<a class=\"anchor\" href=\"File.html\">File</a>s produced directly by this "
62-
+ "target.</li>"
63-
+ "<li><h3 id=\"modules.Target.aspect_ids\">aspect_ids</h3><code><a class=\"anchor\""
64-
+ "href=\"list.html\">list</a> Target.aspect_ids </code><br>The list of "
65-
+ "<a class=\"anchor\" href=\"ctx.html#aspect_id\">aspect_id</a>s applied to this "
66-
+ "target.</li>"
67-
+ "<li><h3 id=\"modules.Target.extraproviders\">Extra providers</h3>For rule targets all "
68-
+ "additional providers provided by this target are accessible as <code>struct</code> "
69-
+ "fields. These extra providers are defined in the <code>struct</code> returned by the "
70-
+ "rule implementation function.</li>"
71-
+ "</ul>"
72-
)
73-
public interface TransitiveInfoCollection extends SkylarkIndexable, SkylarkProviderCollection {
47+
public interface TransitiveInfoCollection
48+
extends SkylarkIndexable, SkylarkProviderCollection, TransitiveInfoCollectionApi {
7449

75-
@SkylarkCallable(name = "output_group",
76-
documented = false, // TODO(dslomov): document.
77-
parameters = {
78-
@Param(name = "group_name", type = String.class, doc = "Output group name", named = true)
79-
}
80-
)
50+
@Override
8151
default SkylarkNestedSet outputGroup(String group) {
8252
OutputGroupInfo provider = OutputGroupInfo.get(this);
8353
NestedSet<Artifact> result = provider != null

src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@
5151
import com.google.devtools.build.lib.packages.Target;
5252
import com.google.devtools.build.lib.packages.TestTimeout;
5353
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
54-
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
54+
import com.google.devtools.build.lib.skylarkbuildapi.BuildConfigurationApi;
5555
import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
5656
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
57-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
5857
import com.google.devtools.build.lib.util.OS;
5958
import com.google.devtools.build.lib.util.RegexFilter;
6059
import com.google.devtools.build.lib.vfs.Path;
@@ -102,18 +101,10 @@
102101
*
103102
* <pre>c1.equals(c2) <=> c1==c2.</pre>
104103
*/
105-
@SkylarkModule(
106-
name = "configuration",
107-
category = SkylarkModuleCategory.BUILTIN,
108-
doc =
109-
"This object holds information about the environment in which the build is running. See "
110-
+ "the <a href='../rules.$DOC_EXT#configurations'>Rules page</a> for more on the general "
111-
+ "concept of configurations."
112-
)
113104
// TODO(janakr): If overhead of fragments class names is too high, add constructor that just takes
114105
// fragments and gets names from them.
115106
@AutoCodec
116-
public class BuildConfiguration {
107+
public class BuildConfiguration implements BuildConfigurationApi {
117108
/**
118109
* Sorts fragments by class name. This produces a stable order which, e.g., facilitates consistent
119110
* output from buildMnemonic.
@@ -1453,8 +1444,7 @@ public ArtifactRoot getOutputDirectory(RepositoryName repositoryName) {
14531444
}
14541445

14551446
/** Returns the bin directory for this build configuration. */
1456-
@SkylarkCallable(name = "bin_dir", structField = true, documented = false)
1457-
@Deprecated
1447+
@Override
14581448
public ArtifactRoot getBinDirectory() {
14591449
return getBinDirectory(RepositoryName.MAIN);
14601450
}
@@ -1488,8 +1478,7 @@ public ArtifactRoot getIncludeDirectory(RepositoryName repositoryName) {
14881478
}
14891479

14901480
/** Returns the genfiles directory for this build configuration. */
1491-
@SkylarkCallable(name = "genfiles_dir", structField = true, documented = false)
1492-
@Deprecated
1481+
@Override
14931482
public ArtifactRoot getGenfilesDirectory() {
14941483
return getGenfilesDirectory(RepositoryName.MAIN);
14951484
}
@@ -1538,8 +1527,7 @@ public PathFragment getGenfilesFragment() {
15381527
* not match the host platform. You should only use this when invoking tools that are known to use
15391528
* the native path separator, i.e., the path separator for the machine that they run on.
15401529
*/
1541-
@SkylarkCallable(name = "host_path_separator", structField = true,
1542-
doc = "Returns the separator for PATH environment variable, which is ':' on Unix.")
1530+
@Override
15431531
public String getHostPathSeparator() {
15441532
// TODO(bazel-team): Maybe do this in the constructor instead? This isn't serialization-safe.
15451533
return OS.getCurrent() == OS.WINDOWS ? ";" : ":";
@@ -1578,13 +1566,6 @@ public ActionEnvironment getActionEnvironment() {
15781566
return actionEnv;
15791567
}
15801568

1581-
@SkylarkCallable(
1582-
name = "default_shell_env",
1583-
structField = true,
1584-
doc =
1585-
"A dictionary representing the static local shell environment. It maps variables "
1586-
+ "to their values (strings)."
1587-
)
15881569
/**
15891570
* Return the "fixed" part of the actions' environment variables.
15901571
*
@@ -1596,7 +1577,7 @@ public ActionEnvironment getActionEnvironment() {
15961577
* <p>Since values of the "fixed" variables are already known at analysis phase, it is returned
15971578
* here as a map.
15981579
*/
1599-
@Deprecated // Use getActionEnvironment instead.
1580+
@Override
16001581
public ImmutableMap<String, String> getLocalShellEnvironment() {
16011582
return actionEnv.getFixedEnv();
16021583
}
@@ -1749,14 +1730,7 @@ public boolean legacyExternalRunfiles() {
17491730
* Returns user-specified test environment variables and their values, as set by the --test_env
17501731
* options.
17511732
*/
1752-
@Deprecated
1753-
@SkylarkCallable(
1754-
name = "test_env",
1755-
structField = true,
1756-
doc =
1757-
"A dictionary containing user-specified test environment variables and their values, "
1758-
+ "as set by the --test_env options. DO NOT USE! This is not the complete environment!"
1759-
)
1733+
@Override
17601734
public ImmutableMap<String, String> getTestEnv() {
17611735
return testEnv.getFixedEnv();
17621736
}
@@ -1785,11 +1759,7 @@ public boolean deferParamFiles() {
17851759
return options.deferParamFiles;
17861760
}
17871761

1788-
@SkylarkCallable(name = "coverage_enabled", structField = true,
1789-
doc = "A boolean that tells whether code coverage is enabled for this run. Note that this "
1790-
+ "does not compute whether a specific rule should be instrumented for code coverage "
1791-
+ "data collection. For that, see the <a href=\"ctx.html#coverage_instrumented\"><code>"
1792-
+ "ctx.coverage_instrumented</code></a> function.")
1762+
@Override
17931763
public boolean isCodeCoverageEnabled() {
17941764
return options.collectCodeCoverage;
17951765
}

src/main/java/com/google/devtools/build/lib/analysis/config/FragmentCollection.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,13 @@
1818
import com.google.devtools.build.lib.analysis.RuleContext;
1919
import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
2020
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
21-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
22-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
23-
import com.google.devtools.build.lib.syntax.ClassObject;
21+
import com.google.devtools.build.lib.skylarkbuildapi.FragmentCollectionApi;
2422
import javax.annotation.Nullable;
2523

26-
/**
27-
* Represents a collection of configuration fragments in Skylark.
28-
*/
24+
/** Represents a collection of configuration fragments in Skylark. */
2925
// Documentation can be found at ctx.fragments
3026
@Immutable
31-
@SkylarkModule(name = "fragments",
32-
category = SkylarkModuleCategory.NONE,
33-
doc = "Possible fields are "
34-
+ "<a href=\"apple.html\">apple</a>, <a href=\"cpp.html\">cpp</a>, "
35-
+ "<a href=\"java.html\">java</a>, <a href=\"jvm.html\">jvm</a> and "
36-
+ "<a href=\"objc.html\">objc</a>, <a href=\"android.html\">android</a>. "
37-
+ "Access a specific fragment by its field name ex:</p><code>ctx.fragments.apple</code></p>"
38-
+ "Note that rules have to declare their required fragments in order to access them "
39-
+ "(see <a href=\"../rules.md#fragments\">here</a>).")
40-
public class FragmentCollection implements ClassObject {
27+
public class FragmentCollection implements FragmentCollectionApi {
4128
private final RuleContext ruleContext;
4229
private final ConfigurationTransition transition;
4330

src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkAttributesCollection.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@
2424
import com.google.devtools.build.lib.packages.BuildType;
2525
import com.google.devtools.build.lib.packages.Info;
2626
import com.google.devtools.build.lib.packages.NativeProvider;
27-
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
28-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
29-
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
27+
import com.google.devtools.build.lib.skylarkbuildapi.SkylarkAttributesCollectionApi;
3028
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
31-
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
3229
import com.google.devtools.build.lib.syntax.Environment;
3330
import com.google.devtools.build.lib.syntax.EvalException;
3431
import com.google.devtools.build.lib.syntax.Runtime;
@@ -41,12 +38,8 @@
4138
import java.util.List;
4239
import java.util.Map;
4340

44-
@SkylarkModule(
45-
name = "rule_attributes",
46-
category = SkylarkModuleCategory.NONE,
47-
doc = "Information about attributes of a rule an aspect is applied to."
48-
)
49-
class SkylarkAttributesCollection implements SkylarkValue {
41+
/** Information about attributes of a rule an aspect is applied to. */
42+
class SkylarkAttributesCollection implements SkylarkAttributesCollectionApi {
5043
private final SkylarkRuleContext skylarkRuleContext;
5144
private final Info attrObject;
5245
private final Info executableObject;
@@ -91,35 +84,31 @@ private void checkMutable(String attrName) throws EvalException {
9184
skylarkRuleContext.checkMutable("rule." + attrName);
9285
}
9386

94-
@SkylarkCallable(name = "attr", structField = true, doc = SkylarkRuleContext.ATTR_DOC)
87+
@Override
9588
public Info getAttr() throws EvalException {
9689
checkMutable("attr");
9790
return attrObject;
9891
}
9992

100-
@SkylarkCallable(name = "executable", structField = true, doc = SkylarkRuleContext.EXECUTABLE_DOC)
93+
@Override
10194
public Info getExecutable() throws EvalException {
10295
checkMutable("executable");
10396
return executableObject;
10497
}
10598

106-
@SkylarkCallable(name = "file", structField = true, doc = SkylarkRuleContext.FILE_DOC)
99+
@Override
107100
public Info getFile() throws EvalException {
108101
checkMutable("file");
109102
return fileObject;
110103
}
111104

112-
@SkylarkCallable(name = "files", structField = true, doc = SkylarkRuleContext.FILES_DOC)
105+
@Override
113106
public Info getFiles() throws EvalException {
114107
checkMutable("files");
115108
return filesObject;
116109
}
117110

118-
@SkylarkCallable(
119-
name = "kind",
120-
structField = true,
121-
doc = "The kind of a rule, such as 'cc_library'"
122-
)
111+
@Override
123112
public String getRuleClassName() throws EvalException {
124113
checkMutable("kind");
125114
return ruleClassName;

0 commit comments

Comments
 (0)