This commit is contained in:
Thomas Pöchtrager 2019-06-24 13:02:34 +02:00
parent 88cb6e8d0d
commit 16efae8992
3 changed files with 19 additions and 11 deletions

View File

@ -74,7 +74,7 @@ bool getToolPath(Target &target, std::string &toolpath, const char *tool) {
if (!fileExists(toolpath.c_str())) {
// Fall back to system executables so 'xcrun git status' etc. works.
if (!isxcodetool && realPath(tool, toolpath))
if (!isxcodetool && realPath(tool, toolpath, nullptr, nullptr, 0))
return true;
err << "xcrun: cannot find '" << tool << "' executable" << err.endl();
@ -200,14 +200,16 @@ int xcrun(int argc, char **argv, Target &target) {
if (getenv("xcrun_log"))
showCommand = true;
constexpr const char *ENVVARS[] = {
"DEVELOPER_DIR", "TOOLCHAINS", "xcrun_verbose"
};
if (!getenv("OSXCROSS_XCRUN_NO_ENV_WARNING")) {
constexpr const char *ENVVARS[] = {
"DEVELOPER_DIR", "TOOLCHAINS", "xcrun_verbose"
};
for (const char *evar : ENVVARS) {
if (getenv(evar)) {
warn << "xcrun: ignoring environment variable "
<< "'" << evar << "'" << warn.endl();
for (const char *evar : ENVVARS) {
if (getenv(evar)) {
warn << "xcrun: ignoring environment variable "
<< "'" << evar << "'" << warn.endl();
}
}
}

View File

@ -344,7 +344,8 @@ bool ignoreCCACHE(const char *f, const struct stat &) {
}
bool realPath(const char *file, std::string &result,
realpathcmp cmp1, realpathcmp cmp2) {
realpathcmp cmp1, realpathcmp cmp2,
const size_t maxSymbolicLinkDepth) {
char *PATH = getenv("PATH");
const char *p = PATH ? PATH : "";
struct stat st;
@ -362,6 +363,9 @@ bool realPath(const char *file, std::string &result,
result += file;
if (!stat(result.c_str(), &st)) {
if (maxSymbolicLinkDepth == 0)
return true;
char buf[PATH_MAX + 1];
if (realpath(result.c_str(), buf)) {
@ -379,6 +383,7 @@ bool realPath(const char *file, std::string &result,
else
++pathlen; // PATHDIV
memcpy(path, result.c_str(), pathlen); // not null terminated
while ((len = readlink(result.c_str(), buf, PATH_MAX)) != -1) {
@ -390,7 +395,7 @@ bool realPath(const char *file, std::string &result,
pathlen = strrchr(buf, PATHDIV) - buf + 1; // + 1: PATHDIV
memcpy(path, buf, pathlen);
}
if (++n >= 1000) {
if (++n >= maxSymbolicLinkDepth) {
err << result << ": too many levels of symbolic links"
<< err.endl();
result.clear();

View File

@ -161,7 +161,8 @@ typedef bool (*realpathcmp)(const char *file, const struct stat &st);
bool isExecutable(const char *f, const struct stat &);
bool ignoreCCACHE(const char *f, const struct stat &);
bool realPath(const char *file, std::string &result,
realpathcmp cmp1 = nullptr, realpathcmp cmp2 = nullptr);
realpathcmp cmp1 = nullptr, realpathcmp cmp2 = nullptr,
const size_t maxSymobolicLinkDepth = 1000);
bool getPathOfCommand(const char *command, std::string &result,
realpathcmp cmp = nullptr);