blob: eba823ae2b80a32a216803712f64c7b3950c22b8 [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
Lukacs T. Berki2388f642022-05-06 12:42:05 +020034// These binaries can be run from $PATH, nonhermetically. There should be as
35// few as possible of these, since this means that the build depends on tools
36// that are not shipped in the source tree and whose behavior is therefore
37// unpredictable.
Dan Willemsen18490112018-05-25 16:30:04 -070038var Allowed = PathConfig{
39 Symlink: true,
40 Log: false,
41 Error: false,
42}
43
Lukacs T. Berki2388f642022-05-06 12:42:05 +020044// This tool is specifically disallowed and calling it will result in an
45// "executable no found" error.
Dan Willemsen18490112018-05-25 16:30:04 -070046var Forbidden = PathConfig{
47 Symlink: false,
48 Log: true,
49 Error: true,
50}
51
Lukacs T. Berki2388f642022-05-06 12:42:05 +020052// This tool is allowed, but access to it will be logged.
Dan Willemsen3eec9c52018-10-04 23:21:40 +000053var Log = PathConfig{
54 Symlink: true,
Dan Willemsene9e20dd2018-10-09 23:23:19 +000055 Log: true,
56 Error: false,
Dan Willemsen3eec9c52018-10-04 23:21:40 +000057}
58
Dan Willemsen18490112018-05-25 16:30:04 -070059// The configuration used if the tool is not listed in the config below.
Dan Willemsen8125d2a2018-08-15 15:26:39 -070060// Currently this will create the symlink, but log and error when it's used. In
61// the future, I expect the symlink to be removed, and this will be equivalent
Lukacs T. Berki2388f642022-05-06 12:42:05 +020062// to Forbidden. This applies to every tool not specifically mentioned in the
63// configuration.
Dan Willemsen18490112018-05-25 16:30:04 -070064var Missing = PathConfig{
65 Symlink: true,
66 Log: true,
Dan Willemsen8125d2a2018-08-15 15:26:39 -070067 Error: true,
Dan Willemsen18490112018-05-25 16:30:04 -070068}
69
Lukacs T. Berki2388f642022-05-06 12:42:05 +020070// This is used for binaries for which we have prebuilt versions, but only for
71// Linux. Thus, their execution from $PATH is only allowed on Mac OS.
Dan Willemsen91219732019-02-14 20:00:56 -080072var LinuxOnlyPrebuilt = PathConfig{
73 Symlink: false,
74 Log: true,
75 Error: true,
76 LinuxOnlyPrebuilt: true,
Dan Willemsen417be1f2018-10-30 23:18:54 -070077}
78
Dan Willemsen18490112018-05-25 16:30:04 -070079func GetConfig(name string) PathConfig {
80 if config, ok := Configuration[name]; ok {
81 return config
82 }
83 return Missing
84}
85
Lukacs T. Berki2388f642022-05-06 12:42:05 +020086// This list specifies whether a particular binary from $PATH is allowed to be
87// run during the build. For more documentation, see path_interposer.go .
Dan Willemsen18490112018-05-25 16:30:04 -070088var Configuration = map[string]PathConfig{
Kousik Kumar5c5c57d2023-06-05 10:57:07 -040089 "bash": Allowed,
Kousik Kumar5c5c57d2023-06-05 10:57:07 -040090 "diff": Allowed,
91 "dlv": Allowed,
92 "expr": Allowed,
93 "fuser": Allowed,
94 "gcert": Allowed,
95 "getopt": Allowed,
96 "git": Allowed,
97 "hexdump": Allowed,
98 "jar": Allowed,
99 "java": Allowed,
100 "javap": Allowed,
101 "lsof": Allowed,
102 "openssl": Allowed,
103 "prodcertstatus": Allowed,
104 "pstree": Allowed,
105 "rsync": Allowed,
106 "sh": Allowed,
107 "stubby": Allowed,
108 "tr": Allowed,
109 "unzip": Allowed,
110 "zip": 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 Hughesf1ff2262019-08-27 15:17:32 -0700126 // These are toybox tools that only work on Linux.
127 "pgrep": LinuxOnlyPrebuilt,
128 "pkill": LinuxOnlyPrebuilt,
129 "ps": LinuxOnlyPrebuilt,
Dan Willemsen18490112018-05-25 16:30:04 -0700130}
131
132func init() {
133 if runtime.GOOS == "darwin" {
Dan Willemsen18490112018-05-25 16:30:04 -0700134 Configuration["sw_vers"] = Allowed
135 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700136
Elliott Hughes34b49d12019-09-06 14:42:24 -0700137 // We don't have darwin prebuilts for some tools,
Dan Willemsen91219732019-02-14 20:00:56 -0800138 // so allow the host versions.
Dan Willemsen417be1f2018-10-30 23:18:54 -0700139 for name, config := range Configuration {
Dan Willemsen91219732019-02-14 20:00:56 -0800140 if config.LinuxOnlyPrebuilt {
Dan Willemsen417be1f2018-10-30 23:18:54 -0700141 Configuration[name] = Allowed
142 }
143 }
Dan Willemsen18490112018-05-25 16:30:04 -0700144 }
145}