From 81096f0ef3bb811198e3522a2150bfbe9b5da2d6 Mon Sep 17 00:00:00 2001 From: cparsons Date: Fri, 25 May 2018 13:41:10 -0700 Subject: Migrate FilesToRunProvider, Target, and TemplateVariableInfo to skylarkbuildapi RELNOTES: None. PiperOrigin-RevId: 198095817 --- .../build/lib/analysis/FilesToRunProvider.java | 6 +-- .../build/lib/analysis/TemplateVariableInfo.java | 27 ++----------- .../google/devtools/build/lib/packages/Target.java | 20 +--------- .../lib/skylarkbuildapi/FilesToRunProviderApi.java | 43 ++++++++++++++++++++ .../build/lib/skylarkbuildapi/TargetApi.java | 38 ++++++++++++++++++ .../skylarkbuildapi/TemplateVariableInfoApi.java | 46 ++++++++++++++++++++++ 6 files changed, 134 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/google/devtools/build/lib/skylarkbuildapi/FilesToRunProviderApi.java create mode 100644 src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TargetApi.java create mode 100644 src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TemplateVariableInfoApi.java (limited to 'src') 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 = "WARNING: The constructor of this provider is experimental and may go away at any " - + "time." - + "

Encapsulates template variables, that is, variables that can be referenced by " - + "strings like $(VARIABLE) in BUILD files and expanded by " - + "ctx.expand_make_variables and implicitly in certain attributes of " - + "built-in rules." - + "

" - + "

TemplateVariableInfo can be created by calling its eponymous " - + "constructor with a string-to-string dict as an argument that specifies the variables " - + "provided." - + "

" - + "

Example: platform_common.TemplateVariableInfo({'FOO': 'bar'})" - + "

") @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 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 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 { + + @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 = "WARNING: The constructor of this provider is experimental and may go away at any " + + "time." + + "

Encapsulates template variables, that is, variables that can be referenced by " + + "strings like $(VARIABLE) in BUILD files and expanded by " + + "ctx.expand_make_variables and implicitly in certain attributes of " + + "built-in rules." + + "

" + + "

TemplateVariableInfo can be created by calling its eponymous " + + "constructor with a string-to-string dict as an argument that specifies the variables " + + "provided." + + "

" + + "

Example: platform_common.TemplateVariableInfo({'FOO': 'bar'})" + + "

") +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 getVariables(); +} -- cgit v1.2.3