Skip to content

Commit

Permalink
bazel syntax: make @Skylark-annotated classes implement SkylarkValue
Browse files Browse the repository at this point in the history
This CL adds a check to the @SkylarkCallable annotation processor to require
that all SkylarkModule- or SkylarkGlobalLibary-annotated classes implement
SkylarkValue, thus ensuring that all Starlark values besides str/int/bool
satisfy this interface.

Future changes will add assertions at the public API (e.g. StarlarkList.add)
that Object values conform to this requirement.

All changes except to .../main/.../{skylarkinterface,syntax}/* are mechanical.

PiperOrigin-RevId: 278876512
  • Loading branch information
Googler authored and copybara-github committed Nov 6, 2019
1 parent 9d5394e commit 9331632
Show file tree
Hide file tree
Showing 119 changed files with 543 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.CallUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand All @@ -37,12 +38,11 @@
*/
final class SkylarkDocumentationCollector {
@SkylarkModule(
name = "globals",
title = "Globals",
category = SkylarkModuleCategory.TOP_LEVEL_TYPE,
doc = "Objects, functions and modules registered in the global environment."
)
private static final class TopLevelModule {}
name = "globals",
title = "Globals",
category = SkylarkModuleCategory.TOP_LEVEL_TYPE,
doc = "Objects, functions and modules registered in the global environment.")
private static final class TopLevelModule implements SkylarkValue {}

private SkylarkDocumentationCollector() {}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load(":merge_licenses.bzl", "merge_licenses")

# Description:
# Main Java code for Bazel
package(
default_visibility = ["//src:__subpackages__"],
)

load(":merge_licenses.bzl", "merge_licenses")

# Generate list of all srcs via:
# bazel query 'filter("srcs", kind("filegroup rule", //src/main/java/com/google/devtools/build/lib/...))' | sort | sed -e "s/^/\"/" | sed -e "s/$/\",/" | fgrep -v "build/lib:srcs"
filegroup(
Expand Down Expand Up @@ -399,6 +398,7 @@ java_library(
],
deps = [
":skylark_semantics",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//third_party:jsr305",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Set;

/** A global library of Starlark functions which are available only when evaluating BUILD files. */
@SkylarkGlobalLibrary()
@SkylarkGlobalLibrary
class StarlarkBuildLibrary {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.SkylarkList;
import java.util.List;
Expand All @@ -35,7 +36,7 @@
/** Marks configured targets that are able to supply message bundles to their dependents. */
@AutoCodec
@Immutable
public final class MessageBundleInfo extends NativeInfo {
public final class MessageBundleInfo extends NativeInfo implements SkylarkValue {

public static final String SKYLARK_NAME = "MessageBundleInfo";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.common.options.TriState;

Expand All @@ -35,7 +36,7 @@
name = "py",
doc = "A configuration fragment for Python.",
category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT)
public class PythonConfiguration extends BuildConfiguration.Fragment {
public class PythonConfiguration extends BuildConfiguration.Fragment implements SkylarkValue {

private final PythonVersion version;
private final PythonVersion defaultVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/** Interface for a configuration object which holds information about the build environment. */
@SkylarkModule(
name = "configuration",
category = SkylarkModuleCategory.BUILTIN,
doc = "This object holds information about the environment in which the build is running. See "
+ "the <a href='../rules.$DOC_EXT#configurations'>Rules page</a> for more on the general "
+ "concept of configurations."
)
public interface BuildConfigurationApi {
doc =
"This object holds information about the environment in which the build is running. See"
+ " the <a href='../rules.$DOC_EXT#configurations'>Rules page</a> for more on the"
+ " general concept of configurations.")
public interface BuildConfigurationApi extends SkylarkValue {

@SkylarkCallable(name = "bin_dir", structField = true, documented = false)
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/** A representation of the concept "this builds these files". */
@SkylarkModule(
name = "file_provider",
doc = "An interface for rules that provide files.",
category = SkylarkModuleCategory.PROVIDER)
public interface FileProviderApi {
public interface FileProviderApi extends SkylarkValue {

/**
* Returns the set of files that are the "output" of this rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import javax.annotation.Nullable;

/** Returns information about executables produced by a target and the files needed to run it. */
@SkylarkModule(name = "FilesToRunProvider", doc = "", category = SkylarkModuleCategory.PROVIDER)
public interface FilesToRunProviderApi<FileT extends FileApi> {
public interface FilesToRunProviderApi<FileT extends FileApi> extends SkylarkValue {

@SkylarkCallable(
name = "executable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@
package com.google.devtools.build.lib.skylarkbuildapi;

import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/**
* A value object used to represent an entry inside a "Fileset" BUILD rule.
*/
@SkylarkModule(
name = "FilesetEntry",
doc = "",
documented = false)
public interface FilesetEntryApi {
}
/** A value object used to represent an entry inside a "Fileset" BUILD rule. */
@SkylarkModule(name = "FilesetEntry", doc = "", documented = false)
public interface FilesetEntryApi extends SkylarkValue {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.ClassObject;

/** Represents a collection of configuration fragments in Skylark. */
Expand All @@ -31,4 +32,4 @@
+ "ex:</p><code>ctx.fragments.apple</code></p>"
+ "Note that rules have to declare their required fragments in order to access them "
+ "(see <a href=\"../rules.md#fragments\">here</a>).")
public interface FragmentCollectionApi extends ClassObject {}
public interface FragmentCollectionApi extends ClassObject, SkylarkValue {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/**
* A configuration fragment representing protocol buffers.
*/
/** A configuration fragment representing protocol buffers. */
@SkylarkModule(
name = "proto",
category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT,
doc = "A configuration fragment representing protocol buffers."
)
public interface ProtoConfigurationApi {
}
doc = "A configuration fragment representing protocol buffers.")
public interface ProtoConfigurationApi extends SkylarkValue {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/** An interface for a set of runfiles. */
@SkylarkModule(
name = "runfiles",
category = SkylarkModuleCategory.BUILTIN,
doc = "An interface for a set of runfiles.")
public interface RunfilesApi {
public interface RunfilesApi extends SkylarkValue {

@SkylarkCallable(
name = "files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.skylarkinterface.StarlarkDeprecated;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
Expand All @@ -29,7 +30,7 @@
category = SkylarkModuleCategory.TOP_LEVEL_TYPE,
doc = "Deprecated. Module for creating memory efficient command lines.")
@StarlarkDeprecated
public interface SkylarkCommandLineApi {
public interface SkylarkCommandLineApi extends SkylarkValue {

@SkylarkCallable(
name = "join_paths",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkDict;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.StarlarkThread;

/**
* Interface for a module with native rule and package helper functions.
*/
/** Interface for a module with native rule and package helper functions. */
@SkylarkModule(
name = "native",
category = SkylarkModuleCategory.BUILTIN,
Expand All @@ -38,9 +37,8 @@
+ "Note that the native module is only available in the loading phase "
+ "(i.e. for macros, not for rule implementations). Attributes will ignore "
+ "<code>None</code> values, and treat them as if the attribute was unset.<br>"
+ "The following functions are also available:"
)
public interface SkylarkNativeModuleApi {
+ "The following functions are also available:")
public interface SkylarkNativeModuleApi extends SkylarkValue {

@SkylarkCallable(
name = "glob",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/**
* A node in the build dependency graph, identified by a Label.
*/
/** A node in the build dependency graph, identified by a Label. */
@SkylarkModule(name = "target", doc = "", documented = false)
public interface TargetApi {
public interface TargetApi extends SkylarkValue {

/**
* Returns the label of this target. (e.g. "//foo:bar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,29 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier;

/**
* Interface for a build target.
*/
/** Interface for a build target. */
@SkylarkModule(
name = "Target",
category = SkylarkModuleCategory.BUILTIN,
doc =
"A BUILD target. It is essentially a <code>struct</code> with the following fields:"
+ "<ul>"
+ "<li><h3 id=\"modules.Target.label\">label</h3><code><a class=\"anchor\" "
+ "href=\"Label.html\">Label</a> Target.label</code><br>The identifier of the "
+ "target.</li>"
+ "<li><h3 id=\"modules.Target.files\">files</h3><code><a class=\"anchor\" "
+ "href=\"depset.html\">depset</a> Target.files </code><br>The set of "
+ "<a class=\"anchor\" href=\"File.html\">File</a>s produced directly by this "
+ "target.</li>"
+ "<li><h3 id=\"modules.Target.aspect_ids\">aspect_ids</h3><code><a class=\"anchor\""
+ "href=\"list.html\">list</a> Target.aspect_ids </code><br>The list of "
+ "<a class=\"anchor\" href=\"ctx.html#aspect_id\">aspect_id</a>s applied to this "
+ "target.</li>"
+ "<li><h3 id=\"modules.Target.extraproviders\">Extra providers</h3>For rule targets all "
+ "additional providers provided by this target are accessible as <code>struct</code> "
+ "fields. These extra providers are defined in the <code>struct</code> returned by the "
+ "rule implementation function.</li>"
+ "</ul>"
)
public interface TransitiveInfoCollectionApi {
name = "Target",
category = SkylarkModuleCategory.BUILTIN,
doc =
"A BUILD target. It is essentially a <code>struct</code> with the following fields:"
+ "<ul><li><h3 id=\"modules.Target.label\">label</h3><code><a class=\"anchor\""
+ " href=\"Label.html\">Label</a> Target.label</code><br>The identifier of the "
+ "target.</li><li><h3 id=\"modules.Target.files\">files</h3><code><a class=\"anchor\""
+ " href=\"depset.html\">depset</a> Target.files </code><br>The set of <a"
+ " class=\"anchor\" href=\"File.html\">File</a>s produced directly by this "
+ "target.</li><li><h3 id=\"modules.Target.aspect_ids\">aspect_ids</h3><code><a"
+ " class=\"anchor\"href=\"list.html\">list</a> Target.aspect_ids </code><br>The list"
+ " of <a class=\"anchor\" href=\"ctx.html#aspect_id\">aspect_id</a>s applied to this "
+ "target.</li><li><h3 id=\"modules.Target.extraproviders\">Extra providers</h3>For"
+ " rule targets all additional providers provided by this target are accessible as"
+ " <code>struct</code> fields. These extra providers are defined in the"
+ " <code>struct</code> returned by the rule implementation function.</li></ul>")
public interface TransitiveInfoCollectionApi extends SkylarkValue {

@SkylarkCallable(
name = "output_group",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skylarkbuildapi.android;

import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/** Wraps common settings for working with android binary assets, resources, and manifests. */
@SkylarkModule(
Expand All @@ -24,4 +25,4 @@
+ "Wraps common settings for working with android binary assets, resources, and "
+ "manifest",
documented = false)
public interface AndroidBinaryDataSettingsApi {}
public interface AndroidBinaryDataSettingsApi extends SkylarkValue {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/** Configuration fragment for Android rules. */
@SkylarkModule(
Expand All @@ -27,7 +28,7 @@
+ "A configuration fragment for Android.",
documented = false,
category = SkylarkModuleCategory.CONFIGURATION_FRAGMENT)
public interface AndroidConfigurationApi {
public interface AndroidConfigurationApi extends SkylarkValue {

@SkylarkCallable(
name = "android_cpu",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skylarkbuildapi.android;

import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;

/**
* Wraps common tools and settings used for working with Android assets, resources, and manifests.
Expand All @@ -26,4 +27,4 @@
+ "Wraps common tools and settings used for working with Android assets, resources, and"
+ " manifests",
documented = false)
public interface AndroidDataContextApi {}
public interface AndroidDataContextApi extends SkylarkValue {}
Loading

0 comments on commit 9331632

Please sign in to comment.