blob: 39a776c6de466deef78bd4cadb6b468e7268ec3b [file] [log] [blame]
Colin Cross9d34f352019-11-22 16:03:51 -08001// Copyright 2020 Google Inc. 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 soongconfig
16
17import "strings"
18
19type SoongConfig interface {
20 // Bool interprets the variable named `name` as a boolean, returning true if, after
21 // lowercasing, it matches one of "1", "y", "yes", "on", or "true". Unset, or any other
22 // value will return false.
23 Bool(name string) bool
24
25 // String returns the string value of `name`. If the variable was not set, it will
26 // return the empty string.
27 String(name string) string
28
29 // IsSet returns whether the variable `name` was set by Make.
30 IsSet(name string) bool
31}
32
33func Config(vars map[string]string) SoongConfig {
34 return soongConfig(vars)
35}
36
37type soongConfig map[string]string
38
39func (c soongConfig) Bool(name string) bool {
40 v := strings.ToLower(c[name])
41 return v == "1" || v == "y" || v == "yes" || v == "on" || v == "true"
42}
43
44func (c soongConfig) String(name string) string {
45 return c[name]
46}
47
48func (c soongConfig) IsSet(name string) bool {
49 _, ok := c[name]
50 return ok
51}