blob: 6ef7fe92348088728f5ea05465c91c66d0399602 [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
Dan Willemsen91219732019-02-14 20:00:56 -080029 // Whether we use a linux-specific prebuilt for this tool. On Darwin,
30 // we'll allow the host executable instead.
31 LinuxOnlyPrebuilt 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 Willemsen91219732019-02-14 20:00:56 -080062var LinuxOnlyPrebuilt = PathConfig{
63 Symlink: false,
64 Log: true,
65 Error: true,
66 LinuxOnlyPrebuilt: true,
Dan Willemsen417be1f2018-10-30 23:18:54 -070067}
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.
Dan Willemsen91219732019-02-14 20:00:56 -0800129 "basename": LinuxOnlyPrebuilt,
130 "cat": LinuxOnlyPrebuilt,
131 "chmod": LinuxOnlyPrebuilt,
132 "cmp": LinuxOnlyPrebuilt,
133 "cp": LinuxOnlyPrebuilt,
134 "comm": LinuxOnlyPrebuilt,
135 "cut": LinuxOnlyPrebuilt,
136 "dirname": LinuxOnlyPrebuilt,
137 "du": LinuxOnlyPrebuilt,
138 "echo": LinuxOnlyPrebuilt,
139 "env": LinuxOnlyPrebuilt,
140 "expr": LinuxOnlyPrebuilt,
141 "head": LinuxOnlyPrebuilt,
142 "getconf": LinuxOnlyPrebuilt,
143 "hostname": LinuxOnlyPrebuilt,
144 "id": LinuxOnlyPrebuilt,
145 "ln": LinuxOnlyPrebuilt,
146 "ls": LinuxOnlyPrebuilt,
147 "md5sum": LinuxOnlyPrebuilt,
148 "mkdir": LinuxOnlyPrebuilt,
149 "mktemp": LinuxOnlyPrebuilt,
150 "mv": LinuxOnlyPrebuilt,
151 "od": LinuxOnlyPrebuilt,
152 "paste": LinuxOnlyPrebuilt,
153 "pgrep": LinuxOnlyPrebuilt,
154 "pkill": LinuxOnlyPrebuilt,
155 "ps": LinuxOnlyPrebuilt,
156 "pwd": LinuxOnlyPrebuilt,
157 "readlink": LinuxOnlyPrebuilt,
158 "rm": LinuxOnlyPrebuilt,
159 "rmdir": LinuxOnlyPrebuilt,
160 "setsid": LinuxOnlyPrebuilt,
161 "sha1sum": LinuxOnlyPrebuilt,
162 "sha256sum": LinuxOnlyPrebuilt,
163 "sha512sum": LinuxOnlyPrebuilt,
164 "sleep": LinuxOnlyPrebuilt,
165 "sort": LinuxOnlyPrebuilt,
166 "stat": LinuxOnlyPrebuilt,
167 "tail": LinuxOnlyPrebuilt,
168 "tee": LinuxOnlyPrebuilt,
169 "touch": LinuxOnlyPrebuilt,
170 "true": LinuxOnlyPrebuilt,
171 "uname": LinuxOnlyPrebuilt,
172 "uniq": LinuxOnlyPrebuilt,
173 "unix2dos": LinuxOnlyPrebuilt,
174 "wc": LinuxOnlyPrebuilt,
175 "whoami": LinuxOnlyPrebuilt,
176 "which": LinuxOnlyPrebuilt,
177 "xargs": LinuxOnlyPrebuilt,
178 "xxd": LinuxOnlyPrebuilt,
Dan Willemsen18490112018-05-25 16:30:04 -0700179}
180
181func init() {
182 if runtime.GOOS == "darwin" {
183 Configuration["md5"] = Allowed
184 Configuration["sw_vers"] = Allowed
185 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700186
Dan Willemsen91219732019-02-14 20:00:56 -0800187 // We don't have darwin prebuilts for some tools (like toybox),
188 // so allow the host versions.
Dan Willemsen417be1f2018-10-30 23:18:54 -0700189 for name, config := range Configuration {
Dan Willemsen91219732019-02-14 20:00:56 -0800190 if config.LinuxOnlyPrebuilt {
Dan Willemsen417be1f2018-10-30 23:18:54 -0700191 Configuration[name] = Allowed
192 }
193 }
Dan Willemsen18490112018-05-25 16:30:04 -0700194 }
195}