blob: c816cd6e34b209b2441a21a290b46956c5fa5a7d [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;
18
19/**
20 * Options that affect Skylark semantics.
21 *
22 * <p>For descriptions of what these options do, see {@link SkylarkSemanticsOptions}.
23 */
24// TODO(brandjon): User error messages that reference options should maybe be substituted with the
25// option name outside of the core Skylark interpreter?
26// TODO(brandjon): Eventually these should be documented in full here, and SkylarkSemanticsOptions
27// should refer to this class for documentation. But this doesn't play nice with the options
28// parser's annotation mechanism.
29@AutoValue
30public abstract class SkylarkSemantics {
31
brandjon617f8ff2017-10-06 06:07:13 +020032 /**
33 * The AutoValue-generated concrete class implementing this one.
34 *
35 * <p>AutoValue implementation classes are usually package-private. We expose it here for the
36 * benefit of code that relies on reflection.
37 */
38 public static final Class<? extends SkylarkSemantics> IMPL_CLASS =
39 AutoValue_SkylarkSemantics.class;
40
brandjon60be5312017-10-04 23:06:41 +020041 // <== Add new options here in alphabetic order ==>
42 public abstract boolean incompatibleBzlDisallowLoadAfterStatement();
43 public abstract boolean incompatibleCheckedArithmetic();
44 public abstract boolean incompatibleComprehensionVariablesDoNotLeak();
45 public abstract boolean incompatibleDepsetIsNotIterable();
laurentlb2bbda4a2017-12-07 10:38:46 -080046
47 public abstract boolean incompatibleDepsetUnion();
48
brandjon60be5312017-10-04 23:06:41 +020049 public abstract boolean incompatibleDictLiteralHasNoDuplicates();
laurentlbd7f87aa2017-12-12 07:55:15 -080050
51 public abstract boolean incompatibleDisableGlobTracking();
52
brandjon60be5312017-10-04 23:06:41 +020053 public abstract boolean incompatibleDisallowDictPlus();
54 public abstract boolean incompatibleDisallowKeywordOnlyArgs();
brandjon60be5312017-10-04 23:06:41 +020055 public abstract boolean incompatibleDisallowToplevelIfStatement();
vladmos9bb93ee2017-11-21 04:40:08 -080056 public abstract boolean incompatibleDisallowUncalledSetConstructor();
brandjon60be5312017-10-04 23:06:41 +020057 public abstract boolean incompatibleLoadArgumentIsLabel();
58 public abstract boolean incompatibleNewActionsApi();
vladmos1df46352017-11-30 03:02:36 -080059 public abstract boolean incompatibleShowAllPrintMessages();
brandjon60be5312017-10-04 23:06:41 +020060 public abstract boolean incompatibleStringIsNotIterable();
brandjon60be5312017-10-04 23:06:41 +020061 public abstract boolean internalSkylarkFlagTestCanary();
62
brandjon6ac92f92017-12-06 13:57:15 -080063 /** Returns a {@link Builder} initialized with the values of this instance. */
64 public abstract Builder toBuilder();
65
brandjon60be5312017-10-04 23:06:41 +020066 public static Builder builder() {
67 return new AutoValue_SkylarkSemantics.Builder();
68 }
69
brandjon6ac92f92017-12-06 13:57:15 -080070 /** Returns a {@link Builder} initialized with default values for all options. */
71 public static Builder builderWithDefaults() {
72 return DEFAULT_SEMANTICS.toBuilder();
73 }
74
vladmos1df46352017-11-30 03:02:36 -080075 public static final SkylarkSemantics DEFAULT_SEMANTICS =
76 builder()
77 // <== Add new options here in alphabetic order ==>
78 .incompatibleBzlDisallowLoadAfterStatement(false)
79 .incompatibleCheckedArithmetic(true)
80 .incompatibleComprehensionVariablesDoNotLeak(true)
81 .incompatibleDepsetIsNotIterable(false)
laurentlb2bbda4a2017-12-07 10:38:46 -080082 .incompatibleDepsetUnion(false)
vladmos1df46352017-11-30 03:02:36 -080083 .incompatibleDictLiteralHasNoDuplicates(true)
laurentlbd7f87aa2017-12-12 07:55:15 -080084 .incompatibleDisableGlobTracking(false)
vladmos1df46352017-11-30 03:02:36 -080085 .incompatibleDisallowDictPlus(false)
86 .incompatibleDisallowKeywordOnlyArgs(true)
87 .incompatibleDisallowToplevelIfStatement(true)
vladmos31320242017-12-06 06:02:01 -080088 .incompatibleDisallowUncalledSetConstructor(true)
laurentlb7cf1c692017-12-04 05:44:54 -080089 .incompatibleLoadArgumentIsLabel(true)
vladmos1df46352017-11-30 03:02:36 -080090 .incompatibleNewActionsApi(false)
91 .incompatibleShowAllPrintMessages(true)
brandjon85e8d512017-12-21 16:57:31 -080092 .incompatibleStringIsNotIterable(false)
93 .internalSkylarkFlagTestCanary(false)
94 .build();
brandjon60be5312017-10-04 23:06:41 +020095
96 /** Builder for {@link SkylarkSemantics}. All fields are mandatory. */
97 @AutoValue.Builder
98 public abstract static class Builder {
99
100 // <== Add new options here in alphabetic order ==>
101 public abstract Builder incompatibleBzlDisallowLoadAfterStatement(boolean value);
102 public abstract Builder incompatibleCheckedArithmetic(boolean value);
103 public abstract Builder incompatibleComprehensionVariablesDoNotLeak(boolean value);
104 public abstract Builder incompatibleDepsetIsNotIterable(boolean value);
laurentlb2bbda4a2017-12-07 10:38:46 -0800105
106 public abstract Builder incompatibleDepsetUnion(boolean value);
107
brandjon60be5312017-10-04 23:06:41 +0200108 public abstract Builder incompatibleDictLiteralHasNoDuplicates(boolean value);
laurentlbd7f87aa2017-12-12 07:55:15 -0800109
110 public abstract Builder incompatibleDisableGlobTracking(boolean value);
111
brandjon60be5312017-10-04 23:06:41 +0200112 public abstract Builder incompatibleDisallowDictPlus(boolean value);
113 public abstract Builder incompatibleDisallowKeywordOnlyArgs(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200114 public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value);
vladmos9bb93ee2017-11-21 04:40:08 -0800115 public abstract Builder incompatibleDisallowUncalledSetConstructor(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200116 public abstract Builder incompatibleLoadArgumentIsLabel(boolean value);
117 public abstract Builder incompatibleNewActionsApi(boolean value);
vladmos1df46352017-11-30 03:02:36 -0800118 public abstract Builder incompatibleShowAllPrintMessages(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200119 public abstract Builder incompatibleStringIsNotIterable(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200120 public abstract Builder internalSkylarkFlagTestCanary(boolean value);
121
122 public abstract SkylarkSemantics build();
123 }
124}