blob: 1d8684b8e871abf75bcd03c15dec903545532284 [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{
77 "awk": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070078 "bash": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -070079 "bc": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070080 "bzip2": Allowed,
Elliott Hughesc33514e2019-01-10 06:02:12 +000081 "cp": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070082 "date": Allowed,
83 "dd": Allowed,
84 "diff": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070085 "egrep": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070086 "find": Allowed,
Dan Willemsenb4d01442018-08-27 16:14:23 -070087 "fuser": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070088 "getopt": Allowed,
89 "git": Allowed,
90 "grep": Allowed,
91 "gzip": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070092 "hexdump": Allowed,
93 "hostname": Allowed,
94 "jar": Allowed,
95 "java": Allowed,
96 "javap": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -070097 "lsof": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070098 "m4": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070099 "md5sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700100 "openssl": Allowed,
101 "patch": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700102 "pgrep": Allowed,
103 "pkill": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700104 "ps": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700105 "pstree": Allowed,
106 "python": Allowed,
107 "python2.7": Allowed,
108 "python3": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700109 "realpath": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700110 "rsync": Allowed,
Elliott Hughesde62ce12019-01-12 00:07:40 +0000111 "sed": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700112 "sh": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700113 "sha1sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700114 "sha256sum": Allowed,
115 "sha512sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700116 "tar": Allowed,
Elliott Hughesbe3cfa52018-10-27 08:09:18 -0700117 "timeout": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700118 "tr": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700119 "unzip": Allowed,
120 "wc": Allowed,
121 "which": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700122 "xz": Allowed,
123 "zip": Allowed,
124 "zipinfo": Allowed,
125
126 // Host toolchain is removed. In-tree toolchain should be used instead.
127 // GCC also can't find cc1 with this implementation.
128 "ar": Forbidden,
129 "as": Forbidden,
130 "cc": Forbidden,
131 "clang": Forbidden,
132 "clang++": Forbidden,
133 "gcc": Forbidden,
134 "g++": Forbidden,
135 "ld": Forbidden,
136 "ld.bfd": Forbidden,
137 "ld.gold": Forbidden,
138 "pkg-config": Forbidden,
139
Dan Willemsen417be1f2018-10-30 23:18:54 -0700140 // On linux we'll use the toybox version of these instead
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800141 "basename": Toybox,
142 "cat": Toybox,
Elliott Hughes97295bd2018-12-17 14:55:10 -0800143 "chmod": Toybox,
Elliott Hughes66469042018-12-05 10:03:31 -0800144 "cmp": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800145 "comm": Toybox,
Elliott Hughes9add81e2018-12-11 09:39:48 -0800146 "cut": Toybox,
Elliott Hughes2ebfd492018-12-06 08:57:31 -0800147 "dirname": Toybox,
Elliott Hughese0e24412018-12-17 15:08:27 -0800148 "du": Toybox,
Elliott Hughese1184be2018-12-17 15:10:09 -0800149 "echo": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800150 "env": Toybox,
Elliott Hughes6491f8d2018-12-17 14:50:13 -0800151 "expr": Toybox,
Elliott Hughesed461642018-11-26 10:45:08 -0800152 "head": Toybox,
Elliott Hughesc8a454c2019-01-11 13:29:17 -0800153 "getconf": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800154 "id": Toybox,
Elliott Hughes3a1fd8e2018-12-17 15:07:30 -0800155 "ln": Toybox,
Elliott Hughes0b11f652018-12-17 14:52:17 -0800156 "ls": Toybox,
Elliott Hughescc857702018-12-06 22:30:45 -0800157 "mkdir": Toybox,
Elliott Hughesf1f016e2018-11-26 21:24:57 -0800158 "mktemp": Toybox,
Elliott Hughes60647922018-12-17 15:06:30 -0800159 "mv": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800160 "od": Toybox,
161 "paste": Toybox,
162 "pwd": Toybox,
Elliott Hughes61456d12019-01-11 13:31:16 -0800163 "readlink": Toybox,
Elliott Hughesc0cf4542018-12-17 14:48:07 -0800164 "rm": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800165 "rmdir": Toybox,
166 "setsid": Toybox,
167 "sleep": Toybox,
Elliott Hughes713ae392018-12-11 10:02:19 -0800168 "sort": Toybox,
Elliott Hughesfa6c8a12018-12-17 14:57:26 -0800169 "stat": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800170 "tail": Toybox,
171 "tee": Toybox,
Elliott Hughes734a7802018-12-07 18:30:52 -0800172 "touch": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800173 "true": Toybox,
174 "uname": Toybox,
175 "uniq": Toybox,
Elliott Hughes5172a8b2018-12-05 19:42:43 -0800176 "unix2dos": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800177 "whoami": Toybox,
Elliott Hughes6712c0e2018-12-17 15:09:22 -0800178 "xargs": Toybox,
Elliott Hughes6141a7d2018-12-04 13:42:46 -0800179 "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}