aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-10-03 15:52:29 -0700
committerRobert Schumacher <roschuma@microsoft.com>2017-10-03 15:52:29 -0700
commitd5705e87c42784607bf462159bebe14044a88eca (patch)
treeaded4a5806480ad3e6980b8c5f4dacd61a004614 /toolsrc/src
parentc167c70c272a417779e601fffcbdb72278da1848 (diff)
parent3838d5880470fdc884f035ed3d1c67d3bdd1e16e (diff)
downloadvcpkg-d5705e87c42784607bf462159bebe14044a88eca.tar.gz
vcpkg-d5705e87c42784607bf462159bebe14044a88eca.zip
Merge branch 'master' into martin-s-patch-vs2013
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/Paragraphs.cpp18
-rw-r--r--toolsrc/src/PostBuildLint.cpp4
-rw-r--r--toolsrc/src/SourceParagraph.cpp4
-rw-r--r--toolsrc/src/VcpkgPaths.cpp77
-rw-r--r--toolsrc/src/commands_ci.cpp52
-rw-r--r--toolsrc/src/commands_edit.cpp16
-rw-r--r--toolsrc/src/commands_install.cpp166
-rw-r--r--toolsrc/src/commands_integrate.cpp11
-rw-r--r--toolsrc/src/commands_portsdiff.cpp10
-rw-r--r--toolsrc/src/commands_remove.cpp85
-rw-r--r--toolsrc/src/commands_search.cpp21
-rw-r--r--toolsrc/src/commands_update.cpp28
-rw-r--r--toolsrc/src/commands_version.cpp33
-rw-r--r--toolsrc/src/metrics.cpp130
-rw-r--r--toolsrc/src/tests_package_spec.cpp2
-rw-r--r--toolsrc/src/vcpkg.cpp8
-rw-r--r--toolsrc/src/vcpkg_Build.cpp11
-rw-r--r--toolsrc/src/vcpkg_Dependencies.cpp15
-rw-r--r--toolsrc/src/vcpkg_Strings.cpp27
-rw-r--r--toolsrc/src/vcpkg_System.cpp13
20 files changed, 407 insertions, 324 deletions
diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp
index a7dee4fd3..6a6f191df 100644
--- a/toolsrc/src/Paragraphs.cpp
+++ b/toolsrc/src/Paragraphs.cpp
@@ -254,7 +254,7 @@ namespace vcpkg::Paragraphs
for (auto&& path : fs.get_files_non_recursive(ports_dir))
{
auto maybe_spgh = try_load_port(fs, path);
- if (auto spgh = maybe_spgh.get())
+ if (const auto spgh = maybe_spgh.get())
{
ret.paragraphs.emplace_back(std::move(*spgh));
}
@@ -272,8 +272,20 @@ namespace vcpkg::Paragraphs
auto results = try_load_all_ports(fs, ports_dir);
if (!results.errors.empty())
{
- print_error_message(results.errors);
- Checks::exit_fail(VCPKG_LINE_INFO);
+ if (GlobalState::debugging)
+ {
+ print_error_message(results.errors);
+ }
+ else
+ {
+ for (auto&& error : results.errors)
+ {
+ System::println(
+ System::Color::warning, "Warning: an error occurred while parsing '%s'", error->name);
+ }
+ System::println(System::Color::warning,
+ "Use '--debug' to get more information about the parse failures.\n");
+ }
}
return std::move(results.paragraphs);
}
diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp
index 33dc446cf..69008fab3 100644
--- a/toolsrc/src/PostBuildLint.cpp
+++ b/toolsrc/src/PostBuildLint.cpp
@@ -38,7 +38,7 @@ namespace vcpkg::PostBuildLint
}
};
- const std::vector<OutdatedDynamicCrt>& get_outdated_dynamic_crts()
+ Span<const OutdatedDynamicCrt> get_outdated_dynamic_crts(CStringView toolset)
{
static const std::vector<OutdatedDynamicCrt> V_NO_MSVCRT = {
{"msvcp100.dll", R"(msvcp100\.dll)"},
@@ -662,7 +662,7 @@ namespace vcpkg::PostBuildLint
"Running command:\n %s\n failed",
Strings::to_utf8(cmd_line));
- for (const OutdatedDynamicCrt& outdated_crt : get_outdated_dynamic_crts())
+ for (const OutdatedDynamicCrt& outdated_crt : get_outdated_dynamic_crts("v141"))
{
if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.regex))
{
diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp
index 171689ce7..0f1a38d19 100644
--- a/toolsrc/src/SourceParagraph.cpp
+++ b/toolsrc/src/SourceParagraph.cpp
@@ -25,7 +25,7 @@ namespace vcpkg
static const std::string VERSION = "Version";
}
- static span<const std::string> get_list_of_valid_fields()
+ static Span<const std::string> get_list_of_valid_fields()
{
static const std::string valid_fields[] = {
Fields::SOURCE,
@@ -38,7 +38,7 @@ namespace vcpkg
return valid_fields;
}
- void print_error_message(span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list)
+ void print_error_message(Span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list)
{
Checks::check_exit(VCPKG_LINE_INFO, error_info_list.size() > 0);
diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp
index 71a35d24c..651d4d834 100644
--- a/toolsrc/src/VcpkgPaths.cpp
+++ b/toolsrc/src/VcpkgPaths.cpp
@@ -10,6 +10,10 @@
namespace vcpkg
{
+ static constexpr CWStringView V_120 = L"v120";
+ static constexpr CWStringView V_140 = L"v140";
+ static constexpr CWStringView V_141 = L"v141";
+
static bool exists_and_has_equal_or_greater_version(const std::wstring& version_cmd,
const std::array<int, 3>& expected_version)
{
@@ -63,18 +67,23 @@ namespace vcpkg
const fs::path& expected_downloaded_path,
const std::array<int, 3>& version)
{
+ const std::string tool_name_utf8 = Strings::to_utf8(tool_name);
+ const std::string version_as_string = Strings::format("%d.%d.%d", version[0], version[1], version[2]);
+ System::println("A suitable version of %s was not found (required v%s). Downloading portable %s v%s...",
+ tool_name_utf8,
+ version_as_string,
+ tool_name_utf8,
+ version_as_string);
const fs::path script = scripts_folder / "fetchDependency.ps1";
const auto install_cmd =
System::create_powershell_script_cmd(script, Strings::wformat(L"-Dependency %s", tool_name));
const System::ExitCodeAndOutput rc = System::cmd_execute_and_capture_output(install_cmd);
if (rc.exit_code)
{
- const std::string version_as_string = Strings::format("%d.%d.%d", version[0], version[1], version[2]);
-
System::println(System::Color::error,
"Launching powershell failed or was denied when trying to fetch %s version %s.\n"
"(No sufficient installed version was found)",
- Strings::to_utf8(tool_name),
+ tool_name_utf8,
version_as_string);
{
auto locked_metrics = Metrics::g_metrics.lock();
@@ -97,10 +106,10 @@ namespace vcpkg
static fs::path get_cmake_path(const fs::path& downloads_folder, const fs::path& scripts_folder)
{
- static constexpr std::array<int, 3> EXPECTED_VERSION = {3, 9, 1};
+ static constexpr std::array<int, 3> EXPECTED_VERSION = {3, 9, 3};
static const std::wstring VERSION_CHECK_ARGUMENTS = L"--version";
- const fs::path downloaded_copy = downloads_folder / "cmake-3.9.1-win32-x86" / "bin" / "cmake.exe";
+ const fs::path downloaded_copy = downloads_folder / "cmake-3.9.3-win32-x86" / "bin" / "cmake.exe";
const std::vector<fs::path> from_path = Files::find_from_PATH(L"cmake");
std::vector<fs::path> candidate_paths;
@@ -358,11 +367,13 @@ namespace vcpkg
if (fs.exists(vs2015_dumpbin_exe))
{
found_toolsets.push_back(
- {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140", supported_architectures});
+ {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, {}, V_140, supported_architectures});
}
}
}
+ const std::vector<std::string> vs2017_installation_instances = get_vs2017_installation_instances(paths);
+
// VS2017
Optional<Toolset> vs2017_toolset;
const std::vector<std::string> vs2017_installation_instances = get_vs2017_installation_instances(paths);
@@ -407,14 +418,13 @@ namespace vcpkg
paths_examined.push_back(dumpbin_path);
if (fs.exists(dumpbin_path))
{
- vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, L"v141", supported_architectures};
+ vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, {}, V_141, supported_architectures};
break;
}
}
if (const auto value = vs2017_toolset.get())
{
found_toolsets.push_back(*value);
- break;
}
}
@@ -432,20 +442,63 @@ namespace vcpkg
return found_toolsets;
}
+ static std::vector<Toolset> create_vs2017_v140_toolset_instances(const std::vector<Toolset>& vs_toolsets)
+ {
+ std::vector<Toolset> vs2017_v140_toolsets;
+
+ // In constrast to v141 and above, there can only be a single instance of v140 (VS2017 vs VS2015).
+ const auto it = Util::find_if(vs_toolsets, [&](const Toolset& t) { return t.version == V_140; });
+
+ // If v140 is not available, then VS2017 cant use them. Return empty.
+ if (it == vs_toolsets.cend())
+ {
+ return vs2017_v140_toolsets;
+ }
+
+ // If it does exist, then create a matching v140 toolset for each v141 toolset
+ const Toolset v140_toolset = *it;
+ for (const Toolset& toolset : vs_toolsets)
+ {
+ if (toolset.version != V_141)
+ {
+ continue;
+ }
+
+ Toolset t = Toolset{
+ toolset.dumpbin, toolset.vcvarsall, {L"-vcvars_ver=14.0"}, V_140, toolset.supported_architectures};
+ vs2017_v140_toolsets.push_back(std::move(t));
+ }
+
+ return vs2017_v140_toolsets;
+ }
+
const Toolset& VcpkgPaths::get_toolset(const std::string& toolset_version) const
{
+ const std::wstring& w_toolset_version = Strings::to_utf16(toolset_version);
+
// Invariant: toolsets are non-empty and sorted with newest at back()
- const auto& vs_toolsets = this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
+ const std::vector<Toolset>& vs_toolsets =
+ this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
- if (toolset_version.empty())
+ if (w_toolset_version.empty())
{
return vs_toolsets.back();
}
- const auto toolset = Util::find_if(
- vs_toolsets, [&](const Toolset& t) { return toolset_version == Strings::to_utf8(t.version); });
+ const auto toolset =
+ Util::find_if(vs_toolsets, [&](const Toolset& t) { return w_toolset_version == t.version; });
Checks::check_exit(
VCPKG_LINE_INFO, toolset != vs_toolsets.end(), "Could not find toolset '%s'", toolset_version);
+
+ // If v140 is the selected toolset and VS2017 is available, then use VS2017's vcvarsall with the
+ // -vcvars_ver=14.0 option
+ const std::vector<Toolset>& vs2017_v140_toolsets = this->toolsets_vs2017_v140.get_lazy(
+ [&vs_toolsets]() { return create_vs2017_v140_toolset_instances(vs_toolsets); });
+ if (w_toolset_version == V_140 && !vs2017_v140_toolsets.empty())
+ {
+ return vs2017_v140_toolsets.back();
+ }
+
return *toolset;
}
diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp
index ca5e8a9a9..75ff65556 100644
--- a/toolsrc/src/commands_ci.cpp
+++ b/toolsrc/src/commands_ci.cpp
@@ -41,57 +41,19 @@ namespace vcpkg::Commands::CI
StatusParagraphs status_db = database_load_check(paths);
const auto& paths_port_file = Dependencies::PathsPortFile(paths);
- const std::vector<InstallPlanAction> install_plan =
+ std::vector<InstallPlanAction> install_plan =
Dependencies::create_install_plan(paths_port_file, specs, status_db);
Checks::check_exit(VCPKG_LINE_INFO, !install_plan.empty(), "Install plan cannot be empty");
- std::vector<BuildResult> results;
- std::vector<std::string> timing;
- const ElapsedTime timer = ElapsedTime::create_started();
- size_t counter = 0;
- const size_t package_count = install_plan.size();
const Build::BuildPackageOptions install_plan_options = {Build::UseHeadVersion::NO, Build::AllowDownloads::YES};
- for (const InstallPlanAction& action : install_plan)
- {
- const ElapsedTime build_timer = ElapsedTime::create_started();
- counter++;
- const std::string display_name = action.spec.to_string();
- System::println("Starting package %d/%d: %s", counter, package_count, display_name);
+ const std::vector<Dependencies::AnyAction> action_plan =
+ Util::fmap(install_plan, [](InstallPlanAction& install_action) {
+ return Dependencies::AnyAction(std::move(install_action));
+ });
- timing.push_back("0");
- results.push_back(BuildResult::NULLVALUE);
-
- const BuildResult result =
- Install::perform_install_plan_action(paths, action, install_plan_options, status_db);
- timing.back() = build_timer.to_string();
- results.back() = result;
- System::println("Elapsed time for package %s: %s", action.spec, build_timer.to_string());
- }
-
- System::println("Total time taken: %s", timer.to_string());
-
- for (size_t i = 0; i < results.size(); i++)
- {
- System::println("%s: %s: %s", install_plan[i].spec, Build::to_string(results[i]), timing[i]);
- }
-
- std::map<BuildResult, int> summary;
- for (const BuildResult& v : Build::BuildResult_values)
- {
- summary[v] = 0;
- }
-
- for (const BuildResult& r : results)
- {
- summary[r]++;
- }
-
- System::println("\n\nSUMMARY");
- for (const std::pair<const BuildResult, int>& entry : summary)
- {
- System::println(" %s: %d", Build::to_string(entry.first), entry.second);
- }
+ Install::perform_and_exit(
+ action_plan, install_plan_options, Install::KeepGoing::YES, Install::PrintSummary::YES, paths, status_db);
Checks::exit_success(VCPKG_LINE_INFO);
}
diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp
index dc28de737..823c87534 100644
--- a/toolsrc/src/commands_edit.cpp
+++ b/toolsrc/src/commands_edit.cpp
@@ -8,11 +8,10 @@ namespace vcpkg::Commands::Edit
{
static std::vector<fs::path> find_from_registry()
{
- static const std::array<const wchar_t*, 4> REGKEYS = {
+ static const std::array<const wchar_t*, 3> REGKEYS = {
LR"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1)",
- LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1)",
+ LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1)",
LR"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1)",
- LR"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1)",
};
std::vector<fs::path> output;
@@ -23,8 +22,8 @@ namespace vcpkg::Commands::Edit
if (const auto c = code_installpath.get())
{
const fs::path install_path = fs::path(*c);
- output.push_back(install_path / "Code.exe");
output.push_back(install_path / "Code - Insiders.exe");
+ output.push_back(install_path / "Code.exe");
}
}
return output;
@@ -34,6 +33,9 @@ namespace vcpkg::Commands::Edit
{
static const std::string OPTION_BUILDTREES = "--buildtrees";
+ static const fs::path VS_CODE_INSIDERS = fs::path{"Microsoft VS Code Insiders"} / "Code - Insiders.exe";
+ static const fs::path VS_CODE = fs::path{"Microsoft VS Code"} / "Code.exe";
+
auto& fs = paths.get_filesystem();
static const std::string EXAMPLE = Commands::Help::create_example_string("edit zlib");
@@ -48,8 +50,10 @@ namespace vcpkg::Commands::Edit
std::vector<fs::path> candidate_paths;
const std::vector<fs::path> from_path = Files::find_from_PATH(L"EDITOR");
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
- candidate_paths.push_back(System::get_program_files_platform_bitness() / "Microsoft VS Code" / "Code.exe");
- candidate_paths.push_back(System::get_program_files_32_bit() / "Microsoft VS Code" / "Code.exe");
+ candidate_paths.push_back(System::get_program_files_platform_bitness() / VS_CODE_INSIDERS);
+ candidate_paths.push_back(System::get_program_files_32_bit() / VS_CODE_INSIDERS);
+ candidate_paths.push_back(System::get_program_files_platform_bitness() / VS_CODE);
+ candidate_paths.push_back(System::get_program_files_32_bit() / VS_CODE);
const std::vector<fs::path> from_registry = find_from_registry();
candidate_paths.insert(candidate_paths.end(), from_registry.cbegin(), from_registry.cend());
diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp
index d7c14f39c..d815332fe 100644
--- a/toolsrc/src/commands_install.cpp
+++ b/toolsrc/src/commands_install.cpp
@@ -59,7 +59,7 @@ namespace vcpkg::Commands::Install
auto files = fs.get_files_recursive(source_dir);
for (auto&& file : files)
{
- auto status = fs.status(file, ec);
+ const auto status = fs.status(file, ec);
if (ec)
{
System::println(System::Color::error, "failed: %s: %s", file.u8string(), ec.message());
@@ -309,7 +309,7 @@ namespace vcpkg::Commands::Install
const BinaryControlFile bcf =
Paragraphs::try_load_cached_control_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
System::println("Installing package %s... ", display_name_with_features);
- auto install_result = install_package(paths, bcf, &status_db);
+ const auto install_result = install_package(paths, bcf, &status_db);
switch (install_result)
{
case InstallResult::SUCCESS:
@@ -328,7 +328,7 @@ namespace vcpkg::Commands::Install
System::Color::warning, "Package %s is already built -- not building from HEAD", display_name);
}
System::println("Installing package %s... ", display_name);
- auto install_result = install_package(
+ const auto install_result = install_package(
paths, action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO), &status_db);
switch (install_result)
{
@@ -442,12 +442,93 @@ namespace vcpkg::Commands::Install
}
}
+ void perform_and_exit(const std::vector<AnyAction>& action_plan,
+ const Build::BuildPackageOptions& install_plan_options,
+ const KeepGoing keep_going,
+ const PrintSummary print_summary,
+ const VcpkgPaths& paths,
+ StatusParagraphs& status_db)
+ {
+ std::vector<BuildResult> results;
+ std::vector<std::string> timing;
+ const ElapsedTime timer = ElapsedTime::create_started();
+ size_t counter = 0;
+ const size_t package_count = action_plan.size();
+
+ for (const auto& action : action_plan)
+ {
+ const ElapsedTime build_timer = ElapsedTime::create_started();
+ counter++;
+
+ const std::string display_name = action.spec().to_string();
+ System::println("Starting package %d/%d: %s", counter, package_count, display_name);
+
+ timing.push_back("0");
+ results.push_back(BuildResult::NULLVALUE);
+
+ if (const auto install_action = action.install_plan.get())
+ {
+ const BuildResult result =
+ perform_install_plan_action(paths, *install_action, install_plan_options, status_db);
+ if (result != BuildResult::SUCCEEDED && keep_going == KeepGoing::NO)
+ {
+ System::println(Build::create_user_troubleshooting_message(install_action->spec));
+ Checks::exit_fail(VCPKG_LINE_INFO);
+ }
+
+ results.back() = result;
+ }
+ else if (const auto remove_action = action.remove_plan.get())
+ {
+ Checks::check_exit(VCPKG_LINE_INFO, GlobalState::feature_packages);
+ Remove::perform_remove_plan_action(paths, *remove_action, Remove::Purge::YES, status_db);
+ }
+ else
+ {
+ Checks::unreachable(VCPKG_LINE_INFO);
+ }
+
+ timing.back() = build_timer.to_string();
+ System::println("Elapsed time for package %s: %s", display_name, build_timer.to_string());
+ }
+
+ System::println("Total time taken: %s", timer.to_string());
+
+ if (print_summary == PrintSummary::YES)
+ {
+ for (size_t i = 0; i < results.size(); i++)
+ {
+ System::println("%s: %s: %s", action_plan[i].spec(), Build::to_string(results[i]), timing[i]);
+ }
+
+ std::map<BuildResult, int> summary;
+ for (const BuildResult& v : Build::BUILD_RESULT_VALUES)
+ {
+ summary[v] = 0;
+ }
+
+ for (const BuildResult& r : results)
+ {
+ summary[r]++;
+ }
+
+ System::println("\n\nSUMMARY");
+ for (const std::pair<const BuildResult, int>& entry : summary)
+ {
+ System::println(" %s: %d", Build::to_string(entry.first), entry.second);
+ }
+ }
+
+ Checks::exit_success(VCPKG_LINE_INFO);
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
{
static const std::string OPTION_DRY_RUN = "--dry-run";
static const std::string OPTION_USE_HEAD_VERSION = "--head";
static const std::string OPTION_NO_DOWNLOADS = "--no-downloads";
static const std::string OPTION_RECURSE = "--recurse";
+ static const std::string OPTION_KEEP_GOING = "--keep-going";
// input sanitization
static const std::string EXAMPLE =
@@ -469,11 +550,12 @@ namespace vcpkg::Commands::Install
}
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments(
- {OPTION_DRY_RUN, OPTION_USE_HEAD_VERSION, OPTION_NO_DOWNLOADS, OPTION_RECURSE});
- const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend();
+ {OPTION_DRY_RUN, OPTION_USE_HEAD_VERSION, OPTION_NO_DOWNLOADS, OPTION_RECURSE, OPTION_KEEP_GOING});
+ const bool dry_run = options.find(OPTION_DRY_RUN) != options.cend();
const bool use_head_version = options.find(OPTION_USE_HEAD_VERSION) != options.cend();
const bool no_downloads = options.find(OPTION_NO_DOWNLOADS) != options.cend();
const bool is_recursive = options.find(OPTION_RECURSE) != options.cend();
+ const KeepGoing keep_going = to_keep_going(options.find(OPTION_KEEP_GOING) != options.cend());
// create the plan
StatusParagraphs status_db = database_load_check(paths);
@@ -486,8 +568,8 @@ namespace vcpkg::Commands::Install
if (GlobalState::feature_packages)
{
std::unordered_map<std::string, SourceControlFile> scf_map;
- auto all_ports = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);
- for (auto&& port : all_ports.paragraphs)
+ auto all_ports = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports);
+ for (auto&& port : all_ports)
{
scf_map[port->core_paragraph->name] = std::move(*port);
}
@@ -519,78 +601,12 @@ namespace vcpkg::Commands::Install
print_plan(action_plan, is_recursive);
- if (dryRun)
+ if (dry_run)
{
Checks::exit_success(VCPKG_LINE_INFO);
}
- // execute the plan
- if (GlobalState::feature_packages)
- {
- for (const auto& action : action_plan)
- {
- if (auto install_action = action.install_plan.get())
- {
- const BuildResult result =
- perform_install_plan_action(paths, *install_action, install_plan_options, status_db);
- if (result != BuildResult::SUCCEEDED)
- {
- System::println(Build::create_user_troubleshooting_message(install_action->spec));
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
- }
- else if (auto remove_action = action.remove_plan.get())
- {
- static const std::string OPTION_PURGE = "--purge";
- static const std::string OPTION_NO_PURGE = "--no-purge";
-
- const bool alsoRemoveFolderFromPackages = options.find(OPTION_NO_PURGE) == options.end();
- if (options.find(OPTION_PURGE) != options.end() && !alsoRemoveFolderFromPackages)
- {
- // User specified --purge and --no-purge
- System::println(System::Color::error, "Error: cannot specify both --no-purge and --purge.");
- System::print(EXAMPLE);
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
- const std::string display_name = remove_action->spec.to_string();
- switch (remove_action->plan_type)
- {
- case RemovePlanType::NOT_INSTALLED:
- System::println(System::Color::success, "Package %s is not installed", display_name);
- break;
- case RemovePlanType::REMOVE:
- System::println("Removing package %s... ", display_name);
- Commands::Remove::remove_package(paths, remove_action->spec, &status_db);
- System::println(System::Color::success, "Removing package %s... done", display_name);
- break;
- case RemovePlanType::UNKNOWN:
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
-
- if (alsoRemoveFolderFromPackages)
- {
- System::println("Purging package %s... ", display_name);
- Files::Filesystem& fs = paths.get_filesystem();
- std::error_code ec;
- fs.remove_all(paths.packages / remove_action->spec.dir(), ec);
- System::println(System::Color::success, "Purging package %s... done", display_name);
- }
- }
- }
- }
- else
- {
- for (const auto& action : action_plan)
- {
- const auto& iaction = action.install_plan.value_or_exit(VCPKG_LINE_INFO);
- const BuildResult result = perform_install_plan_action(paths, iaction, install_plan_options, status_db);
- if (result != BuildResult::SUCCEEDED)
- {
- System::println(Build::create_user_troubleshooting_message(iaction.spec));
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
- }
- }
+ perform_and_exit(action_plan, install_plan_options, keep_going, PrintSummary::NO, paths, status_db);
Checks::exit_success(VCPKG_LINE_INFO);
}
diff --git a/toolsrc/src/commands_integrate.cpp b/toolsrc/src/commands_integrate.cpp
index 1bf26910c..fd2f11294 100644
--- a/toolsrc/src/commands_integrate.cpp
+++ b/toolsrc/src/commands_integrate.cpp
@@ -113,19 +113,20 @@ namespace vcpkg::Commands::Integrate
static ElevationPromptChoice elevated_cmd_execute(const std::string& param)
{
- SHELLEXECUTEINFO sh_ex_info = {0};
+ SHELLEXECUTEINFOW sh_ex_info = {0};
sh_ex_info.cbSize = sizeof(sh_ex_info);
sh_ex_info.fMask = SEE_MASK_NOCLOSEPROCESS;
sh_ex_info.hwnd = nullptr;
- sh_ex_info.lpVerb = "runas";
- sh_ex_info.lpFile = "cmd"; // Application to start
+ sh_ex_info.lpVerb = L"runas";
+ sh_ex_info.lpFile = L"cmd"; // Application to start
- sh_ex_info.lpParameters = param.c_str(); // Additional parameters
+ auto wparam = Strings::to_utf16(param);
+ sh_ex_info.lpParameters = wparam.c_str(); // Additional parameters
sh_ex_info.lpDirectory = nullptr;
sh_ex_info.nShow = SW_HIDE;
sh_ex_info.hInstApp = nullptr;
- if (!ShellExecuteExA(&sh_ex_info))
+ if (!ShellExecuteExW(&sh_ex_info))
{
return ElevationPromptChoice::NO;
}
diff --git a/toolsrc/src/commands_portsdiff.cpp b/toolsrc/src/commands_portsdiff.cpp
index 32bc3de3c..2334b2270 100644
--- a/toolsrc/src/commands_portsdiff.cpp
+++ b/toolsrc/src/commands_portsdiff.cpp
@@ -68,7 +68,7 @@ namespace vcpkg::Commands::PortsDiff
for (const std::string& name : ports_to_print)
{
const VersionT& version = names_and_versions.at(name);
- System::println("%-20s %-16s", name, version);
+ System::println(" - %-14s %-16s", name, version);
}
}
@@ -147,14 +147,14 @@ namespace vcpkg::Commands::PortsDiff
const std::vector<std::string>& added_ports = setp.only_left;
if (!added_ports.empty())
{
- System::println("\nThe following %d ports were added:\n", added_ports.size());
+ System::println("\nThe following %d ports were added:", added_ports.size());
do_print_name_and_version(added_ports, current_names_and_versions);
}
const std::vector<std::string>& removed_ports = setp.only_right;
if (!removed_ports.empty())
{
- System::println("\nThe following %d ports were removed:\n", removed_ports.size());
+ System::println("\nThe following %d ports were removed:", removed_ports.size());
do_print_name_and_version(removed_ports, previous_names_and_versions);
}
@@ -164,10 +164,10 @@ namespace vcpkg::Commands::PortsDiff
if (!updated_ports.empty())
{
- System::println("\nThe following %d ports were updated:\n", updated_ports.size());
+ System::println("\nThe following %d ports were updated:", updated_ports.size());
for (const UpdatedPort& p : updated_ports)
{
- System::println("%-20s %-16s", p.port, p.version_diff.to_string());
+ System::println(" - %-14s %-16s", p.port, p.version_diff.to_string());
}
}
diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp
index 2b5033166..a9f1b2564 100644
--- a/toolsrc/src/commands_remove.cpp
+++ b/toolsrc/src/commands_remove.cpp
@@ -18,7 +18,7 @@ namespace vcpkg::Commands::Remove
{
auto& fs = paths.get_filesystem();
auto spghs = status_db->find_all(spec.name(), spec.triplet());
- auto core_pkg = **status_db->find(spec.name(), spec.triplet(), Strings::EMPTY);
+ const auto core_pkg = **status_db->find(spec.name(), spec.triplet(), Strings::EMPTY);
for (auto&& spgh : spghs)
{
@@ -31,7 +31,7 @@ namespace vcpkg::Commands::Remove
auto maybe_lines = fs.read_lines(paths.listfile_path(core_pkg.package));
- if (auto lines = maybe_lines.get())
+ if (const auto lines = maybe_lines.get())
{
std::vector<fs::path> dirs_touched;
for (auto&& suffix : *lines)
@@ -42,7 +42,7 @@ namespace vcpkg::Commands::Remove
auto target = paths.installed / suffix;
- auto status = fs.status(target, ec);
+ const auto status = fs.status(target, ec);
if (ec)
{
System::println(System::Color::error, "failed: %s", ec.message());
@@ -72,7 +72,7 @@ namespace vcpkg::Commands::Remove
}
auto b = dirs_touched.rbegin();
- auto e = dirs_touched.rend();
+ const auto e = dirs_touched.rend();
for (; b != e; ++b)
{
if (fs.is_empty(*b))
@@ -100,11 +100,11 @@ namespace vcpkg::Commands::Remove
static void print_plan(const std::map<RemovePlanType, std::vector<const RemovePlanAction*>>& group_by_plan_type)
{
- static constexpr std::array<RemovePlanType, 2> order = {RemovePlanType::NOT_INSTALLED, RemovePlanType::REMOVE};
+ static constexpr std::array<RemovePlanType, 2> ORDER = {RemovePlanType::NOT_INSTALLED, RemovePlanType::REMOVE};
- for (const RemovePlanType plan_type : order)
+ for (const RemovePlanType plan_type : ORDER)
{
- auto it = group_by_plan_type.find(plan_type);
+ const auto it = group_by_plan_type.find(plan_type);
if (it == group_by_plan_type.cend())
{
continue;
@@ -129,6 +129,37 @@ namespace vcpkg::Commands::Remove
}
}
+ void perform_remove_plan_action(const VcpkgPaths& paths,
+ const RemovePlanAction& action,
+ const Purge purge,
+ StatusParagraphs& status_db)
+ {
+ const std::string display_name = action.spec.to_string();
+
+ switch (action.plan_type)
+ {
+ case RemovePlanType::NOT_INSTALLED:
+ System::println(System::Color::success, "Package %s is not installed", display_name);
+ break;
+ case RemovePlanType::REMOVE:
+ System::println("Removing package %s... ", display_name);
+ remove_package(paths, action.spec, &status_db);
+ System::println(System::Color::success, "Removing package %s... done", display_name);
+ break;
+ case RemovePlanType::UNKNOWN:
+ default: Checks::unreachable(VCPKG_LINE_INFO);
+ }
+
+ if (purge == Purge::YES)
+ {
+ System::println("Purging package %s... ", display_name);
+ Files::Filesystem& fs = paths.get_filesystem();
+ std::error_code ec;
+ fs.remove_all(paths.packages / action.spec.dir(), ec);
+ System::println(System::Color::success, "Purging package %s... done", display_name);
+ }
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
{
static const std::string OPTION_PURGE = "--purge";
@@ -166,16 +197,17 @@ namespace vcpkg::Commands::Remove
Input::check_triplet(spec.triplet(), paths);
}
- const bool alsoRemoveFolderFromPackages = options.find(OPTION_NO_PURGE) == options.end();
- if (options.find(OPTION_PURGE) != options.end() && !alsoRemoveFolderFromPackages)
+ const bool no_purge_was_passed = options.find(OPTION_NO_PURGE) != options.end();
+ const bool purge_was_passed = options.find(OPTION_PURGE) != options.end();
+ if (purge_was_passed && no_purge_was_passed)
{
- // User specified --purge and --no-purge
System::println(System::Color::error, "Error: cannot specify both --no-purge and --purge.");
System::print(EXAMPLE);
Checks::exit_fail(VCPKG_LINE_INFO);
}
- const bool isRecursive = options.find(OPTION_RECURSE) != options.cend();
- const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend();
+ const Purge purge = to_purge(purge_was_passed || !no_purge_was_passed);
+ const bool is_recursive = options.find(OPTION_RECURSE) != options.cend();
+ const bool dry_run = options.find(OPTION_DRY_RUN) != options.cend();
const std::vector<RemovePlanAction> remove_plan = Dependencies::create_remove_plan(specs, status_db);
Checks::check_exit(VCPKG_LINE_INFO, !remove_plan.empty(), "Remove plan cannot be empty");
@@ -194,7 +226,7 @@ namespace vcpkg::Commands::Remove
System::println(System::Color::warning,
"Additional packages (*) need to be removed to complete this operation.");
- if (!isRecursive)
+ if (!is_recursive)
{
System::println(System::Color::warning,
"If you are sure you want to remove them, run the command with the --recurse option");
@@ -202,37 +234,14 @@ namespace vcpkg::Commands::Remove
}
}
- if (dryRun)
+ if (dry_run)
{
Checks::exit_success(VCPKG_LINE_INFO);
}
for (const RemovePlanAction& action : remove_plan)
{
- const std::string display_name = action.spec.to_string();
-
- switch (action.plan_type)
- {
- case RemovePlanType::NOT_INSTALLED:
- System::println(System::Color::success, "Package %s is not installed", display_name);
- break;
- case RemovePlanType::REMOVE:
- System::println("Removing package %s... ", display_name);
- remove_package(paths, action.spec, &status_db);
- System::println(System::Color::success, "Removing package %s... done", display_name);
- break;
- case RemovePlanType::UNKNOWN:
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
-
- if (alsoRemoveFolderFromPackages)
- {
- System::println("Purging package %s... ", display_name);
- Files::Filesystem& fs = paths.get_filesystem();
- std::error_code ec;
- fs.remove_all(paths.packages / action.spec.dir(), ec);
- System::println(System::Color::success, "Purging package %s... done", display_name);
- }
+ perform_remove_plan_action(paths, action, purge, status_db);
}
Checks::exit_success(VCPKG_LINE_INFO);
diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp
index 1ccec9fbe..d35a546c4 100644
--- a/toolsrc/src/commands_search.cpp
+++ b/toolsrc/src/commands_search.cpp
@@ -87,27 +87,8 @@ namespace vcpkg::Commands::Search
const std::unordered_set<std::string> options =
args.check_and_get_optional_command_arguments({OPTION_GRAPH, OPTION_FULLDESC});
- auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);
+ auto source_paragraphs = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports);
- if (!sources_and_errors.errors.empty())
- {
- if (GlobalState::debugging)
- {
- print_error_message(sources_and_errors.errors);
- }
- else
- {
- for (auto&& error : sources_and_errors.errors)
- {
- System::println(
- System::Color::warning, "Warning: an error occurred while parsing '%s'", error->name);
- }
- System::println(System::Color::warning,
- "Use '--debug' to get more information about the parse failures.\n");
- }
- }
-
- auto& source_paragraphs = sources_and_errors.paragraphs;
if (options.find(OPTION_GRAPH) != options.cend())
{
const std::string graph_as_string = create_graph_as_string(source_paragraphs);
diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp
index 35f24af12..71ea4b063 100644
--- a/toolsrc/src/commands_update.cpp
+++ b/toolsrc/src/commands_update.cpp
@@ -2,7 +2,6 @@
#include "Paragraphs.h"
#include "vcpkg_Commands.h"
-#include "vcpkg_Files.h"
#include "vcpkg_System.h"
#include "vcpkglib.h"
@@ -22,7 +21,7 @@ namespace vcpkg::Commands::Update
std::vector<OutdatedPackage> output;
for (const StatusParagraph* pgh : installed_packages)
{
- auto it = src_names_to_versions.find(pgh->package.spec.name());
+ const auto it = src_names_to_versions.find(pgh->package.spec.name());
if (it == src_names_to_versions.end())
{
// Package was not installed from portfile
@@ -69,31 +68,6 @@ namespace vcpkg::Commands::Update
install_line);
}
- auto version_file = paths.get_filesystem().read_contents(paths.root / "toolsrc" / "VERSION.txt");
- if (auto version_contents = version_file.get())
- {
- int maj1, min1, rev1;
- auto num1 = sscanf_s(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1);
-
- int maj2, min2, rev2;
- auto num2 = sscanf_s(Version::version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2);
-
- if (num1 == 3 && num2 == 3)
- {
- if (maj1 != maj2 || min1 != min2 || rev1 != rev2)
- {
- System::println("Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use "
- ".\\bootstrap-vcpkg.bat to update.",
- maj2,
- min2,
- rev2,
- maj1,
- min1,
- rev1);
- }
- }
- }
-
Checks::exit_success(VCPKG_LINE_INFO);
}
}
diff --git a/toolsrc/src/commands_version.cpp b/toolsrc/src/commands_version.cpp
index af81cd26e..5744ea9ef 100644
--- a/toolsrc/src/commands_version.cpp
+++ b/toolsrc/src/commands_version.cpp
@@ -13,7 +13,7 @@ namespace vcpkg::Commands::Version
{
const std::string& version()
{
- static const std::string s_version =
+ static const std::string S_VERSION =
#include "../VERSION.txt"
+std::string(VCPKG_VERSION_AS_STRING)
@@ -21,7 +21,36 @@ namespace vcpkg::Commands::Version
+ std::string("-debug")
#endif
+ std::string(Metrics::get_compiled_metrics_enabled() ? Strings::EMPTY : "-external");
- return s_version;
+ return S_VERSION;
+ }
+
+ void warn_if_vcpkg_version_mismatch(const VcpkgPaths& paths)
+ {
+ auto version_file = paths.get_filesystem().read_contents(paths.root / "toolsrc" / "VERSION.txt");
+ if (const auto version_contents = version_file.get())
+ {
+ int maj1, min1, rev1;
+ const auto num1 = sscanf_s(version_contents->c_str(), "\"%d.%d.%d\"", &maj1, &min1, &rev1);
+
+ int maj2, min2, rev2;
+ const auto num2 = sscanf_s(Version::version().c_str(), "%d.%d.%d-", &maj2, &min2, &rev2);
+
+ if (num1 == 3 && num2 == 3)
+ {
+ if (maj1 != maj2 || min1 != min2 || rev1 != rev2)
+ {
+ System::println(System::Color::warning,
+ "Warning: Different source is available for vcpkg (%d.%d.%d -> %d.%d.%d). Use "
+ ".\\bootstrap-vcpkg.bat to update.",
+ maj2,
+ min2,
+ rev2,
+ maj1,
+ min1,
+ rev1);
+ }
+ }
+ }
}
void perform_and_exit(const VcpkgCmdArguments& args)
diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp
index 8a7d02a30..8a0050bfc 100644
--- a/toolsrc/src/metrics.cpp
+++ b/toolsrc/src/metrics.cpp
@@ -20,9 +20,9 @@ namespace vcpkg::Metrics
_ftime_s(&timebuffer);
time_t now = timebuffer.time;
- int milli = timebuffer.millitm;
+ const int milli = timebuffer.millitm;
- errno_t err = gmtime_s(&newtime, &now);
+ const errno_t err = gmtime_s(&newtime, &now);
if (err)
{
return Strings::EMPTY;
@@ -34,7 +34,7 @@ namespace vcpkg::Metrics
static std::string generate_random_UUID()
{
- int partSizes[] = {8, 4, 4, 4, 12};
+ int part_sizes[] = {8, 4, 4, 4, 12};
char uuid[37];
memset(uuid, 0, sizeof(uuid));
int num;
@@ -50,7 +50,7 @@ namespace vcpkg::Metrics
// Generating UUID format version 4
// http://en.wikipedia.org/wiki/Universally_unique_identifier
- for (int i = 0; i < partSizes[part]; i++, index++)
+ for (int i = 0; i < part_sizes[part]; i++, index++)
{
if (part == 2 && i == 0)
{
@@ -81,8 +81,8 @@ namespace vcpkg::Metrics
static const std::string& get_session_id()
{
- static const std::string id = generate_random_UUID();
- return id;
+ static const std::string ID = generate_random_UUID();
+ return ID;
}
static std::string to_json_string(const std::string& str)
@@ -101,11 +101,11 @@ namespace vcpkg::Metrics
else if (ch < 0x20 || ch >= 0x80)
{
// Note: this treats incoming Strings as Latin-1
- static constexpr const char hex[16] = {
+ static constexpr const char HEX[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
encoded.append("\\u00");
- encoded.push_back(hex[ch / 16]);
- encoded.push_back(hex[ch % 16]);
+ encoded.push_back(HEX[ch / 16]);
+ encoded.push_back(HEX[ch % 16]);
}
else
{
@@ -120,11 +120,11 @@ namespace vcpkg::Metrics
{
std::wstring path;
path.resize(MAX_PATH);
- auto n = GetSystemDirectoryW(&path[0], static_cast<UINT>(path.size()));
+ const auto n = GetSystemDirectoryW(&path[0], static_cast<UINT>(path.size()));
path.resize(n);
path += L"\\kernel32.dll";
- auto versz = GetFileVersionInfoSizeW(path.c_str(), nullptr);
+ const auto versz = GetFileVersionInfoSizeW(path.c_str(), nullptr);
if (versz == 0) return Strings::EMPTY;
std::vector<char> verbuf;
@@ -152,7 +152,7 @@ namespace vcpkg::Metrics
std::string properties;
std::string measurements;
- void TrackProperty(const std::string& name, const std::string& value)
+ void track_property(const std::string& name, const std::string& value)
{
if (properties.size() != 0) properties.push_back(',');
properties.append(to_json_string(name));
@@ -160,7 +160,7 @@ namespace vcpkg::Metrics
properties.append(to_json_string(value));
}
- void TrackMetric(const std::string& name, double value)
+ void track_metric(const std::string& name, double value)
{
if (measurements.size() != 0) measurements.push_back(',');
measurements.append(to_json_string(name));
@@ -241,7 +241,7 @@ namespace vcpkg::Metrics
void Metrics::set_print_metrics(bool should_print_metrics) { g_should_print_metrics = should_print_metrics; }
- void Metrics::track_metric(const std::string& name, double value) { g_metricmessage.TrackMetric(name, value); }
+ void Metrics::track_metric(const std::string& name, double value) { g_metricmessage.track_metric(name, value); }
void Metrics::track_property(const std::string& name, const std::wstring& value)
{
@@ -251,85 +251,85 @@ namespace vcpkg::Metrics
std::transform(
value.begin(), value.end(), converted_value.begin(), [](wchar_t ch) { return static_cast<char>(ch); });
- g_metricmessage.TrackProperty(name, converted_value);
+ g_metricmessage.track_property(name, converted_value);
}
void Metrics::track_property(const std::string& name, const std::string& value)
{
- g_metricmessage.TrackProperty(name, value);
+ g_metricmessage.track_property(name, value);
}
void Metrics::upload(const std::string& payload)
{
- HINTERNET hSession = nullptr, hConnect = nullptr, hRequest = nullptr;
- BOOL bResults = FALSE;
+ HINTERNET connect = nullptr, request = nullptr;
+ BOOL results = FALSE;
- hSession = WinHttpOpen(
+ const HINTERNET session = WinHttpOpen(
L"vcpkg/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
- if (hSession)
- hConnect = WinHttpConnect(hSession, L"dc.services.visualstudio.com", INTERNET_DEFAULT_HTTPS_PORT, 0);
-
- if (hConnect)
- hRequest = WinHttpOpenRequest(hConnect,
- L"POST",
- L"/v2/track",
- nullptr,
- WINHTTP_NO_REFERER,
- WINHTTP_DEFAULT_ACCEPT_TYPES,
- WINHTTP_FLAG_SECURE);
-
- if (hRequest)
+ if (session) connect = WinHttpConnect(session, L"dc.services.visualstudio.com", INTERNET_DEFAULT_HTTPS_PORT, 0);
+
+ if (connect)
+ request = WinHttpOpenRequest(connect,
+ L"POST",
+ L"/v2/track",
+ nullptr,
+ WINHTTP_NO_REFERER,
+ WINHTTP_DEFAULT_ACCEPT_TYPES,
+ WINHTTP_FLAG_SECURE);
+
+ if (request)
{
if (MAXDWORD <= payload.size()) abort();
std::wstring hdrs = L"Content-Type: application/json\r\n";
- bResults = WinHttpSendRequest(hRequest,
- hdrs.c_str(),
- static_cast<DWORD>(hdrs.size()),
- (void*)&payload[0],
- static_cast<DWORD>(payload.size()),
- static_cast<DWORD>(payload.size()),
- 0);
+ std::string& p = const_cast<std::string&>(payload);
+ results = WinHttpSendRequest(request,
+ hdrs.c_str(),
+ static_cast<DWORD>(hdrs.size()),
+ static_cast<void*>(&p[0]),
+ static_cast<DWORD>(payload.size()),
+ static_cast<DWORD>(payload.size()),
+ 0);
}
- if (bResults)
+ if (results)
{
- bResults = WinHttpReceiveResponse(hRequest, nullptr);
+ results = WinHttpReceiveResponse(request, nullptr);
}
DWORD http_code = 0, junk = sizeof(DWORD);
- if (bResults)
+ if (results)
{
- bResults = WinHttpQueryHeaders(hRequest,
- WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
- nullptr,
- &http_code,
- &junk,
- WINHTTP_NO_HEADER_INDEX);
+ results = WinHttpQueryHeaders(request,
+ WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
+ nullptr,
+ &http_code,
+ &junk,
+ WINHTTP_NO_HEADER_INDEX);
}
- std::vector<char> responseBuffer;
- if (bResults)
+ std::vector<char> response_buffer;
+ if (results)
{
- DWORD availableData = 0, readData = 0, totalData = 0;
- while ((bResults = WinHttpQueryDataAvailable(hRequest, &availableData)) == TRUE && availableData > 0)
+ DWORD available_data = 0, read_data = 0, total_data = 0;
+ while ((results = WinHttpQueryDataAvailable(request, &available_data)) == TRUE && available_data > 0)
{
- responseBuffer.resize(responseBuffer.size() + availableData);
+ response_buffer.resize(response_buffer.size() + available_data);
- bResults = WinHttpReadData(hRequest, &responseBuffer.data()[totalData], availableData, &readData);
+ results = WinHttpReadData(request, &response_buffer.data()[total_data], available_data, &read_data);
- if (!bResults)
+ if (!results)
{
break;
}
- totalData += readData;
+ total_data += read_data;
- responseBuffer.resize(totalData);
+ response_buffer.resize(total_data);
}
}
- if (!bResults)
+ if (!results)
{
#ifndef NDEBUG
__debugbreak();
@@ -338,22 +338,22 @@ namespace vcpkg::Metrics
#endif
}
- if (hRequest) WinHttpCloseHandle(hRequest);
- if (hConnect) WinHttpCloseHandle(hConnect);
- if (hSession) WinHttpCloseHandle(hSession);
+ if (request) WinHttpCloseHandle(request);
+ if (connect) WinHttpCloseHandle(connect);
+ if (session) WinHttpCloseHandle(session);
}
static fs::path get_bindir()
{
wchar_t buf[_MAX_PATH];
- int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH);
+ const int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH);
if (bytes == 0) std::abort();
return fs::path(buf, buf + bytes);
}
void Metrics::flush()
{
- std::string payload = g_metricmessage.format_event_data_template();
+ const std::string payload = g_metricmessage.format_event_data_template();
if (g_should_print_metrics) std::cerr << payload << "\n";
if (!g_should_send_metrics) return;
@@ -388,8 +388,8 @@ namespace vcpkg::Metrics
const fs::path vcpkg_metrics_txt_path = temp_folder_path / ("vcpkg" + generate_random_UUID() + ".txt");
fs.write_contents(vcpkg_metrics_txt_path, payload);
- const std::wstring cmdLine =
+ const std::wstring cmd_line =
Strings::wformat(L"start %s %s", temp_folder_path_exe.native(), vcpkg_metrics_txt_path.native());
- System::cmd_execute_clean(cmdLine);
+ System::cmd_execute_clean(cmd_line);
}
}
diff --git a/toolsrc/src/tests_package_spec.cpp b/toolsrc/src/tests_package_spec.cpp
index fa201b372..a6b9d5b13 100644
--- a/toolsrc/src/tests_package_spec.cpp
+++ b/toolsrc/src/tests_package_spec.cpp
@@ -43,7 +43,7 @@ namespace UnitTest1
std::array<const char*, 6> features = {"", "0", "1", "", "2", "3"};
std::array<PackageSpec*, 6> specs = {&a_spec, &a_spec, &a_spec, &b_spec, &b_spec, &b_spec};
- for (int i = 0; i < features.size(); ++i)
+ for (size_t i = 0; i < features.size(); ++i)
{
Assert::AreEqual(features[i], fspecs[i].feature().c_str());
Assert::AreEqual(*specs[i], fspecs[i].spec());
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index 781f03585..706c641fb 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -11,7 +11,10 @@
#include "vcpkg_Strings.h"
#include "vcpkg_System.h"
#include "vcpkglib.h"
+#pragma warning(push)
+#pragma warning(disable : 4768)
#include <Shlobj.h>
+#pragma warning(pop)
#include <cassert>
#include <fstream>
#include <memory>
@@ -69,6 +72,7 @@ static void inner(const VcpkgCmdArguments& args)
const VcpkgPaths paths = expected_paths.value_or_exit(VCPKG_LINE_INFO);
const int exit_code = _wchdir(paths.root.c_str());
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed");
+ Commands::Version::warn_if_vcpkg_version_mismatch(paths);
if (const auto command_function = Commands::find(args.command, Commands::get_available_commands_type_b()))
{
@@ -104,7 +108,7 @@ static void inner(const VcpkgCmdArguments& args)
return invalid_command(args.command);
}
-static void loadConfig()
+static void load_config()
{
fs::path localappdata;
{
@@ -207,7 +211,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
locked_metrics->track_property("version", Commands::Version::version());
locked_metrics->track_property("cmdline", trimmed_command_line);
}
- loadConfig();
+ load_config();
Metrics::g_metrics.lock()->track_property("sqmuser", Metrics::get_SQM_user());
const VcpkgCmdArguments args = VcpkgCmdArguments::create_from_command_line(argc, argv);
diff --git a/toolsrc/src/vcpkg_Build.cpp b/toolsrc/src/vcpkg_Build.cpp
index a2fa99ac8..853f84998 100644
--- a/toolsrc/src/vcpkg_Build.cpp
+++ b/toolsrc/src/vcpkg_Build.cpp
@@ -67,7 +67,12 @@ namespace vcpkg::Build
const auto arch = to_vcvarsall_toolchain(pre_build_info.target_architecture, toolset);
const auto target = to_vcvarsall_target(pre_build_info.cmake_system_name);
- return Strings::wformat(LR"("%s" %s %s %s 2>&1)", toolset.vcvarsall.native(), arch, target, tonull);
+ return Strings::wformat(LR"("%s" %s %s %s %s 2>&1)",
+ toolset.vcvarsall.native(),
+ Strings::join(L" ", toolset.vcvarsall_options),
+ arch,
+ target,
+ tonull);
}
static void create_binary_feature_control_file(const SourceParagraph& source_paragraph,
@@ -160,7 +165,7 @@ namespace vcpkg::Build
{L"PORT", config.src.name},
{L"CURRENT_PORT_DIR", config.port_dir / "/."},
{L"TARGET_TRIPLET", triplet.canonical_name()},
- {L"VCPKG_PLATFORM_TOOLSET", toolset.version},
+ {L"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
{L"VCPKG_USE_HEAD_VERSION", to_bool(config.build_package_options.use_head_version) ? L"1" : L"0"},
{L"_VCPKG_NO_DOWNLOADS", !to_bool(config.build_package_options.allow_downloads) ? L"1" : L"0"},
{L"GIT", git_exe_path},
@@ -289,7 +294,7 @@ namespace vcpkg::Build
if (!version.empty()) build_info.version = std::move(version);
std::map<BuildPolicy, bool> policies;
- for (auto policy : g_all_policies)
+ for (auto policy : G_ALL_POLICIES)
{
const auto setting = parser.optional_field(to_string(policy));
if (setting.empty()) continue;
diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp
index 1a0f0a6ed..8dd60a2eb 100644
--- a/toolsrc/src/vcpkg_Dependencies.cpp
+++ b/toolsrc/src/vcpkg_Dependencies.cpp
@@ -213,6 +213,21 @@ namespace vcpkg::Dependencies
{
}
+ const PackageSpec& AnyAction::spec() const
+ {
+ if (const auto p = install_plan.get())
+ {
+ return p->spec;
+ }
+
+ if (const auto p = remove_plan.get())
+ {
+ return p->spec;
+ }
+
+ Checks::exit_with_message(VCPKG_LINE_INFO, "Null action");
+ }
+
bool ExportPlanAction::compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right)
{
return left->spec.name() < right->spec.name();
diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp
index 15851829d..21df2c309 100644
--- a/toolsrc/src/vcpkg_Strings.cpp
+++ b/toolsrc/src/vcpkg_Strings.cpp
@@ -73,14 +73,20 @@ namespace vcpkg::Strings
{
std::wstring to_utf16(const CStringView s)
{
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
- return conversion.from_bytes(s);
+ const int size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
+ std::wstring output;
+ output.resize(size - 1);
+ MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, output.data(), size - 1);
+ return output;
}
std::string to_utf8(const CWStringView w)
{
- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
- return conversion.to_bytes(w);
+ const int size = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, nullptr, 0, nullptr, nullptr);
+ std::string output;
+ output.resize(size - 1);
+ WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, output.data(), size - 1, nullptr, nullptr);
+ return output;
}
std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern)
@@ -100,7 +106,7 @@ namespace vcpkg::Strings
int case_insensitive_ascii_compare(const CStringView left, const CStringView right)
{
- return _stricmp(left, right);
+ return _stricmp(left.c_str(), right.c_str());
}
std::string ascii_to_lowercase(const std::string& input)
@@ -110,6 +116,11 @@ namespace vcpkg::Strings
return output;
}
+ bool case_insensitive_ascii_starts_with(const std::string& s, const std::string& pattern)
+ {
+ return _strnicmp(s.c_str(), pattern.c_str(), pattern.size()) == 0;
+ }
+
void trim(std::string* s)
{
s->erase(std::find_if_not(s->rbegin(), s->rend(), details::isspace).base(), s->end());
@@ -137,6 +148,12 @@ namespace vcpkg::Strings
{
std::vector<std::string> output;
+ if (delimiter.empty())
+ {
+ output.push_back(s);
+ return output;
+ }
+
size_t i = 0;
for (size_t pos = s.find(delimiter); pos != std::string::npos; pos = s.find(delimiter, pos))
{
diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp
index 40e335117..4d2e88b73 100644
--- a/toolsrc/src/vcpkg_System.cpp
+++ b/toolsrc/src/vcpkg_System.cpp
@@ -226,7 +226,7 @@ namespace vcpkg::System
void println() { println(Strings::EMPTY); }
- void print(const CStringView message) { fputs(message, stdout); }
+ void print(const CStringView message) { fputs(message.c_str(), stdout); }
void println(const CStringView message)
{
@@ -255,13 +255,13 @@ namespace vcpkg::System
Optional<std::wstring> get_environment_variable(const CWStringView varname) noexcept
{
- const auto sz = GetEnvironmentVariableW(varname, nullptr, 0);
+ const auto sz = GetEnvironmentVariableW(varname.c_str(), nullptr, 0);
if (sz == 0) return nullopt;
std::wstring ret(sz, L'\0');
Checks::check_exit(VCPKG_LINE_INFO, MAXDWORD >= ret.size());
- const auto sz2 = GetEnvironmentVariableW(varname, ret.data(), static_cast<DWORD>(ret.size()));
+ const auto sz2 = GetEnvironmentVariableW(varname.c_str(), ret.data(), static_cast<DWORD>(ret.size()));
Checks::check_exit(VCPKG_LINE_INFO, sz2 + 1 == sz);
ret.pop_back();
return ret;
@@ -275,19 +275,20 @@ namespace vcpkg::System
Optional<std::wstring> get_registry_string(HKEY base, const CWStringView sub_key, const CWStringView valuename)
{
HKEY k = nullptr;
- const LSTATUS ec = RegOpenKeyExW(base, sub_key, NULL, KEY_READ, &k);
+ const LSTATUS ec = RegOpenKeyExW(base, sub_key.c_str(), NULL, KEY_READ, &k);
if (ec != ERROR_SUCCESS) return nullopt;
DWORD dw_buffer_size = 0;
DWORD dw_type = 0;
- auto rc = RegQueryValueExW(k, valuename, nullptr, &dw_type, nullptr, &dw_buffer_size);
+ auto rc = RegQueryValueExW(k, valuename.c_str(), nullptr, &dw_type, nullptr, &dw_buffer_size);
if (rc != ERROR_SUCCESS || !is_string_keytype(dw_type) || dw_buffer_size == 0 ||
dw_buffer_size % sizeof(wchar_t) != 0)
return nullopt;
std::wstring ret;
ret.resize(dw_buffer_size / sizeof(wchar_t));
- rc = RegQueryValueExW(k, valuename, nullptr, &dw_type, reinterpret_cast<LPBYTE>(ret.data()), &dw_buffer_size);
+ rc = RegQueryValueExW(
+ k, valuename.c_str(), nullptr, &dw_type, reinterpret_cast<LPBYTE>(ret.data()), &dw_buffer_size);
if (rc != ERROR_SUCCESS || !is_string_keytype(dw_type) || dw_buffer_size != sizeof(wchar_t) * ret.size())
return nullopt;