From c434dc99868989ca55aef5e445ac6a0a4c3430f7 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Sat, 8 Apr 2017 16:26:26 -0700 Subject: [vcpkg] Initial addition of Filesystem abstraction to enable testing. --- toolsrc/include/Paragraphs.h | 8 ++++---- toolsrc/include/PostBuildLint_BuildInfo.h | 3 ++- toolsrc/include/VcpkgPaths.h | 3 +++ toolsrc/include/vcpkg_Files.h | 8 +++++++- 4 files changed, 16 insertions(+), 6 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h index 610ebbad6..cdd35e425 100644 --- a/toolsrc/include/Paragraphs.h +++ b/toolsrc/include/Paragraphs.h @@ -11,16 +11,16 @@ namespace vcpkg::Paragraphs { using ParagraphDataMap = std::unordered_map; - Expected get_single_paragraph(const fs::path& control_path); - Expected> get_paragraphs(const fs::path& control_path); + Expected get_single_paragraph(Files::Filesystem& fs, const fs::path& control_path); + Expected> get_paragraphs(Files::Filesystem& fs, const fs::path& control_path); Expected parse_single_paragraph(const std::string& str); Expected> parse_paragraphs(const std::string& str); - Expected try_load_port(const fs::path& control_path); + Expected try_load_port(Files::Filesystem& fs, const fs::path& control_path); Expected try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec); - std::vector load_all_ports(const fs::path& ports_dir); + std::vector load_all_ports(Files::Filesystem& fs, const fs::path& ports_dir); std::map extract_port_names_and_versions(const std::vector& source_paragraphs); } diff --git a/toolsrc/include/PostBuildLint_BuildInfo.h b/toolsrc/include/PostBuildLint_BuildInfo.h index 8bac18861..c54ea0fa5 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 policies; }; - BuildInfo read_build_info(const fs::path& filepath); + BuildInfo read_build_info(Files::Filesystem& fs, const fs::path& filepath); } 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 cmake_exe; Lazy git_exe; diff --git a/toolsrc/include/vcpkg_Files.h b/toolsrc/include/vcpkg_Files.h index c1cf5b371..a114354bc 100644 --- a/toolsrc/include/vcpkg_Files.h +++ b/toolsrc/include/vcpkg_Files.h @@ -6,11 +6,17 @@ namespace vcpkg::Files { + __interface Filesystem + { + virtual Expected read_contents(const fs::path& file_path) noexcept = 0; + }; + + Filesystem& get_real_filesystem(); + static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)"; bool has_invalid_chars_for_filesystem(const std::string& s); - Expected read_contents(const fs::path& file_path) noexcept; Expected> read_all_lines(const fs::path& file_path); -- cgit v1.2.3