]> git.cworth.org Git - apitrace/blob - cli/cli_resources.cpp
cli: Fix script search for out of source build.
[apitrace] / cli / cli_resources.cpp
1 /*********************************************************************
2  *
3  * Copyright 2011 Intel Corporation
4  * All Rights Reserved.
5  *
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:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
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
24  * SOFTWARE.
25  *
26  *********************************************************************/
27
28
29 #include <iostream>
30
31 #include "os_string.hpp"
32
33 #include "cli_resources.hpp"
34
35
36 os::String
37 findProgram(const char*programFilename)
38 {
39     os::String programPath;
40
41     os::String processDir = os::getProcessName();
42     processDir.trimFilename();
43
44     programPath = processDir;
45     programPath.join(programFilename);
46     if (programPath.exists()) {
47         return programPath;
48     }
49
50 #ifndef _WIN32
51     // Try absolute install directory
52     programPath = APITRACE_PROGRAMS_INSTALL_DIR;
53     programPath.join(programFilename);
54     if (programPath.exists()) {
55         return programPath;
56     }
57 #endif
58
59     return "";
60 }
61
62 os::String
63 findWrapper(const char *wrapperFilename)
64 {
65     os::String wrapperPath;
66
67     os::String processDir = os::getProcessName();
68     processDir.trimFilename();
69
70     // Try relative build directory
71     // XXX: Just make build and install directory layout match
72     wrapperPath = processDir;
73     wrapperPath.join("wrappers");
74     wrapperPath.join(wrapperFilename);
75     if (wrapperPath.exists()) {
76         return wrapperPath;
77     }
78
79     // Try relative install directory
80     wrapperPath = processDir;
81 #if defined(_WIN32)
82     wrapperPath.join("..\\lib\\wrappers");
83 #elif defined(__APPLE__)
84     wrapperPath.join("../lib/wrappers");
85 #else
86     wrapperPath.join("../lib/apitrace/wrappers");
87 #endif
88     wrapperPath.join(wrapperFilename);
89     if (wrapperPath.exists()) {
90         return wrapperPath;
91     }
92
93 #ifndef _WIN32
94     // Try absolute install directory
95     wrapperPath = APITRACE_WRAPPERS_INSTALL_DIR;
96     wrapperPath.join(wrapperFilename);
97     if (wrapperPath.exists()) {
98         return wrapperPath;
99     }
100 #endif
101
102     return "";
103 }
104
105 os::String
106 findScript(const char *scriptFilename)
107 {
108     os::String scriptPath;
109
110     os::String processDir = os::getProcessName();
111     processDir.trimFilename();
112
113     // Try relative build directory
114     // XXX: Just make build and install directory layout match
115 #if defined(APITRACE_SOURCE_DIR)
116     scriptPath = APITRACE_SOURCE_DIR;
117     scriptPath.join("scripts");
118     scriptPath.join(scriptFilename);
119     if (scriptPath.exists()) {
120         return scriptPath;
121     }
122 #endif
123
124     // Try relative install directory
125     scriptPath = processDir;
126 #if defined(_WIN32)
127     scriptPath.join("..\\lib\\scripts");
128 #elif defined(__APPLE__)
129     scriptPath.join("../lib/scripts");
130 #else
131     scriptPath.join("../lib/apitrace/scripts");
132 #endif
133     scriptPath.join(scriptFilename);
134     if (scriptPath.exists()) {
135         return scriptPath;
136     }
137
138 #ifndef _WIN32
139     // Try absolute install directory
140     scriptPath = APITRACE_SCRIPTS_INSTALL_DIR;
141     scriptPath.join(scriptFilename);
142     if (scriptPath.exists()) {
143         return scriptPath;
144     }
145 #endif
146
147     std::cerr << "error: cannot find " << scriptFilename << " script\n";
148
149     return "";
150 }