Skip to content

Commit c53ad9e

Browse files
author
Romaric JODIN
committed
dpu: clang: fix getupmemsdkpath to look for a installed package.
If no installed package is found, fallback to the UPMEM_HOME environment variable. Ref #1
1 parent 9f9b079 commit c53ad9e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

clang/lib/Driver/ToolChains/DPURTE.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "clang/Driver/DriverDiagnostic.h"
1515
#include "clang/Driver/Options.h"
1616
#include "llvm/Option/ArgList.h"
17+
#include "clang/Basic/VirtualFileSystem.h"
1718

1819
using namespace llvm::opt;
1920

@@ -31,16 +32,22 @@ void DPURTE::AddClangSystemIncludeArgs(
3132
addSystemInclude(DriverArgs, CC1Args, StringRef(PathToSyslibIncludes));
3233
}
3334

34-
char *DPURTE::GetUpmemSdkPath(const char *Path) const {
35-
char *UpmemHome = getenv("UPMEM_HOME");
36-
if (UpmemHome == nullptr) {
37-
// Assume that the toolchain is installed at system root
38-
return strdup(Path);
39-
} else {
40-
char *result;
41-
asprintf(&result, "%s%s", UpmemHome, Path);
35+
char *DPURTE::GetUpmemSdkPath(const char *Path) {
36+
char *result;
37+
if (PathToSDK != NULL) {
38+
asprintf(&result, "%s%s", PathToSDK, Path);
4239
return result;
4340
}
41+
const std::string InstalledDir(getDriver().getInstalledDir());
42+
const std::string UpmemDir(InstalledDir + "/../share/upmem");
43+
if (getVFS().exists(UpmemDir)) {
44+
PathToSDK = strdup((InstalledDir + "/../..").c_str());
45+
asprintf(&result, "%s%s", PathToSDK, Path);
46+
return result;
47+
}
48+
PathToSDK = strdup(getenv("UPMEM_HOME"));
49+
asprintf(&result, "%s%s", PathToSDK, Path);
50+
return result;
4451
}
4552

4653
Tool *DPURTE::buildLinker() const {

clang/lib/Driver/ToolChains/DPURTE.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ class LLVM_LIBRARY_VISIBILITY DPURTE : public Generic_ELF {
7070
Tool *buildLinker() const override;
7171

7272
private:
73-
char *GetUpmemSdkPath(const char *Path) const;
73+
char *GetUpmemSdkPath(const char *Path);
7474

75+
char *PathToSDK = NULL;
7576
char *PathToSyslibIncludes;
7677
char *PathToStdlibIncludes;
7778
char *PathToLinkScript;

0 commit comments

Comments
 (0)