On Fri, Aug 9, 2013 at 6:40 PM, Rafael Espindola <[email protected]> wrote: > Author: rafael > Date: Fri Aug 9 20:40:10 2013 > New Revision: 188128 > > URL: http://llvm.org/viewvc/llvm-project?rev=188128&view=rev > Log: > Simplify now that llvm::sys::current_path checks $PWD. > > Modified: > cfe/trunk/include/clang/Tooling/Tooling.h > cfe/trunk/lib/Driver/Tools.cpp > cfe/trunk/lib/Tooling/Tooling.cpp > cfe/trunk/test/Tooling/auto-detect-from-source-parent-of-cwd.cpp > cfe/trunk/test/Tooling/clang-check-pwd.cpp > > Modified: cfe/trunk/include/clang/Tooling/Tooling.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=188128&r1=188127&r2=188128&view=diff > ============================================================================== > --- cfe/trunk/include/clang/Tooling/Tooling.h (original) > +++ cfe/trunk/include/clang/Tooling/Tooling.h Fri Aug 9 20:40:10 2013 > @@ -305,10 +305,8 @@ inline FrontendActionFactory *newFronten > /// Otherwise, the returned path will contain the literal path-concatenation > of > /// the current directory and \c File. > /// > -/// The difference to llvm::sys::fs::make_absolute is that we prefer > -/// ::getenv("PWD") if available. > -/// FIXME: Make this functionality available from llvm::sys::fs and delete > -/// this function. > +/// The difference to llvm::sys::fs::make_absolute is the canonicalization > this > +/// does by removing "./" and computing native paths. > /// > /// \param File Either an absolute or relative path. > std::string getAbsolutePath(StringRef File); > > Modified: cfe/trunk/lib/Driver/Tools.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=188128&r1=188127&r2=188128&view=diff > ============================================================================== > --- cfe/trunk/lib/Driver/Tools.cpp (original) > +++ cfe/trunk/lib/Driver/Tools.cpp Fri Aug 9 20:40:10 2013 > @@ -1780,24 +1780,8 @@ static bool shouldUseLeafFramePointer(co > return true; > } > > -/// If the PWD environment variable is set, add a CC1 option to specify the > -/// debug compilation directory. > +/// Add a CC1 option to specify the debug compilation directory. > static void addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs) { > - const char *pwd = ::getenv("PWD"); > - if (!pwd) > - return; > - > - llvm::sys::fs::file_status PWDStatus, DotStatus; > - if (llvm::sys::path::is_absolute(pwd) && > - !llvm::sys::fs::status(pwd, PWDStatus) && > - !llvm::sys::fs::status(".", DotStatus) && > - PWDStatus.getUniqueID() == DotStatus.getUniqueID()) { > - CmdArgs.push_back("-fdebug-compilation-dir"); > - CmdArgs.push_back(Args.MakeArgString(pwd)); > - return; > - } > - > - // Fall back to using getcwd. > SmallString<128> cwd; > if (!llvm::sys::fs::current_path(cwd)) { > CmdArgs.push_back("-fdebug-compilation-dir"); > @@ -2494,12 +2478,10 @@ void Clang::ConstructJob(Compilation &C, > CmdArgs.push_back("-coverage-file"); > SmallString<128> CoverageFilename(Output.getFilename()); > if (llvm::sys::path::is_relative(CoverageFilename.str())) { > - if (const char *pwd = ::getenv("PWD")) { > - if (llvm::sys::path::is_absolute(pwd)) { > - SmallString<128> Pwd(pwd); > - llvm::sys::path::append(Pwd, CoverageFilename.str()); > - CoverageFilename.swap(Pwd); > - } > + SmallString<128> Pwd; > + if (!llvm::sys::fs::current_path(Pwd)) { > + llvm::sys::path::append(Pwd, CoverageFilename.str()); > + CoverageFilename.swap(Pwd); > } > } > CmdArgs.push_back(Args.MakeArgString(CoverageFilename)); > > Modified: cfe/trunk/lib/Tooling/Tooling.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=188128&r1=188127&r2=188128&view=diff > ============================================================================== > --- cfe/trunk/lib/Tooling/Tooling.cpp (original) > +++ cfe/trunk/lib/Tooling/Tooling.cpp Fri Aug 9 20:40:10 2013 > @@ -124,23 +124,16 @@ bool runToolOnCodeWithArgs(clang::Fronte > } > > std::string getAbsolutePath(StringRef File) { > - SmallString<1024> BaseDirectory; > - if (const char *PWD = ::getenv("PWD")) > - BaseDirectory = PWD; > - else > - llvm::sys::fs::current_path(BaseDirectory); > - SmallString<1024> PathStorage; > - if (llvm::sys::path::is_absolute(File)) { > - llvm::sys::path::native(File, PathStorage); > - return PathStorage.str(); > - } > StringRef RelativePath(File); > // FIXME: Should '.\\' be accepted on Win32? > if (RelativePath.startswith("./")) { > RelativePath = RelativePath.substr(strlen("./")); > } > - SmallString<1024> AbsolutePath(BaseDirectory); > - llvm::sys::path::append(AbsolutePath, RelativePath); > + > + SmallString<1024> AbsolutePath = RelativePath; > + llvm::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath); > + assert(!EC);
EC is unused in -asserts builds. _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
