blob: d92649f442e3c5bf0cba81ac5ef1affeeb4c9821 [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{
Elliott Hughes6b3a0dd2019-04-30 22:19:26 -070077 "bash": Allowed,
78 "bc": Allowed,
79 // We need bzip2 here even though we provide a bzip2 binary because
80 // GNU tar seems to avoid calling ours.
Elliott Hughes3d873022019-04-30 21:55:23 +000081 "bzip2": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080082 "date": Allowed,
83 "dd": Allowed,
84 "diff": Allowed,
85 "egrep": Allowed,
Elliott Hughes3a653f42019-05-01 12:52:25 -070086 "expr": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080087 "find": Allowed,
88 "fuser": Allowed,
89 "getopt": Allowed,
90 "git": Allowed,
91 "grep": Allowed,
92 "gzip": Allowed,
93 "hexdump": Allowed,
94 "jar": Allowed,
95 "java": Allowed,
96 "javap": Allowed,
97 "lsof": Allowed,
98 "m4": Allowed,
99 "openssl": Allowed,
100 "patch": Allowed,
101 "pstree": Allowed,
102 "python3": Allowed,
103 "realpath": Allowed,
104 "rsync": Allowed,
105 "sh": Allowed,
106 "tar": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -0800107 "tr": Allowed,
108 "unzip": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -0800109 "zip": Allowed,
110 "zipinfo": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700111
112 // Host toolchain is removed. In-tree toolchain should be used instead.
113 // GCC also can't find cc1 with this implementation.
114 "ar": Forbidden,
115 "as": Forbidden,
116 "cc": Forbidden,
117 "clang": Forbidden,
118 "clang++": Forbidden,
119 "gcc": Forbidden,
120 "g++": Forbidden,
121 "ld": Forbidden,
122 "ld.bfd": Forbidden,
123 "ld.gold": Forbidden,
124 "pkg-config": Forbidden,
125
Elliott Hughesc97a9112019-01-11 13:34:13 -0800126 // On Linux we'll use the toybox versions of these instead.
Dan Willemsen91219732019-02-14 20:00:56 -0800127 "basename": LinuxOnlyPrebuilt,
128 "cat": LinuxOnlyPrebuilt,
129 "chmod": LinuxOnlyPrebuilt,
130 "cmp": LinuxOnlyPrebuilt,
131 "cp": LinuxOnlyPrebuilt,
132 "comm": LinuxOnlyPrebuilt,
133 "cut": LinuxOnlyPrebuilt,
134 "dirname": LinuxOnlyPrebuilt,
135 "du": LinuxOnlyPrebuilt,
136 "echo": LinuxOnlyPrebuilt,
137 "env": LinuxOnlyPrebuilt,
Dan Willemsen91219732019-02-14 20:00:56 -0800138 "head": LinuxOnlyPrebuilt,
139 "getconf": LinuxOnlyPrebuilt,
140 "hostname": LinuxOnlyPrebuilt,
141 "id": LinuxOnlyPrebuilt,
142 "ln": LinuxOnlyPrebuilt,
143 "ls": LinuxOnlyPrebuilt,
144 "md5sum": LinuxOnlyPrebuilt,
145 "mkdir": LinuxOnlyPrebuilt,
146 "mktemp": LinuxOnlyPrebuilt,
147 "mv": LinuxOnlyPrebuilt,
148 "od": LinuxOnlyPrebuilt,
149 "paste": LinuxOnlyPrebuilt,
150 "pgrep": LinuxOnlyPrebuilt,
151 "pkill": LinuxOnlyPrebuilt,
152 "ps": LinuxOnlyPrebuilt,
153 "pwd": LinuxOnlyPrebuilt,
154 "readlink": LinuxOnlyPrebuilt,
155 "rm": LinuxOnlyPrebuilt,
156 "rmdir": LinuxOnlyPrebuilt,
Elliott Hughesc1bfeed2019-06-07 13:10:04 -0700157 "sed": LinuxOnlyPrebuilt,
Elliott Hughesc2dbadc2019-04-08 09:19:45 -0700158 "seq": LinuxOnlyPrebuilt,
Dan Willemsen91219732019-02-14 20:00:56 -0800159 "setsid": LinuxOnlyPrebuilt,
160 "sha1sum": LinuxOnlyPrebuilt,
161 "sha256sum": LinuxOnlyPrebuilt,
162 "sha512sum": LinuxOnlyPrebuilt,
163 "sleep": LinuxOnlyPrebuilt,
164 "sort": LinuxOnlyPrebuilt,
165 "stat": LinuxOnlyPrebuilt,
166 "tail": LinuxOnlyPrebuilt,
167 "tee": LinuxOnlyPrebuilt,
Elliott Hughese9f47162019-06-06 21:41:48 -0700168 "timeout": LinuxOnlyPrebuilt,
Dan Willemsen91219732019-02-14 20:00:56 -0800169 "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}