blob: b4d76c43a45cc695d5e712546b0466f4d45b0282 [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,
82 "cat": Allowed,
83 "chmod": Allowed,
84 "cmp": Allowed,
85 "comm": Allowed,
86 "cp": Allowed,
87 "cut": Allowed,
88 "date": Allowed,
89 "dd": Allowed,
90 "diff": Allowed,
91 "dirname": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -070092 "du": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070093 "echo": Allowed,
94 "egrep": Allowed,
95 "env": Allowed,
96 "expr": Allowed,
97 "find": Allowed,
Dan Willemsenb4d01442018-08-27 16:14:23 -070098 "fuser": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070099 "getconf": Allowed,
100 "getopt": Allowed,
101 "git": Allowed,
102 "grep": Allowed,
103 "gzip": Allowed,
104 "head": Allowed,
105 "hexdump": Allowed,
106 "hostname": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700107 "id": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700108 "jar": Allowed,
109 "java": Allowed,
110 "javap": Allowed,
111 "ln": Allowed,
112 "ls": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700113 "lsof": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700114 "m4": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700115 "md5sum": Allowed,
116 "mkdir": Allowed,
117 "mktemp": Allowed,
118 "mv": Allowed,
Dan Willemsen2d31ace2018-08-30 16:51:42 -0700119 "od": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700120 "openssl": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700121 "paste": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700122 "patch": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700123 "pgrep": Allowed,
124 "pkill": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700125 "ps": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700126 "pstree": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700127 "pwd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700128 "python": Allowed,
129 "python2.7": Allowed,
130 "python3": Allowed,
131 "readlink": Allowed,
132 "realpath": Allowed,
133 "rm": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700134 "rmdir": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700135 "rsync": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700136 "sed": Allowed,
137 "setsid": Allowed,
138 "sh": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700139 "sha1sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700140 "sha256sum": Allowed,
141 "sha512sum": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700142 "sleep": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700143 "sort": Allowed,
144 "stat": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700145 "tar": Allowed,
146 "tail": Allowed,
Dan Willemsen090ec582018-08-31 08:12:22 +0000147 "tee": Allowed,
Elliott Hughesbe3cfa52018-10-27 08:09:18 -0700148 "timeout": Allowed,
Dan Willemsen7a08bc52018-08-28 00:18:02 -0700149 "todos": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700150 "touch": Allowed,
151 "tr": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700152 "uniq": Allowed,
Dan Willemsen6fa18f42018-08-29 10:26:47 -0700153 "unix2dos": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700154 "unzip": Allowed,
155 "wc": Allowed,
156 "which": Allowed,
157 "whoami": Allowed,
158 "xargs": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700159 "xxd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700160 "xz": Allowed,
161 "zip": Allowed,
162 "zipinfo": Allowed,
163
164 // Host toolchain is removed. In-tree toolchain should be used instead.
165 // GCC also can't find cc1 with this implementation.
166 "ar": Forbidden,
167 "as": Forbidden,
168 "cc": Forbidden,
169 "clang": Forbidden,
170 "clang++": Forbidden,
171 "gcc": Forbidden,
172 "g++": Forbidden,
173 "ld": Forbidden,
174 "ld.bfd": Forbidden,
175 "ld.gold": Forbidden,
176 "pkg-config": Forbidden,
177
Dan Willemsen417be1f2018-10-30 23:18:54 -0700178 // On linux we'll use the toybox version of these instead
179 "true": Toybox,
180 "uname": 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}