diff options
author | 2018-05-25 13:41:10 -0700 | |
---|---|---|
committer | 2018-05-25 13:42:27 -0700 | |
commit | 81096f0ef3bb811198e3522a2150bfbe9b5da2d6 (patch) | |
tree | 3864c36a917300ca1713d5d30615abed47cfd510 /src | |
parent | 9b5d886524cd0a65b27079ca76299403a18d2bb7 (diff) |
Migrate FilesToRunProvider, Target, and TemplateVariableInfo to skylarkbuildapi
RELNOTES: None.
PiperOrigin-RevId: 198095817
Diffstat (limited to 'src')
6 files changed, 134 insertions, 46 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java index 8a72fd069f..01c79257b5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java @@ -22,16 +22,14 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.lib.skylarkbuildapi.FilesToRunProviderApi; 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 javax.annotation.Nullable; /** Returns information about executables produced by a target and the files needed to run it. */ @Immutable -@SkylarkModule(name = "FilesToRunProvider", doc = "", category = SkylarkModuleCategory.PROVIDER) @AutoCodec -public final class FilesToRunProvider implements TransitiveInfoProvider { +public final class FilesToRunProvider implements TransitiveInfoProvider, FilesToRunProviderApi { /** The name of the field in Skylark used to access this class. */ public static final String SKYLARK_NAME = "files_to_run"; diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TemplateVariableInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/TemplateVariableInfo.java index 9c4307e03d..14097b2cd8 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TemplateVariableInfo.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TemplateVariableInfo.java @@ -21,8 +21,7 @@ import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.NativeInfo; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; +import com.google.devtools.build.lib.skylarkbuildapi.TemplateVariableInfoApi; import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.FunctionSignature; @@ -31,24 +30,9 @@ import com.google.devtools.build.lib.syntax.SkylarkType; import java.util.Map; /** Provides access to make variables from the current fragments. */ -@SkylarkModule( - name = "TemplateVariableInfo", - doc = "<b>WARNING</b>: The constructor of this provider is experimental and may go away at any " - + "time." - + "<p>Encapsulates template variables, that is, variables that can be referenced by " - + "strings like <code>$(VARIABLE)</code> in BUILD files and expanded by " - + "<code>ctx.expand_make_variables</code> and implicitly in certain attributes of " - + "built-in rules." - + "</p>" - + "<p><code>TemplateVariableInfo</code> can be created by calling its eponymous " - + "constructor with a string-to-string dict as an argument that specifies the variables " - + "provided." - + "</p>" - + "<p>Example: <code>platform_common.TemplateVariableInfo({'FOO': 'bar'})</code>" - + "</p>") @Immutable @AutoCodec -public final class TemplateVariableInfo extends NativeInfo { +public final class TemplateVariableInfo extends NativeInfo implements TemplateVariableInfoApi { public static final String SKYLARK_NAME = "TemplateVariableInfo"; private static final FunctionSignature.WithValues<Object, SkylarkType> SIGNATURE = @@ -77,12 +61,7 @@ public final class TemplateVariableInfo extends NativeInfo { this.variables = variables; } - @SkylarkCallable( - name = "variables", - doc = "Returns the make variables defined by this target as a dictionary with string keys " - + "and string values", - structField = true - ) + @Override public ImmutableMap<String, String> getVariables() { return variables; } diff --git a/src/main/java/com/google/devtools/build/lib/packages/Target.java b/src/main/java/com/google/devtools/build/lib/packages/Target.java index 52c6e8f595..c85eb994b8 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Target.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Target.java @@ -14,12 +14,9 @@ package com.google.devtools.build.lib.packages; -import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.packages.License.DistributionType; -import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; -import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; - +import com.google.devtools.build.lib.skylarkbuildapi.TargetApi; import java.util.Set; import javax.annotation.Nullable; @@ -29,20 +26,7 @@ import javax.annotation.Nullable; * This SkylarkModule does not contain any documentation since Skylark's Target type refers to * TransitiveInfoCollection.class, which contains the appropriate documentation. */ -@SkylarkModule(name = "target", doc = "", documented = false) -public interface Target { - - /** - * Returns the label of this target. (e.g. "//foo:bar") - */ - @SkylarkCallable(name = "label", documented = false) - Label getLabel(); - - /** - * Returns the name of this rule (relative to its owning package). - */ - @SkylarkCallable(name = "name", documented = false) - String getName(); +public interface Target extends TargetApi { /** * Returns the Package to which this rule belongs. diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FilesToRunProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FilesToRunProviderApi.java new file mode 100644 index 0000000000..6fb18ea692 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FilesToRunProviderApi.java @@ -0,0 +1,43 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi; + +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 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> { + + @SkylarkCallable( + name = "executable", + doc = "The main executable or None if it does not exist.", + structField = true, + allowReturnNones = true + ) + @Nullable + public FileT getExecutable(); + + @SkylarkCallable( + name = "runfiles_manifest", + doc = "The runfiles manifest or None if it does not exist.", + structField = true, + allowReturnNones = true + ) + @Nullable + public FileT getRunfilesManifest(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TargetApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TargetApi.java new file mode 100644 index 0000000000..549e8640ea --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TargetApi.java @@ -0,0 +1,38 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi; + +import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; + +/** + * A node in the build dependency graph, identified by a Label. + */ +@SkylarkModule(name = "target", doc = "", documented = false) +public interface TargetApi { + + /** + * Returns the label of this target. (e.g. "//foo:bar") + */ + @SkylarkCallable(name = "label", documented = false) + Label getLabel(); + + /** + * Returns the name of this rule (relative to its owning package). + */ + @SkylarkCallable(name = "name", documented = false) + String getName(); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TemplateVariableInfoApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TemplateVariableInfoApi.java new file mode 100644 index 0000000000..0af0811075 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TemplateVariableInfoApi.java @@ -0,0 +1,46 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.skylarkbuildapi; + +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; +import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; + +/** Provides access to make variables from the current fragments. */ +@SkylarkModule( + name = "TemplateVariableInfo", + doc = "<b>WARNING</b>: The constructor of this provider is experimental and may go away at any " + + "time." + + "<p>Encapsulates template variables, that is, variables that can be referenced by " + + "strings like <code>$(VARIABLE)</code> in BUILD files and expanded by " + + "<code>ctx.expand_make_variables</code> and implicitly in certain attributes of " + + "built-in rules." + + "</p>" + + "<p><code>TemplateVariableInfo</code> can be created by calling its eponymous " + + "constructor with a string-to-string dict as an argument that specifies the variables " + + "provided." + + "</p>" + + "<p>Example: <code>platform_common.TemplateVariableInfo({'FOO': 'bar'})</code>" + + "</p>") +public interface TemplateVariableInfoApi extends StructApi { + + @SkylarkCallable( + name = "variables", + doc = "Returns the make variables defined by this target as a dictionary with string keys " + + "and string values", + structField = true + ) + public ImmutableMap<String, String> getVariables(); +} |