mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-24 11:37:12 +01:00
Introduce PowershellParameter to add '' to parameter values.
Also place that and CMakeVariable in System.h
This commit is contained in:
parent
3d8ba3e775
commit
1313a418cf
@ -10,6 +10,28 @@ namespace vcpkg::System
|
|||||||
|
|
||||||
fs::path get_exe_path_of_current_process();
|
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
|
struct ExitCodeAndOutput
|
||||||
{
|
{
|
||||||
int exit_code;
|
int exit_code;
|
||||||
@ -24,7 +46,7 @@ namespace vcpkg::System
|
|||||||
|
|
||||||
std::string powershell_execute_and_capture_output(const std::string& title,
|
std::string powershell_execute_and_capture_output(const std::string& title,
|
||||||
const fs::path& script_path,
|
const fs::path& script_path,
|
||||||
const CStringView args = "");
|
const std::vector<PowershellParameter>& parameters = {});
|
||||||
|
|
||||||
enum class Color
|
enum class Color
|
||||||
{
|
{
|
||||||
|
@ -20,18 +20,5 @@ namespace vcpkg
|
|||||||
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const VcpkgPaths& paths,
|
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const VcpkgPaths& paths,
|
||||||
const StatusParagraphs& status_db);
|
const StatusParagraphs& status_db);
|
||||||
|
|
||||||
struct CMakeVariable
|
std::string shorten_text(const std::string& desc, const size_t length);
|
||||||
{
|
|
||||||
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);
|
|
||||||
} // namespace vcpkg
|
} // namespace vcpkg
|
||||||
|
@ -72,6 +72,43 @@ namespace vcpkg::System
|
|||||||
return supported_architectures;
|
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)
|
int cmd_execute_clean(const CStringView cmd_line)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@ -272,8 +309,10 @@ namespace vcpkg::System
|
|||||||
|
|
||||||
std::string powershell_execute_and_capture_output(const std::string& title,
|
std::string powershell_execute_and_capture_output(const std::string& title,
|
||||||
const fs::path& script_path,
|
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
|
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
|
||||||
const std::string cmd = Strings::format(
|
const std::string cmd = Strings::format(
|
||||||
R"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.u8string(), args);
|
R"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.u8string(), args);
|
||||||
|
@ -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 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,
|
cmake_exe_path,
|
||||||
ports_cmake_script_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 ports_cmake_script_path = paths.scripts / "get_triplet_environment.cmake";
|
||||||
const fs::path triplet_file_path = paths.triplets / (triplet.canonical_name() + ".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,
|
ports_cmake_script_path,
|
||||||
{
|
{
|
||||||
{"CMAKE_TRIPLET_FILE", triplet_file_path},
|
{"CMAKE_TRIPLET_FILE", triplet_file_path},
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include <vcpkg/base/system.h>
|
#include <vcpkg/base/system.h>
|
||||||
#include <vcpkg/commands.h>
|
#include <vcpkg/commands.h>
|
||||||
#include <vcpkg/help.h>
|
#include <vcpkg/help.h>
|
||||||
#include <vcpkg/vcpkglib.h>
|
|
||||||
|
|
||||||
namespace vcpkg::Commands::Create
|
namespace vcpkg::Commands::Create
|
||||||
{
|
{
|
||||||
@ -25,7 +24,7 @@ namespace vcpkg::Commands::Create
|
|||||||
|
|
||||||
const fs::path& cmake_exe = paths.get_cmake_exe();
|
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)
|
if (args.command_arguments.size() >= 3)
|
||||||
{
|
{
|
||||||
|
@ -369,7 +369,8 @@ namespace vcpkg::Export
|
|||||||
static void print_next_step_info(const fs::path& prefix)
|
static void print_next_step_info(const fs::path& prefix)
|
||||||
{
|
{
|
||||||
const fs::path cmake_toolchain = prefix / "scripts" / "buildsystems" / "vcpkg.cmake";
|
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"
|
System::println("\n"
|
||||||
"To use the exported libraries in CMake projects use:"
|
"To use the exported libraries in CMake projects use:"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -255,9 +255,10 @@ namespace vcpkg::Metrics
|
|||||||
auto match = *next;
|
auto match = *next;
|
||||||
if (match[0] != "00-00-00-00-00-00")
|
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(
|
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,
|
Util::erase_remove_if(hash_result,
|
||||||
[](char ch) { return !(ch >= 'A' && ch <= 'F') && !(ch >= '0' && ch <= '9'); });
|
[](char ch) { return !(ch >= 'A' && ch <= 'F') && !(ch >= '0' && ch <= '9'); });
|
||||||
hash_result = Strings::ascii_to_lowercase(hash_result);
|
hash_result = Strings::ascii_to_lowercase(hash_result);
|
||||||
|
@ -212,29 +212,7 @@ namespace vcpkg
|
|||||||
return installed_files;
|
return installed_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeVariable::CMakeVariable(const CStringView varname, const char* varvalue)
|
std::string shorten_text(const std::string& desc, const size_t length)
|
||||||
: 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)
|
|
||||||
{
|
{
|
||||||
Checks::check_exit(VCPKG_LINE_INFO, length >= 3);
|
Checks::check_exit(VCPKG_LINE_INFO, length >= 3);
|
||||||
auto simple_desc = std::regex_replace(desc, std::regex("\\s+"), " ");
|
auto simple_desc = std::regex_replace(desc, std::regex("\\s+"), " ");
|
||||||
|
@ -92,8 +92,8 @@ namespace vcpkg
|
|||||||
version_as_string);
|
version_as_string);
|
||||||
const fs::path script = scripts_folder / "fetchDependency.ps1";
|
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 title = "Fetching %s version %s (No sufficient installed version was found)";
|
||||||
const std::string output =
|
const System::PowershellParameter dependency_param("Dependency", tool_name);
|
||||||
System::powershell_execute_and_capture_output(title, script, Strings::format("-Dependency %s", 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);
|
const std::vector<std::string> dependency_path = keep_data_lines(output);
|
||||||
Checks::check_exit(
|
Checks::check_exit(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user