This commit is contained in:
Patrick Bader 2017-01-06 19:09:17 +01:00
commit 04f8da985c
37 changed files with 144 additions and 79 deletions

View File

@ -4,7 +4,7 @@
#include "Paragraphs.h"
#include <regex>
namespace vcpkg { namespace PostBuildLint
namespace vcpkg::PostBuildLint
{
enum class LinkageType
{
@ -126,4 +126,4 @@ namespace vcpkg { namespace PostBuildLint
};
BuildInfo read_build_info(const fs::path& filepath);
}}
}

View File

@ -0,0 +1,48 @@
#pragma once
#include <vector>
#include <algorithm>
// Add more forwarding functions to the delegate std::vector as needed.
namespace vcpkg
{
template <class T>
class ImmutableSortedVector
{
public:
static ImmutableSortedVector<T> create(std::vector<T> vector)
{
ImmutableSortedVector out;
out.delegate = std::move(vector);
if (!std::is_sorted(out.delegate.cbegin(), out.delegate.cend()))
{
std::sort(out.delegate.begin(), out.delegate.end());
}
return out;
}
typename std::vector<T>::const_iterator begin() const
{
return this->delegate.cbegin();
}
typename std::vector<T>::const_iterator end() const
{
return this->delegate.cend();
}
typename std::vector<T>::const_iterator cbegin() const
{
return this->delegate.cbegin();
}
typename std::vector<T>::const_iterator cend() const
{
return this->delegate.cend();
}
private:
std::vector<T> delegate;
};
}

View File

@ -3,8 +3,8 @@
#include "filesystem_fs.h"
#include <unordered_map>
namespace vcpkg { namespace Paragraphs
namespace vcpkg::Paragraphs
{
std::vector<std::unordered_map<std::string, std::string>> get_paragraphs(const fs::path& control_path);
std::vector<std::unordered_map<std::string, std::string>> parse_paragraphs(const std::string& str);
}}
}

View File

@ -3,7 +3,7 @@
#include "MachineType.h"
#include "filesystem_fs.h"
namespace vcpkg {namespace COFFFileReader
namespace vcpkg::COFFFileReader
{
struct dll_info
{
@ -18,4 +18,4 @@ namespace vcpkg {namespace COFFFileReader
dll_info read_dll(const fs::path& path);
lib_info read_lib(const fs::path& path);
}}
}

View File

@ -2,7 +2,7 @@
#include "package_spec.h"
#include "vcpkg_paths.h"
namespace vcpkg {namespace PostBuildLint
namespace vcpkg::PostBuildLint
{
void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths);
}}
}

View File

@ -4,6 +4,7 @@
#include "BinaryParagraph.h"
#include "StatusParagraphs.h"
#include "vcpkg_paths.h"
#include "ImmutableSortedVector.h"
namespace vcpkg
{
@ -14,7 +15,7 @@ namespace vcpkg
struct StatusParagraph_and_associated_files
{
StatusParagraph pgh;
std::vector<std::string> files;
ImmutableSortedVector<std::string> files;
};
std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db);

View File

@ -2,7 +2,7 @@
#include "vcpkg_Strings.h"
namespace vcpkg {namespace Checks
namespace vcpkg::Checks
{
__declspec(noreturn) void unreachable();
@ -46,4 +46,4 @@ namespace vcpkg {namespace Checks
exit_with_message(Strings::format(errorMessageTemplate, errorMessageArgs...).c_str());
}
}
}}
}

View File

@ -4,7 +4,7 @@
#include "StatusParagraphs.h"
#include "vcpkg_paths.h"
namespace vcpkg {namespace Dependencies
namespace vcpkg::Dependencies
{
enum class install_plan_type
{
@ -27,4 +27,4 @@ namespace vcpkg {namespace Dependencies
};
std::vector<package_spec_with_install_plan> create_install_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db);
}}
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "vcpkg_paths.h"
namespace vcpkg {namespace Environment
namespace vcpkg::Environment
{
void ensure_nuget_on_path(const vcpkg_paths& paths);
@ -14,4 +14,4 @@ namespace vcpkg {namespace Environment
ensure_cmake_on_path(paths);
ensure_git_on_path(paths);
}
}}
}

View File

@ -4,7 +4,7 @@
#include "filesystem_fs.h"
#include <iterator>
namespace vcpkg {namespace Files
namespace vcpkg::Files
{
static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)";
@ -53,4 +53,4 @@ namespace vcpkg {namespace Files
std::vector<fs::path> non_recursive_find_all_files_in_dir(const fs::path& dir);
void print_paths(const std::vector<fs::path>& paths);
}}
}

View File

@ -3,7 +3,7 @@
#include <unordered_map>
#include <unordered_set>
namespace vcpkg { namespace Graphs
namespace vcpkg::Graphs
{
enum class ExplorationStatus
{
@ -117,4 +117,4 @@ namespace vcpkg { namespace Graphs
private:
std::unordered_map<V, std::unordered_set<V>> vertices;
};
}}
}

View File

@ -3,7 +3,7 @@
#include "package_spec.h"
#include "vcpkg_paths.h"
namespace vcpkg {namespace Input
namespace vcpkg::Input
{
package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text);
@ -11,5 +11,5 @@ namespace vcpkg {namespace Input
void check_triplet(const triplet& t, const vcpkg_paths& paths);
void check_triplets(std::vector<package_spec> triplets, const vcpkg_paths& paths);
}}
void check_triplets(const std::vector<package_spec>& triplets, const vcpkg_paths& paths);
}

View File

@ -4,7 +4,7 @@
#include <unordered_set>
#include <map>
namespace vcpkg { namespace Maps
namespace vcpkg::Maps
{
template <typename K, typename V>
std::unordered_set<K> extract_key_set(const std::unordered_map<K, V>& input_map)
@ -38,4 +38,4 @@ namespace vcpkg { namespace Maps
}
return key_set;
}
}}
}

View File

@ -3,7 +3,7 @@
#include "vcpkg_Checks.h"
#include <unordered_set>
namespace vcpkg { namespace Sets
namespace vcpkg::Sets
{
template <typename T, typename Container>
void remove_all(std::unordered_set<T>* input_set, Container remove_these)
@ -14,4 +14,4 @@ namespace vcpkg { namespace Sets
input_set->erase(r);
}
}
}}
}

View File

@ -2,7 +2,7 @@
#include <vector>
namespace vcpkg {namespace Strings {namespace details
namespace vcpkg::Strings::details
{
inline const char* to_printf_arg(const std::string& s)
{
@ -42,9 +42,9 @@ namespace vcpkg {namespace Strings {namespace details
}
std::wstring wformat_internal(const wchar_t* fmtstr, ...);
}}}
}
namespace vcpkg {namespace Strings
namespace vcpkg::Strings
{
template <class...Args>
std::string format(const char* fmtstr, const Args&...args)
@ -75,4 +75,4 @@ namespace vcpkg {namespace Strings
std::string trimmed(const std::string& s);
void trim_all_and_remove_whitespace_strings(std::vector<std::string>* strings);
}}
}

View File

@ -3,7 +3,7 @@
#include "vcpkg_Strings.h"
#include "filesystem_fs.h"
namespace vcpkg {namespace System
namespace vcpkg::System
{
fs::path get_exe_path_of_current_process();
@ -93,4 +93,4 @@ namespace vcpkg {namespace System
};
std::wstring wdupenv_str(const wchar_t* varname) noexcept;
}}
}

View File

@ -2,9 +2,9 @@
#include <string>
namespace vcpkg { namespace Info
namespace vcpkg::Info
{
const std::string& version();
const std::string& email();
}}
}

View File

@ -2,7 +2,7 @@
#include <unordered_map>
namespace vcpkg {namespace details
namespace vcpkg::details
{
std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname);
std::string remove_optional_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname);
@ -11,4 +11,4 @@ namespace vcpkg {namespace details
std::string remove_required_field(std::unordered_map<std::string, std::string>* fields, const std::string& fieldname);
std::string shorten_description(const std::string& desc);
}}
}

View File

@ -2,7 +2,7 @@
#include "vcpkg_Checks.h"
#include "vcpkglib_helpers.h"
namespace vcpkg { namespace PostBuildLint
namespace vcpkg::PostBuildLint
{
const ConfigurationType& BuildType::config() const
{
@ -161,4 +161,4 @@ namespace vcpkg { namespace PostBuildLint
{
return this->m_dll_name;
}
}}
}

View File

@ -1,7 +1,7 @@
#include "Paragraphs.h"
#include "vcpkg_Files.h"
namespace vcpkg { namespace Paragraphs
namespace vcpkg::Paragraphs
{
struct Parser
{
@ -160,4 +160,4 @@ namespace vcpkg { namespace Paragraphs
{
return Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs();
}
}}
}

View File

@ -6,7 +6,7 @@
using namespace std;
namespace vcpkg { namespace COFFFileReader
namespace vcpkg::COFFFileReader
{
template <class T>
static T reinterpret_bytes(const char* data)
@ -306,4 +306,4 @@ namespace vcpkg { namespace COFFFileReader
return {std::vector<MachineType>(machine_types.cbegin(), machine_types.cend())};
}
}}
}

View File

@ -164,9 +164,8 @@ namespace vcpkg
return output;
}
void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db)
static ImmutableSortedVector<std::string> build_list_of_package_files(const fs::path& package_dir)
{
const fs::path package_dir = paths.package_dir(binary_paragraph.spec);
const std::vector<fs::path> package_file_paths = Files::recursive_find_all_files_in_dir(package_dir);
std::vector<std::string> package_files;
const size_t package_remove_char_count = package_dir.generic_string().size() + 1; // +1 for the slash
@ -176,14 +175,27 @@ namespace vcpkg
as_string.erase(0, package_remove_char_count);
return std::move(as_string);
});
std::sort(package_files.begin(), package_files.end());
const std::vector<StatusParagraph_and_associated_files>& pgh_and_files = get_installed_files(paths, status_db);
const triplet& triplet = binary_paragraph.spec.target_triplet();
return ImmutableSortedVector<std::string>::create(std::move(package_files));
}
static ImmutableSortedVector<std::string> build_list_of_installed_files(const std::vector<StatusParagraph_and_associated_files>& pgh_and_files, const triplet& triplet)
{
std::vector<std::string> installed_files = extract_files_in_triplet(pgh_and_files, triplet);
const size_t installed_remove_char_count = triplet.canonical_name().size() + 1; // +1 for the slash
remove_first_n_chars(&installed_files, installed_remove_char_count);
std::sort(installed_files.begin(), installed_files.end()); // Should already be sorted
return ImmutableSortedVector<std::string>::create(std::move(installed_files));
}
void install_package(const vcpkg_paths& paths, const BinaryParagraph& binary_paragraph, StatusParagraphs& status_db)
{
const fs::path package_dir = paths.package_dir(binary_paragraph.spec);
const triplet& triplet = binary_paragraph.spec.target_triplet();
const std::vector<StatusParagraph_and_associated_files> pgh_and_files = get_installed_files(paths, status_db);
const ImmutableSortedVector<std::string> package_files = build_list_of_package_files(package_dir);
const ImmutableSortedVector<std::string> installed_files = build_list_of_installed_files(pgh_and_files, triplet);
std::vector<std::string> intersection;
std::set_intersection(package_files.cbegin(), package_files.cend(),

View File

@ -237,13 +237,13 @@ true
std::wstring GetSQMUser()
{
LONG err = NULL;
LONG err;
struct RAII_HKEY {
HKEY hkey = NULL;
HKEY hkey = nullptr;
~RAII_HKEY()
{
if (hkey != NULL)
if (hkey != nullptr)
RegCloseKey(hkey);
}
} HKCU_SQMClient;
@ -257,7 +257,7 @@ true
std::array<wchar_t,128> buffer;
DWORD lType = 0;
DWORD dwBufferSize = static_cast<DWORD>(buffer.size() * sizeof(wchar_t));
err = RegQueryValueExW(HKCU_SQMClient.hkey, L"UserId", NULL, &lType, reinterpret_cast<LPBYTE>(buffer.data()), &dwBufferSize);
err = RegQueryValueExW(HKCU_SQMClient.hkey, L"UserId", nullptr, &lType, reinterpret_cast<LPBYTE>(buffer.data()), &dwBufferSize);
if (err == ERROR_SUCCESS && lType == REG_SZ && dwBufferSize >= sizeof(wchar_t))
{
size_t sz = dwBufferSize / sizeof(wchar_t);

View File

@ -7,7 +7,7 @@
#include "BuildInfo.h"
#include <regex>
namespace vcpkg { namespace PostBuildLint
namespace vcpkg::PostBuildLint
{
enum class lint_status
{
@ -668,4 +668,4 @@ namespace vcpkg { namespace PostBuildLint
System::println("-- Performing post-build validation done");
}
}}
}

View File

@ -7,14 +7,14 @@
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Microsoft { namespace VisualStudio { namespace CppUnitTestFramework
namespace Microsoft::VisualStudio::CppUnitTestFramework
{
template <>
inline std::wstring ToString<vcpkg::package_spec_parse_result>(const vcpkg::package_spec_parse_result& t)
{
return ToString(static_cast<uint32_t>(t));
}
}}}
}
namespace UnitTest1
{

View File

@ -204,7 +204,7 @@ std::vector<StatusParagraph_and_associated_files> vcpkg::get_installed_files(con
}
), installed_files_of_current_pgh.end());
StatusParagraph_and_associated_files pgh_and_files = {*pgh, std::move(installed_files_of_current_pgh)};
StatusParagraph_and_associated_files pgh_and_files = {*pgh, ImmutableSortedVector<std::string>::create(std::move(installed_files_of_current_pgh))};
installed_files.push_back(std::move(pgh_and_files));
}

View File

@ -3,7 +3,7 @@
#include <stdexcept>
#include "vcpkg_System.h"
namespace vcpkg {namespace Checks
namespace vcpkg::Checks
{
void unreachable()
{
@ -41,4 +41,4 @@ namespace vcpkg {namespace Checks
exit_with_message(errorMessage);
}
}
}}
}

View File

@ -9,7 +9,7 @@
#include "vcpkg_Files.h"
#include "vcpkg.h"
namespace vcpkg { namespace Dependencies
namespace vcpkg::Dependencies
{
std::vector<package_spec_with_install_plan> create_install_plan(const vcpkg_paths& paths, const std::vector<package_spec>& specs, const StatusParagraphs& status_db)
{
@ -72,4 +72,4 @@ namespace vcpkg { namespace Dependencies
}
return ret;
}
}}
}

View File

@ -5,7 +5,7 @@
#include "metrics.h"
#include "vcpkg_System.h"
namespace vcpkg {namespace Environment
namespace vcpkg::Environment
{
static const fs::path default_cmake_installation_dir = "C:/Program Files/CMake/bin";
static const fs::path default_cmake_installation_dir_x86 = "C:/Program Files (x86)/CMake/bin";
@ -83,4 +83,4 @@ namespace vcpkg {namespace Environment
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
ensure_on_path(nuget_version, L"nuget 2>&1", L"powershell -ExecutionPolicy Bypass scripts\\fetchDependency.ps1 -Dependency nuget");
}
}}
}

View File

@ -3,7 +3,7 @@
#include <regex>
#include "vcpkg_System.h"
namespace vcpkg {namespace Files
namespace vcpkg::Files
{
static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])");
@ -140,4 +140,4 @@ namespace vcpkg {namespace Files
}
System::println("");
}
}}
}

View File

@ -3,7 +3,7 @@
#include "metrics.h"
#include "vcpkg_Commands.h"
namespace vcpkg {namespace Input
namespace vcpkg::Input
{
package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, const std::string& example_text)
{
@ -42,11 +42,11 @@ namespace vcpkg {namespace Input
}
}
void check_triplets(std::vector<package_spec> triplets, const vcpkg_paths& paths)
void check_triplets(const std::vector<package_spec>& triplets, const vcpkg_paths& paths)
{
for (const package_spec& spec : triplets)
{
check_triplet(spec.target_triplet(), paths);
}
}
}}
}

View File

@ -7,7 +7,7 @@
#include <functional>
#include <cctype>
namespace vcpkg {namespace Strings {namespace details
namespace vcpkg::Strings::details
{
// To disambiguate between two overloads
static const auto isspace = [](const char c)
@ -40,9 +40,9 @@ namespace vcpkg {namespace Strings {namespace details
return output;
}
}}}
}
namespace vcpkg {namespace Strings
namespace vcpkg::Strings
{
std::wstring utf8_to_utf16(const std::string& s)
{
@ -119,4 +119,4 @@ namespace vcpkg {namespace Strings
return s == "";
}), strings->end());
}
}}
}

View File

@ -3,7 +3,7 @@
#include <Windows.h>
#include <regex>
namespace vcpkg {namespace System
namespace vcpkg::System
{
fs::path get_exe_path_of_current_process()
{
@ -104,6 +104,6 @@ namespace vcpkg {namespace System
double Stopwatch2::microseconds() const
{
return (reinterpret_cast<const LARGE_INTEGER*>(&end_time)->QuadPart -
reinterpret_cast<const LARGE_INTEGER*>(&start_time)->QuadPart) * 1000000.0 / reinterpret_cast<const LARGE_INTEGER*>(&freq)->QuadPart;
reinterpret_cast<const LARGE_INTEGER*>(&start_time)->QuadPart) * 1000000.0 / reinterpret_cast<const LARGE_INTEGER*>(&freq)->QuadPart;
}
}}
}

View File

@ -6,7 +6,7 @@
#define VCPKG_VERSION_AS_STRING MACRO_TO_STRING(VCPKG_VERSION)"" // Double quotes needed at the end to prevent blank token
namespace vcpkg { namespace Info
namespace vcpkg::Info
{
const std::string& version()
{
@ -31,4 +31,4 @@ namespace vcpkg { namespace Info
static const std::string s_email = R"(vcpkg@microsoft.com)";
return s_email;
}
}}
}

View File

@ -3,7 +3,7 @@
#include <unordered_map>
#include <regex>
namespace vcpkg {namespace details
namespace vcpkg::details
{
std::string optional_field(const std::unordered_map<std::string, std::string>& fields, const std::string& fieldname)
{
@ -53,4 +53,4 @@ namespace vcpkg {namespace details
simple_desc.append("...");
return simple_desc;
}
}}
}

View File

@ -128,6 +128,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\expected.h" />
<ClInclude Include="..\include\ImmutableSortedVector.h" />
<ClInclude Include="..\include\opt_bool.h" />
<ClInclude Include="..\include\Stopwatch.h" />
<ClInclude Include="..\include\vcpkg_Checks.h" />

View File

@ -62,5 +62,8 @@
<ClInclude Include="..\include\Stopwatch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\ImmutableSortedVector.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>