Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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 | |
| 15 | package com.google.devtools.build.lib.packages; |
| 16 | |
dannark | d102a39 | 2019-01-09 13:12:01 -0800 | [diff] [blame] | 17 | import com.google.common.collect.ImmutableMap; |
John Field | a97e17f | 2015-11-13 02:19:52 +0000 | [diff] [blame] | 18 | import com.google.devtools.build.lib.cmdline.Label; |
dannark | d102a39 | 2019-01-09 13:12:01 -0800 | [diff] [blame] | 19 | import com.google.devtools.build.lib.cmdline.RepositoryName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 20 | import com.google.devtools.build.lib.events.EventHandler; |
gregce | 4aa059a | 2019-02-26 13:20:47 -0800 | [diff] [blame] | 21 | import com.google.devtools.build.lib.packages.RuleClass.Builder.ThirdPartyLicenseExistencePolicy; |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 22 | import com.google.devtools.build.lib.syntax.Environment; |
| 23 | import com.google.devtools.build.lib.syntax.Environment.Extension; |
| 24 | import com.google.devtools.build.lib.syntax.Mutability; |
laurentlb | 6659b4c | 2019-02-18 07:23:36 -0800 | [diff] [blame] | 25 | import com.google.devtools.build.lib.syntax.StarlarkSemantics; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 26 | import java.util.Map; |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 27 | import javax.annotation.Nullable; |
| 28 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | /** |
| 30 | * The collection of the supported build rules. Provides an Environment for Skylark rule creation. |
| 31 | */ |
| 32 | public interface RuleClassProvider { |
Ulf Adams | fdfdd92 | 2015-09-01 08:36:29 +0000 | [diff] [blame] | 33 | |
| 34 | /** |
John Field | a97e17f | 2015-11-13 02:19:52 +0000 | [diff] [blame] | 35 | * Label referencing the prelude file. |
Ulf Adams | fdfdd92 | 2015-09-01 08:36:29 +0000 | [diff] [blame] | 36 | */ |
John Field | a97e17f | 2015-11-13 02:19:52 +0000 | [diff] [blame] | 37 | Label getPreludeLabel(); |
Ulf Adams | fdfdd92 | 2015-09-01 08:36:29 +0000 | [diff] [blame] | 38 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 39 | /** |
Ulf Adams | d13207c | 2015-09-04 14:53:43 +0000 | [diff] [blame] | 40 | * The default runfiles prefix (may be overwritten by the WORKSPACE file). |
| 41 | */ |
| 42 | String getRunfilesPrefix(); |
| 43 | |
| 44 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | * Returns a map from rule names to rule class objects. |
| 46 | */ |
| 47 | Map<String, RuleClass> getRuleClassMap(); |
| 48 | |
| 49 | /** |
dannark | d102a39 | 2019-01-09 13:12:01 -0800 | [diff] [blame] | 50 | * 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 Chodorow | 6f15335 | 2016-03-21 16:20:06 +0000 | [diff] [blame] | 52 | * |
| 53 | * @param label the location of the rule. |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 54 | * @param mutability the Mutability for the current evaluation context |
laurentlb | 6659b4c | 2019-02-18 07:23:36 -0800 | [diff] [blame] | 55 | * @param starlarkSemantics the semantics options that modify the interpreter |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 56 | * @param eventHandler the EventHandler for warnings, errors, etc. |
| 57 | * @param astFileContentHashCode the hash code identifying this environment. |
dannark | d102a39 | 2019-01-09 13:12:01 -0800 | [diff] [blame] | 58 | * @param importMap map from import string to Extension |
| 59 | * @param repoMapping map of RepositoryNames to be remapped |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 60 | * @return an Environment, in which to evaluate load time skylark forms. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 61 | */ |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 62 | Environment createSkylarkRuleClassEnvironment( |
Kristina Chodorow | 6f15335 | 2016-03-21 16:20:06 +0000 | [diff] [blame] | 63 | Label label, |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 64 | Mutability mutability, |
laurentlb | 6659b4c | 2019-02-18 07:23:36 -0800 | [diff] [blame] | 65 | StarlarkSemantics starlarkSemantics, |
Francois-Rene Rideau | 89312fb | 2015-09-10 18:53:03 +0000 | [diff] [blame] | 66 | EventHandler eventHandler, |
| 67 | @Nullable String astFileContentHashCode, |
dannark | d102a39 | 2019-01-09 13:12:01 -0800 | [diff] [blame] | 68 | @Nullable Map<String, Extension> importMap, |
| 69 | ImmutableMap<RepositoryName, RepositoryName> repoMapping); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 70 | |
| 71 | /** |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 72 | * Returns a map from aspect names to aspect factory objects. |
| 73 | */ |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 74 | Map<String, NativeAspectClass> getNativeAspectClassMap(); |
Dmitry Lomov | c15ba2e | 2015-10-30 15:50:01 +0000 | [diff] [blame] | 75 | |
| 76 | /** |
Damien Martin-Guillerez | 585c87b | 2016-03-31 08:24:37 +0000 | [diff] [blame] | 77 | * Returns the default content that should be added at the beginning of the WORKSPACE file. |
Lukacs Berki | e753ecf | 2015-06-15 07:12:46 +0000 | [diff] [blame] | 78 | * |
| 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 Chodorow | bc4b4b1 | 2015-02-11 15:54:50 +0000 | [diff] [blame] | 81 | */ |
Damien Martin-Guillerez | 585c87b | 2016-03-31 08:24:37 +0000 | [diff] [blame] | 82 | 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 Duque | 90511e1 | 2016-01-28 10:49:58 +0000 | [diff] [blame] | 92 | /** |
| 93 | * Returns the path to the tools repository |
| 94 | */ |
| 95 | String getToolsRepository(); |
Luis Fernando Pino Duque | e82713d | 2016-04-26 16:22:38 +0000 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Retrieves an aspect from the aspect factory map using the key provided |
| 99 | */ |
| 100 | NativeAspectClass getNativeAspectClass(String key); |
cparsons | caceacd | 2017-11-04 01:00:59 +0100 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Retrieves a {@link Map} from skylark configuration fragment name to configuration fragment |
| 104 | * class. |
| 105 | */ |
| 106 | Map<String, Class<?>> getConfigurationFragmentMap(); |
gregce | 4aa059a | 2019-02-26 13:20:47 -0800 | [diff] [blame] | 107 | |
| 108 | /** Returns the policy on checking that third-party rules have licenses. */ |
| 109 | ThirdPartyLicenseExistencePolicy getThirdPartyLicenseExistencePolicy(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 110 | } |