aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/test
diff options
context:
space:
mode:
authorGravatar Sergio Campama <kaipi@google.com>2016-12-09 21:47:35 +0000
committerGravatar John Cater <jcater@google.com>2016-12-12 20:35:09 +0000
commitfd93143f93a9873218cd2eb783a0bff322847213 (patch)
treeec2f06ee63d37446a63aec7ceb7a5a24ff8cd91b /src/main/java/com/google/devtools/build/lib/rules/test
parent905a29d0e61d5393f2b7646fae8e6b4a819e68f4 (diff)
Add a testing Skylark module that exposes an ExecutionInfoProvider constructor.
-- PiperOrigin-RevId: 141594768 MOS_MIGRATED_REVID=141594768
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/test')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/test/ExecutionInfoProvider.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModule.java65
2 files changed, 74 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/ExecutionInfoProvider.java b/src/main/java/com/google/devtools/build/lib/rules/test/ExecutionInfoProvider.java
index 5eb084e244..37639c6ce2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/ExecutionInfoProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/ExecutionInfoProvider.java
@@ -16,7 +16,8 @@ package com.google.devtools.build.lib.rules.test;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-
+import com.google.devtools.build.lib.packages.SkylarkClassObject;
+import com.google.devtools.build.lib.packages.SkylarkClassObjectConstructor;
import java.util.Map;
/**
@@ -24,11 +25,17 @@ import java.util.Map;
* tests).
*/
@Immutable
-public final class ExecutionInfoProvider implements TransitiveInfoProvider {
+public final class ExecutionInfoProvider extends SkylarkClassObject
+ implements TransitiveInfoProvider {
+
+ /** Skylark constructor and identifier for ExecutionInfoProvider. */
+ public static final SkylarkClassObjectConstructor SKYLARK_CONSTRUCTOR =
+ SkylarkClassObjectConstructor.createNative("ExecutionInfo");
private final ImmutableMap<String, String> executionInfo;
public ExecutionInfoProvider(Map<String, String> requirements) {
+ super(SKYLARK_CONSTRUCTOR, ImmutableMap.<String, Object>of("requirements", requirements));
this.executionInfo = ImmutableMap.copyOf(requirements);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModule.java b/src/main/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModule.java
new file mode 100644
index 0000000000..7714d59240
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModule.java
@@ -0,0 +1,65 @@
+// Copyright 2016 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.rules.test;
+
+import com.google.devtools.build.lib.skylarkinterface.Param;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature;
+import com.google.devtools.build.lib.syntax.BuiltinFunction;
+import com.google.devtools.build.lib.syntax.SkylarkDict;
+import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
+
+/** A class that exposes testing infrastructure to skylark. */
+@SkylarkModule(
+ name = "testing",
+ doc = "Helper methods for skylark to access testing infrastructure."
+)
+public class SkylarkTestingModule {
+
+ // TODO(bazel-team): Change this BuiltinFunction to be the actual
+ // ExecutionInfoProvider.SKYLARK_CONSTRUCTOR.
+ @SkylarkSignature(
+ name = "ExecutionInfo",
+ objectType = SkylarkTestingModule.class,
+ returnType = ExecutionInfoProvider.class,
+ doc =
+ "Creates a new execution info provider. Use this provider to specify special"
+ + "environments requirements needed to run tests.",
+ parameters = {
+ @Param(name = "self", type = SkylarkTestingModule.class, doc = "The 'testing' instance."),
+ @Param(
+ name = "requirements",
+ type = SkylarkDict.class,
+ named = false,
+ positional = true,
+ doc =
+ "A map of string keys and values to indicate special execution requirements, such as"
+ + " hardware platforms, etc. These keys and values are passed to the executor of"
+ + " the test action as parameters to configure the execution environment."
+ )
+ }
+ )
+ public static final BuiltinFunction NEW_EXECUTION_INFO_PROVIDER =
+ new BuiltinFunction("ExecutionInfo") {
+ @SuppressWarnings("unused")
+ // This method is registered statically for skylark, and never called directly.
+ public ExecutionInfoProvider invoke(SkylarkTestingModule self, SkylarkDict requirements) {
+ return new ExecutionInfoProvider(requirements);
+ }
+ };
+
+ static {
+ SkylarkSignatureProcessor.configureSkylarkFunctions(SkylarkTestingModule.class);
+ }
+}