blob: bd7f3d0c0e1da4ec4e5a01d7365c0249a2c19df6 [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
Cole Faust5bd681b2025-01-17 15:28:21 -080045// "executable not 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{
Colin Cross8a49a3d2024-05-20 12:22:27 -070089 "bash": Allowed,
90 "diff": Allowed,
91 "dlv": Allowed,
92 "expr": Allowed,
93 "fuser": Allowed,
94 "gcert": Allowed,
95 "gcertstatus": Allowed,
96 "gcloud": Allowed,
97 "git": Allowed,
98 "hexdump": Allowed,
99 "jar": Allowed,
100 "java": Allowed,
101 "javap": Allowed,
102 "lsof": Allowed,
103 "openssl": Allowed,
104 "pstree": Allowed,
105 "rsync": Allowed,
106 "sh": Allowed,
107 "stubby": Allowed,
108 "tr": Allowed,
109 "unzip": Allowed,
110 "zip": Allowed,
Ali Hasande991e92020-10-03 10:56:20 +0500111 "nproc": Allowed,
112 "perl": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -0700113
114 // Host toolchain is removed. In-tree toolchain should be used instead.
115 // GCC also can't find cc1 with this implementation.
116 "ar": Forbidden,
117 "as": Forbidden,
118 "cc": Forbidden,
119 "clang": Forbidden,
120 "clang++": Forbidden,
121 "gcc": Forbidden,
122 "g++": Forbidden,
123 "ld": Forbidden,
124 "ld.bfd": Forbidden,
125 "ld.gold": Forbidden,
126 "pkg-config": Forbidden,
Cole Faust5bd681b2025-01-17 15:28:21 -0800127 "python": Forbidden,
128 "python2": Forbidden,
129 "python2.7": Forbidden,
130 "python3": Forbidden,
Dan Willemsen18490112018-05-25 16:30:04 -0700131
Elliott Hughesf1ff2262019-08-27 15:17:32 -0700132 // These are toybox tools that only work on Linux.
133 "pgrep": LinuxOnlyPrebuilt,
134 "pkill": LinuxOnlyPrebuilt,
135 "ps": LinuxOnlyPrebuilt,
Dan Willemsen18490112018-05-25 16:30:04 -0700136}
137
138func init() {
139 if runtime.GOOS == "darwin" {
Dan Willemsen18490112018-05-25 16:30:04 -0700140 Configuration["sw_vers"] = Allowed
141 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700142
Elliott Hughes34b49d12019-09-06 14:42:24 -0700143 // We don't have darwin prebuilts for some tools,
Dan Willemsen91219732019-02-14 20:00:56 -0800144 // so allow the host versions.
Dan Willemsen417be1f2018-10-30 23:18:54 -0700145 for name, config := range Configuration {
Dan Willemsen91219732019-02-14 20:00:56 -0800146 if config.LinuxOnlyPrebuilt {
Dan Willemsen417be1f2018-10-30 23:18:54 -0700147 Configuration[name] = Allowed
148 }
149 }
Dan Willemsen18490112018-05-25 16:30:04 -0700150 }
151}