From 32bef4edba854303800b3b01cb49a282e5da4f69 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Mon, 10 Jan 2011 02:34:13 +0000 Subject: [PATCH] Replace all uses of PathV1::exists with PathV2::fs::exists. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123150 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 14 +++-- lib/Driver/ToolChains.cpp | 87 +++++++++++++++++++------------ lib/Driver/Tools.cpp | 8 +-- lib/Frontend/CompilerInstance.cpp | 4 +- lib/Lex/HeaderSearch.cpp | 5 +- 5 files changed, 76 insertions(+), 42 deletions(-) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 8340c0f129..6f2cfb879a 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1229,7 +1229,8 @@ std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { if (!PrefixDir.empty()) { llvm::sys::Path P(PrefixDir); P.appendComponent(Name); - if (P.exists()) + bool Exists; + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) return P.str(); } @@ -1238,7 +1239,8 @@ std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { it = List.begin(), ie = List.end(); it != ie; ++it) { llvm::sys::Path P(*it); P.appendComponent(Name); - if (P.exists()) + bool Exists; + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) return P.str(); } @@ -1252,7 +1254,9 @@ std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC, if (!PrefixDir.empty()) { llvm::sys::Path P(PrefixDir); P.appendComponent(Name); - if (WantFile ? P.exists() : P.canExecute()) + bool Exists; + if (WantFile ? !llvm::sys::fs::exists(P.str(), Exists) && Exists + : P.canExecute()) return P.str(); } @@ -1261,7 +1265,9 @@ std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC, it = List.begin(), ie = List.end(); it != ie; ++it) { llvm::sys::Path P(*it); P.appendComponent(Name); - if (WantFile ? P.exists() : P.canExecute()) + bool Exists; + if (WantFile ? !llvm::sys::fs::exists(P.str(), Exists) && Exists + : P.canExecute()) return P.str(); } diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 0ae5d10b6e..ca6050749b 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -23,6 +23,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Path.h" @@ -148,7 +149,8 @@ DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple) // Try the next major version if that tool chain dir is invalid. std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; - if (!llvm::sys::Path(Tmp).exists()) { + bool Exists; + if (llvm::sys::fs::exists(Tmp, Exists) || Exists) { std::string Next = "i686-apple-darwin"; Next += llvm::utostr(DarwinVersion[0] + 1); Next += "/"; @@ -162,7 +164,7 @@ DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple) // // FIXME: Drop dependency on gcc's tool chain. Tmp = "/usr/lib/gcc/" + Next; - if (llvm::sys::Path(Tmp).exists()) + if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) ToolChainDir = Next; } @@ -307,19 +309,20 @@ void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir; - if (llvm::sys::Path(Tmp).exists()) + bool Exists; + if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); Tmp = getDriver().Dir + "/../lib/gcc"; - if (llvm::sys::Path(Tmp).exists()) + if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); // Intentionally duplicated for (temporary) gcc bug compatibility. CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); Tmp = getDriver().Dir + "/../lib/" + ToolChainDir; - if (llvm::sys::Path(Tmp).exists()) + if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); Tmp = getDriver().Dir + "/../lib"; - if (llvm::sys::Path(Tmp).exists()) + if (!llvm::sys::fs::exists(Tmp, Exists) && Exists) CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + "/../../../" + ToolChainDir)); @@ -457,12 +460,14 @@ void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, if (ArchSpecificDir) { P.appendComponent(ArchSpecificDir); - if (P.exists()) + bool Exists; + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); P.eraseComponent(); } - if (P.exists()) + bool Exists; + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); } @@ -528,7 +533,8 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build. - if (P.exists()) + bool Exists; + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) CmdArgs.push_back(Args.MakeArgString(P.str())); } } @@ -622,16 +628,17 @@ void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, // explicitly if we can't see an obvious -lstdc++ candidate. // Check in the sysroot first. + bool Exists; if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { llvm::sys::Path P(A->getValue(Args)); P.appendComponent("usr"); P.appendComponent("lib"); P.appendComponent("libstdc++.dylib"); - if (!P.exists()) { + if (llvm::sys::fs::exists(P.str(), Exists) || !Exists) { P.eraseComponent(); P.appendComponent("libstdc++.6.dylib"); - if (P.exists()) { + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { CmdArgs.push_back(Args.MakeArgString(P.str())); return; } @@ -639,8 +646,8 @@ void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, } // Otherwise, look in the root. - if (!llvm::sys::Path("/usr/lib/libstdc++.dylib").exists() && - llvm::sys::Path("/usr/lib/libstdc++.6.dylib").exists()) { + if ((llvm::sys::fs::exists("/usr/lib/libstdc++.dylib", Exists) || !Exists)&& + (!llvm::sys::fs::exists("/usr/lib/libstdc++.6.dylib", Exists) && Exists)){ CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); return; } @@ -666,7 +673,8 @@ void DarwinClang::AddCCKextLibArgs(const ArgList &Args, // For now, allow missing resource libraries to support developers who may // not have compiler-rt checked out or integrated into their build. - if (P.exists()) + bool Exists; + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) CmdArgs.push_back(Args.MakeArgString(P.str())); } @@ -1233,7 +1241,9 @@ static bool IsDebianBased(enum LinuxDistro Distro) { static bool HasMultilib(llvm::Triple::ArchType Arch, enum LinuxDistro Distro) { if (Arch == llvm::Triple::x86_64) { - if (Distro == Exherbo && !llvm::sys::Path("/usr/lib32/libc.so").exists()) + bool Exists; + if (Distro == Exherbo && + (llvm::sys::fs::exists("/usr/lib32/libc.so", Exists) || !Exists)) return false; return true; @@ -1287,7 +1297,8 @@ static LinuxDistro DetectLinuxDistro(llvm::Triple::ArchType Arch) { return UnknownDistro; } - if (llvm::sys::Path("/etc/exherbo-release").exists()) + bool Exists; + if (!llvm::sys::fs::exists("/etc/exherbo-release", Exists) && Exists) return Exherbo; return UnknownDistro; @@ -1308,39 +1319,51 @@ Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple) std::string Lib32 = "lib"; - if ( llvm::sys::Path("/lib32").exists()) + bool Exists; + if (!llvm::sys::fs::exists("/lib32", Exists) && Exists) Lib32 = "lib32"; std::string Lib64 = "lib"; llvm::sys::Path Lib64Path("/lib64"); - if (Lib64Path.exists() && !Lib64Path.isSymLink()) + if (!llvm::sys::fs::exists(Lib64Path.str(), Exists) && Exists && + !Lib64Path.isSymLink()) Lib64 = "lib64"; std::string GccTriple = ""; if (Arch == llvm::Triple::arm) { - if (llvm::sys::Path("/usr/lib/gcc/arm-linux-gnueabi").exists()) + if (!llvm::sys::fs::exists("/usr/lib/gcc/arm-linux-gnueabi", Exists) && + Exists) GccTriple = "arm-linux-gnueabi"; } else if (Arch == llvm::Triple::x86_64) { - if (llvm::sys::Path("/usr/lib/gcc/x86_64-linux-gnu").exists()) + if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-linux-gnu", Exists) && + Exists) GccTriple = "x86_64-linux-gnu"; - else if (llvm::sys::Path("/usr/lib/gcc/x86_64-unknown-linux-gnu").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-unknown-linux-gnu", + Exists) && Exists) GccTriple = "x86_64-unknown-linux-gnu"; - else if (llvm::sys::Path("/usr/lib/gcc/x86_64-pc-linux-gnu").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-pc-linux-gnu", + Exists) && Exists) GccTriple = "x86_64-pc-linux-gnu"; - else if (llvm::sys::Path("/usr/lib/gcc/x86_64-redhat-linux").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/x86_64-redhat-linux", + Exists) && Exists) GccTriple = "x86_64-redhat-linux"; - else if (llvm::sys::Path("/usr/lib64/gcc/x86_64-suse-linux").exists()) + else if (!llvm::sys::fs::exists("/usr/lib64/gcc/x86_64-suse-linux", + Exists) && Exists) GccTriple = "x86_64-suse-linux"; } else if (Arch == llvm::Triple::x86) { - if (llvm::sys::Path("/usr/lib/gcc/i686-linux-gnu").exists()) + if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-linux-gnu", Exists) && Exists) GccTriple = "i686-linux-gnu"; - else if (llvm::sys::Path("/usr/lib/gcc/i686-pc-linux-gnu").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-pc-linux-gnu", Exists) && + Exists) GccTriple = "i686-pc-linux-gnu"; - else if (llvm::sys::Path("/usr/lib/gcc/i486-linux-gnu").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/i486-linux-gnu", Exists) && + Exists) GccTriple = "i486-linux-gnu"; - else if (llvm::sys::Path("/usr/lib/gcc/i686-redhat-linux").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/i686-redhat-linux", Exists) && + Exists) GccTriple = "i686-redhat-linux"; - else if (llvm::sys::Path("/usr/lib/gcc/i586-suse-linux").exists()) + else if (!llvm::sys::fs::exists("/usr/lib/gcc/i586-suse-linux", Exists) && + Exists) GccTriple = "i586-suse-linux"; } @@ -1350,12 +1373,12 @@ Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple) for (unsigned i = 0; i < sizeof(GccVersions)/sizeof(char*); ++i) { std::string Suffix = GccTriple + "/" + GccVersions[i]; std::string t1 = "/usr/lib/gcc/" + Suffix; - if (llvm::sys::Path(t1 + "/crtbegin.o").exists()) { + if (!llvm::sys::fs::exists(t1 + "/crtbegin.o", Exists) && Exists) { Base = t1; break; } std::string t2 = "/usr/lib64/gcc/" + Suffix; - if (llvm::sys::Path(t2 + "/crtbegin.o").exists()) { + if (!llvm::sys::fs::exists(t2 + "/crtbegin.o", Exists) && Exists) { Base = t2; break; } @@ -1376,7 +1399,7 @@ Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple) } llvm::sys::Path LinkerPath(Base + "/../../../../" + GccTriple + "/bin/ld"); - if (LinkerPath.exists()) + if (!llvm::sys::fs::exists(LinkerPath.str(), Exists) && Exists) Linker = LinkerPath.str(); else Linker = GetProgramPath("ld"); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index ee77f48c7c..50f32958d5 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -25,6 +25,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Twine.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Host.h" @@ -224,9 +225,10 @@ void Clang::AddPreprocessingOptions(const Driver &D, bool FoundPTH = false; bool FoundPCH = false; llvm::sys::Path P(A->getValue(Args)); + bool Exists; if (UsePCH) { P.appendSuffix("pch"); - if (P.exists()) + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) FoundPCH = true; else P.eraseSuffix(); @@ -234,7 +236,7 @@ void Clang::AddPreprocessingOptions(const Driver &D, if (!FoundPCH) { P.appendSuffix("pth"); - if (P.exists()) + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) FoundPTH = true; else P.eraseSuffix(); @@ -242,7 +244,7 @@ void Clang::AddPreprocessingOptions(const Driver &D, if (!FoundPCH && !FoundPTH) { P.appendSuffix("gch"); - if (P.exists()) { + if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { FoundPCH = UsePCH; FoundPTH = !UsePCH; } diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index d97e8c7727..901f8fa927 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -28,6 +28,7 @@ #include "clang/Serialization/ASTReader.h" #include "clang/Sema/CodeCompleteConsumer.h" #include "llvm/LLVMContext.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/Statistic.h" @@ -433,7 +434,8 @@ CompilerInstance::createOutputFile(llvm::StringRef OutputPath, llvm::sys::Path OutPath(OutFile); // Only create the temporary if we can actually write to OutPath, otherwise // we want to fail early. - if (!OutPath.exists() || + bool Exists; + if ((llvm::sys::fs::exists(OutPath.str(), Exists) || !Exists) || (OutPath.isRegularFile() && OutPath.canWrite())) { // Create a temporary file. llvm::sys::Path TempPath(OutFile); diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index d11e87f8a9..428af8648b 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -15,6 +15,7 @@ #include "clang/Lex/HeaderMap.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/ADT/SmallString.h" #include @@ -170,8 +171,8 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(llvm::StringRef Filename, // If the framework dir doesn't exist, we fail. // FIXME: It's probably more efficient to query this with FileMgr.getDir. - if (!llvm::sys::Path(std::string(FrameworkName.begin(), - FrameworkName.end())).exists()) + bool Exists; + if (llvm::sys::fs::exists(FrameworkName.str(), Exists) || !Exists) return 0; // Otherwise, if it does, remember that this is the right direntry for this -- 2.40.0