| 173 | } |
| 174 | |
| 175 | rdcstr getToolPath(ToolDir subdir, const rdcstr &toolname, bool checkExist) |
| 176 | { |
| 177 | // search path for tools: |
| 178 | // 1. First look relative to the configured paths, these come from the user manually setting them |
| 179 | // so they always have priority. |
| 180 | // 2. Next we try to auto-locate it. |
| 181 | // - First check if the tool is in the path, assuming the user configured it to their system. |
| 182 | // - Otherwise check environment variables or default locations |
| 183 | // 3. Finally if those paths don't exist or the tool isn't found, we search relative to our |
| 184 | // executable looking for an android/ subfolder, and look for the tool in there. |
| 185 | // |
| 186 | // The main reason we check our bundled folder last is because adb requires a *precise* match in |
| 187 | // its client-server setup, so if we run our bundled adb that might be newer than the user's, they |
| 188 | // will then get fighting back and forth when trying to run their own. |
| 189 | |
| 190 | rdcstr sdk = Android_SDKDirPath(); |
| 191 | rdcstr jdk = Android_JDKDirPath(); |
| 192 | |
| 193 | ToolPathCache &cache = getCache(); |
| 194 | |
| 195 | // invalidate the cache when these settings change |
| 196 | if(sdk != cache.sdk || jdk != cache.jdk) |
| 197 | { |
| 198 | cache.paths.clear(); |
| 199 | cache.sdk = sdk; |
| 200 | cache.jdk = jdk; |
| 201 | } |
| 202 | |
| 203 | // if we have the path cached and it's still valid, return it |
| 204 | if(toolExists(cache.paths[toolname])) |
| 205 | return cache.paths[toolname]; |
| 206 | |
| 207 | rdcstr &toolpath = cache.paths[toolname]; |
| 208 | |
| 209 | // first try according to the configured paths |
| 210 | toolpath = getToolInSDK(subdir, jdk, sdk, toolname); |
| 211 | |
| 212 | if(toolExists(toolpath)) |
| 213 | return toolpath; |
| 214 | |
| 215 | // need to try to auto-guess the tool's location |
| 216 | |
| 217 | // first try in PATH |
| 218 | if(subdir != ToolDir::None) |
| 219 | { |
| 220 | toolpath = FileIO::FindFileInPath(toolname); |
| 221 | |
| 222 | if(toolExists(toolpath)) |
| 223 | return toolpath; |
| 224 | |
| 225 | // if the tool name contains a .jar then try stripping that and look for the non-.jar version in |
| 226 | // the PATH. |
| 227 | if(toolname.contains(".jar")) |
| 228 | { |
| 229 | toolpath = strip_extension(toolname); |
| 230 | toolpath = FileIO::FindFileInPath(toolpath); |
| 231 | |
| 232 | if(toolExists(toolpath)) |
no test coverage detected