| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 1 | // Copyright 2021 Google LLC | 
|  | 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 mk2rbc | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "fmt" | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 19 | "strings" | 
|  | 20 | ) | 
|  | 21 |  | 
|  | 22 | type variable interface { | 
|  | 23 | name() string | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 24 | emitGet(gctx *generationContext) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 25 | emitSet(gctx *generationContext, asgn *assignmentNode) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 26 | valueType() starlarkType | 
| Sasha Smundak | 9d011ab | 2021-07-09 16:00:57 -0700 | [diff] [blame] | 27 | setValueType(t starlarkType) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 28 | defaultValueString() string | 
|  | 29 | isPreset() bool | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | type baseVariable struct { | 
|  | 33 | nam    string | 
|  | 34 | typ    starlarkType | 
|  | 35 | preset bool // true if it has been initialized at startup | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | func (v baseVariable) name() string { | 
|  | 39 | return v.nam | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | func (v baseVariable) valueType() starlarkType { | 
|  | 43 | return v.typ | 
|  | 44 | } | 
|  | 45 |  | 
| Sasha Smundak | 9d011ab | 2021-07-09 16:00:57 -0700 | [diff] [blame] | 46 | func (v *baseVariable) setValueType(t starlarkType) { | 
|  | 47 | v.typ = t | 
|  | 48 | } | 
|  | 49 |  | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 50 | func (v baseVariable) isPreset() bool { | 
|  | 51 | return v.preset | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | var defaultValuesByType = map[starlarkType]string{ | 
|  | 55 | starlarkTypeUnknown: `""`, | 
|  | 56 | starlarkTypeList:    "[]", | 
|  | 57 | starlarkTypeString:  `""`, | 
|  | 58 | starlarkTypeInt:     "0", | 
|  | 59 | starlarkTypeBool:    "False", | 
|  | 60 | starlarkTypeVoid:    "None", | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | func (v baseVariable) defaultValueString() string { | 
|  | 64 | if v, ok := defaultValuesByType[v.valueType()]; ok { | 
|  | 65 | return v | 
|  | 66 | } | 
|  | 67 | panic(fmt.Errorf("%s has unknown type %q", v.name(), v.valueType())) | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | type productConfigVariable struct { | 
|  | 71 | baseVariable | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | func (pcv productConfigVariable) emitSet(gctx *generationContext, asgn *assignmentNode) { | 
|  | 75 | emitAssignment := func() { | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 76 | gctx.writef("cfg[%q] = ", pcv.nam) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 77 | asgn.value.emitListVarCopy(gctx) | 
|  | 78 | } | 
|  | 79 | emitAppend := func() { | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 80 | gctx.writef("cfg[%q] += ", pcv.nam) | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 81 | value := asgn.value | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 82 | if pcv.valueType() == starlarkTypeString { | 
|  | 83 | gctx.writef(`" " + `) | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 84 | value = &toStringExpr{expr: value} | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 85 | } | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 86 | value.emit(gctx) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 87 | } | 
| Cole Faust | 816e080 | 2022-03-04 12:04:31 -0800 | [diff] [blame] | 88 | emitSetDefault := func() { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 89 | if pcv.typ == starlarkTypeList { | 
|  | 90 | gctx.writef("%s(handle, %q)", cfnSetListDefault, pcv.name()) | 
|  | 91 | } else { | 
|  | 92 | gctx.writef("cfg.setdefault(%q, %s)", pcv.name(), pcv.defaultValueString()) | 
|  | 93 | } | 
|  | 94 | gctx.newLine() | 
| Cole Faust | 816e080 | 2022-03-04 12:04:31 -0800 | [diff] [blame] | 95 | } | 
|  | 96 |  | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 97 | // If we are not sure variable has been assigned before, emit setdefault | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 98 | needsSetDefault := !gctx.hasBeenAssigned(&pcv) && !pcv.isPreset() && asgn.isSelfReferential() | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 99 |  | 
| Cole Faust | 816e080 | 2022-03-04 12:04:31 -0800 | [diff] [blame] | 100 | switch asgn.flavor { | 
|  | 101 | case asgnSet: | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 102 | if needsSetDefault { | 
| Cole Faust | 816e080 | 2022-03-04 12:04:31 -0800 | [diff] [blame] | 103 | emitSetDefault() | 
|  | 104 | } | 
|  | 105 | emitAssignment() | 
|  | 106 | case asgnAppend: | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 107 | if needsSetDefault { | 
|  | 108 | emitSetDefault() | 
|  | 109 | } | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 110 | emitAppend() | 
|  | 111 | case asgnMaybeSet: | 
| Cole Faust | 8e15f69 | 2023-10-09 12:26:21 -0700 | [diff] [blame] | 112 | // In mk2rbc.go we never emit a maybeSet assignment for product config variables, because | 
|  | 113 | // they are set to empty strings before running product config. | 
|  | 114 | panic("Should never get here") | 
|  | 115 | default: | 
|  | 116 | panic("Unknown assignment flavor") | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 117 | } | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | gctx.setHasBeenAssigned(&pcv) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 122 | func (pcv productConfigVariable) emitGet(gctx *generationContext) { | 
|  | 123 | if gctx.hasBeenAssigned(&pcv) || pcv.isPreset() { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 124 | gctx.writef("cfg[%q]", pcv.nam) | 
|  | 125 | } else { | 
|  | 126 | gctx.writef("cfg.get(%q, %s)", pcv.nam, pcv.defaultValueString()) | 
|  | 127 | } | 
|  | 128 | } | 
|  | 129 |  | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 130 | type otherGlobalVariable struct { | 
|  | 131 | baseVariable | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | func (scv otherGlobalVariable) emitSet(gctx *generationContext, asgn *assignmentNode) { | 
|  | 135 | emitAssignment := func() { | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 136 | gctx.writef("g[%q] = ", scv.nam) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 137 | asgn.value.emitListVarCopy(gctx) | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | emitAppend := func() { | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 141 | gctx.writef("g[%q] += ", scv.nam) | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 142 | value := asgn.value | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 143 | if scv.valueType() == starlarkTypeString { | 
|  | 144 | gctx.writef(`" " + `) | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 145 | value = &toStringExpr{expr: value} | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 146 | } | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 147 | value.emit(gctx) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 150 | // If we are not sure variable has been assigned before, emit setdefault | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 151 | needsSetDefault := !gctx.hasBeenAssigned(&scv) && !scv.isPreset() && asgn.isSelfReferential() | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 152 |  | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 153 | switch asgn.flavor { | 
|  | 154 | case asgnSet: | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 155 | if needsSetDefault { | 
|  | 156 | gctx.writef("g.setdefault(%q, %s)", scv.name(), scv.defaultValueString()) | 
|  | 157 | gctx.newLine() | 
|  | 158 | } | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 159 | emitAssignment() | 
|  | 160 | case asgnAppend: | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 161 | if needsSetDefault { | 
|  | 162 | gctx.writef("g.setdefault(%q, %s)", scv.name(), scv.defaultValueString()) | 
|  | 163 | gctx.newLine() | 
|  | 164 | } | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 165 | emitAppend() | 
|  | 166 | case asgnMaybeSet: | 
|  | 167 | gctx.writef("if g.get(%q) == None:", scv.nam) | 
|  | 168 | gctx.indentLevel++ | 
|  | 169 | gctx.newLine() | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 170 | if needsSetDefault { | 
|  | 171 | gctx.writef("g.setdefault(%q, %s)", scv.name(), scv.defaultValueString()) | 
|  | 172 | gctx.newLine() | 
|  | 173 | } | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 174 | emitAssignment() | 
|  | 175 | gctx.indentLevel-- | 
|  | 176 | } | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 177 |  | 
|  | 178 | gctx.setHasBeenAssigned(&scv) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 179 | } | 
|  | 180 |  | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 181 | func (scv otherGlobalVariable) emitGet(gctx *generationContext) { | 
|  | 182 | if gctx.hasBeenAssigned(&scv) || scv.isPreset() { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 183 | gctx.writef("g[%q]", scv.nam) | 
|  | 184 | } else { | 
|  | 185 | gctx.writef("g.get(%q, %s)", scv.nam, scv.defaultValueString()) | 
|  | 186 | } | 
|  | 187 | } | 
|  | 188 |  | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 189 | type localVariable struct { | 
|  | 190 | baseVariable | 
|  | 191 | } | 
|  | 192 |  | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 193 | func (lv localVariable) String() string { | 
|  | 194 | return "_" + lv.nam | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | func (lv localVariable) emitSet(gctx *generationContext, asgn *assignmentNode) { | 
|  | 198 | switch asgn.flavor { | 
| Cole Faust | e2a3798 | 2022-03-09 16:00:17 -0800 | [diff] [blame] | 199 | case asgnSet, asgnMaybeSet: | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 200 | gctx.writef("%s = ", lv) | 
|  | 201 | asgn.value.emitListVarCopy(gctx) | 
|  | 202 | case asgnAppend: | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 203 | gctx.writef("%s += ", lv) | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 204 | value := asgn.value | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 205 | if lv.valueType() == starlarkTypeString { | 
|  | 206 | gctx.writef(`" " + `) | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 207 | value = &toStringExpr{expr: value} | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 208 | } | 
| Cole Faust | 0484c23 | 2021-12-22 14:08:08 -0800 | [diff] [blame] | 209 | value.emit(gctx) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 210 | } | 
|  | 211 | } | 
|  | 212 |  | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 213 | func (lv localVariable) emitGet(gctx *generationContext) { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 214 | gctx.writef("%s", lv) | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | type predefinedVariable struct { | 
|  | 218 | baseVariable | 
|  | 219 | value starlarkExpr | 
|  | 220 | } | 
|  | 221 |  | 
| Cole Faust | f063266 | 2022-04-07 13:59:24 -0700 | [diff] [blame] | 222 | func (pv predefinedVariable) emitGet(gctx *generationContext) { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 223 | pv.value.emit(gctx) | 
|  | 224 | } | 
|  | 225 |  | 
| Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 226 | func (pv predefinedVariable) emitSet(gctx *generationContext, asgn *assignmentNode) { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 227 | if expectedValue, ok1 := maybeString(pv.value); ok1 { | 
|  | 228 | actualValue, ok2 := maybeString(asgn.value) | 
|  | 229 | if ok2 { | 
|  | 230 | if actualValue == expectedValue { | 
|  | 231 | return | 
|  | 232 | } | 
| Sasha Smundak | 422b614 | 2021-11-11 18:31:59 -0800 | [diff] [blame] | 233 | gctx.emitConversionError(asgn.location, | 
|  | 234 | fmt.Sprintf("cannot set predefined variable %s to %q, its value should be %q", | 
|  | 235 | pv.name(), actualValue, expectedValue)) | 
| Sasha Smundak | 6609ba7 | 2021-07-22 18:32:56 -0700 | [diff] [blame] | 236 | gctx.starScript.hasErrors = true | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 237 | return | 
|  | 238 | } | 
|  | 239 | } | 
|  | 240 | panic(fmt.Errorf("cannot set predefined variable %s to %q", pv.name(), asgn.mkValue.Dump())) | 
|  | 241 | } | 
|  | 242 |  | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 243 | var localProductConfigVariables = map[string]string{ | 
|  | 244 | "LOCAL_AUDIO_PRODUCT_PACKAGE":         "PRODUCT_PACKAGES", | 
|  | 245 | "LOCAL_AUDIO_PRODUCT_COPY_FILES":      "PRODUCT_COPY_FILES", | 
|  | 246 | "LOCAL_AUDIO_DEVICE_PACKAGE_OVERLAYS": "DEVICE_PACKAGE_OVERLAYS", | 
|  | 247 | "LOCAL_DUMPSTATE_PRODUCT_PACKAGE":     "PRODUCT_PACKAGES", | 
|  | 248 | "LOCAL_GATEKEEPER_PRODUCT_PACKAGE":    "PRODUCT_PACKAGES", | 
|  | 249 | "LOCAL_HEALTH_PRODUCT_PACKAGE":        "PRODUCT_PACKAGES", | 
|  | 250 | "LOCAL_SENSOR_PRODUCT_PACKAGE":        "PRODUCT_PACKAGES", | 
|  | 251 | "LOCAL_KEYMASTER_PRODUCT_PACKAGE":     "PRODUCT_PACKAGES", | 
|  | 252 | "LOCAL_KEYMINT_PRODUCT_PACKAGE":       "PRODUCT_PACKAGES", | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | var presetVariables = map[string]bool{ | 
|  | 256 | "BUILD_ID":                  true, | 
|  | 257 | "HOST_ARCH":                 true, | 
|  | 258 | "HOST_OS":                   true, | 
|  | 259 | "HOST_BUILD_TYPE":           true, | 
|  | 260 | "OUT_DIR":                   true, | 
|  | 261 | "PLATFORM_VERSION_CODENAME": true, | 
|  | 262 | "PLATFORM_VERSION":          true, | 
|  | 263 | "TARGET_ARCH":               true, | 
|  | 264 | "TARGET_ARCH_VARIANT":       true, | 
|  | 265 | "TARGET_BUILD_TYPE":         true, | 
|  | 266 | "TARGET_BUILD_VARIANT":      true, | 
|  | 267 | "TARGET_PRODUCT":            true, | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | // addVariable returns a variable with a given name. A variable is | 
|  | 271 | // added if it does not exist yet. | 
|  | 272 | func (ctx *parseContext) addVariable(name string) variable { | 
| Cole Faust | f92c9f2 | 2022-03-14 14:35:50 -0700 | [diff] [blame] | 273 | // Get the hintType before potentially changing the variable name | 
|  | 274 | var hintType starlarkType | 
|  | 275 | var ok bool | 
|  | 276 | if hintType, ok = ctx.typeHints[name]; !ok { | 
|  | 277 | hintType = starlarkTypeUnknown | 
|  | 278 | } | 
| Cole Faust | 3c4fc99 | 2022-02-28 16:05:01 -0800 | [diff] [blame] | 279 | // Heuristics: if variable's name is all lowercase, consider it local | 
|  | 280 | // string variable. | 
|  | 281 | isLocalVariable := name == strings.ToLower(name) | 
|  | 282 | // Local variables can't have special characters in them, because they | 
|  | 283 | // will be used as starlark identifiers | 
|  | 284 | if isLocalVariable { | 
|  | 285 | name = strings.ReplaceAll(strings.TrimSpace(name), "-", "_") | 
|  | 286 | } | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 287 | v, found := ctx.variables[name] | 
|  | 288 | if !found { | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 289 | if vi, found := KnownVariables[name]; found { | 
| Cole Faust | f92c9f2 | 2022-03-14 14:35:50 -0700 | [diff] [blame] | 290 | _, preset := presetVariables[name] | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 291 | switch vi.class { | 
|  | 292 | case VarClassConfig: | 
|  | 293 | v = &productConfigVariable{baseVariable{nam: name, typ: vi.valueType, preset: preset}} | 
|  | 294 | case VarClassSoong: | 
|  | 295 | v = &otherGlobalVariable{baseVariable{nam: name, typ: vi.valueType, preset: preset}} | 
|  | 296 | } | 
| Cole Faust | 3c4fc99 | 2022-02-28 16:05:01 -0800 | [diff] [blame] | 297 | } else if isLocalVariable { | 
| Cole Faust | f92c9f2 | 2022-03-14 14:35:50 -0700 | [diff] [blame] | 298 | v = &localVariable{baseVariable{nam: name, typ: hintType}} | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 299 | } else { | 
| Cole Faust | f92c9f2 | 2022-03-14 14:35:50 -0700 | [diff] [blame] | 300 | vt := hintType | 
| Cole Faust | f5adedc | 2022-03-18 14:05:06 -0700 | [diff] [blame] | 301 | // Heuristics: local variables that contribute to corresponding config variables | 
|  | 302 | if cfgVarName, found := localProductConfigVariables[name]; found && vt == starlarkTypeUnknown { | 
|  | 303 | vi, found2 := KnownVariables[cfgVarName] | 
|  | 304 | if !found2 { | 
|  | 305 | panic(fmt.Errorf("unknown config variable %s for %s", cfgVarName, name)) | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 306 | } | 
| Cole Faust | f5adedc | 2022-03-18 14:05:06 -0700 | [diff] [blame] | 307 | vt = vi.valueType | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 308 | } | 
| Sasha Smundak | 468e11f | 2021-08-26 09:10:23 -0700 | [diff] [blame] | 309 | if strings.HasSuffix(name, "_LIST") && vt == starlarkTypeUnknown { | 
|  | 310 | // Heuristics: Variables with "_LIST" suffix are lists | 
|  | 311 | vt = starlarkTypeList | 
|  | 312 | } | 
| Sasha Smundak | b051c4e | 2020-11-05 20:45:07 -0800 | [diff] [blame] | 313 | v = &otherGlobalVariable{baseVariable{nam: name, typ: vt}} | 
|  | 314 | } | 
|  | 315 | ctx.variables[name] = v | 
|  | 316 | } | 
|  | 317 | return v | 
|  | 318 | } |