blob: b9713feefd7fc841c5439f83bf8631d3657fbc15 [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
Dan Willemsen417be1f2018-10-30 23:18:54 -070028
29 // Whether we use a toybox prebuilt for this tool. Since we don't have
30 // toybox for Darwin, we'll use the host version instead.
31 Toybox bool
Dan Willemsen18490112018-05-25 16:30:04 -070032}
33
34var Allowed = PathConfig{
35 Symlink: true,
36 Log: false,
37 Error: false,
38}
39
40var Forbidden = PathConfig{
41 Symlink: false,
42 Log: true,
43 Error: true,
44}
45
Dan Willemsen3eec9c52018-10-04 23:21:40 +000046var Log = PathConfig{
47 Symlink: true,
Dan Willemsene9e20dd2018-10-09 23:23:19 +000048 Log: true,
49 Error: false,
Dan Willemsen3eec9c52018-10-04 23:21:40 +000050}
51
Dan Willemsen18490112018-05-25 16:30:04 -070052// The configuration used if the tool is not listed in the config below.
Dan Willemsen8125d2a2018-08-15 15:26:39 -070053// Currently this will create the symlink, but log and error when it's used. In
54// the future, I expect the symlink to be removed, and this will be equivalent
55// to Forbidden.
Dan Willemsen18490112018-05-25 16:30:04 -070056var Missing = PathConfig{
57 Symlink: true,
58 Log: true,
Dan Willemsen8125d2a2018-08-15 15:26:39 -070059 Error: true,
Dan Willemsen18490112018-05-25 16:30:04 -070060}
61
Dan Willemsen417be1f2018-10-30 23:18:54 -070062var Toybox = PathConfig{
63 Symlink: false,
64 Log: true,
65 Error: true,
66 Toybox: true,
67}
68
Dan Willemsen18490112018-05-25 16:30:04 -070069func GetConfig(name string) PathConfig {
70 if config, ok := Configuration[name]; ok {
71 return config
72 }
73 return Missing
74}
75
76var Configuration = map[string]PathConfig{
Dan Willemsen18490112018-05-25 16:30:04 -070077 "bash": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -070078 "bc": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070079 "bzip2": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070080 "date": Allowed,
81 "dd": Allowed,
82 "diff": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070083 "egrep": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070084 "find": Allowed,
Dan Willemsenb4d01442018-08-27 16:14:23 -070085 "fuser": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070086 "getopt": Allowed,
87 "git": Allowed,
88 "grep": Allowed,
89 "gzip": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070090 "hexdump": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070091 "jar": Allowed,
92 "java": Allowed,
93 "javap": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -070094 "lsof": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070095 "m4": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070096 "openssl": Allowed,
97 "patch": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070098 "pstree": Allowed,
99 "python": Allowed,
100 "python2.7": Allowed,
101 "python3": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700102 "realpath": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700103 "rsync": Allowed,
Elliott Hughesde62ce12019-01-12 00:07:40 +0000104 "sed": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700105 "sh": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700106 "tar": Allowed,
Elliott Hughesbe3cfa52018-10-27 08:09:18 -0700107 "timeout": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700108 "tr": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700109 "unzip": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700110 "xz": Allowed,
111 "zip": Allowed,
112 "zipinfo": Allowed,
113
114 // Host toolchain is removed. In-tree toolchain should be used instead.
115 // GCC also can't find cc1 with this implementation.
116 "ar": Forbidden,
117 "as": Forbidden,
118 "cc": Forbidden,
119 "clang": Forbidden,
120 "clang++": Forbidden,
121 "gcc": Forbidden,
122 "g++": Forbidden,
123 "ld": Forbidden,
124 "ld.bfd": Forbidden,
125 "ld.gold": Forbidden,
126 "pkg-config": Forbidden,
127
Elliott Hughesc97a9112019-01-11 13:34:13 -0800128 // On Linux we'll use the toybox versions of these instead.
Elliott Hughescc74d592019-01-23 14:33:20 -0800129 "awk": Toybox, // Strictly one-true-awk, but...
Elliott Hughesc97a9112019-01-11 13:34:13 -0800130 "basename": Toybox,
131 "cat": Toybox,
132 "chmod": Toybox,
133 "cmp": Toybox,
Elliott Hughes48d716c2019-01-24 15:18:50 -0800134 "cp": Toybox,
Elliott Hughesc97a9112019-01-11 13:34:13 -0800135 "comm": Toybox,
136 "cut": Toybox,
137 "dirname": Toybox,
138 "du": Toybox,
139 "echo": Toybox,
140 "env": Toybox,
141 "expr": Toybox,
142 "head": Toybox,
143 "getconf": Toybox,
Elliott Hughesd5fdd3a2019-01-24 15:18:06 -0800144 "hostname": Toybox,
Elliott Hughesc97a9112019-01-11 13:34:13 -0800145 "id": Toybox,
146 "ln": Toybox,
147 "ls": Toybox,
148 "md5sum": Toybox,
149 "mkdir": Toybox,
150 "mktemp": Toybox,
151 "mv": Toybox,
152 "od": Toybox,
153 "paste": Toybox,
Elliott Hughesdb96fc82019-01-18 13:08:05 -0800154 "pgrep": Toybox,
155 "pkill": Toybox,
156 "ps": Toybox,
Elliott Hughesc97a9112019-01-11 13:34:13 -0800157 "pwd": Toybox,
158 "readlink": Toybox,
159 "rm": Toybox,
160 "rmdir": Toybox,
161 "setsid": Toybox,
162 "sha1sum": Toybox,
163 "sha256sum": Toybox,
164 "sha512sum": Toybox,
165 "sleep": Toybox,
166 "sort": Toybox,
167 "stat": Toybox,
168 "tail": Toybox,
169 "tee": Toybox,
170 "touch": Toybox,
171 "true": Toybox,
172 "uname": Toybox,
173 "uniq": Toybox,
174 "unix2dos": Toybox,
Elliott Hughes46e68632019-01-18 08:28:54 -0800175 "wc": Toybox,
Elliott Hughesc97a9112019-01-11 13:34:13 -0800176 "whoami": Toybox,
Elliott Hughes44f0d4e2019-01-18 15:18:54 -0800177 "which": Toybox,
Elliott Hughesc97a9112019-01-11 13:34:13 -0800178 "xargs": Toybox,
179 "xxd": Toybox,
Dan Willemsen18490112018-05-25 16:30:04 -0700180}
181
182func init() {
183 if runtime.GOOS == "darwin" {
184 Configuration["md5"] = Allowed
185 Configuration["sw_vers"] = Allowed
186 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700187
188 // We don't have toybox prebuilts for darwin, so allow the
189 // host versions.
190 for name, config := range Configuration {
191 if config.Toybox {
192 Configuration[name] = Allowed
193 }
194 }
Dan Willemsen18490112018-05-25 16:30:04 -0700195 }
196}