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 | |
| 29 | // Whether we use a toybox prebuilt for this tool. Since we don't have |
| 30 | // toybox for Darwin, we'll use the host version instead. |
| 31 | Toybox 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 | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 62 | var Toybox = PathConfig{ |
| 63 | Symlink: false, |
| 64 | Log: true, |
| 65 | Error: true, |
| 66 | Toybox: true, |
| 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{ |
| 77 | "awk": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 78 | "bash": Allowed, |
Dan Willemsen | 16dbb39 | 2018-06-06 11:02:42 -0700 | [diff] [blame] | 79 | "bc": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 80 | "bzip2": Allowed, |
Elliott Hughes | c33514e | 2019-01-10 06:02:12 +0000 | [diff] [blame] | 81 | "cp": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 82 | "date": Allowed, |
| 83 | "dd": Allowed, |
| 84 | "diff": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 85 | "egrep": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 86 | "find": Allowed, |
Dan Willemsen | b4d0144 | 2018-08-27 16:14:23 -0700 | [diff] [blame] | 87 | "fuser": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 88 | "getconf": Allowed, |
| 89 | "getopt": Allowed, |
| 90 | "git": Allowed, |
| 91 | "grep": Allowed, |
| 92 | "gzip": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 93 | "hexdump": Allowed, |
| 94 | "hostname": Allowed, |
| 95 | "jar": Allowed, |
| 96 | "java": Allowed, |
| 97 | "javap": Allowed, |
Dan Willemsen | 42740f2 | 2018-08-15 10:14:40 -0700 | [diff] [blame] | 98 | "lsof": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 99 | "m4": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 100 | "md5sum": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 101 | "mktemp": Allowed, |
| 102 | "mv": Allowed, |
| 103 | "openssl": Allowed, |
| 104 | "patch": Allowed, |
Dan Willemsen | 16dbb39 | 2018-06-06 11:02:42 -0700 | [diff] [blame] | 105 | "pgrep": Allowed, |
| 106 | "pkill": Allowed, |
Dan Willemsen | 42740f2 | 2018-08-15 10:14:40 -0700 | [diff] [blame] | 107 | "ps": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 108 | "pstree": Allowed, |
| 109 | "python": Allowed, |
| 110 | "python2.7": Allowed, |
| 111 | "python3": Allowed, |
| 112 | "readlink": Allowed, |
| 113 | "realpath": Allowed, |
| 114 | "rm": Allowed, |
| 115 | "rsync": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 116 | "sh": Allowed, |
Dan Willemsen | f6d3006 | 2018-06-01 10:58:58 -0700 | [diff] [blame] | 117 | "sha1sum": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 118 | "sha256sum": Allowed, |
| 119 | "sha512sum": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 120 | "sort": Allowed, |
| 121 | "stat": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 122 | "tar": Allowed, |
Elliott Hughes | be3cfa5 | 2018-10-27 08:09:18 -0700 | [diff] [blame] | 123 | "timeout": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 124 | "tr": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 125 | "unzip": Allowed, |
| 126 | "wc": Allowed, |
| 127 | "which": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 128 | "xargs": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 129 | "xz": Allowed, |
| 130 | "zip": Allowed, |
| 131 | "zipinfo": Allowed, |
| 132 | |
| 133 | // Host toolchain is removed. In-tree toolchain should be used instead. |
| 134 | // GCC also can't find cc1 with this implementation. |
| 135 | "ar": Forbidden, |
| 136 | "as": Forbidden, |
| 137 | "cc": Forbidden, |
| 138 | "clang": Forbidden, |
| 139 | "clang++": Forbidden, |
| 140 | "gcc": Forbidden, |
| 141 | "g++": Forbidden, |
| 142 | "ld": Forbidden, |
| 143 | "ld.bfd": Forbidden, |
| 144 | "ld.gold": Forbidden, |
| 145 | "pkg-config": Forbidden, |
| 146 | |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 147 | // On linux we'll use the toybox version of these instead |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 148 | "basename": Toybox, |
| 149 | "cat": Toybox, |
Elliott Hughes | 97295bd | 2018-12-17 14:55:10 -0800 | [diff] [blame] | 150 | "chmod": Toybox, |
Elliott Hughes | 6646904 | 2018-12-05 10:03:31 -0800 | [diff] [blame] | 151 | "cmp": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 152 | "comm": Toybox, |
Elliott Hughes | 9add81e | 2018-12-11 09:39:48 -0800 | [diff] [blame] | 153 | "cut": Toybox, |
Elliott Hughes | 2ebfd49 | 2018-12-06 08:57:31 -0800 | [diff] [blame] | 154 | "dirname": Toybox, |
Elliott Hughes | e0e2441 | 2018-12-17 15:08:27 -0800 | [diff] [blame] | 155 | "du": Toybox, |
Elliott Hughes | e1184be | 2018-12-17 15:10:09 -0800 | [diff] [blame] | 156 | "echo": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 157 | "env": Toybox, |
Elliott Hughes | 6491f8d | 2018-12-17 14:50:13 -0800 | [diff] [blame] | 158 | "expr": Toybox, |
Elliott Hughes | ed46164 | 2018-11-26 10:45:08 -0800 | [diff] [blame] | 159 | "head": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 160 | "id": Toybox, |
Elliott Hughes | 3a1fd8e | 2018-12-17 15:07:30 -0800 | [diff] [blame] | 161 | "ln": Toybox, |
Elliott Hughes | 0b11f65 | 2018-12-17 14:52:17 -0800 | [diff] [blame] | 162 | "ls": Toybox, |
Elliott Hughes | cc85770 | 2018-12-06 22:30:45 -0800 | [diff] [blame] | 163 | "mkdir": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 164 | "od": Toybox, |
| 165 | "paste": Toybox, |
| 166 | "pwd": Toybox, |
| 167 | "rmdir": Toybox, |
Elliott Hughes | e259a66 | 2018-12-11 10:16:42 -0800 | [diff] [blame^] | 168 | "sed": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 169 | "setsid": Toybox, |
| 170 | "sleep": Toybox, |
| 171 | "tail": Toybox, |
| 172 | "tee": Toybox, |
Elliott Hughes | 734a780 | 2018-12-07 18:30:52 -0800 | [diff] [blame] | 173 | "touch": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 174 | "true": Toybox, |
| 175 | "uname": Toybox, |
| 176 | "uniq": Toybox, |
Elliott Hughes | 5172a8b | 2018-12-05 19:42:43 -0800 | [diff] [blame] | 177 | "unix2dos": Toybox, |
Elliott Hughes | 6141a7d | 2018-12-04 13:42:46 -0800 | [diff] [blame] | 178 | "whoami": Toybox, |
| 179 | "xxd": Toybox, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | func init() { |
| 183 | if runtime.GOOS == "darwin" { |
| 184 | Configuration["md5"] = Allowed |
| 185 | Configuration["sw_vers"] = Allowed |
| 186 | Configuration["xcrun"] = Allowed |
Dan Willemsen | 417be1f | 2018-10-30 23:18:54 -0700 | [diff] [blame] | 187 | |
| 188 | // We don't have toybox prebuilts for darwin, so allow the |
| 189 | // host versions. |
| 190 | for name, config := range Configuration { |
| 191 | if config.Toybox { |
| 192 | Configuration[name] = Allowed |
| 193 | } |
| 194 | } |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 195 | } |
| 196 | } |