aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/test/SkylarkTestingModule.java
blob: d95302634f424cddc6a2542ffe030e815ffb4198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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.analysis.test.ExecutionInfo;
import com.google.devtools.build.lib.analysis.test.TestEnvironmentInfo;
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
  // ExecutionInfo.PROVIDER.
  @SkylarkSignature(
    name = "ExecutionInfo",
    objectType = SkylarkTestingModule.class,
    returnType = ExecutionInfo.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 ExecutionInfo invoke(SkylarkTestingModule self, SkylarkDict requirements) {
          return new ExecutionInfo(requirements);
        }
      };

  // TODO(bazel-team): Change this BuiltinFunction to be the actual
  // TestEnvironmentInfo.PROVIDER.
  @SkylarkSignature(
    name = "TestEnvironment",
    objectType = SkylarkTestingModule.class,
    returnType = TestEnvironmentInfo.class,
    doc =
        "Creates a new test environment provider. Use this provider to specify extra"
            + "environment variables to be made available during test execution.",
    parameters = {
      @Param(name = "self", type = SkylarkTestingModule.class, doc = "The 'testing' instance."),
      @Param(
        name = "environment",
        type = SkylarkDict.class,
        named = false,
        positional = true,
        doc =
            "A map of string keys and values that represent environment variables and their values."
                + " These will be made available during the test execution."
      )
    }
  )
  public static final BuiltinFunction NEW_TEST_ENVIRONMENT_PROVIDER =
      new BuiltinFunction("TestEnvironment") {
        @SuppressWarnings("unused")
        // This method is registered statically for skylark, and never called directly.
        public TestEnvironmentInfo invoke(SkylarkTestingModule self, SkylarkDict environment) {
          return new TestEnvironmentInfo(environment);
        }
      };

  static {
    SkylarkSignatureProcessor.configureSkylarkFunctions(SkylarkTestingModule.class);
  }
}