зеркало из https://github.com/microsoft/vcpkg.git
[vcpkg] Fix create by extracting common paths settings (#11842)
Resolves #11784
This commit is contained in:
Родитель
7192d3affa
Коммит
04e214eb0e
|
@ -78,7 +78,7 @@ if(CMD MATCHES "^BUILD$")
|
|||
elseif(CMD MATCHES "^CREATE$")
|
||||
file(TO_NATIVE_PATH ${VCPKG_ROOT_DIR} NATIVE_VCPKG_ROOT_DIR)
|
||||
file(TO_NATIVE_PATH ${DOWNLOADS} NATIVE_DOWNLOADS)
|
||||
if(EXISTS ports/${PORT}/portfile.cmake)
|
||||
if(EXISTS ${VCPKG_ROOT_DIR}/ports/${PORT}/portfile.cmake)
|
||||
message(FATAL_ERROR "Portfile already exists: '${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake'")
|
||||
endif()
|
||||
if(NOT FILENAME)
|
||||
|
@ -99,9 +99,9 @@ elseif(CMD MATCHES "^CREATE$")
|
|||
endif()
|
||||
file(SHA512 ${DOWNLOADS}/${FILENAME} SHA512)
|
||||
|
||||
file(MAKE_DIRECTORY ports/${PORT})
|
||||
configure_file(${SCRIPTS}/templates/portfile.in.cmake ports/${PORT}/portfile.cmake @ONLY)
|
||||
configure_file(${SCRIPTS}/templates/CONTROL.in ports/${PORT}/CONTROL @ONLY)
|
||||
file(MAKE_DIRECTORY ${VCPKG_ROOT_DIR}/ports/${PORT})
|
||||
configure_file(${SCRIPTS}/templates/portfile.in.cmake ${VCPKG_ROOT_DIR}/ports/${PORT}/portfile.cmake @ONLY)
|
||||
configure_file(${SCRIPTS}/templates/CONTROL.in ${VCPKG_ROOT_DIR}/ports/${PORT}/CONTROL @ONLY)
|
||||
|
||||
message(STATUS "Generated portfile: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\portfile.cmake")
|
||||
message(STATUS "Generated CONTROL: ${NATIVE_VCPKG_ROOT_DIR}\\ports\\${PORT}\\CONTROL")
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace vcpkg::System
|
|||
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 make_basic_cmake_cmd(const fs::path& cmake_tool_path,
|
||||
const fs::path& cmake_script,
|
||||
const std::vector<CMakeVariable>& pass_variables);
|
||||
|
||||
fs::path get_exe_path_of_current_process();
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include <vcpkg/base/system.process.h>
|
||||
#include <vcpkg/vcpkgpaths.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
std::string make_cmake_cmd(const VcpkgPaths& paths,
|
||||
const fs::path& cmake_script,
|
||||
std::vector<System::CMakeVariable>&& pass_variables);
|
||||
}
|
|
@ -41,6 +41,7 @@ namespace vcpkg::Commands
|
|||
namespace Create
|
||||
{
|
||||
extern const CommandStructure COMMAND_STRUCTURE;
|
||||
int perform(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
|
||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/commands.h>
|
||||
#include <vcpkg/vcpkgcmdarguments.h>
|
||||
#include <vcpkg/vcpkgpaths.h>
|
||||
|
||||
TEST_CASE ("smoke test", "[create]")
|
||||
{
|
||||
using namespace vcpkg;
|
||||
static const std::string argsRaw[] = {"create", "zlib2", "http://zlib.net/zlib-1.2.11.tar.gz", "zlib-1.2.11.zip"};
|
||||
|
||||
auto& fsWrapper = Files::get_real_filesystem();
|
||||
VcpkgCmdArguments args = VcpkgCmdArguments::create_from_arg_sequence(std::begin(argsRaw), std::end(argsRaw));
|
||||
VcpkgPaths paths(fsWrapper, args);
|
||||
const auto exit_code = Commands::Create::perform(args, paths);
|
||||
REQUIRE(exit_code == 0);
|
||||
const auto expected_port = paths.ports / fs::u8path("zlib2");
|
||||
const auto expected_portfile_cmake = expected_port / fs::u8path("portfile.cmake");
|
||||
const auto lines = fsWrapper.read_lines(expected_portfile_cmake);
|
||||
REQUIRE(lines.has_value());
|
||||
fsWrapper.remove_all(expected_port, ignore_errors);
|
||||
}
|
|
@ -179,20 +179,22 @@ namespace vcpkg
|
|||
{
|
||||
}
|
||||
|
||||
std::string System::make_cmake_cmd(const fs::path& cmake_exe,
|
||||
const fs::path& cmake_script,
|
||||
const std::vector<CMakeVariable>& pass_variables)
|
||||
std::string System::make_basic_cmake_cmd(const fs::path& cmake_tool_path,
|
||||
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());
|
||||
return Strings::format(R"("%s" %s -P "%s")",
|
||||
cmake_tool_path.u8string(),
|
||||
Strings::join(" ", pass_variables, [](auto&& v) { return v.s; }),
|
||||
cmake_script.generic_u8string());
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
Environment System::get_modified_clean_environment(const std::unordered_map<std::string, std::string>& extra_env,
|
||||
const std::string& prepend_to_path)
|
||||
{
|
||||
static const std::string system_root_env = get_environment_variable("SystemRoot").value_or_exit(VCPKG_LINE_INFO);
|
||||
static const std::string system_root_env =
|
||||
get_environment_variable("SystemRoot").value_or_exit(VCPKG_LINE_INFO);
|
||||
static const std::string system32_env = system_root_env + R"(\system32)";
|
||||
std::string new_path = Strings::format(R"(Path=%s%s;%s;%s\Wbem;%s\WindowsPowerShell\v1.0\)",
|
||||
prepend_to_path,
|
||||
|
@ -385,8 +387,8 @@ namespace vcpkg
|
|||
// Flush stdout before launching external process
|
||||
fflush(nullptr);
|
||||
|
||||
VCPKG_MSVC_WARNING(suppress : 6335) // Leaking process information handle 'process_info.proc_info.hProcess'
|
||||
// /analyze can't tell that we transferred ownership here
|
||||
VCPKG_MSVC_WARNING(suppress : 6335) // Leaking process information handle 'process_info.proc_info.hProcess'
|
||||
// /analyze can't tell that we transferred ownership here
|
||||
bool succeeded =
|
||||
TRUE == CreateProcessW(nullptr,
|
||||
Strings::to_utf16(cmd_line).data(),
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <vcpkg/binarycaching.h>
|
||||
#include <vcpkg/build.h>
|
||||
#include <vcpkg/buildenvironment.h>
|
||||
#include <vcpkg/commands.h>
|
||||
#include <vcpkg/dependencies.h>
|
||||
#include <vcpkg/globalstate.h>
|
||||
|
@ -376,15 +377,10 @@ namespace vcpkg::Build
|
|||
{"CMD", "BUILD"},
|
||||
{"PORT", scf.core_paragraph->name},
|
||||
{"CURRENT_PORT_DIR", scfl.source_location},
|
||||
{"VCPKG_ROOT_DIR", paths.root},
|
||||
{"PACKAGES_DIR", paths.packages},
|
||||
{"BUILDTREES_DIR", paths.buildtrees},
|
||||
{"_VCPKG_INSTALLED_DIR", paths.installed},
|
||||
{"TARGET_TRIPLET", triplet.canonical_name()},
|
||||
{"TARGET_TRIPLET_FILE", paths.get_triplet_file_path(triplet).u8string()},
|
||||
{"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
|
||||
{"VCPKG_USE_HEAD_VERSION", Util::Enum::to_bool(action.build_options.use_head_version) ? "1" : "0"},
|
||||
{"DOWNLOADS", paths.downloads},
|
||||
{"_VCPKG_NO_DOWNLOADS", !Util::Enum::to_bool(action.build_options.allow_downloads) ? "1" : "0"},
|
||||
{"_VCPKG_DOWNLOAD_TOOL", to_string(action.build_options.download_tool)},
|
||||
{"FEATURES", Strings::join(";", action.feature_list)},
|
||||
|
@ -460,8 +456,8 @@ namespace vcpkg::Build
|
|||
else if (pre_build_info.cmake_system_name == "Darwin")
|
||||
{
|
||||
hash += "-";
|
||||
hash += Hash::get_file_hash(
|
||||
VCPKG_LINE_INFO, fs, paths.scripts / fs::u8path("toolchains/osx.cmake"), algo);
|
||||
hash +=
|
||||
Hash::get_file_hash(VCPKG_LINE_INFO, fs, paths.scripts / fs::u8path("toolchains/osx.cmake"), algo);
|
||||
}
|
||||
else if (pre_build_info.cmake_system_name == "FreeBSD")
|
||||
{
|
||||
|
@ -520,10 +516,8 @@ namespace vcpkg::Build
|
|||
|
||||
const auto timer = Chrono::ElapsedTimer::create_started();
|
||||
|
||||
auto command =
|
||||
System::make_cmake_cmd(paths.get_tool_exe(Tools::CMAKE),
|
||||
paths.ports_cmake,
|
||||
get_cmake_vars(paths, action, triplet, paths.get_toolset(pre_build_info)));
|
||||
auto command = vcpkg::make_cmake_cmd(
|
||||
paths, paths.ports_cmake, get_cmake_vars(paths, action, triplet, paths.get_toolset(pre_build_info)));
|
||||
#if defined(_WIN32)
|
||||
std::string build_env_cmd = make_build_env_cmd(pre_build_info, paths.get_toolset(pre_build_info));
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include <vcpkg/buildenvironment.h>
|
||||
|
||||
namespace vcpkg
|
||||
{
|
||||
std::string make_cmake_cmd(const VcpkgPaths& paths,
|
||||
const fs::path& cmake_script,
|
||||
std::vector<System::CMakeVariable>&& pass_variables)
|
||||
{
|
||||
auto local_variables = std::move(pass_variables);
|
||||
local_variables.emplace_back("VCPKG_ROOT_DIR", paths.root);
|
||||
local_variables.emplace_back("PACKAGES_DIR", paths.packages);
|
||||
local_variables.emplace_back("BUILDTREES_DIR", paths.buildtrees);
|
||||
local_variables.emplace_back("_VCPKG_INSTALLED_DIR", paths.installed);
|
||||
local_variables.emplace_back("DOWNLOADS", paths.downloads);
|
||||
return System::make_basic_cmake_cmd(paths.get_tool_exe(Tools::CMAKE), cmake_script, local_variables);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include <vcpkg/base/util.h>
|
||||
|
||||
#include <vcpkg/cmakevars.h>
|
||||
#include <vcpkg/buildenvironment.h>
|
||||
#include <vcpkg/dependencies.h>
|
||||
|
||||
using namespace vcpkg;
|
||||
|
@ -58,7 +59,6 @@ namespace vcpkg::CMakeVars
|
|||
std::vector<std::vector<std::pair<std::string, std::string>>>& vars) const;
|
||||
|
||||
const VcpkgPaths& paths;
|
||||
const fs::path& cmake_exe_path = paths.get_tool_exe(Tools::CMAKE);
|
||||
const fs::path get_tags_path = paths.scripts / "vcpkg_get_tags.cmake";
|
||||
const fs::path get_dep_info_path = paths.scripts / "vcpkg_get_dep_info.cmake";
|
||||
mutable std::unordered_map<PackageSpec, std::unordered_map<std::string, std::string>> dep_resolution_vars;
|
||||
|
@ -170,7 +170,7 @@ namespace vcpkg::CMakeVars
|
|||
static constexpr CStringView BLOCK_START_GUID = "c35112b6-d1ba-415b-aa5d-81de856ef8eb";
|
||||
static constexpr CStringView BLOCK_END_GUID = "e1e74b5c-18cb-4474-a6bd-5c1c8bc81f3f";
|
||||
|
||||
const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path, script_path, {});
|
||||
const auto cmd_launch_cmake = vcpkg::make_cmake_cmd(paths, script_path, {});
|
||||
const auto ec_data = System::cmd_execute_and_capture_output(cmd_launch_cmake);
|
||||
Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, ec_data.output);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <vcpkg/base/checks.h>
|
||||
#include <vcpkg/base/files.h>
|
||||
#include <vcpkg/base/system.process.h>
|
||||
#include <vcpkg/buildenvironment.h>
|
||||
#include <vcpkg/commands.h>
|
||||
#include <vcpkg/help.h>
|
||||
|
||||
|
@ -16,15 +16,13 @@ namespace vcpkg::Commands::Create
|
|||
nullptr,
|
||||
};
|
||||
|
||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
|
||||
int perform(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
|
||||
{
|
||||
Util::unused(args.parse_arguments(COMMAND_STRUCTURE));
|
||||
const std::string port_name = args.command_arguments.at(0);
|
||||
const std::string url = args.command_arguments.at(1);
|
||||
|
||||
const fs::path& cmake_exe = paths.get_tool_exe(Tools::CMAKE);
|
||||
|
||||
std::vector<System::CMakeVariable> cmake_args{{"CMD", "CREATE"}, {"PORT", port_name}, {"URL", url}, {"VCPKG_ROOT_DIR", paths.root}};
|
||||
std::vector<System::CMakeVariable> cmake_args{{"CMD", "CREATE"}, {"PORT", port_name}, {"URL", url}};
|
||||
|
||||
if (args.command_arguments.size() >= 3)
|
||||
{
|
||||
|
@ -37,7 +35,12 @@ namespace vcpkg::Commands::Create
|
|||
cmake_args.emplace_back("FILENAME", zip_file_name);
|
||||
}
|
||||
|
||||
const std::string cmd_launch_cmake = make_cmake_cmd(cmake_exe, paths.ports_cmake, cmake_args);
|
||||
Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute_clean(cmd_launch_cmake));
|
||||
const std::string cmd_launch_cmake = make_cmake_cmd(paths, paths.ports_cmake, std::move(cmake_args));
|
||||
return System::cmd_execute_clean(cmd_launch_cmake);
|
||||
}
|
||||
|
||||
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
|
||||
{
|
||||
Checks::exit_with_code(VCPKG_LINE_INFO, perform(args, paths));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,6 +177,7 @@
|
|||
<ClInclude Include="..\include\vcpkg\binarycaching.h" />
|
||||
<ClInclude Include="..\include\vcpkg\binaryparagraph.h" />
|
||||
<ClInclude Include="..\include\vcpkg\build.h" />
|
||||
<ClInclude Include="..\include\vcpkg\buildenvironment.h" />
|
||||
<ClInclude Include="..\include\vcpkg\cmakevars.h" />
|
||||
<ClInclude Include="..\include\vcpkg\commands.h" />
|
||||
<ClInclude Include="..\include\vcpkg\dependencies.h" />
|
||||
|
@ -239,6 +240,7 @@
|
|||
<ClCompile Include="..\src\vcpkg\binarycaching.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\binaryparagraph.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\build.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\buildenvironment.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\cmakevars.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\commands.autocomplete.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\commands.buildexternal.cpp" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче