diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2016-11-16 11:01:32 +0000 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2016-11-16 16:01:16 +0000 |
commit | 251bf035962bb84745436326982250678d25a7d1 (patch) | |
tree | 00ab1daaf208a78bd4b694588978a869ccc6b3db /src/main/cpp/util/file.h | |
parent | 544d89ae6c46127f5a1894adf893f89b252b3a09 (diff) |
Bazel client: implement directory tree walking
This change:
- merges the //src/{main,test}/cpp:file and
//src/{main,test}/cpp:file_platform libraries
because "file" and "file_platform" need each other
and this makes logical sense anyway
- implements a function in file_<platform> to run
a custom function on every child of a directory
- implements a function in file.cc to recursively
traverse a directory tree, based on the previosly
mentioned function
- removes the corresponding logic from the Bazel
client to make it more portable
--
MOS_MIGRATED_REVID=139309562
Diffstat (limited to 'src/main/cpp/util/file.h')
-rw-r--r-- | src/main/cpp/util/file.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/main/cpp/util/file.h b/src/main/cpp/util/file.h index 238ccf0d9f..dfa08ad629 100644 --- a/src/main/cpp/util/file.h +++ b/src/main/cpp/util/file.h @@ -15,6 +15,7 @@ #define BAZEL_SRC_MAIN_CPP_UTIL_FILE_H_ #include <string> +#include <vector> namespace blaze_util { @@ -29,6 +30,26 @@ std::string Basename(const std::string &path); std::string JoinPath(const std::string &path1, const std::string &path2); +// Lists all files in `path` and all of its subdirectories. +// +// Does not follow symlinks / junctions. +// +// Populates `result` with the full paths of the files. Every entry will have +// `path` as its prefix. If `path` is a file, `result` contains just this file. +void GetAllFilesUnder(const std::string &path, + std::vector<std::string> *result); + +class DirectoryEntryConsumer; + +// Visible for testing only. +typedef void (*_ForEachDirectoryEntry)(const std::string &path, + DirectoryEntryConsumer *consume); + +// Visible for testing only. +void _GetAllFilesUnder(const std::string &path, + std::vector<std::string> *result, + _ForEachDirectoryEntry walk_entries); + } // namespace blaze_util #endif // BAZEL_SRC_MAIN_CPP_UTIL_FILE_H_ |