blob: bfe662dd1286439049ab87e9101aeb9563a96f95 [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,
Dan Willemsen0f021462019-02-17 12:24:24 -080078 "dd": Allowed,
79 "diff": Allowed,
Colin Crossaa812d12019-06-19 13:33:24 -070080 "dlv": Allowed,
Elliott Hughes3a653f42019-05-01 12:52:25 -070081 "expr": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080082 "fuser": Allowed,
83 "getopt": Allowed,
84 "git": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080085 "hexdump": Allowed,
86 "jar": Allowed,
87 "java": Allowed,
88 "javap": Allowed,
89 "lsof": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080090 "openssl": Allowed,
91 "patch": Allowed,
92 "pstree": Allowed,
93 "python3": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080094 "rsync": Allowed,
95 "sh": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080096 "tr": Allowed,
97 "unzip": Allowed,
Dan Willemsen0f021462019-02-17 12:24:24 -080098 "zip": Allowed,
Dan Willemsen18490112018-05-25 16:30:04 -070099
100 // Host toolchain is removed. In-tree toolchain should be used instead.
101 // GCC also can't find cc1 with this implementation.
102 "ar": Forbidden,
103 "as": Forbidden,
104 "cc": Forbidden,
105 "clang": Forbidden,
106 "clang++": Forbidden,
107 "gcc": Forbidden,
108 "g++": Forbidden,
109 "ld": Forbidden,
110 "ld.bfd": Forbidden,
111 "ld.gold": Forbidden,
112 "pkg-config": Forbidden,
113
Elliott Hughesf1ff2262019-08-27 15:17:32 -0700114 // These are toybox tools that only work on Linux.
115 "pgrep": LinuxOnlyPrebuilt,
116 "pkill": LinuxOnlyPrebuilt,
117 "ps": LinuxOnlyPrebuilt,
Dan Willemsen18490112018-05-25 16:30:04 -0700118}
119
120func init() {
121 if runtime.GOOS == "darwin" {
Dan Willemsen18490112018-05-25 16:30:04 -0700122 Configuration["sw_vers"] = Allowed
123 Configuration["xcrun"] = Allowed
Dan Willemsen417be1f2018-10-30 23:18:54 -0700124
Elliott Hughes34b49d12019-09-06 14:42:24 -0700125 // We don't have darwin prebuilts for some tools,
Dan Willemsen91219732019-02-14 20:00:56 -0800126 // so allow the host versions.
Dan Willemsen417be1f2018-10-30 23:18:54 -0700127 for name, config := range Configuration {
Dan Willemsen91219732019-02-14 20:00:56 -0800128 if config.LinuxOnlyPrebuilt {
Dan Willemsen417be1f2018-10-30 23:18:54 -0700129 Configuration[name] = Allowed
130 }
131 }
Dan Willemsen18490112018-05-25 16:30:04 -0700132 }
133}