Skip to content

Commit

Permalink
fix: remove manual input and use autodetect
Browse files Browse the repository at this point in the history
add info to the console

macos: auto fix dependencies
  • Loading branch information
xiaoyifang committed Sep 26, 2023
1 parent 63105a5 commit ebbdef8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/Dependency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ Dependency::Dependency(std::string path, const std::string& dependent_file)
std::cerr << "\n/!\\ WARNING : Library " << filename << " has an incomplete name (location unknown)" << std::endl;
missing_prefixes = true;

Settings::addSearchPath(getUserInputDirForFile(filename));
auto path = getUserInputDirForFile(filename);
if (!path.empty())
Settings::addSearchPath(path);
}

new_name = filename;
Expand Down
15 changes: 13 additions & 2 deletions src/DylibBundler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str
{
char buffer[PATH_MAX];
std::string fullpath;
std::string suffix = std::regex_replace(rpath_file, std::regex("^@[a-z_]+path/"), "");
std::string suffix = rpath_file.substr(rpath_file.rfind('/')+1);

const auto check_path = [&](std::string path)
{
Expand Down Expand Up @@ -163,10 +163,21 @@ std::string searchFilenameInRpaths(const std::string& rpath_file, const std::str

if (fullpath.empty())
{
const int searchPathAmount = Settings::searchPathAmount();
std::cout << "\n search file:" << suffix;
int searchPathAmount = Settings::searchPathAmount();
std::cout << "\n search path count:" << searchPathAmount;
if (searchPathAmount==0)
{
Settings::addSearchPath("/usr/local/");
searchPathAmount = 1;
}

for (int n=0; n<searchPathAmount; n++)
{
std::string search_path = Settings::searchPath(n);
if (search_path[search_path.size()-1] != '/') search_path += "/";

std::cout << "\n search path:" << search_path<< " file " << search_path+suffix;
if (fileExists(search_path+suffix))
{
fullpath = search_path + suffix;
Expand Down
52 changes: 22 additions & 30 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ THE SOFTWARE.
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <memory>
#include <vector> // For std::vector
#include <fstream>
using namespace std;

/*
Expand Down Expand Up @@ -67,6 +70,18 @@ void tokenize(const string& str, const char* delim, vector<string>* vectorarg)

}

vector<std::string> exec(const char *cmd) {
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) return {};
char buffer[128];
vector<std::string> outputs;
while (!feof(pipe.get())) {
if (fgets(buffer, 256, pipe.get()) != NULL) {
outputs.emplace_back(buffer);
}
}
return outputs;
}


bool fileExists(const std::string& filename)
Expand Down Expand Up @@ -183,39 +198,16 @@ std::string getUserInputDirForFile(const std::string& filename)
for(int n=0; n<searchPathAmount; n++)
{
auto searchPath = Settings::searchPath(n);
if( !searchPath.empty() && searchPath[ searchPath.size()-1 ] != '/' ) searchPath += "/";

if( fileExists( searchPath+filename ) )
{
std::cerr << (searchPath+filename) << " was found. /!\\ DYLIBBUNDLER MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: Manually check the executable with 'otool -L'" << std::endl;
return searchPath;
}
}

while (true)
{
std::cout << "Please specify the directory where this library is located (or enter 'quit' to abort): "; fflush(stdout);

std::string prefix;
std::cin >> prefix;
std::cout << std::endl;

if(prefix.compare("quit")==0) exit(1);

if( !prefix.empty() && prefix[ prefix.size()-1 ] != '/' ) prefix += "/";
string cmd = "find " + searchPath + " -name " + filename;
vector<string> files = exec(cmd.c_str());

if( !fileExists( prefix+filename ) )
{
std::cerr << (prefix+filename) << " does not exist. Try again" << std::endl;
continue;
}
else
{
std::cerr << (prefix+filename) << " was found. /!\\ DYLIBBUNDLER MAY NOT CORRECTLY HANDLE THIS DEPENDENCY: Manually check the executable with 'otool -L'" << std::endl;
Settings::addSearchPath(prefix);
return prefix;
if (!files.empty()) {
string f = files.at(0);
std::cout << "found file "<< filename << " at " << f;
return files.at(0).substr(0, f.length() - filename.length()-1);
}
}
return {};
}

void adhocCodeSign(const std::string& file)
Expand Down

0 comments on commit ebbdef8

Please sign in to comment.