blob: 85c3e491759cdbc87c22f81fc6a13b1650ecdab4 [file] [log] [blame]
brandjon60be5312017-10-04 23:06:41 +02001// Copyright 2017 The Bazel Authors. All rights reserved.
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
15package com.google.devtools.build.lib.syntax;
16
17import com.google.auto.value.AutoValue;
laurentlbe5894f02018-10-25 13:02:00 -070018import com.google.common.base.Ascii;
cparsons507b00f2018-09-12 11:59:07 -070019import com.google.common.base.Preconditions;
plf7e41f9b2018-08-03 01:47:22 -070020import com.google.common.collect.ImmutableList;
21import java.util.List;
cparsons507b00f2018-09-12 11:59:07 -070022import java.util.function.Function;
brandjon60be5312017-10-04 23:06:41 +020023
24/**
25 * Options that affect Skylark semantics.
26 *
27 * <p>For descriptions of what these options do, see {@link SkylarkSemanticsOptions}.
28 */
29// TODO(brandjon): User error messages that reference options should maybe be substituted with the
30// option name outside of the core Skylark interpreter?
31// TODO(brandjon): Eventually these should be documented in full here, and SkylarkSemanticsOptions
32// should refer to this class for documentation. But this doesn't play nice with the options
33// parser's annotation mechanism.
34@AutoValue
35public abstract class SkylarkSemantics {
36
cparsons6622e6f2018-10-17 15:00:09 -070037 /**
38 * Enum where each element represents a skylark semantics flag. The name of each value should
39 * be the exact name of the flag transformed to upper case (for error representation).
40 */
cparsons507b00f2018-09-12 11:59:07 -070041 public enum FlagIdentifier {
Googler91eb3d22018-10-18 00:05:29 -070042 EXPERIMENTAL_ENABLE_ANDROID_MIGRATION_APIS(
43 SkylarkSemantics::experimentalEnableAndroidMigrationApis),
juliexxia1f332e02018-10-31 14:20:55 -070044 EXPERIMENTAL_BUILD_SETTING_API(SkylarkSemantics::experimentalBuildSettingApi),
cparsons140c0762018-10-05 14:07:19 -070045 EXPERIMENTAL_PLATFORM_API(SkylarkSemantics::experimentalPlatformsApi),
juliexxiadeb028e2019-01-05 17:19:21 -080046 EXPERIMENTAL_STARLARK_CONFIG_TRANSITION(
47 SkylarkSemantics::experimentalStarlarkConfigTransitions),
cparsons507b00f2018-09-12 11:59:07 -070048 INCOMPATIBLE_DISABLE_OBJC_PROVIDER_RESOURCES(
49 SkylarkSemantics::incompatibleDisableObjcProviderResources),
cparsons1832ed32018-11-13 14:15:32 -080050 INCOMPATIBLE_NO_OUTPUT_ATTR_DEFAULT(SkylarkSemantics::incompatibleNoOutputAttrDefault),
cparsons3cb3a5d2018-10-01 10:36:08 -070051 INCOMPATIBLE_NO_TARGET_OUTPUT_GROUP(
52 SkylarkSemantics::incompatibleNoTargetOutputGroup),
laurentlbd8d37762018-10-26 14:08:33 -070053 INCOMPATIBLE_NO_ATTR_LICENSE(SkylarkSemantics::incompatibleNoAttrLicense),
hlopko70191312018-12-28 07:44:21 -080054 INCOMPATIBLE_REQUIRE_FEATURE_CONFIGURATION_FOR_PIC(
55 SkylarkSemantics::incompatibleRequireFeatureConfigurationForPic),
cparsons507b00f2018-09-12 11:59:07 -070056 NONE(null);
57
58 // Using a Function here makes the enum definitions far cleaner, and, since this is
59 // a private field, and we can ensure no callers treat this field as mutable.
60 @SuppressWarnings("ImmutableEnumChecker")
61 private final Function<SkylarkSemantics, Boolean> semanticsFunction;
62
63 FlagIdentifier(Function<SkylarkSemantics, Boolean> semanticsFunction) {
64 this.semanticsFunction = semanticsFunction;
65 }
cparsons6622e6f2018-10-17 15:00:09 -070066
67 /**
68 * Returns the name of the flag that this identifier controls. For example, EXPERIMENTAL_FOO
69 * would return 'experimental_foo'.
70 */
71 public String getFlagName() {
laurentlbe5894f02018-10-25 13:02:00 -070072 return Ascii.toLowerCase(this.name());
cparsons6622e6f2018-10-17 15:00:09 -070073 }
cparsons507b00f2018-09-12 11:59:07 -070074 }
75
76 /**
77 * Returns true if a feature attached to the given toggling flags should be enabled.
78 *
79 * <ul>
80 * <li>If both parameters are {@code NONE}, this indicates the feature is not
81 * controlled by flags, and should thus be enabled.</li>
82 * <li>If the {@code enablingFlag} parameter is non-{@code NONE}, this returns
83 * true if and only if that flag is true. (This represents a feature that is only on
84 * if a given flag is *on*).</li>
85 * <li>If the {@code disablingFlag} parameter is non-{@code NONE}, this returns
86 * true if and only if that flag is false. (This represents a feature that is only on
87 * if a given flag is *off*).</li>
88 * <li>It is illegal to pass both parameters as non-{@code NONE}.</li>
89 * </ul>
90 */
91 public boolean isFeatureEnabledBasedOnTogglingFlags(
92 FlagIdentifier enablingFlag,
93 FlagIdentifier disablingFlag) {
94 Preconditions.checkArgument(enablingFlag == FlagIdentifier.NONE
95 || disablingFlag == FlagIdentifier.NONE,
96 "at least one of 'enablingFlag' or 'disablingFlag' must be NONE");
97 if (enablingFlag != FlagIdentifier.NONE) {
98 return enablingFlag.semanticsFunction.apply(this);
99 } else {
100 return disablingFlag == FlagIdentifier.NONE || !disablingFlag.semanticsFunction.apply(this);
101 }
102 }
103
cparsons1832ed32018-11-13 14:15:32 -0800104 /** Returns the value of the given flag. */
105 public boolean flagValue(FlagIdentifier flagIdentifier) {
106 return flagIdentifier.semanticsFunction.apply(this);
107 }
108
brandjon617f8ff2017-10-06 06:07:13 +0200109 /**
110 * The AutoValue-generated concrete class implementing this one.
111 *
112 * <p>AutoValue implementation classes are usually package-private. We expose it here for the
113 * benefit of code that relies on reflection.
114 */
115 public static final Class<? extends SkylarkSemantics> IMPL_CLASS =
116 AutoValue_SkylarkSemantics.class;
117
brandjon60be5312017-10-04 23:06:41 +0200118 // <== Add new options here in alphabetic order ==>
juliexxia1f332e02018-10-31 14:20:55 -0700119 public abstract boolean experimentalBuildSettingApi();
120
plf7e41f9b2018-08-03 01:47:22 -0700121 public abstract List<String> experimentalCcSkylarkApiEnabledPackages();
122
Googlerc2cd9572018-10-02 14:38:15 -0700123 public abstract boolean experimentalEnableAndroidMigrationApis();
124
dannarkf2a358e2018-06-05 11:39:18 -0700125 public abstract boolean experimentalEnableRepoMapping();
126
elenairinae679d022019-01-07 07:49:27 -0800127 public abstract ImmutableList<String> experimentalJavaCommonCreateProviderEnabledPackages();
128
dannarked598bc2018-08-07 16:31:52 -0700129 public abstract boolean experimentalRemapMainRepo();
130
cparsons140c0762018-10-05 14:07:19 -0700131 public abstract boolean experimentalPlatformsApi();
132
cparsonse0efc142018-10-17 09:39:10 -0700133 public abstract boolean experimentalStarlarkConfigTransitions();
134
brandjon60be5312017-10-04 23:06:41 +0200135 public abstract boolean incompatibleBzlDisallowLoadAfterStatement();
laurentlb1cbce0f2018-03-27 12:43:22 -0700136
brandjon60be5312017-10-04 23:06:41 +0200137 public abstract boolean incompatibleDepsetIsNotIterable();
laurentlb1cbce0f2018-03-27 12:43:22 -0700138
laurentlb2bbda4a2017-12-07 10:38:46 -0800139 public abstract boolean incompatibleDepsetUnion();
laurentlb1cbce0f2018-03-27 12:43:22 -0700140
cparsonse5068582018-07-16 13:33:33 -0700141 public abstract boolean incompatibleDisableDeprecatedAttrParams();
142
cparsons99be8b42018-03-01 15:16:46 -0800143 public abstract boolean incompatibleDisableObjcProviderResources();
laurentlb1cbce0f2018-03-27 12:43:22 -0700144
cparsons5a6fc8d2018-08-15 14:36:43 -0700145 public abstract boolean incompatibleDisallowConflictingProviders();
146
gregcebceecab2018-06-27 17:44:45 -0700147 public abstract boolean incompatibleDisallowDataTransition();
148
brandjon60be5312017-10-04 23:06:41 +0200149 public abstract boolean incompatibleDisallowDictPlus();
laurentlb1cbce0f2018-03-27 12:43:22 -0700150
laurentlb707acfe2018-04-13 06:09:30 -0700151 public abstract boolean incompatibleDisallowFileType();
152
elenairina2fe38c12019-01-10 00:49:13 -0800153 public abstract boolean incompatibleDisallowLegacyJavaProvider();
154
tomlue3749702018-05-02 09:38:00 -0700155 public abstract boolean incompatibleDisallowLegacyJavaInfo();
156
nharmatad86b5092018-10-16 15:50:21 -0700157 public abstract boolean incompatibleDisallowLoadLabelsToCrossPackageBoundaries();
158
tomlubeafd7e2018-04-05 15:03:19 -0700159 public abstract boolean incompatibleDisallowOldStyleArgsAdd();
160
laurentlbc381cf12018-04-11 04:12:14 -0700161 public abstract boolean incompatibleDisallowSlashOperator();
162
tomlu774bfe02018-08-24 14:15:44 -0700163 public abstract boolean incompatibleExpandDirectories();
164
elenairina1458c612018-06-29 08:10:12 -0700165 public abstract boolean incompatibleGenerateJavaCommonSourceJar();
166
brandjon60be5312017-10-04 23:06:41 +0200167 public abstract boolean incompatibleNewActionsApi();
laurentlb1cbce0f2018-03-27 12:43:22 -0700168
laurentlbd8d37762018-10-26 14:08:33 -0700169 public abstract boolean incompatibleNoAttrLicense();
170
cparsonsfbc828b2018-10-04 14:38:50 -0700171 public abstract boolean incompatibleNoOutputAttrDefault();
172
tomluaaf11e92018-06-02 10:20:16 -0700173 public abstract boolean incompatibleNoSupportToolsInActionInputs();
174
cparsons3cb3a5d2018-10-01 10:36:08 -0700175 public abstract boolean incompatibleNoTargetOutputGroup();
176
laurentlb9d179e12018-09-27 08:15:42 -0700177 public abstract boolean incompatibleNoTransitiveLoads();
178
Danna Kelmer21f4bd32018-11-29 11:04:48 -0800179 public abstract boolean incompatibleRemoveNativeMavenJar();
180
hlopko70191312018-12-28 07:44:21 -0800181 public abstract boolean incompatibleRequireFeatureConfigurationForPic();
182
laurentlb1e5352d2018-11-06 12:25:55 -0800183 public abstract boolean incompatibleStricArgumentOrdering();
184
brandjon60be5312017-10-04 23:06:41 +0200185 public abstract boolean incompatibleStringIsNotIterable();
laurentlb1cbce0f2018-03-27 12:43:22 -0700186
brandjon60be5312017-10-04 23:06:41 +0200187 public abstract boolean internalSkylarkFlagTestCanary();
188
brandjon6ac92f92017-12-06 13:57:15 -0800189 /** Returns a {@link Builder} initialized with the values of this instance. */
190 public abstract Builder toBuilder();
191
brandjon60be5312017-10-04 23:06:41 +0200192 public static Builder builder() {
193 return new AutoValue_SkylarkSemantics.Builder();
194 }
195
brandjon6ac92f92017-12-06 13:57:15 -0800196 /** Returns a {@link Builder} initialized with default values for all options. */
197 public static Builder builderWithDefaults() {
198 return DEFAULT_SEMANTICS.toBuilder();
199 }
200
vladmos1df46352017-11-30 03:02:36 -0800201 public static final SkylarkSemantics DEFAULT_SEMANTICS =
202 builder()
203 // <== Add new options here in alphabetic order ==>
juliexxia1f332e02018-10-31 14:20:55 -0700204 .experimentalBuildSettingApi(false)
plf7e41f9b2018-08-03 01:47:22 -0700205 .experimentalCcSkylarkApiEnabledPackages(ImmutableList.of())
Googlerc2cd9572018-10-02 14:38:15 -0700206 .experimentalEnableAndroidMigrationApis(false)
dannarkf2a358e2018-06-05 11:39:18 -0700207 .experimentalEnableRepoMapping(false)
elenairinae679d022019-01-07 07:49:27 -0800208 .experimentalJavaCommonCreateProviderEnabledPackages(ImmutableList.of())
dannarked598bc2018-08-07 16:31:52 -0700209 .experimentalRemapMainRepo(false)
cparsons140c0762018-10-05 14:07:19 -0700210 .experimentalPlatformsApi(false)
cparsonse0efc142018-10-17 09:39:10 -0700211 .experimentalStarlarkConfigTransitions(false)
vladmos1df46352017-11-30 03:02:36 -0800212 .incompatibleBzlDisallowLoadAfterStatement(false)
vladmos1df46352017-11-30 03:02:36 -0800213 .incompatibleDepsetIsNotIterable(false)
laurentlb2bbda4a2017-12-07 10:38:46 -0800214 .incompatibleDepsetUnion(false)
cparsonse5068582018-07-16 13:33:33 -0700215 .incompatibleDisableDeprecatedAttrParams(false)
cparsons99be8b42018-03-01 15:16:46 -0800216 .incompatibleDisableObjcProviderResources(false)
laurentlb8ef1e6b2018-10-29 09:49:37 -0700217 .incompatibleDisallowConflictingProviders(true)
gregcebceecab2018-06-27 17:44:45 -0700218 .incompatibleDisallowDataTransition(false)
vladmos1df46352017-11-30 03:02:36 -0800219 .incompatibleDisallowDictPlus(false)
laurentlb707acfe2018-04-13 06:09:30 -0700220 .incompatibleDisallowFileType(false)
elenairina2fe38c12019-01-10 00:49:13 -0800221 .incompatibleDisallowLegacyJavaProvider(false)
tomlue3749702018-05-02 09:38:00 -0700222 .incompatibleDisallowLegacyJavaInfo(false)
nharmatad86b5092018-10-16 15:50:21 -0700223 .incompatibleDisallowLoadLabelsToCrossPackageBoundaries(false)
tomlubeafd7e2018-04-05 15:03:19 -0700224 .incompatibleDisallowOldStyleArgsAdd(false)
laurentlb58dab6c2018-11-12 11:34:30 -0800225 .incompatibleDisallowSlashOperator(true)
tomlu774bfe02018-08-24 14:15:44 -0700226 .incompatibleExpandDirectories(false)
elenairina1458c612018-06-29 08:10:12 -0700227 .incompatibleGenerateJavaCommonSourceJar(false)
vladmos1df46352017-11-30 03:02:36 -0800228 .incompatibleNewActionsApi(false)
laurentlbd8d37762018-10-26 14:08:33 -0700229 .incompatibleNoAttrLicense(false)
cparsonsfbc828b2018-10-04 14:38:50 -0700230 .incompatibleNoOutputAttrDefault(false)
tomluaaf11e92018-06-02 10:20:16 -0700231 .incompatibleNoSupportToolsInActionInputs(false)
cparsons3cb3a5d2018-10-01 10:36:08 -0700232 .incompatibleNoTargetOutputGroup(false)
laurentlb9d179e12018-09-27 08:15:42 -0700233 .incompatibleNoTransitiveLoads(false)
Danna Kelmer21f4bd32018-11-29 11:04:48 -0800234 .incompatibleRemoveNativeMavenJar(false)
hlopko70191312018-12-28 07:44:21 -0800235 .incompatibleRequireFeatureConfigurationForPic(false)
laurentlb1e5352d2018-11-06 12:25:55 -0800236 .incompatibleStricArgumentOrdering(false)
laurentlb0d5d3a52018-12-18 05:26:35 -0800237 .incompatibleStringIsNotIterable(true)
Klaus Aehliga7b34a12018-02-20 09:31:37 -0800238 .internalSkylarkFlagTestCanary(false)
239 .build();
brandjon60be5312017-10-04 23:06:41 +0200240
241 /** Builder for {@link SkylarkSemantics}. All fields are mandatory. */
242 @AutoValue.Builder
243 public abstract static class Builder {
244
245 // <== Add new options here in alphabetic order ==>
juliexxia1f332e02018-10-31 14:20:55 -0700246 public abstract Builder experimentalBuildSettingApi(boolean value);
247
plf7e41f9b2018-08-03 01:47:22 -0700248 public abstract Builder experimentalCcSkylarkApiEnabledPackages(List<String> value);
249
Googlerc2cd9572018-10-02 14:38:15 -0700250 public abstract Builder experimentalEnableAndroidMigrationApis(boolean value);
251
dannarkf2a358e2018-06-05 11:39:18 -0700252 public abstract Builder experimentalEnableRepoMapping(boolean value);
253
dannarked598bc2018-08-07 16:31:52 -0700254 public abstract Builder experimentalRemapMainRepo(boolean value);
255
elenairinae679d022019-01-07 07:49:27 -0800256 public abstract Builder experimentalJavaCommonCreateProviderEnabledPackages(List<String> value);
257
cparsons140c0762018-10-05 14:07:19 -0700258 public abstract Builder experimentalPlatformsApi(boolean value);
259
cparsonse0efc142018-10-17 09:39:10 -0700260 public abstract Builder experimentalStarlarkConfigTransitions(boolean value);
261
brandjon60be5312017-10-04 23:06:41 +0200262 public abstract Builder incompatibleBzlDisallowLoadAfterStatement(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700263
brandjon60be5312017-10-04 23:06:41 +0200264 public abstract Builder incompatibleDepsetIsNotIterable(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700265
laurentlb2bbda4a2017-12-07 10:38:46 -0800266 public abstract Builder incompatibleDepsetUnion(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700267
cparsonse5068582018-07-16 13:33:33 -0700268 public abstract Builder incompatibleDisableDeprecatedAttrParams(boolean value);
269
hlopko70191312018-12-28 07:44:21 -0800270 public abstract Builder incompatibleRequireFeatureConfigurationForPic(boolean value);
271
cparsons99be8b42018-03-01 15:16:46 -0800272 public abstract Builder incompatibleDisableObjcProviderResources(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700273
cparsons5a6fc8d2018-08-15 14:36:43 -0700274 public abstract Builder incompatibleDisallowConflictingProviders(boolean value);
275
gregcebceecab2018-06-27 17:44:45 -0700276 public abstract Builder incompatibleDisallowDataTransition(boolean value);
277
brandjon60be5312017-10-04 23:06:41 +0200278 public abstract Builder incompatibleDisallowDictPlus(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700279
laurentlb707acfe2018-04-13 06:09:30 -0700280 public abstract Builder incompatibleDisallowFileType(boolean value);
281
elenairina2fe38c12019-01-10 00:49:13 -0800282 public abstract Builder incompatibleDisallowLegacyJavaProvider(boolean value);
283
tomlue3749702018-05-02 09:38:00 -0700284 public abstract Builder incompatibleDisallowLegacyJavaInfo(boolean value);
285
nharmatad86b5092018-10-16 15:50:21 -0700286 public abstract Builder incompatibleDisallowLoadLabelsToCrossPackageBoundaries(boolean value);
287
tomlubeafd7e2018-04-05 15:03:19 -0700288 public abstract Builder incompatibleDisallowOldStyleArgsAdd(boolean value);
289
laurentlbc381cf12018-04-11 04:12:14 -0700290 public abstract Builder incompatibleDisallowSlashOperator(boolean value);
291
tomlu774bfe02018-08-24 14:15:44 -0700292 public abstract Builder incompatibleExpandDirectories(boolean value);
293
elenairina1458c612018-06-29 08:10:12 -0700294 public abstract Builder incompatibleGenerateJavaCommonSourceJar(boolean value);
295
brandjon60be5312017-10-04 23:06:41 +0200296 public abstract Builder incompatibleNewActionsApi(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700297
laurentlbd8d37762018-10-26 14:08:33 -0700298 public abstract Builder incompatibleNoAttrLicense(boolean value);
299
cparsonsfbc828b2018-10-04 14:38:50 -0700300 public abstract Builder incompatibleNoOutputAttrDefault(boolean value);
301
tomluaaf11e92018-06-02 10:20:16 -0700302 public abstract Builder incompatibleNoSupportToolsInActionInputs(boolean value);
303
cparsons3cb3a5d2018-10-01 10:36:08 -0700304 public abstract Builder incompatibleNoTargetOutputGroup(boolean value);
305
laurentlb9d179e12018-09-27 08:15:42 -0700306 public abstract Builder incompatibleNoTransitiveLoads(boolean value);
307
Danna Kelmer21f4bd32018-11-29 11:04:48 -0800308 public abstract Builder incompatibleRemoveNativeMavenJar(boolean value);
309
laurentlb1e5352d2018-11-06 12:25:55 -0800310 public abstract Builder incompatibleStricArgumentOrdering(boolean value);
311
brandjon60be5312017-10-04 23:06:41 +0200312 public abstract Builder incompatibleStringIsNotIterable(boolean value);
laurentlb1cbce0f2018-03-27 12:43:22 -0700313
brandjon60be5312017-10-04 23:06:41 +0200314 public abstract Builder internalSkylarkFlagTestCanary(boolean value);
315
brandjon60be5312017-10-04 23:06:41 +0200316 public abstract SkylarkSemantics build();
317 }
318}