1 /*********************************************************************
3 * Copyright 2011 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 *********************************************************************/
31 #include "os_string.hpp"
33 #include "cli_resources.hpp"
37 tryPath(const os::String &path, bool verbose)
39 bool exists = path.exists();
41 std::cerr << "info: " << (exists ? "found" : "did not find") << " " << path.str() << "\n";
47 findProgram(const char *programFilename, bool verbose)
49 os::String programPath;
51 os::String processDir = os::getProcessName();
52 processDir.trimFilename();
54 programPath = processDir;
55 programPath.join(programFilename);
56 if (tryPath(programPath, verbose)) {
61 // Try absolute install directory
62 programPath = APITRACE_PROGRAMS_INSTALL_DIR;
63 programPath.join(programFilename);
64 if (tryPath(programPath, verbose)) {
73 findWrapper(const char *wrapperFilename, bool verbose)
75 os::String wrapperPath;
77 os::String processDir = os::getProcessName();
78 processDir.trimFilename();
80 // Try relative build directory
81 // XXX: Just make build and install directory layout match
82 wrapperPath = processDir;
83 #if defined(APITRACE_CONFIGURATION_SUBDIR)
84 // Go from `Debug\apitrace.exe` to `wrappers\Debug\foo.dll` on MSVC builds.
85 wrapperPath.join("..");
86 wrapperPath.join("wrappers");
87 wrapperPath.join(APITRACE_CONFIGURATION_SUBDIR);
89 wrapperPath.join("wrappers");
91 wrapperPath.join(wrapperFilename);
92 if (tryPath(wrapperPath, verbose)) {
96 // Try relative install directory
97 wrapperPath = processDir;
99 wrapperPath.join("..\\lib\\wrappers");
100 #elif defined(__APPLE__)
101 wrapperPath.join("../lib/wrappers");
103 wrapperPath.join("../lib/apitrace/wrappers");
105 wrapperPath.join(wrapperFilename);
106 if (tryPath(wrapperPath, verbose)) {
111 // Try absolute install directory
112 wrapperPath = APITRACE_WRAPPERS_INSTALL_DIR;
113 wrapperPath.join(wrapperFilename);
114 if (tryPath(wrapperPath, verbose)) {
123 findScript(const char *scriptFilename, bool verbose)
125 os::String scriptPath;
127 os::String processDir = os::getProcessName();
128 processDir.trimFilename();
130 // Try relative build directory
131 // XXX: Just make build and install directory layout match
132 #if defined(APITRACE_SOURCE_DIR)
133 scriptPath = APITRACE_SOURCE_DIR;
134 scriptPath.join("scripts");
135 scriptPath.join(scriptFilename);
136 if (tryPath(scriptPath, verbose)) {
141 // Try relative install directory
142 scriptPath = processDir;
144 scriptPath.join("..\\lib\\scripts");
145 #elif defined(__APPLE__)
146 scriptPath.join("../lib/scripts");
148 scriptPath.join("../lib/apitrace/scripts");
150 scriptPath.join(scriptFilename);
151 if (tryPath(scriptPath, verbose)) {
156 // Try absolute install directory
157 scriptPath = APITRACE_SCRIPTS_INSTALL_DIR;
158 scriptPath.join(scriptFilename);
159 if (tryPath(scriptPath, verbose)) {
164 std::cerr << "error: cannot find " << scriptFilename << " script\n";