blob: 49b830e0ad2de6e5107f1a55edf53b8b474a2c64 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.packages;
16
dannarkd102a392019-01-09 13:12:01 -080017import com.google.common.collect.ImmutableMap;
John Fielda97e17f2015-11-13 02:19:52 +000018import com.google.devtools.build.lib.cmdline.Label;
dannarkd102a392019-01-09 13:12:01 -080019import com.google.devtools.build.lib.cmdline.RepositoryName;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010020import com.google.devtools.build.lib.events.EventHandler;
gregce4aa059a2019-02-26 13:20:47 -080021import com.google.devtools.build.lib.packages.RuleClass.Builder.ThirdPartyLicenseExistencePolicy;
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000022import com.google.devtools.build.lib.syntax.Environment;
23import com.google.devtools.build.lib.syntax.Environment.Extension;
24import com.google.devtools.build.lib.syntax.Mutability;
laurentlb6659b4c2019-02-18 07:23:36 -080025import com.google.devtools.build.lib.syntax.StarlarkSemantics;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010026import java.util.Map;
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000027import javax.annotation.Nullable;
28
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010029/**
30 * The collection of the supported build rules. Provides an Environment for Skylark rule creation.
31 */
32public interface RuleClassProvider {
Ulf Adamsfdfdd922015-09-01 08:36:29 +000033
34 /**
John Fielda97e17f2015-11-13 02:19:52 +000035 * Label referencing the prelude file.
Ulf Adamsfdfdd922015-09-01 08:36:29 +000036 */
John Fielda97e17f2015-11-13 02:19:52 +000037 Label getPreludeLabel();
Ulf Adamsfdfdd922015-09-01 08:36:29 +000038
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010039 /**
Ulf Adamsd13207c2015-09-04 14:53:43 +000040 * The default runfiles prefix (may be overwritten by the WORKSPACE file).
41 */
42 String getRunfilesPrefix();
43
44 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010045 * Returns a map from rule names to rule class objects.
46 */
47 Map<String, RuleClass> getRuleClassMap();
48
49 /**
dannarkd102a392019-01-09 13:12:01 -080050 * Returns a new Skylark Environment instance for rule creation. Implementations need to be thread
51 * safe. Be sure to close() the mutability before you return the results of said evaluation.
Kristina Chodorow6f153352016-03-21 16:20:06 +000052 *
53 * @param label the location of the rule.
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000054 * @param mutability the Mutability for the current evaluation context
laurentlb6659b4c2019-02-18 07:23:36 -080055 * @param starlarkSemantics the semantics options that modify the interpreter
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000056 * @param eventHandler the EventHandler for warnings, errors, etc.
57 * @param astFileContentHashCode the hash code identifying this environment.
dannarkd102a392019-01-09 13:12:01 -080058 * @param importMap map from import string to Extension
59 * @param repoMapping map of RepositoryNames to be remapped
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000060 * @return an Environment, in which to evaluate load time skylark forms.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010061 */
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000062 Environment createSkylarkRuleClassEnvironment(
Kristina Chodorow6f153352016-03-21 16:20:06 +000063 Label label,
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000064 Mutability mutability,
laurentlb6659b4c2019-02-18 07:23:36 -080065 StarlarkSemantics starlarkSemantics,
Francois-Rene Rideau89312fb2015-09-10 18:53:03 +000066 EventHandler eventHandler,
67 @Nullable String astFileContentHashCode,
dannarkd102a392019-01-09 13:12:01 -080068 @Nullable Map<String, Extension> importMap,
69 ImmutableMap<RepositoryName, RepositoryName> repoMapping);
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010070
71 /**
Dmitry Lomovc15ba2e2015-10-30 15:50:01 +000072 * Returns a map from aspect names to aspect factory objects.
73 */
Luis Fernando Pino Duquee82713d2016-04-26 16:22:38 +000074 Map<String, NativeAspectClass> getNativeAspectClassMap();
Dmitry Lomovc15ba2e2015-10-30 15:50:01 +000075
76 /**
Damien Martin-Guillerez585c87b2016-03-31 08:24:37 +000077 * Returns the default content that should be added at the beginning of the WORKSPACE file.
Lukacs Berkie753ecf2015-06-15 07:12:46 +000078 *
79 * <p>Used to provide external dependencies for built-in rules. Rules defined here can be
80 * overwritten in the WORKSPACE file in the actual workspace.
Kristina Chodorowbc4b4b12015-02-11 15:54:50 +000081 */
Damien Martin-Guillerez585c87b2016-03-31 08:24:37 +000082 String getDefaultWorkspacePrefix();
83
84
85 /**
86 * Returns the default content that should be added at the end of the WORKSPACE file.
87 *
88 * <p>Used to load skylark repository in the bazel_tools repository.
89 */
90 String getDefaultWorkspaceSuffix();
91
Luis Fernando Pino Duque90511e12016-01-28 10:49:58 +000092 /**
93 * Returns the path to the tools repository
94 */
95 String getToolsRepository();
Luis Fernando Pino Duquee82713d2016-04-26 16:22:38 +000096
97 /**
98 * Retrieves an aspect from the aspect factory map using the key provided
99 */
100 NativeAspectClass getNativeAspectClass(String key);
cparsonscaceacd2017-11-04 01:00:59 +0100101
102 /**
103 * Retrieves a {@link Map} from skylark configuration fragment name to configuration fragment
104 * class.
105 */
106 Map<String, Class<?>> getConfigurationFragmentMap();
gregce4aa059a2019-02-26 13:20:47 -0800107
108 /** Returns the policy on checking that third-party rules have licenses. */
109 ThirdPartyLicenseExistencePolicy getThirdPartyLicenseExistencePolicy();
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100110}