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