Skip to content

Commit ee7f3c2

Browse files
committed
[NFC][hipcc] move getSelfPath into utils
Change-Id: Id30812ea088b7f6dcfb256a092b648a97923f931
1 parent c875e10 commit ee7f3c2

File tree

4 files changed

+57
-32
lines changed

4 files changed

+57
-32
lines changed

amd/hipcc/src/hipBin_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void HipBinBase::constructHipPath() {
327327
if (!hip_path_name.empty()) {
328328
variables_.hipPathEnv_ = hip_path_name;
329329
} else if (envVariables_.hipPathEnv_.empty()) {
330-
fs::path full_path(hipBinUtilPtr_->getSelfPath());
330+
fs::path full_path(hipcc::utils::getSelfPath());
331331
variables_.hipPathEnv_ = (full_path.parent_path()).string();
332332
} else {
333333
variables_.hipPathEnv_ = envVariables_.hipPathEnv_;

amd/hipcc/src/hipBin_util.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class HipBinUtil {
8888
}
8989
virtual ~HipBinUtil();
9090
// Common helper functions
91-
string getSelfPath() const;
9291
vector<string> splitStr(string fullStr, char delimiter) const;
9392
string replaceStr(const string& s, const string& toReplace,
9493
const string& replaceWith) const;
@@ -131,35 +130,6 @@ string HipBinUtil::mktempFile(string name) {
131130
return fileName;
132131
}
133132

134-
// gets the path of the executable name
135-
string HipBinUtil::getSelfPath() const {
136-
int MAX_PATH_CHAR = 1024;
137-
int bufferSize = 0;
138-
string path;
139-
#if defined(_WIN32) || defined(_WIN64)
140-
TCHAR buffer[MAX_PATH] = { 0 };
141-
bufferSize = GetModuleFileName(NULL, buffer, MAX_PATH_CHAR);
142-
TSIZE pos = TSTR(buffer).find_last_of(ENDLINE);
143-
TSTR wide = TSTR(buffer).substr(0, pos);
144-
path = string(wide.begin(), wide.end());
145-
#else
146-
char buff[MAX_PATH_CHAR];
147-
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
148-
if (len > 0) {
149-
buff[len] = '\0';
150-
path = string(buff);
151-
fs::path exePath(path);
152-
path = exePath.parent_path().string();
153-
} else {
154-
std::cerr << "readlink: Error reading the exe path" << endl;
155-
perror("readlink");
156-
exit(-1);
157-
}
158-
#endif
159-
return path;
160-
}
161-
162-
163133
// removes the empty spaces and end lines
164134
string HipBinUtil::trim(string str) const {
165135
string strChomp = str;

amd/hipcc/src/utils.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,50 @@
11
#include "utils.h"
2+
#include "filesystem.h"
3+
4+
#if defined(_WIN32) || defined(_WIN64)
5+
#include <io.h>
6+
#include <tchar.h>
7+
#include <windows.h>
8+
#ifdef _UNICODE
9+
typedef wchar_t TCHAR;
10+
typedef std::wstring TSTR;
11+
typedef std::wstring::size_type TSIZE;
12+
#define ENDLINE L"/\\"
13+
#else
14+
typedef char TCHAR;
15+
typedef std::string TSTR;
16+
typedef std::string::size_type TSIZE;
17+
#define ENDLINE "/\\"
18+
#endif
19+
#else
20+
#include <unistd.h>
21+
#endif
22+
23+
#include <iostream>
24+
25+
std::string hipcc::utils::getSelfPath() {
26+
int MAX_PATH_CHAR = 1024;
27+
int bufferSize = 0;
28+
std::string path;
29+
#if defined(_WIN32) || defined(_WIN64)
30+
TCHAR buffer[MAX_PATH] = {0};
31+
bufferSize = GetModuleFileName(NULL, buffer, MAX_PATH_CHAR);
32+
TSIZE pos = TSTR(buffer).find_last_of(ENDLINE);
33+
TSTR wide = TSTR(buffer).substr(0, pos);
34+
path = std::string(wide.begin(), wide.end());
35+
#else
36+
char buff[MAX_PATH_CHAR];
37+
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
38+
if (len > 0) {
39+
buff[len] = '\0';
40+
path = std::string(buff);
41+
fs::path exePath(path);
42+
path = exePath.parent_path().string();
43+
} else {
44+
std::cerr << "readlink: Error reading the exe path" << std::endl;
45+
perror("readlink");
46+
exit(-1);
47+
}
48+
#endif
49+
return path;
50+
}

amd/hipcc/src/utils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#ifndef HIP_UTILS_H
22
#define HIP_UTILS_H
33

4+
#include <string>
5+
46
namespace hipcc {
5-
namespace utils {}
7+
namespace utils {
8+
// gets the path of the executable name
9+
std::string getSelfPath();
10+
11+
} // namespace utils
612
} // namespace hipcc
713

814
#endif

0 commit comments

Comments
 (0)