[PATCH] Add support to read include/exclude path lists from file
Jack Yang
jack.yang at intel.com
Tue Apr 16 13:45:19 PDT 2013
Hi revane,
Add support to read include/exclude path lists from file
Files containing the list of filepaths to be included and excluded can now be specified through -include-from-file=<FILE> and -exclude-from-file=<FILE> command line options in cpp11-migrate.
http://llvm-reviews.chandlerc.com/D681
Files:
cpp11-migrate/Core/IncludeExcludeInfo.cpp
cpp11-migrate/Core/IncludeExcludeInfo.h
cpp11-migrate/tool/Cpp11Migrate.cpp
Index: cpp11-migrate/Core/IncludeExcludeInfo.cpp
===================================================================
--- cpp11-migrate/Core/IncludeExcludeInfo.cpp
+++ cpp11-migrate/Core/IncludeExcludeInfo.cpp
@@ -16,7 +16,9 @@
#include "IncludeExcludeInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -46,11 +48,12 @@
return true;
}
-/// \brief Helper function to parse a string of comma seperated paths into
+/// \brief Helper function to tokenize a string of filepaths and populate
/// the vector.
-void parseCLInput(StringRef Line, std::vector<std::string> &List) {
+void parseCLInput(StringRef Line, std::vector<std::string> &List,
+ StringRef Seperator) {
SmallVector<StringRef, 32> Tokens;
- Line.split(Tokens, ",", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+ Line.split(Tokens, Seperator, /*MaxSplit=*/-1, /*KeepEmpty=*/false);
for (SmallVectorImpl<StringRef>::iterator I = Tokens.begin(),
E = Tokens.end();
I != E; ++I) {
@@ -63,8 +66,31 @@
} // end anonymous namespace
IncludeExcludeInfo::IncludeExcludeInfo(StringRef Include, StringRef Exclude) {
- parseCLInput(Include, IncludeList);
- parseCLInput(Exclude, ExcludeList);
+ parseCLInput(Include, IncludeList, ",");
+ parseCLInput(Exclude, ExcludeList, ",");
+}
+
+error_code IncludeExcludeInfo::readListFromFile(StringRef IncludeListFile,
+ StringRef ExcludeListFile) {
+ if (!IncludeListFile.empty()) {
+ OwningPtr<MemoryBuffer> FileBuf;
+ if (error_code Err = MemoryBuffer::getFile(IncludeListFile, FileBuf)) {
+ errs() << "Unable to read from exclude file.\n";
+ return Err;
+ }
+ else
+ parseCLInput(FileBuf->getBuffer(), IncludeList, "\n");
+ }
+ if (!ExcludeListFile.empty()) {
+ OwningPtr<MemoryBuffer> FileBuf;
+ if (error_code Err = MemoryBuffer::getFile(ExcludeListFile, FileBuf)) {
+ errs() << "Unable to read from exclude file.\n";
+ return Err;
+ }
+ else
+ parseCLInput(FileBuf->getBuffer(), ExcludeList, "\n");
+ }
+ return error_code::success();
}
bool IncludeExcludeInfo::isFileIncluded(StringRef FilePath) {
Index: cpp11-migrate/Core/IncludeExcludeInfo.h
===================================================================
--- cpp11-migrate/Core/IncludeExcludeInfo.h
+++ cpp11-migrate/Core/IncludeExcludeInfo.h
@@ -16,6 +16,7 @@
#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_INCLUDEEXCLUDEINFO_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/system_error.h"
#include <vector>
/// \brief Class encapsulating the handling of include and exclude paths
@@ -27,6 +28,14 @@
/// \a Include and \a Exclude must be formatted as a comma-seperated list.
IncludeExcludeInfo(llvm::StringRef Include, llvm::StringRef Exclude);
+ /// \brief Read and parse the lists of filepaths from \a IncludeListFile
+ /// and \a ExcludeListFile.
+ ///
+ /// Returns error_code::success() on successful read of both files, or an
+ /// error_code indicating the encountered error.
+ llvm::error_code readListFromFile(llvm::StringRef IncludeListFile,
+ llvm::StringRef ExcludeListFile);
+
/// \brief Determine if the given filepath is in the list of include paths but
/// not in the list of exclude paths.
bool isFileIncluded(llvm::StringRef FilePath);
Index: cpp11-migrate/tool/Cpp11Migrate.cpp
===================================================================
--- cpp11-migrate/tool/Cpp11Migrate.cpp
+++ cpp11-migrate/tool/Cpp11Migrate.cpp
@@ -60,6 +60,14 @@
ExcludePaths("exclude", cl::Hidden,
cl::desc("Comma seperated list of filepaths that can not "
"be transformed"));
+static cl::opt<std::string>
+IncludeFromFile("include-from-file", cl::Hidden,
+ cl::desc("File containing a list of filepaths to consider to "
+ "be transformed"));
+static cl::opt<std::string>
+ExcludeFromFile("exclude-from-file", cl::Hidden,
+ cl::desc("File containing a list of filepaths that can not be "
+ "transforms"));
class EndSyntaxArgumentsAdjuster : public ArgumentsAdjuster {
CommandLineArguments Adjust(const CommandLineArguments &Args) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D681.1.patch
Type: text/x-patch
Size: 4461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130416/27ae9726/attachment.bin>
More information about the cfe-commits
mailing list