Skip to content

Commit e56c505

Browse files
committed
Fix finding foldseek binary as sibling of spacedust's binary
1 parent 6bf2020 commit e56c505

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

src/commons/LocalParameters.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
11
#include "LocalParameters.h"
2+
3+
#ifdef __APPLE__
4+
#include <mach-o/dyld.h>
5+
#include <stdlib.h>
6+
#else
7+
#include <unistd.h>
8+
#endif
9+
10+
std::string LocalParameters::getAbsExePath() {
11+
#ifdef __APPLE__
12+
uint32_t bufSize = 0;
13+
// determine required buffer size.
14+
_NSGetExecutablePath(NULL, &bufSize);
15+
char* pathBuffer = new char[bufSize];
16+
if (_NSGetExecutablePath(pathBuffer, &bufSize) != 0) {
17+
delete[] pathBuffer;
18+
return std::string();
19+
}
20+
char* resolved = realpath(pathBuffer, NULL);
21+
std::string result = resolved ? resolved : pathBuffer;
22+
free(resolved);
23+
delete[] pathBuffer;
24+
return result;
25+
#else
26+
const char* linkPath = "/proc/self/exe";
27+
size_t bufSize = PATH_MAX;
28+
while (true) {
29+
std::vector<char> buf(bufSize);
30+
ssize_t len = readlink(linkPath, buf.data(), bufSize);
31+
if (len < 0) {
32+
return std::string();
33+
}
34+
if (static_cast<size_t>(len) < bufSize) {
35+
buf[len] = '\0'; // null-terminate
36+
char* resolved = realpath(buf.data(), NULL);
37+
std::string result = resolved ? resolved : std::string(buf.data());
38+
free(resolved);
39+
return result;
40+
}
41+
bufSize *= 2;
42+
}
43+
#endif
44+
}

src/commons/LocalParameters.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef LOCALPARAMETERS_H
22
#define LOCALPARAMETERS_H
33

4-
#include <Parameters.h>
4+
#include "Parameters.h"
5+
#include "FileUtil.h"
56

67
const int CITATION_SPACEDUST = CITATION_END;
78

@@ -56,6 +57,7 @@ class LocalParameters : public Parameters {
5657
std::string fileExclude;
5758
std::string foldseekPath;
5859

60+
static std::string getAbsExePath();
5961
private:
6062
LocalParameters() :
6163
Parameters(),
@@ -159,7 +161,8 @@ class LocalParameters : public Parameters {
159161
fileInclude = ".*";
160162
fileExclude = "^$";
161163
gffDir = "";
162-
foldseekPath = "foldseek";
164+
std::string binaryDir = FileUtil::dirName(getAbsExePath());
165+
foldseekPath = binaryDir.empty() ? "foldseek" : binaryDir + "/foldseek";
163166

164167
//TODO: add citations (foldseek & mmseqs & clustersearch)
165168
citations.emplace(CITATION_SPACEDUST, "");

src/workflow/clusterdb.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ void setclusterDbDefaults(LocalParameters *p) {
1515
int clusterdb(int argc, const char **argv, const Command &command) {
1616
LocalParameters &par = LocalParameters::getLocalInstance();
1717
setclusterDbDefaults(&par);
18-
par.foldseekPath = FileUtil::dirName(*(argv - 2)) + "/foldseek";
1918
par.parseParameters(argc, argv, command, true, 0, 0);
2019

2120
if (FileUtil::directoryExists(par.db2.c_str()) == false) {

src/workflow/clustersearch.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void setClusterSearchWorkflowDefaults(LocalParameters *p) {
3939
int clustersearch(int argc, const char **argv, const Command &command) {
4040
LocalParameters &par = LocalParameters::getLocalInstance();
4141
setClusterSearchWorkflowDefaults(&par);
42-
par.foldseekPath = FileUtil::dirName(*(argv - 2)) + "/foldseek";
4342

4443
par.PARAM_MAX_REJECTED.addCategory(MMseqsParameter::COMMAND_EXPERT);
4544
par.PARAM_DB_OUTPUT.addCategory(MMseqsParameter::COMMAND_EXPERT);

0 commit comments

Comments
 (0)