blob: 54bc5a84c08b08afd130e2b470b02a4912ccfd4d [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 Willemsen0f021462019-02-17 12:24:24 -080077 "bash": Allowed,
78 "bc": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080079 "date": Allowed,
80 "dd": Allowed,
81 "diff": Allowed,
82 "egrep": Allowed,
83 "find": Allowed,
84 "fuser": Allowed,
85 "getopt": Allowed,
86 "git": Allowed,
87 "grep": Allowed,
88 "gzip": Allowed,
89 "hexdump": Allowed,
90 "jar": Allowed,
91 "java": Allowed,
92 "javap": Allowed,
93 "lsof": Allowed,
94 "m4": Allowed,
95 "openssl": Allowed,
96 "patch": Allowed,
97 "pstree": Allowed,
98 "python3": Allowed,
99 "realpath": Allowed,
100 "rsync": Allowed,
101 "sh": Allowed,
102 "tar": Allowed,
103 "timeout": Allowed,
104 "tr": Allowed,
105 "unzip": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -0800106 "zip": Allowed,
107 "zipinfo": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700108
109 // Host toolchain is removed. In-tree toolchain should be used instead.
110 // GCC also can't find cc1 with this implementation.
111 "ar": Forbidden,
112 "as": Forbidden,
113 "cc": Forbidden,
114 "clang": Forbidden,
115 "clang++": Forbidden,
116 "gcc": Forbidden,
117 "g++": Forbidden,
118 "ld": Forbidden,
119 "ld.bfd": Forbidden,
120 "ld.gold": Forbidden,
121 "pkg-config": Forbidden,
122
Elliott Hughesc97a9112019-01-11 13:34:13 -0800123 // On Linux we'll use the toybox versions of these instead.
Dan Willemsen91219732019-02-14 20:00:56 -0800124 "basename": LinuxOnlyPrebuilt,
125 "cat": LinuxOnlyPrebuilt,
126 "chmod": LinuxOnlyPrebuilt,
127 "cmp": LinuxOnlyPrebuilt,
128 "cp": LinuxOnlyPrebuilt,
129 "comm": LinuxOnlyPrebuilt,
130 "cut": LinuxOnlyPrebuilt,
131 "dirname": LinuxOnlyPrebuilt,
132 "du": LinuxOnlyPrebuilt,
133 "echo": LinuxOnlyPrebuilt,
134 "env": LinuxOnlyPrebuilt,
135 "expr": LinuxOnlyPrebuilt,
136 "head": LinuxOnlyPrebuilt,
137 "getconf": LinuxOnlyPrebuilt,
138 "hostname": LinuxOnlyPrebuilt,
139 "id": LinuxOnlyPrebuilt,
140 "ln": LinuxOnlyPrebuilt,
141 "ls": LinuxOnlyPrebuilt,
142 "md5sum": LinuxOnlyPrebuilt,
143 "mkdir": LinuxOnlyPrebuilt,
144 "mktemp": LinuxOnlyPrebuilt,
145 "mv": LinuxOnlyPrebuilt,
146 "od": LinuxOnlyPrebuilt,
147 "paste": LinuxOnlyPrebuilt,
148 "pgrep": LinuxOnlyPrebuilt,
149 "pkill": LinuxOnlyPrebuilt,
150 "ps": LinuxOnlyPrebuilt,
151 "pwd": LinuxOnlyPrebuilt,
152 "readlink": LinuxOnlyPrebuilt,
153 "rm": LinuxOnlyPrebuilt,
154 "rmdir": LinuxOnlyPrebuilt,
Elliott Hughes47de2a22019-01-24 15:19:30 -0800155 "sed": LinuxOnlyPrebuilt,
Elliott Hughesc2dbadc2019-04-08 09:19:45 -0700156 "seq": LinuxOnlyPrebuilt,
Dan Willemsen91219732019-02-14 20:00:56 -0800157 "setsid": LinuxOnlyPrebuilt,
158 "sha1sum": LinuxOnlyPrebuilt,
159 "sha256sum": LinuxOnlyPrebuilt,
160 "sha512sum": LinuxOnlyPrebuilt,
161 "sleep": LinuxOnlyPrebuilt,
162 "sort": LinuxOnlyPrebuilt,
163 "stat": LinuxOnlyPrebuilt,
164 "tail": LinuxOnlyPrebuilt,
165 "tee": LinuxOnlyPrebuilt,
166 "touch": LinuxOnlyPrebuilt,
167 "true": LinuxOnlyPrebuilt,
168 "uname": LinuxOnlyPrebuilt,
169 "uniq": LinuxOnlyPrebuilt,
170 "unix2dos": LinuxOnlyPrebuilt,
171 "wc": LinuxOnlyPrebuilt,
172 "whoami": LinuxOnlyPrebuilt,
173 "which": LinuxOnlyPrebuilt,
174 "xargs": LinuxOnlyPrebuilt,
175 "xxd": LinuxOnlyPrebuilt,
Dan Willemsen18490112018-05-25 16:30:04 -0700176}
177
178func init() {
179 if runtime.GOOS == "darwin" {
180 Configuration["md5"] = Allowed
181 Configuration["sw_vers"] = Allowed
182 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700183
Dan Willemsen91219732019-02-14 20:00:56 -0800184 // We don't have darwin prebuilts for some tools (like toybox),
185 // so allow the host versions.
Dan Willemsen417be1f2018-10-30 23:18:54 -0700186 for name, config := range Configuration {
Dan Willemsen91219732019-02-14 20:00:56 -0800187 if config.LinuxOnlyPrebuilt {
Dan Willemsen417be1f2018-10-30 23:18:54 -0700188 Configuration[name] = Allowed
189 }
190 }
Dan Willemsen18490112018-05-25 16:30:04 -0700191 }
192}