Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package paths |
| 16 | |
| 17 | import "runtime" |
| 18 | |
| 19 | type 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 Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 28 | |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 29 | // Whether we use a linux-specific prebuilt for this tool. On Darwin, |
| 30 | // we'll allow the host executable instead. |
| 31 | LinuxOnlyPrebuilt bool |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | var Allowed = PathConfig{ |
| 35 | Symlink: true, |
| 36 | Log: false, |
| 37 | Error: false, |
| 38 | } |
| 39 | |
| 40 | var Forbidden = PathConfig{ |
| 41 | Symlink: false, |
| 42 | Log: true, |
| 43 | Error: true, |
| 44 | } |
| 45 | |
Dan Willemsen | 3eec9c5 | 2018-10-04 23:21:40 +0000 | [diff] [blame] | 46 | var Log = PathConfig{ |
| 47 | Symlink: true, |
Dan Willemsen | e9e20dd | 2018-10-09 23:23:19 +0000 | [diff] [blame] | 48 | Log: true, |
| 49 | Error: false, |
Dan Willemsen | 3eec9c5 | 2018-10-04 23:21:40 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 52 | // The configuration used if the tool is not listed in the config below. |
Dan Willemsen | 8125d2a | 2018-08-15 15:26:39 -0700 | [diff] [blame] | 53 | // 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 Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 56 | var Missing = PathConfig{ |
| 57 | Symlink: true, |
| 58 | Log: true, |
Dan Willemsen | 8125d2a | 2018-08-15 15:26:39 -0700 | [diff] [blame] | 59 | Error: true, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 62 | var LinuxOnlyPrebuilt = PathConfig{ |
| 63 | Symlink: false, |
| 64 | Log: true, |
| 65 | Error: true, |
| 66 | LinuxOnlyPrebuilt: true, |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 69 | func GetConfig(name string) PathConfig { |
| 70 | if config, ok := Configuration[name]; ok { |
| 71 | return config |
| 72 | } |
| 73 | return Missing |
| 74 | } |
| 75 | |
| 76 | var Configuration = map[string]PathConfig{ |
Dan Willemsen | 0f02146 | 2019-02-17 12:24:24 -0800 | [diff] [blame] | 77 | "bash": Allowed, |
| 78 | "bc": Allowed, |
| 79 | "bzip2": Allowed, |
| 80 | "date": Allowed, |
| 81 | "dd": Allowed, |
| 82 | "diff": Allowed, |
| 83 | "egrep": Allowed, |
| 84 | "find": Allowed, |
| 85 | "fuser": Allowed, |
| 86 | "getopt": Allowed, |
| 87 | "git": Allowed, |
| 88 | "grep": Allowed, |
| 89 | "gzip": Allowed, |
| 90 | "hexdump": Allowed, |
| 91 | "jar": Allowed, |
| 92 | "java": Allowed, |
| 93 | "javap": Allowed, |
| 94 | "lsof": Allowed, |
| 95 | "m4": Allowed, |
| 96 | "openssl": Allowed, |
| 97 | "patch": Allowed, |
| 98 | "pstree": Allowed, |
| 99 | "python3": Allowed, |
| 100 | "realpath": Allowed, |
| 101 | "rsync": Allowed, |
| 102 | "sh": Allowed, |
| 103 | "tar": Allowed, |
| 104 | "timeout": Allowed, |
| 105 | "tr": Allowed, |
| 106 | "unzip": Allowed, |
| 107 | "xz": Allowed, |
| 108 | "zip": Allowed, |
| 109 | "zipinfo": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 110 | |
| 111 | // Host toolchain is removed. In-tree toolchain should be used instead. |
| 112 | // GCC also can't find cc1 with this implementation. |
| 113 | "ar": Forbidden, |
| 114 | "as": Forbidden, |
| 115 | "cc": Forbidden, |
| 116 | "clang": Forbidden, |
| 117 | "clang++": Forbidden, |
| 118 | "gcc": Forbidden, |
| 119 | "g++": Forbidden, |
| 120 | "ld": Forbidden, |
| 121 | "ld.bfd": Forbidden, |
| 122 | "ld.gold": Forbidden, |
| 123 | "pkg-config": Forbidden, |
| 124 | |
Elliott Hughes | c97a911 | 2019-01-11 13:34:13 -0800 | [diff] [blame] | 125 | // On Linux we'll use the toybox versions of these instead. |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 126 | "basename": LinuxOnlyPrebuilt, |
| 127 | "cat": LinuxOnlyPrebuilt, |
| 128 | "chmod": LinuxOnlyPrebuilt, |
| 129 | "cmp": LinuxOnlyPrebuilt, |
| 130 | "cp": LinuxOnlyPrebuilt, |
| 131 | "comm": LinuxOnlyPrebuilt, |
| 132 | "cut": LinuxOnlyPrebuilt, |
| 133 | "dirname": LinuxOnlyPrebuilt, |
| 134 | "du": LinuxOnlyPrebuilt, |
| 135 | "echo": LinuxOnlyPrebuilt, |
| 136 | "env": LinuxOnlyPrebuilt, |
| 137 | "expr": LinuxOnlyPrebuilt, |
| 138 | "head": LinuxOnlyPrebuilt, |
| 139 | "getconf": LinuxOnlyPrebuilt, |
| 140 | "hostname": LinuxOnlyPrebuilt, |
| 141 | "id": LinuxOnlyPrebuilt, |
| 142 | "ln": LinuxOnlyPrebuilt, |
| 143 | "ls": LinuxOnlyPrebuilt, |
| 144 | "md5sum": LinuxOnlyPrebuilt, |
| 145 | "mkdir": LinuxOnlyPrebuilt, |
| 146 | "mktemp": LinuxOnlyPrebuilt, |
| 147 | "mv": LinuxOnlyPrebuilt, |
| 148 | "od": LinuxOnlyPrebuilt, |
| 149 | "paste": LinuxOnlyPrebuilt, |
| 150 | "pgrep": LinuxOnlyPrebuilt, |
| 151 | "pkill": LinuxOnlyPrebuilt, |
| 152 | "ps": LinuxOnlyPrebuilt, |
| 153 | "pwd": LinuxOnlyPrebuilt, |
| 154 | "readlink": LinuxOnlyPrebuilt, |
| 155 | "rm": LinuxOnlyPrebuilt, |
| 156 | "rmdir": LinuxOnlyPrebuilt, |
Elliott Hughes | 47de2a2 | 2019-01-24 15:19:30 -0800 | [diff] [blame] | 157 | "sed": LinuxOnlyPrebuilt, |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 158 | "setsid": LinuxOnlyPrebuilt, |
| 159 | "sha1sum": LinuxOnlyPrebuilt, |
| 160 | "sha256sum": LinuxOnlyPrebuilt, |
| 161 | "sha512sum": LinuxOnlyPrebuilt, |
| 162 | "sleep": LinuxOnlyPrebuilt, |
| 163 | "sort": LinuxOnlyPrebuilt, |
| 164 | "stat": LinuxOnlyPrebuilt, |
| 165 | "tail": LinuxOnlyPrebuilt, |
| 166 | "tee": LinuxOnlyPrebuilt, |
| 167 | "touch": LinuxOnlyPrebuilt, |
| 168 | "true": LinuxOnlyPrebuilt, |
| 169 | "uname": LinuxOnlyPrebuilt, |
| 170 | "uniq": LinuxOnlyPrebuilt, |
| 171 | "unix2dos": LinuxOnlyPrebuilt, |
| 172 | "wc": LinuxOnlyPrebuilt, |
| 173 | "whoami": LinuxOnlyPrebuilt, |
| 174 | "which": LinuxOnlyPrebuilt, |
| 175 | "xargs": LinuxOnlyPrebuilt, |
| 176 | "xxd": LinuxOnlyPrebuilt, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | func init() { |
| 180 | if runtime.GOOS == "darwin" { |
| 181 | Configuration["md5"] = Allowed |
| 182 | Configuration["sw_vers"] = Allowed |
| 183 | Configuration["xcrun"] = Allowed |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 184 | |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 185 | // We don't have darwin prebuilts for some tools (like toybox), |
| 186 | // so allow the host versions. |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 187 | for name, config := range Configuration { |
Dan Willemsen | 9121973 | 2019-02-14 20:00:56 -0800 | [diff] [blame] | 188 | if config.LinuxOnlyPrebuilt { |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 189 | Configuration[name] = Allowed |
| 190 | } |
| 191 | } |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 192 | } |
| 193 | } |