blob: 9d67a628dd7253cdd72b418452ea67e78e6d2601 [file] [log] [blame]
Dan Willemsen18490112018-05-25 16:30:04 -07001// Copyright 2018 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 paths
16
17import "runtime"
18
19type PathConfig struct {
20 // Whether to create the symlink in the new PATH for this tool.
21 Symlink bool
22
23 // Whether to log about usages of this tool to the soong.log
24 Log bool
25
26 // Whether to exit with an error instead of invoking the underlying tool.
27 Error bool
28}
29
30var Allowed = PathConfig{
31 Symlink: true,
32 Log: false,
33 Error: false,
34}
35
36var Forbidden = PathConfig{
37 Symlink: false,
38 Log: true,
39 Error: true,
40}
41
42// The configuration used if the tool is not listed in the config below.
43// Currently this will create the symlink, but log a warning. In the future,
44// I expect this to move closer to Forbidden.
45var Missing = PathConfig{
46 Symlink: true,
47 Log: true,
48 Error: false,
49}
50
51func GetConfig(name string) PathConfig {
52 if config, ok := Configuration[name]; ok {
53 return config
54 }
55 return Missing
56}
57
58var Configuration = map[string]PathConfig{
59 "awk": Allowed,
60 "basename": Allowed,
61 "bash": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -070062 "bc": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070063 "bzip2": Allowed,
64 "cat": Allowed,
65 "chmod": Allowed,
66 "cmp": Allowed,
67 "comm": Allowed,
68 "cp": Allowed,
69 "cut": Allowed,
70 "date": Allowed,
71 "dd": Allowed,
72 "diff": Allowed,
73 "dirname": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -070074 "du": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070075 "echo": Allowed,
76 "egrep": Allowed,
77 "env": Allowed,
78 "expr": Allowed,
79 "find": Allowed,
80 "getconf": Allowed,
81 "getopt": Allowed,
82 "git": Allowed,
83 "grep": Allowed,
84 "gzip": Allowed,
85 "head": Allowed,
86 "hexdump": Allowed,
87 "hostname": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -070088 "id": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070089 "jar": Allowed,
90 "java": Allowed,
91 "javap": Allowed,
92 "ln": Allowed,
93 "ls": Allowed,
94 "m4": Allowed,
95 "make": Allowed,
96 "md5sum": Allowed,
97 "mkdir": Allowed,
98 "mktemp": Allowed,
99 "mv": Allowed,
100 "openssl": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700101 "paste": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700102 "patch": Allowed,
103 "perl": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700104 "pgrep": Allowed,
105 "pkill": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700106 "pstree": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700107 "pwd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700108 "python": Allowed,
109 "python2.7": Allowed,
110 "python3": Allowed,
111 "readlink": Allowed,
112 "realpath": Allowed,
113 "rm": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700114 "rmdir": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700115 "rsync": Allowed,
116 "runalarm": Allowed,
117 "sed": Allowed,
118 "setsid": Allowed,
119 "sh": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700120 "sha1sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700121 "sha256sum": Allowed,
122 "sha512sum": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700123 "sleep": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700124 "sort": Allowed,
125 "stat": Allowed,
126 "sum": Allowed,
127 "tar": Allowed,
128 "tail": Allowed,
129 "touch": Allowed,
130 "tr": Allowed,
131 "true": Allowed,
132 "uname": Allowed,
133 "uniq": Allowed,
134 "unzip": Allowed,
135 "wc": Allowed,
136 "which": Allowed,
137 "whoami": Allowed,
138 "xargs": Allowed,
139 "xmllint": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700140 "xxd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700141 "xz": Allowed,
142 "zip": Allowed,
143 "zipinfo": Allowed,
144
145 // Host toolchain is removed. In-tree toolchain should be used instead.
146 // GCC also can't find cc1 with this implementation.
147 "ar": Forbidden,
148 "as": Forbidden,
149 "cc": Forbidden,
150 "clang": Forbidden,
151 "clang++": Forbidden,
152 "gcc": Forbidden,
153 "g++": Forbidden,
154 "ld": Forbidden,
155 "ld.bfd": Forbidden,
156 "ld.gold": Forbidden,
157 "pkg-config": Forbidden,
158
159 // We've got prebuilts of these
160 //"dtc": Forbidden,
161 //"lz4": Forbidden,
162 //"lz4c": Forbidden,
163}
164
165func init() {
166 if runtime.GOOS == "darwin" {
167 Configuration["md5"] = Allowed
168 Configuration["sw_vers"] = Allowed
169 Configuration["xcrun"] = Allowed
170 }
171}