blob: c0ebebe9745c28497df0040bea3b80916250d9b2 [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();
50 public abstract boolean incompatibleDisallowDictPlus();
51 public abstract boolean incompatibleDisallowKeywordOnlyArgs();
brandjon60be5312017-10-04 23:06:41 +020052 public abstract boolean incompatibleDisallowToplevelIfStatement();
vladmos9bb93ee2017-11-21 04:40:08 -080053 public abstract boolean incompatibleDisallowUncalledSetConstructor();
brandjon60be5312017-10-04 23:06:41 +020054 public abstract boolean incompatibleLoadArgumentIsLabel();
55 public abstract boolean incompatibleNewActionsApi();
vladmos1df46352017-11-30 03:02:36 -080056 public abstract boolean incompatibleShowAllPrintMessages();
brandjon60be5312017-10-04 23:06:41 +020057 public abstract boolean incompatibleStringIsNotIterable();
58 public abstract boolean internalDoNotExportBuiltins();
59 public abstract boolean internalSkylarkFlagTestCanary();
60
brandjon6ac92f92017-12-06 13:57:15 -080061 /** Returns a {@link Builder} initialized with the values of this instance. */
62 public abstract Builder toBuilder();
63
brandjon60be5312017-10-04 23:06:41 +020064 public static Builder builder() {
65 return new AutoValue_SkylarkSemantics.Builder();
66 }
67
brandjon6ac92f92017-12-06 13:57:15 -080068 /** Returns a {@link Builder} initialized with default values for all options. */
69 public static Builder builderWithDefaults() {
70 return DEFAULT_SEMANTICS.toBuilder();
71 }
72
vladmos1df46352017-11-30 03:02:36 -080073 public static final SkylarkSemantics DEFAULT_SEMANTICS =
74 builder()
75 // <== Add new options here in alphabetic order ==>
76 .incompatibleBzlDisallowLoadAfterStatement(false)
77 .incompatibleCheckedArithmetic(true)
78 .incompatibleComprehensionVariablesDoNotLeak(true)
79 .incompatibleDepsetIsNotIterable(false)
laurentlb2bbda4a2017-12-07 10:38:46 -080080 .incompatibleDepsetUnion(false)
vladmos1df46352017-11-30 03:02:36 -080081 .incompatibleDictLiteralHasNoDuplicates(true)
82 .incompatibleDisallowDictPlus(false)
83 .incompatibleDisallowKeywordOnlyArgs(true)
84 .incompatibleDisallowToplevelIfStatement(true)
vladmos31320242017-12-06 06:02:01 -080085 .incompatibleDisallowUncalledSetConstructor(true)
laurentlb7cf1c692017-12-04 05:44:54 -080086 .incompatibleLoadArgumentIsLabel(true)
vladmos1df46352017-11-30 03:02:36 -080087 .incompatibleNewActionsApi(false)
88 .incompatibleShowAllPrintMessages(true)
89 .incompatibleStringIsNotIterable(false)
90 .internalDoNotExportBuiltins(false)
91 .internalSkylarkFlagTestCanary(false)
92 .build();
brandjon60be5312017-10-04 23:06:41 +020093
94 /** Builder for {@link SkylarkSemantics}. All fields are mandatory. */
95 @AutoValue.Builder
96 public abstract static class Builder {
97
98 // <== Add new options here in alphabetic order ==>
99 public abstract Builder incompatibleBzlDisallowLoadAfterStatement(boolean value);
100 public abstract Builder incompatibleCheckedArithmetic(boolean value);
101 public abstract Builder incompatibleComprehensionVariablesDoNotLeak(boolean value);
102 public abstract Builder incompatibleDepsetIsNotIterable(boolean value);
laurentlb2bbda4a2017-12-07 10:38:46 -0800103
104 public abstract Builder incompatibleDepsetUnion(boolean value);
105
brandjon60be5312017-10-04 23:06:41 +0200106 public abstract Builder incompatibleDictLiteralHasNoDuplicates(boolean value);
107 public abstract Builder incompatibleDisallowDictPlus(boolean value);
108 public abstract Builder incompatibleDisallowKeywordOnlyArgs(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200109 public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value);
vladmos9bb93ee2017-11-21 04:40:08 -0800110 public abstract Builder incompatibleDisallowUncalledSetConstructor(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200111 public abstract Builder incompatibleLoadArgumentIsLabel(boolean value);
112 public abstract Builder incompatibleNewActionsApi(boolean value);
vladmos1df46352017-11-30 03:02:36 -0800113 public abstract Builder incompatibleShowAllPrintMessages(boolean value);
brandjon60be5312017-10-04 23:06:41 +0200114 public abstract Builder incompatibleStringIsNotIterable(boolean value);
115 public abstract Builder internalDoNotExportBuiltins(boolean value);
116 public abstract Builder internalSkylarkFlagTestCanary(boolean value);
117
118 public abstract SkylarkSemantics build();
119 }
120}