blob: e846b03aeb966e2556ce35ede0f0e86c837a778d [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
28}
29
30var Allowed = PathConfig{
31 Symlink: true,
32 Log: false,
33 Error: false,
34}
35
36var Forbidden = PathConfig{
37 Symlink: false,
38 Log: true,
39 Error: true,
40}
41
Dan Willemsen3eec9c52018-10-04 23:21:40 +000042var Log = PathConfig{
43 Symlink: true,
Dan Willemsene9e20dd2018-10-09 23:23:19 +000044 Log: true,
45 Error: false,
Dan Willemsen3eec9c52018-10-04 23:21:40 +000046}
47
Dan Willemsen18490112018-05-25 16:30:04 -070048// The configuration used if the tool is not listed in the config below.
Dan Willemsen8125d2a2018-08-15 15:26:39 -070049// Currently this will create the symlink, but log and error when it's used. In
50// the future, I expect the symlink to be removed, and this will be equivalent
51// to Forbidden.
Dan Willemsen18490112018-05-25 16:30:04 -070052var Missing = PathConfig{
53 Symlink: true,
54 Log: true,
Dan Willemsen8125d2a2018-08-15 15:26:39 -070055 Error: true,
Dan Willemsen18490112018-05-25 16:30:04 -070056}
57
58func GetConfig(name string) PathConfig {
59 if config, ok := Configuration[name]; ok {
60 return config
61 }
62 return Missing
63}
64
65var Configuration = map[string]PathConfig{
66 "awk": Allowed,
67 "basename": Allowed,
68 "bash": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -070069 "bc": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070070 "bzip2": Allowed,
71 "cat": Allowed,
72 "chmod": Allowed,
73 "cmp": Allowed,
74 "comm": Allowed,
75 "cp": Allowed,
76 "cut": Allowed,
77 "date": Allowed,
78 "dd": Allowed,
79 "diff": Allowed,
80 "dirname": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -070081 "du": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070082 "echo": Allowed,
83 "egrep": Allowed,
84 "env": Allowed,
85 "expr": Allowed,
86 "find": Allowed,
Dan Willemsenb4d01442018-08-27 16:14:23 -070087 "fuser": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070088 "getconf": Allowed,
89 "getopt": Allowed,
90 "git": Allowed,
91 "grep": Allowed,
92 "gzip": Allowed,
93 "head": Allowed,
94 "hexdump": Allowed,
95 "hostname": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -070096 "id": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070097 "jar": Allowed,
98 "java": Allowed,
99 "javap": Allowed,
100 "ln": Allowed,
101 "ls": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700102 "lsof": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700103 "m4": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700104 "md5sum": Allowed,
105 "mkdir": Allowed,
106 "mktemp": Allowed,
107 "mv": Allowed,
Dan Willemsen2d31ace2018-08-30 16:51:42 -0700108 "od": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700109 "openssl": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700110 "paste": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700111 "patch": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700112 "pgrep": Allowed,
113 "pkill": Allowed,
Dan Willemsen42740f22018-08-15 10:14:40 -0700114 "ps": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700115 "pstree": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700116 "pwd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700117 "python": Allowed,
118 "python2.7": Allowed,
119 "python3": Allowed,
120 "readlink": Allowed,
121 "realpath": Allowed,
122 "rm": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700123 "rmdir": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700124 "rsync": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700125 "sed": Allowed,
126 "setsid": Allowed,
127 "sh": Allowed,
Dan Willemsenf6d30062018-06-01 10:58:58 -0700128 "sha1sum": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700129 "sha256sum": Allowed,
130 "sha512sum": Allowed,
Dan Willemsen16dbb392018-06-06 11:02:42 -0700131 "sleep": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700132 "sort": Allowed,
133 "stat": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700134 "tar": Allowed,
135 "tail": Allowed,
Dan Willemsen090ec582018-08-31 08:12:22 +0000136 "tee": Allowed,
Elliott Hughesbe3cfa52018-10-27 08:09:18 -0700137 "timeout": Allowed,
Dan Willemsen7a08bc52018-08-28 00:18:02 -0700138 "todos": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700139 "touch": Allowed,
140 "tr": Allowed,
141 "true": Allowed,
142 "uname": Allowed,
143 "uniq": Allowed,
Dan Willemsen6fa18f42018-08-29 10:26:47 -0700144 "unix2dos": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700145 "unzip": Allowed,
146 "wc": Allowed,
147 "which": Allowed,
148 "whoami": Allowed,
149 "xargs": Allowed,
Dan Willemsen14eae192018-08-14 23:02:11 -0700150 "xxd": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700151 "xz": Allowed,
152 "zip": Allowed,
153 "zipinfo": Allowed,
154
155 // Host toolchain is removed. In-tree toolchain should be used instead.
156 // GCC also can't find cc1 with this implementation.
157 "ar": Forbidden,
158 "as": Forbidden,
159 "cc": Forbidden,
160 "clang": Forbidden,
161 "clang++": Forbidden,
162 "gcc": Forbidden,
163 "g++": Forbidden,
164 "ld": Forbidden,
165 "ld.bfd": Forbidden,
166 "ld.gold": Forbidden,
167 "pkg-config": Forbidden,
168
169 // We've got prebuilts of these
170 //"dtc": Forbidden,
171 //"lz4": Forbidden,
172 //"lz4c": Forbidden,
173}
174
175func init() {
176 if runtime.GOOS == "darwin" {
177 Configuration["md5"] = Allowed
178 Configuration["sw_vers"] = Allowed
179 Configuration["xcrun"] = Allowed
180 }
181}