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())) { if (!fileExists(toolpath.c_str())) {
// Fall back to system executables so 'xcrun git status' etc. works. // 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; return true;
err << "xcrun: cannot find '" << tool << "' executable" << err.endl(); err << "xcrun: cannot find '" << tool << "' executable" << err.endl();
@ -200,14 +200,16 @@ int xcrun(int argc, char **argv, Target &target) {
if (getenv("xcrun_log")) if (getenv("xcrun_log"))
showCommand = true; showCommand = true;
constexpr const char *ENVVARS[] = { if (!getenv("OSXCROSS_XCRUN_NO_ENV_WARNING")) {
"DEVELOPER_DIR", "TOOLCHAINS", "xcrun_verbose" constexpr const char *ENVVARS[] = {
}; "DEVELOPER_DIR", "TOOLCHAINS", "xcrun_verbose"
};
for (const char *evar : ENVVARS) { for (const char *evar : ENVVARS) {
if (getenv(evar)) { if (getenv(evar)) {
warn << "xcrun: ignoring environment variable " warn << "xcrun: ignoring environment variable "
<< "'" << evar << "'" << warn.endl(); << "'" << 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, bool realPath(const char *file, std::string &result,
realpathcmp cmp1, realpathcmp cmp2) { realpathcmp cmp1, realpathcmp cmp2,
const size_t maxSymbolicLinkDepth) {
char *PATH = getenv("PATH"); char *PATH = getenv("PATH");
const char *p = PATH ? PATH : ""; const char *p = PATH ? PATH : "";
struct stat st; struct stat st;
@ -362,6 +363,9 @@ bool realPath(const char *file, std::string &result,
result += file; result += file;
if (!stat(result.c_str(), &st)) { if (!stat(result.c_str(), &st)) {
if (maxSymbolicLinkDepth == 0)
return true;
char buf[PATH_MAX + 1]; char buf[PATH_MAX + 1];
if (realpath(result.c_str(), buf)) { if (realpath(result.c_str(), buf)) {
@ -379,6 +383,7 @@ bool realPath(const char *file, std::string &result,
else else
++pathlen; // PATHDIV ++pathlen; // PATHDIV
memcpy(path, result.c_str(), pathlen); // not null terminated memcpy(path, result.c_str(), pathlen); // not null terminated
while ((len = readlink(result.c_str(), buf, PATH_MAX)) != -1) { 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 pathlen = strrchr(buf, PATHDIV) - buf + 1; // + 1: PATHDIV
memcpy(path, buf, pathlen); memcpy(path, buf, pathlen);
} }
if (++n >= 1000) { if (++n >= maxSymbolicLinkDepth) {
err << result << ": too many levels of symbolic links" err << result << ": too many levels of symbolic links"
<< err.endl(); << err.endl();
result.clear(); 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 isExecutable(const char *f, const struct stat &);
bool ignoreCCACHE(const char *f, const struct stat &); bool ignoreCCACHE(const char *f, const struct stat &);
bool realPath(const char *file, std::string &result, 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, bool getPathOfCommand(const char *command, std::string &result,
realpathcmp cmp = nullptr); realpathcmp cmp = nullptr);