blob: 738ef40b155406222f091901df960f25eb307ba7 [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 Hughes2ee8b332019-07-22 20:24:17 -070077 "bash": Allowed,
78 "bc": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080079 "dd": Allowed,
80 "diff": Allowed,
Colin Crossaa812d12019-06-19 13:33:24 -070081 "dlv": Allowed,
Elliott Hughes3a653f42019-05-01 12:52:25 -070082 "expr": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080083 "find": Allowed,
84 "fuser": Allowed,
85 "getopt": Allowed,
86 "git": Allowed,
Elliott Hughese671f5a2019-06-19 14:02:02 -070087 "gzcat": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080088 "gzip": Allowed,
89 "hexdump": Allowed,
90 "jar": Allowed,
91 "java": Allowed,
92 "javap": Allowed,
93 "lsof": Allowed,
Dan Willemsenc69d7152019-06-19 10:54:50 -070094 "m4": Log,
Dan Willemsen0f021462019-02-17 12:24:24 -080095 "openssl": Allowed,
96 "patch": Allowed,
97 "pstree": Allowed,
98 "python3": Allowed,
99 "realpath": Allowed,
100 "rsync": Allowed,
101 "sh": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -0800102 "tr": Allowed,
103 "unzip": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -0800104 "zip": Allowed,
105 "zipinfo": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700106
107 // Host toolchain is removed. In-tree toolchain should be used instead.
108 // GCC also can't find cc1 with this implementation.
109 "ar": Forbidden,
110 "as": Forbidden,
111 "cc": Forbidden,
112 "clang": Forbidden,
113 "clang++": Forbidden,
114 "gcc": Forbidden,
115 "g++": Forbidden,
116 "ld": Forbidden,
117 "ld.bfd": Forbidden,
118 "ld.gold": Forbidden,
119 "pkg-config": Forbidden,
120
Elliott Hughesf1ff2262019-08-27 15:17:32 -0700121 // These are currently Linux-only toybox tools (but can be switched now).
122 "date": LinuxOnlyPrebuilt,
123 "stat": LinuxOnlyPrebuilt,
124
125 // These are toybox tools that only work on Linux.
126 "pgrep": LinuxOnlyPrebuilt,
127 "pkill": LinuxOnlyPrebuilt,
128 "ps": LinuxOnlyPrebuilt,
Dan Willemsen18490112018-05-25 16:30:04 -0700129}
130
131func init() {
132 if runtime.GOOS == "darwin" {
Elliott Hughesf1ff2262019-08-27 15:17:32 -0700133 // TODO: move Darwin off md5 and onto our md5sum prebuilt.
Dan Willemsen18490112018-05-25 16:30:04 -0700134 Configuration["md5"] = Allowed
135 Configuration["sw_vers"] = Allowed
136 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700137
Dan Willemsen91219732019-02-14 20:00:56 -0800138 // We don't have darwin prebuilts for some tools (like toybox),
139 // so allow the host versions.
Dan Willemsen417be1f2018-10-30 23:18:54 -0700140 for name, config := range Configuration {
Dan Willemsen91219732019-02-14 20:00:56 -0800141 if config.LinuxOnlyPrebuilt {
Dan Willemsen417be1f2018-10-30 23:18:54 -0700142 Configuration[name] = Allowed
143 }
144 }
Dan Willemsen18490112018-05-25 16:30:04 -0700145 }
146}