diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-04-14 16:07:54 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-04-14 16:07:54 -0700 |
| commit | 20397fc845fac398a1aca2ee17ce5b932fc1a83b (patch) | |
| tree | 51235bc2602a81a89da9605272a37ca4fc1765a8 /toolsrc/include | |
| parent | 8183671a492aa21ec20780a77f923848b0aeca41 (diff) | |
| parent | 1c08a42091cb0addd1e0c1daf27d24bf4e9d237f (diff) | |
| download | vcpkg-20397fc845fac398a1aca2ee17ce5b932fc1a83b.tar.gz vcpkg-20397fc845fac398a1aca2ee17ce5b932fc1a83b.zip | |
Merge branch 'dev/roschuma/fs-testing'
Diffstat (limited to 'toolsrc/include')
| -rw-r--r-- | toolsrc/include/BinaryParagraph.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/Paragraphs.h | 8 | ||||
| -rw-r--r-- | toolsrc/include/PostBuildLint_BuildInfo.h | 3 | ||||
| -rw-r--r-- | toolsrc/include/SourceParagraph.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/StatusParagraph.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/StatusParagraphs.h | 4 | ||||
| -rw-r--r-- | toolsrc/include/VcpkgPaths.h | 3 | ||||
| -rw-r--r-- | toolsrc/include/filesystem_fs.h | 13 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Files.h | 67 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Strings.h | 8 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Util.h | 6 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_optional.h | 1 |
12 files changed, 66 insertions, 53 deletions
diff --git a/toolsrc/include/BinaryParagraph.h b/toolsrc/include/BinaryParagraph.h index e29e0f51b..6cf740920 100644 --- a/toolsrc/include/BinaryParagraph.h +++ b/toolsrc/include/BinaryParagraph.h @@ -25,5 +25,5 @@ namespace vcpkg std::vector<std::string> depends; }; - std::ostream& operator<<(std::ostream& os, const BinaryParagraph& pgh); + void serialize(const BinaryParagraph& pgh, std::string& out_str); } diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h index 610ebbad6..cf21635d7 100644 --- a/toolsrc/include/Paragraphs.h +++ b/toolsrc/include/Paragraphs.h @@ -11,16 +11,16 @@ namespace vcpkg::Paragraphs { using ParagraphDataMap = std::unordered_map<std::string, std::string>; - Expected<ParagraphDataMap> get_single_paragraph(const fs::path& control_path); - Expected<std::vector<ParagraphDataMap>> get_paragraphs(const fs::path& control_path); + Expected<ParagraphDataMap> get_single_paragraph(const Files::Filesystem& fs, const fs::path& control_path); + Expected<std::vector<ParagraphDataMap>> get_paragraphs(const Files::Filesystem& fs, const fs::path& control_path); Expected<ParagraphDataMap> parse_single_paragraph(const std::string& str); Expected<std::vector<ParagraphDataMap>> parse_paragraphs(const std::string& str); - Expected<SourceParagraph> try_load_port(const fs::path& control_path); + Expected<SourceParagraph> try_load_port(const Files::Filesystem& fs, const fs::path& control_path); Expected<BinaryParagraph> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec); - std::vector<SourceParagraph> load_all_ports(const fs::path& ports_dir); + std::vector<SourceParagraph> load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir); std::map<std::string, VersionT> extract_port_names_and_versions(const std::vector<SourceParagraph>& source_paragraphs); } diff --git a/toolsrc/include/PostBuildLint_BuildInfo.h b/toolsrc/include/PostBuildLint_BuildInfo.h index 8bac18861..44776d918 100644 --- a/toolsrc/include/PostBuildLint_BuildInfo.h +++ b/toolsrc/include/PostBuildLint_BuildInfo.h @@ -1,6 +1,7 @@ #pragma once #include "filesystem_fs.h" +#include "vcpkg_Files.h" #include "PostBuildLint_BuildPolicies.h" #include "OptBool.h" #include "PostBuildLint_LinkageType.h" @@ -17,5 +18,5 @@ namespace vcpkg::PostBuildLint std::map<BuildPolicies::Type, OptBoolT> policies; }; - BuildInfo read_build_info(const fs::path& filepath); + BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath); } diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h index 65ba478ee..b66fa131b 100644 --- a/toolsrc/include/SourceParagraph.h +++ b/toolsrc/include/SourceParagraph.h @@ -13,7 +13,7 @@ namespace vcpkg std::string qualifier; }; - std::ostream& operator<<(std::ostream& os, const Dependency& p); + const std::string& to_string(const Dependency& dep); struct SourceParagraph { diff --git a/toolsrc/include/StatusParagraph.h b/toolsrc/include/StatusParagraph.h index bc2766aa2..a71fb7893 100644 --- a/toolsrc/include/StatusParagraph.h +++ b/toolsrc/include/StatusParagraph.h @@ -33,7 +33,7 @@ namespace vcpkg InstallState state; }; - std::ostream& operator<<(std::ostream& os, const StatusParagraph& pgh); + void serialize(const StatusParagraph& pgh, std::string& out_str); std::string to_string(InstallState f); diff --git a/toolsrc/include/StatusParagraphs.h b/toolsrc/include/StatusParagraphs.h index c5ece9616..fcfe99b5a 100644 --- a/toolsrc/include/StatusParagraphs.h +++ b/toolsrc/include/StatusParagraphs.h @@ -29,7 +29,7 @@ namespace vcpkg iterator insert(std::unique_ptr<StatusParagraph>); - friend std::ostream& operator<<(std::ostream&, const StatusParagraphs&); + friend void serialize(const StatusParagraphs& pgh, std::string& out_str); iterator end() { @@ -55,5 +55,5 @@ namespace vcpkg std::vector<std::unique_ptr<StatusParagraph>> paragraphs; }; - std::ostream& operator<<(std::ostream&, const StatusParagraphs&); + void serialize(const StatusParagraphs& pgh, std::string& out_str); } diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h index 880b33b98..fdc4ad235 100644 --- a/toolsrc/include/VcpkgPaths.h +++ b/toolsrc/include/VcpkgPaths.h @@ -4,6 +4,7 @@ #include "PackageSpec.h" #include "BinaryParagraph.h" #include "Lazy.h" +#include "vcpkg_Files.h" namespace vcpkg { @@ -49,6 +50,8 @@ namespace vcpkg const fs::path& get_nuget_exe() const; const Toolset& get_toolset() const; + Files::Filesystem& get_filesystem() const; + private: Lazy<fs::path> cmake_exe; Lazy<fs::path> git_exe; diff --git a/toolsrc/include/filesystem_fs.h b/toolsrc/include/filesystem_fs.h index ece485c23..8e223511d 100644 --- a/toolsrc/include/filesystem_fs.h +++ b/toolsrc/include/filesystem_fs.h @@ -2,4 +2,15 @@ #include <filesystem> -namespace fs = std::tr2::sys;
\ No newline at end of file +namespace fs +{ + namespace stdfs = std::tr2::sys; + + using stdfs::path; + using stdfs::copy_options; + using stdfs::file_status; + + inline bool is_regular_file(file_status s) { return stdfs::is_regular_file(s); } + inline bool is_directory(file_status s) { return stdfs::is_directory(s); } + inline bool status_known(file_status s) { return stdfs::status_known(s); } +}
\ No newline at end of file diff --git a/toolsrc/include/vcpkg_Files.h b/toolsrc/include/vcpkg_Files.h index c1cf5b371..3fbaad363 100644 --- a/toolsrc/include/vcpkg_Files.h +++ b/toolsrc/include/vcpkg_Files.h @@ -2,53 +2,38 @@ #include "vcpkg_expected.h" #include "filesystem_fs.h" -#include <iterator> namespace vcpkg::Files { - static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; - - bool has_invalid_chars_for_filesystem(const std::string& s); - - Expected<std::string> read_contents(const fs::path& file_path) noexcept; - - Expected<std::vector<std::string>> read_all_lines(const fs::path& file_path); - - void write_all_lines(const fs::path& file_path, const std::vector<std::string>& lines); - - fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename); - - template <class Pred> - void non_recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector<fs::path>* output) - { - std::copy_if(fs::directory_iterator(dir), fs::directory_iterator(), std::back_inserter(*output), predicate); - } - - template <class Pred> - void recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate, std::vector<fs::path>* output) - { - std::copy_if(fs::recursive_directory_iterator(dir), fs::recursive_directory_iterator(), std::back_inserter(*output), predicate); - } - - template <class Pred> - std::vector<fs::path> recursive_find_matching_paths_in_dir(const fs::path& dir, const Pred predicate) + __interface Filesystem { - std::vector<fs::path> v; - recursive_find_matching_paths_in_dir(dir, predicate, &v); - return v; - } - - void recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension, std::vector<fs::path>* output); - - std::vector<fs::path> recursive_find_files_with_extension_in_dir(const fs::path& dir, const std::string& extension); + virtual Expected<std::string> read_contents(const fs::path& file_path) const = 0; + virtual Expected<std::vector<std::string>> read_lines(const fs::path& file_path) const = 0; + virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0; + virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const = 0; + virtual std::vector<fs::path> get_files_non_recursive(const fs::path& dir) const = 0; + + virtual void write_lines(const fs::path& file_path, const std::vector<std::string>& lines) = 0; + virtual void write_contents(const fs::path& file_path, const std::string& data) = 0; + virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0; + virtual bool remove(const fs::path& path) = 0; + virtual bool remove(const fs::path& path, std::error_code& ec) = 0; + virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0; + virtual bool exists(const fs::path& path) const = 0; + virtual bool is_directory(const fs::path& path) const = 0; + virtual bool is_regular_file(const fs::path& path) const = 0; + virtual bool is_empty(const fs::path& path) const = 0; + virtual bool create_directory(const fs::path& path, std::error_code& ec) = 0; + virtual void copy(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts) = 0; + virtual bool copy_file(const fs::path& oldpath, const fs::path& newpath, fs::copy_options opts, std::error_code& ec) = 0; + virtual fs::file_status status(const fs::path& path, std::error_code& ec) const = 0; + }; + + Filesystem& get_real_filesystem(); - void recursive_find_all_files_in_dir(const fs::path& dir, std::vector<fs::path>* output); - - std::vector<fs::path> recursive_find_all_files_in_dir(const fs::path& dir); - - void non_recursive_find_all_files_in_dir(const fs::path& dir, std::vector<fs::path>* output); + static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; - std::vector<fs::path> non_recursive_find_all_files_in_dir(const fs::path& dir); + bool has_invalid_chars_for_filesystem(const std::string& s); void print_paths(const std::vector<fs::path>& paths); } diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index 7b031608c..d152eccf5 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -119,4 +119,12 @@ namespace vcpkg::Strings void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings); std::vector<std::string> split(const std::string& s, const std::string& delimiter); + + template<class T> + std::string serialize(const T& t) + { + std::string ret; + serialize(t, ret); + return ret; + } } diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h index 978407bd8..b165001f4 100644 --- a/toolsrc/include/vcpkg_Util.h +++ b/toolsrc/include/vcpkg_Util.h @@ -23,6 +23,12 @@ namespace vcpkg::Util } template<class Container, class Pred> + void unstable_keep_if(Container& cont, Pred pred) + { + cont.erase(std::partition(cont.begin(), cont.end(), pred), cont.end()); + } + + template<class Container, class Pred> void erase_remove_if(Container& cont, Pred pred) { cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end()); diff --git a/toolsrc/include/vcpkg_optional.h b/toolsrc/include/vcpkg_optional.h index 28bdc81fa..380e54f1c 100644 --- a/toolsrc/include/vcpkg_optional.h +++ b/toolsrc/include/vcpkg_optional.h @@ -1,5 +1,4 @@ #pragma once -#include "LineInfo.h" #include "vcpkg_Checks.h" namespace vcpkg |
