blob: 8183e2378dfbc75d2616cf15115e8854a20e8594 [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,
78 "basename": Allowed,
79 "bash": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -070080 "bc": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070081 "bzip2": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070082 "chmod": Allowed,
83 "cmp": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070084 "cp": Allowed,
85 "cut": Allowed,
86 "date": Allowed,
87 "dd": Allowed,
88 "diff": Allowed,
89 "dirname": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -070090 "du": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070091 "echo": Allowed,
92 "egrep": Allowed,
93 "env": Allowed,
94 "expr": Allowed,
95 "find": Allowed,
Dan Willemsenb4d01442018-08-27 16:14:23 -070096 "fuser": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070097 "getconf": Allowed,
98 "getopt": Allowed,
99 "git": Allowed,
100 "grep": Allowed,
101 "gzip": Allowed,
102 "head": Allowed,
103 "hexdump": Allowed,
104 "hostname": Allowed,
105 "jar": Allowed,
106 "java": Allowed,
107 "javap": Allowed,
108 "ln": Allowed,
109 "ls": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700110 "lsof": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700111 "m4": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700112 "md5sum": Allowed,
113 "mkdir": Allowed,
114 "mktemp": Allowed,
115 "mv": Allowed,
Dan Willemsen2d31ace2018-08-30 16:51:42 -0700116 "od": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700117 "openssl": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700118 "paste": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700119 "patch": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700120 "pgrep": Allowed,
121 "pkill": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700122 "ps": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700123 "pstree": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700124 "pwd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700125 "python": Allowed,
126 "python2.7": Allowed,
127 "python3": Allowed,
128 "readlink": Allowed,
129 "realpath": Allowed,
130 "rm": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700131 "rmdir": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700132 "rsync": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700133 "sed": Allowed,
134 "setsid": Allowed,
135 "sh": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700136 "sha1sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700137 "sha256sum": Allowed,
138 "sha512sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700139 "sort": Allowed,
140 "stat": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700141 "tar": Allowed,
142 "tail": Allowed,
Dan Willemsen090ec582018-08-31 08:12:22 +0000143 "tee": Allowed,
Elliott Hughesbe3cfa52018-10-27 08:09:18 -0700144 "timeout": Allowed,
Dan Willemsen7a08bc52018-08-28 00:18:02 -0700145 "todos": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700146 "touch": Allowed,
147 "tr": Allowed,
Dan Willemsen6fa18f42018-08-29 10:26:47 -0700148 "unix2dos": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700149 "unzip": Allowed,
150 "wc": Allowed,
151 "which": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700152 "xargs": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700153 "xxd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700154 "xz": Allowed,
155 "zip": Allowed,
156 "zipinfo": Allowed,
157
158 // Host toolchain is removed. In-tree toolchain should be used instead.
159 // GCC also can't find cc1 with this implementation.
160 "ar": Forbidden,
161 "as": Forbidden,
162 "cc": Forbidden,
163 "clang": Forbidden,
164 "clang++": Forbidden,
165 "gcc": Forbidden,
166 "g++": Forbidden,
167 "ld": Forbidden,
168 "ld.bfd": Forbidden,
169 "ld.gold": Forbidden,
170 "pkg-config": Forbidden,
171
Dan Willemsen417be1f2018-10-30 23:18:54 -0700172 // On linux we'll use the toybox version of these instead
Elliott Hughes5d593232018-11-13 13:08:13 -0800173 "cat": Toybox,
Elliott Hughes6bdad222018-11-14 20:49:52 -0800174 "comm": Toybox,
Elliott Hughes9b370f52018-11-11 10:56:39 -0800175 "id": Toybox,
Elliott Hughes2907cea2018-11-14 14:30:56 -0800176 "sleep": Toybox,
Elliott Hughes9b370f52018-11-11 10:56:39 -0800177 "true": Toybox,
178 "uname": Toybox,
Elliott Hughes7a907c92018-11-13 22:12:30 -0800179 "uniq": Toybox,
Elliott Hughes9b370f52018-11-11 10:56:39 -0800180 "whoami": Toybox,
Dan Willemsen18490112018-05-25 16:30:04 -0700181}
182
183func init() {
184 if runtime.GOOS == "darwin" {
185 Configuration["md5"] = Allowed
186 Configuration["sw_vers"] = Allowed
187 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700188
189 // We don't have toybox prebuilts for darwin, so allow the
190 // host versions.
191 for name, config := range Configuration {
192 if config.Toybox {
193 Configuration[name] = Allowed
194 }
195 }
Dan Willemsen18490112018-05-25 16:30:04 -0700196 }
197}