diff options
author | John Thompson <John.Thompson.JTSoftware@gmail.com> | 2015-02-17 20:43:47 +0000 |
---|---|---|
committer | John Thompson <John.Thompson.JTSoftware@gmail.com> | 2015-02-17 20:43:47 +0000 |
commit | e95f7cefa2efedbf4a8941398c49b5c8b2eedfb8 (patch) | |
tree | f9c98ce45f8f2c02528220501ee35fa2a623047e | |
parent | 302ca996fd274fa58b6ea572f0ee050789b95e9c (diff) |
Add canonical path conversion function and use it so paths are consistent.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@229540 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | modularize/Modularize.cpp | 2 | ||||
-rw-r--r-- | modularize/ModularizeUtilities.cpp | 17 | ||||
-rw-r--r-- | modularize/ModularizeUtilities.h | 11 |
3 files changed, 28 insertions, 2 deletions
diff --git a/modularize/Modularize.cpp b/modularize/Modularize.cpp index 9d91557f..dc317c4f 100644 --- a/modularize/Modularize.cpp +++ b/modularize/Modularize.cpp @@ -239,7 +239,7 @@ std::string findInputFile(const CommandLineArguments &CLArgs) { Opts->ParseArgs(Argv.data(), Argv.data() + Argv.size(), MissingArgIndex, MissingArgCount, IncludedFlagsBitmask)); std::vector<std::string> Inputs = Args->getAllArgValues(OPT_INPUT); - return Inputs.back(); + return ModularizeUtilities::getCanonicalPath(Inputs.back()); } // This arguments adjuster inserts "-include (file)" arguments for header diff --git a/modularize/ModularizeUtilities.cpp b/modularize/ModularizeUtilities.cpp index 14c9f5d2..d3c48c9f 100644 --- a/modularize/ModularizeUtilities.cpp +++ b/modularize/ModularizeUtilities.cpp @@ -114,11 +114,26 @@ std::error_code ModularizeUtilities::loadSingleHeaderListsAndDependencies( llvm::sys::path::append(Dependent, DependentsList[Index]); } llvm::sys::path::native(Dependent); - Dependents.push_back(Dependent.str()); + Dependents.push_back(getCanonicalPath(Dependent.str())); } + // Get canonical form. + HeaderFileName = getCanonicalPath(HeaderFileName); // Save the resulting header file path and dependencies. HeaderFileNames.push_back(HeaderFileName.str()); Dependencies[HeaderFileName.str()] = Dependents; } return std::error_code(); } + +// Convert header path to canonical form. +// The canonical form is basically just use forward slashes, and remove "./". +// \param FilePath The file path, relative to the module map directory. +// \returns The file path in canonical form. +std::string ModularizeUtilities::getCanonicalPath(StringRef FilePath) { + std::string Tmp(FilePath); + std::replace(Tmp.begin(), Tmp.end(), '\\', '/'); + StringRef Tmp2(Tmp); + if (Tmp2.startswith("./")) + Tmp = Tmp2.substr(2); + return Tmp; +} diff --git a/modularize/ModularizeUtilities.h b/modularize/ModularizeUtilities.h index 3cf24fd1..aac79d2f 100644 --- a/modularize/ModularizeUtilities.h +++ b/modularize/ModularizeUtilities.h @@ -67,6 +67,17 @@ protected: /// \returns std::error_code. std::error_code loadSingleHeaderListsAndDependencies( llvm::StringRef InputPath); + +public: + + // Utility functions. + + /// Convert header path to canonical form. + /// The canonical form is basically just use forward slashes, + /// and remove "./". + /// \param FilePath The file path. + /// \returns The file path in canonical form. + static std::string getCanonicalPath(llvm::StringRef FilePath); }; } // end namespace Modularize |