Introduce PowershellParameter to add '' to parameter values.
Also place that and CMakeVariable in System.h
MODIFY
include/vcpkg/base/system.h
include/vcpkg/base/system.h
@@ -10,6 +10,28 @@ namespace vcpkg::System
fs::path get_exe_path_of_current_process();
+ struct CMakeVariable
+ {
+ CMakeVariable(const CStringView varname, const char* varvalue);
+ CMakeVariable(const CStringView varname, const std::string& varvalue);
+ CMakeVariable(const CStringView varname, const fs::path& path);
+
+ std::string s;
+ };
+
+ std::string make_cmake_cmd(const fs::path& cmake_exe,
+ const fs::path& cmake_script,
+ const std::vector<CMakeVariable>& pass_variables);
+
+ struct PowershellParameter
+ {
+ PowershellParameter(const CStringView varname, const char* varvalue);
+ PowershellParameter(const CStringView varname, const std::string& varvalue);
+ PowershellParameter(const CStringView varname, const fs::path& path);
+
+ std::string s;
+ };
+
struct ExitCodeAndOutput
{
int exit_code;
@@ -24,7 +46,7 @@ namespace vcpkg::System
std::string powershell_execute_and_capture_output(const std::string& title,
const fs::path& script_path,
- const CStringView args = "");
+ const std::vector<PowershellParameter>& parameters = {});
enum class Color
{

MODIFY
include/vcpkg/vcpkglib.h
include/vcpkg/vcpkglib.h
@@ -20,18 +20,5 @@ namespace vcpkg
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const VcpkgPaths& paths,
const StatusParagraphs& status_db);
- struct CMakeVariable
- {
- CMakeVariable(const CStringView varname, const char* varvalue);
- CMakeVariable(const CStringView varname, const std::string& varvalue);
- CMakeVariable(const CStringView varname, const fs::path& path);
-
- std::string s;
- };
-
- std::string make_cmake_cmd(const fs::path& cmake_exe,
- const fs::path& cmake_script,
- const std::vector<CMakeVariable>& pass_variables);
-
- std::string shorten_text(const std::string& desc, size_t length);
+ std::string shorten_text(const std::string& desc, const size_t length);
} // namespace vcpkg

MODIFY
src/vcpkg/base/system.cpp
src/vcpkg/base/system.cpp
@@ -72,6 +72,43 @@ namespace vcpkg::System
return supported_architectures;
}
+ CMakeVariable::CMakeVariable(const CStringView varname, const char* varvalue)
+ : s(Strings::format(R"("-D%s=%s")", varname, varvalue))
+ {
+ }
+ CMakeVariable::CMakeVariable(const CStringView varname, const std::string& varvalue)
+ : CMakeVariable(varname, varvalue.c_str())
+ {
+ }
+ CMakeVariable::CMakeVariable(const CStringView varname, const fs::path& path)
+ : CMakeVariable(varname, path.generic_u8string())
+ {
+ }
+
+ std::string make_cmake_cmd(const fs::path& cmake_exe,
+ const fs::path& cmake_script,
+ const std::vector<CMakeVariable>& pass_variables)
+ {
+ const std::string cmd_cmake_pass_variables = Strings::join(" ", pass_variables, [](auto&& v) { return v.s; });
+ return Strings::format(
+ R"("%s" %s -P "%s")", cmake_exe.u8string(), cmd_cmake_pass_variables, cmake_script.generic_u8string());
+ }
+
+ PowershellParameter::PowershellParameter(const CStringView varname, const char* varvalue)
+ : s(Strings::format(R"(-%s '%s')", varname, varvalue))
+ {
+ }
+
+ PowershellParameter::PowershellParameter(const CStringView varname, const std::string& varvalue)
+ : PowershellParameter(varname, varvalue.c_str())
+ {
+ }
+
+ PowershellParameter::PowershellParameter(const CStringView varname, const fs::path& path)
+ : PowershellParameter(varname, path.generic_u8string())
+ {
+ }
+
int cmd_execute_clean(const CStringView cmd_line)
{
#if defined(_WIN32)
@@ -272,8 +309,10 @@ namespace vcpkg::System
std::string powershell_execute_and_capture_output(const std::string& title,
const fs::path& script_path,
- const CStringView args)
+ const std::vector<PowershellParameter>& parameters)
{
+ const std::string args = Strings::join(" ", parameters, [](auto&& v) { return v.s; });
+
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
const std::string cmd = Strings::format(
R"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.u8string(), args);

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
@@ -301,7 +301,7 @@ namespace vcpkg::Build
const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset, pre_build_info.visual_studio_path);
- const std::string cmd_launch_cmake = make_cmake_cmd(
+ const std::string cmd_launch_cmake = System::make_cmake_cmd(
cmake_exe_path,
ports_cmake_script_path,
{
@@ -493,7 +493,7 @@ namespace vcpkg::Build
const fs::path ports_cmake_script_path = paths.scripts / "get_triplet_environment.cmake";
const fs::path triplet_file_path = paths.triplets / (triplet.canonical_name() + ".cmake");
- const auto cmd_launch_cmake = make_cmake_cmd(cmake_exe_path,
+ const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path,
ports_cmake_script_path,
{
{"CMAKE_TRIPLET_FILE", triplet_file_path},

MODIFY
src/vcpkg/commands.create.cpp
src/vcpkg/commands.create.cpp
#include <vcpkg/base/system.h>
#include <vcpkg/commands.h>
#include <vcpkg/help.h>
-#include <vcpkg/vcpkglib.h>
namespace vcpkg::Commands::Create
{
@@ -25,7 +24,7 @@ namespace vcpkg::Commands::Create
const fs::path& cmake_exe = paths.get_cmake_exe();
- std::vector<CMakeVariable> cmake_args{{"CMD", "CREATE"}, {"PORT", port_name}, {"URL", url}};
+ std::vector<System::CMakeVariable> cmake_args{{"CMD", "CREATE"}, {"PORT", port_name}, {"URL", url}};
if (args.command_arguments.size() >= 3)
{

MODIFY
src/vcpkg/export.cpp
src/vcpkg/export.cpp
@@ -369,7 +369,8 @@ namespace vcpkg::Export
static void print_next_step_info(const fs::path& prefix)
{
const fs::path cmake_toolchain = prefix / "scripts" / "buildsystems" / "vcpkg.cmake";
- const CMakeVariable cmake_variable = CMakeVariable("CMAKE_TOOLCHAIN_FILE", cmake_toolchain.generic_string());
+ const System::CMakeVariable cmake_variable =
+ System::CMakeVariable("CMAKE_TOOLCHAIN_FILE", cmake_toolchain.generic_string());
System::println("\n"
"To use the exported libraries in CMake projects use:"
"\n"

MODIFY
src/vcpkg/metrics.cpp
src/vcpkg/metrics.cpp
@@ -255,9 +255,10 @@ namespace vcpkg::Metrics
auto match = *next;
if (match[0] != "00-00-00-00-00-00")
{
- std::string matchstr = match[0];
+ const std::string matchstr = match[0];
+ const System::PowershellParameter value("Value", matchstr);
auto hash_result = System::powershell_execute_and_capture_output(
- "SHA256Hash", get_vcpkg_root() / "SHA256Hash.ps1", Strings::format("-Value \"%s\"", matchstr));
+ "SHA256Hash", get_vcpkg_root() / "SHA256Hash.ps1", {value});
Util::erase_remove_if(hash_result,
[](char ch) { return !(ch >= 'A' && ch <= 'F') && !(ch >= '0' && ch <= '9'); });
hash_result = Strings::ascii_to_lowercase(hash_result);

MODIFY
src/vcpkg/vcpkglib.cpp
src/vcpkg/vcpkglib.cpp
@@ -212,29 +212,7 @@ namespace vcpkg
return installed_files;
}
- CMakeVariable::CMakeVariable(const CStringView varname, const char* varvalue)
- : s(Strings::format(R"("-D%s=%s")", varname, varvalue))
- {
- }
- CMakeVariable::CMakeVariable(const CStringView varname, const std::string& varvalue)
- : CMakeVariable(varname, varvalue.c_str())
- {
- }
- CMakeVariable::CMakeVariable(const CStringView varname, const fs::path& path)
- : CMakeVariable(varname, path.generic_u8string())
- {
- }
-
- std::string make_cmake_cmd(const fs::path& cmake_exe,
- const fs::path& cmake_script,
- const std::vector<CMakeVariable>& pass_variables)
- {
- const std::string cmd_cmake_pass_variables = Strings::join(" ", pass_variables, [](auto&& v) { return v.s; });
- return Strings::format(
- R"("%s" %s -P "%s")", cmake_exe.u8string(), cmd_cmake_pass_variables, cmake_script.generic_u8string());
- }
-
- std::string shorten_text(const std::string& desc, size_t length)
+ std::string shorten_text(const std::string& desc, const size_t length)
{
Checks::check_exit(VCPKG_LINE_INFO, length >= 3);
auto simple_desc = std::regex_replace(desc, std::regex("\\s+"), " ");

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -92,8 +92,8 @@ namespace vcpkg
version_as_string);
const fs::path script = scripts_folder / "fetchDependency.ps1";
const std::string title = "Fetching %s version %s (No sufficient installed version was found)";
- const std::string output =
- System::powershell_execute_and_capture_output(title, script, Strings::format("-Dependency %s", tool_name));
+ const System::PowershellParameter dependency_param("Dependency", tool_name);
+ const std::string output = System::powershell_execute_and_capture_output(title, script, {dependency_param});
const std::vector<std::string> dependency_path = keep_data_lines(output);
Checks::check_exit(

Introduce PowershellParameter to add '' to parameter values.

Also place that and CMakeVariable in System.h