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 |
| 28 | } |
| 29 | |
| 30 | var Allowed = PathConfig{ |
| 31 | Symlink: true, |
| 32 | Log: false, |
| 33 | Error: false, |
| 34 | } |
| 35 | |
| 36 | var Forbidden = PathConfig{ |
| 37 | Symlink: false, |
| 38 | Log: true, |
| 39 | Error: true, |
| 40 | } |
| 41 | |
| 42 | // The configuration used if the tool is not listed in the config below. |
| 43 | // Currently this will create the symlink, but log a warning. In the future, |
| 44 | // I expect this to move closer to Forbidden. |
| 45 | var Missing = PathConfig{ |
| 46 | Symlink: true, |
| 47 | Log: true, |
| 48 | Error: false, |
| 49 | } |
| 50 | |
| 51 | func GetConfig(name string) PathConfig { |
| 52 | if config, ok := Configuration[name]; ok { |
| 53 | return config |
| 54 | } |
| 55 | return Missing |
| 56 | } |
| 57 | |
| 58 | var Configuration = map[string]PathConfig{ |
| 59 | "awk": Allowed, |
| 60 | "basename": Allowed, |
| 61 | "bash": Allowed, |
| 62 | "bzip2": Allowed, |
| 63 | "cat": Allowed, |
| 64 | "chmod": Allowed, |
| 65 | "cmp": Allowed, |
| 66 | "comm": Allowed, |
| 67 | "cp": Allowed, |
| 68 | "cut": Allowed, |
| 69 | "date": Allowed, |
| 70 | "dd": Allowed, |
| 71 | "diff": Allowed, |
| 72 | "dirname": Allowed, |
| 73 | "echo": Allowed, |
| 74 | "egrep": Allowed, |
| 75 | "env": Allowed, |
| 76 | "expr": Allowed, |
| 77 | "find": Allowed, |
| 78 | "getconf": Allowed, |
| 79 | "getopt": Allowed, |
| 80 | "git": Allowed, |
| 81 | "grep": Allowed, |
| 82 | "gzip": Allowed, |
| 83 | "head": Allowed, |
| 84 | "hexdump": Allowed, |
| 85 | "hostname": Allowed, |
Dan Willemsen | f6d3006 | 2018-06-01 10:58:58 -0700 | [diff] [blame] | 86 | "id": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 87 | "jar": Allowed, |
| 88 | "java": Allowed, |
| 89 | "javap": Allowed, |
| 90 | "ln": Allowed, |
| 91 | "ls": Allowed, |
| 92 | "m4": Allowed, |
| 93 | "make": Allowed, |
| 94 | "md5sum": Allowed, |
| 95 | "mkdir": Allowed, |
| 96 | "mktemp": Allowed, |
| 97 | "mv": Allowed, |
| 98 | "openssl": Allowed, |
| 99 | "patch": Allowed, |
| 100 | "perl": Allowed, |
| 101 | "pstree": Allowed, |
| 102 | "python": Allowed, |
| 103 | "python2.7": Allowed, |
| 104 | "python3": Allowed, |
| 105 | "readlink": Allowed, |
| 106 | "realpath": Allowed, |
| 107 | "rm": Allowed, |
Dan Willemsen | f6d3006 | 2018-06-01 10:58:58 -0700 | [diff] [blame] | 108 | "rmdir": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 109 | "rsync": Allowed, |
| 110 | "runalarm": Allowed, |
| 111 | "sed": Allowed, |
| 112 | "setsid": Allowed, |
| 113 | "sh": Allowed, |
Dan Willemsen | f6d3006 | 2018-06-01 10:58:58 -0700 | [diff] [blame] | 114 | "sha1sum": Allowed, |
Dan Willemsen | 1849011 | 2018-05-25 16:30:04 -0700 | [diff] [blame] | 115 | "sha256sum": Allowed, |
| 116 | "sha512sum": Allowed, |
| 117 | "sort": Allowed, |
| 118 | "stat": Allowed, |
| 119 | "sum": Allowed, |
| 120 | "tar": Allowed, |
| 121 | "tail": Allowed, |
| 122 | "touch": Allowed, |
| 123 | "tr": Allowed, |
| 124 | "true": Allowed, |
| 125 | "uname": Allowed, |
| 126 | "uniq": Allowed, |
| 127 | "unzip": Allowed, |
| 128 | "wc": Allowed, |
| 129 | "which": Allowed, |
| 130 | "whoami": Allowed, |
| 131 | "xargs": Allowed, |
| 132 | "xmllint": Allowed, |
| 133 | "xz": Allowed, |
| 134 | "zip": Allowed, |
| 135 | "zipinfo": Allowed, |
| 136 | |
| 137 | // Host toolchain is removed. In-tree toolchain should be used instead. |
| 138 | // GCC also can't find cc1 with this implementation. |
| 139 | "ar": Forbidden, |
| 140 | "as": Forbidden, |
| 141 | "cc": Forbidden, |
| 142 | "clang": Forbidden, |
| 143 | "clang++": Forbidden, |
| 144 | "gcc": Forbidden, |
| 145 | "g++": Forbidden, |
| 146 | "ld": Forbidden, |
| 147 | "ld.bfd": Forbidden, |
| 148 | "ld.gold": Forbidden, |
| 149 | "pkg-config": Forbidden, |
| 150 | |
| 151 | // We've got prebuilts of these |
| 152 | //"dtc": Forbidden, |
| 153 | //"lz4": Forbidden, |
| 154 | //"lz4c": Forbidden, |
| 155 | } |
| 156 | |
| 157 | func init() { |
| 158 | if runtime.GOOS == "darwin" { |
| 159 | Configuration["md5"] = Allowed |
| 160 | Configuration["sw_vers"] = Allowed |
| 161 | Configuration["xcrun"] = Allowed |
| 162 | } |
| 163 | } |