aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly O'Neal <bion@microsoft.com>2020-06-16 11:58:11 -0700
committerGitHub <noreply@github.com>2020-06-16 11:58:11 -0700
commit04e214eb0ef9cd5fc4308dd7a43943e98ae1d534 (patch)
treee11b55a563310307a553811877f6cae21633afd1
parent7192d3affa4b1d8f88e3e730eb561612c24f7d78 (diff)
downloadvcpkg-04e214eb0ef9cd5fc4308dd7a43943e98ae1d534.tar.gz
vcpkg-04e214eb0ef9cd5fc4308dd7a43943e98ae1d534.zip
[vcpkg] Fix create by extracting common paths settings (#11842)
Resolves #11784
-rw-r--r--scripts/ports.cmake8
-rw-r--r--toolsrc/include/vcpkg/base/system.process.h6
-rw-r--r--toolsrc/include/vcpkg/buildenvironment.h12
-rw-r--r--toolsrc/include/vcpkg/commands.h1
-rw-r--r--toolsrc/src/vcpkg-test/commands.create.cpp25
-rw-r--r--toolsrc/src/vcpkg/base/system.process.cpp20
-rw-r--r--toolsrc/src/vcpkg/build.cpp16
-rw-r--r--toolsrc/src/vcpkg/buildenvironment.cpp19
-rw-r--r--toolsrc/src/vcpkg/cmakevars.cpp4
-rw-r--r--toolsrc/src/vcpkg/commands.create.cpp17
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj2
11 files changed, 94 insertions, 36 deletions
diff --git a/scripts/ports.cmake b/scripts/ports.cmake
index 9b33745f9..cd687026f 100644
--- a/scripts/ports.cmake
+++ b/scripts/ports.cmake
@@ -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")
diff --git a/toolsrc/include/vcpkg/base/system.process.h b/toolsrc/include/vcpkg/base/system.process.h
index 51ea728c3..0e6a92444 100644
--- a/toolsrc/include/vcpkg/base/system.process.h
+++ b/toolsrc/include/vcpkg/base/system.process.h
@@ -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();
diff --git a/toolsrc/include/vcpkg/buildenvironment.h b/toolsrc/include/vcpkg/buildenvironment.h
new file mode 100644
index 000000000..4505f4972
--- /dev/null
+++ b/toolsrc/include/vcpkg/buildenvironment.h
@@ -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);
+}
diff --git a/toolsrc/include/vcpkg/commands.h b/toolsrc/include/vcpkg/commands.h
index c4b231433..f6be93bb2 100644
--- a/toolsrc/include/vcpkg/commands.h
+++ b/toolsrc/include/vcpkg/commands.h
@@ -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);
}
diff --git a/toolsrc/src/vcpkg-test/commands.create.cpp b/toolsrc/src/vcpkg-test/commands.create.cpp
new file mode 100644
index 000000000..993be142b
--- /dev/null
+++ b/toolsrc/src/vcpkg-test/commands.create.cpp
@@ -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);
+}
diff --git a/toolsrc/src/vcpkg/base/system.process.cpp b/toolsrc/src/vcpkg/base/system.process.cpp
index f90bd8e1c..2f95c5b0e 100644
--- a/toolsrc/src/vcpkg/base/system.process.cpp
+++ b/toolsrc/src/vcpkg/base/system.process.cpp
@@ -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(),
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp
index 1d7c03933..2c79f71ce 100644
--- a/toolsrc/src/vcpkg/build.cpp
+++ b/toolsrc/src/vcpkg/build.cpp
@@ -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));
diff --git a/toolsrc/src/vcpkg/buildenvironment.cpp b/toolsrc/src/vcpkg/buildenvironment.cpp
new file mode 100644
index 000000000..ea3be7bc8
--- /dev/null
+++ b/toolsrc/src/vcpkg/buildenvironment.cpp
@@ -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);
+ }
+}
diff --git a/toolsrc/src/vcpkg/cmakevars.cpp b/toolsrc/src/vcpkg/cmakevars.cpp
index 114335e2c..c5e2d8822 100644
--- a/toolsrc/src/vcpkg/cmakevars.cpp
+++ b/toolsrc/src/vcpkg/cmakevars.cpp
@@ -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);
diff --git a/toolsrc/src/vcpkg/commands.create.cpp b/toolsrc/src/vcpkg/commands.create.cpp
index 9296eed0e..14824a248 100644
--- a/toolsrc/src/vcpkg/commands.create.cpp
+++ b/toolsrc/src/vcpkg/commands.create.cpp
@@ -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));
}
}
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj
index 005b1c0dc..66fa8a0ba 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj
@@ -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" />