[vcpkg] Improve external toolchain handling.

This commit is contained in:
Robert Schumacher 2017-11-25 11:49:15 -08:00
parent 473d3e4c51
commit 141f10801c
15 changed files with 136 additions and 26 deletions

View File

@ -1,6 +1,11 @@
# Mark variables as used so cmake doesn't complain about them
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)
get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
if( _CMAKE_IN_TRY_COMPILE )
include( "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg.config.cmake" OPTIONAL )
endif()
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
endif()
@ -9,11 +14,6 @@ if(VCPKG_TOOLCHAIN)
return()
endif()
get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
if( _CMAKE_IN_TRY_COMPILE )
include( "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg.config.cmake" OPTIONAL )
endif()
if(VCPKG_TARGET_TRIPLET)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$")
set(_VCPKG_TARGET_TRIPLET_ARCH x86)
@ -77,10 +77,16 @@ if(CMAKE_BUILD_TYPE MATCHES "^Debug$" OR NOT DEFINED CMAKE_BUILD_TYPE)
list(APPEND CMAKE_LIBRARY_PATH
${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib/manual-link
)
list(APPEND CMAKE_FIND_ROOT_PATH
${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug
)
endif()
list(APPEND CMAKE_PREFIX_PATH
${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}
)
list(APPEND CMAKE_FIND_ROOT_PATH
${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}
)
list(APPEND CMAKE_LIBRARY_PATH
${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/manual-link
)

View File

@ -61,14 +61,14 @@ function(vcpkg_configure_cmake)
set(GENERATOR ${_csc_GENERATOR})
elseif(_csc_PREFER_NINJA AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT _csc_HOST_ARCHITECTURE STREQUAL "x86")
set(GENERATOR "Ninja")
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120")
set(GENERATOR "Visual Studio 12 2013")
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120")
set(GENERATOR "Visual Studio 12 2013 Win64")
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "arm" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120")
set(GENERATOR "Visual Studio 12 2013 ARM")
elseif(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
set(GENERATOR "Ninja")
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140")
set(GENERATOR "Visual Studio 14 2015")
elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140")

View File

@ -38,13 +38,14 @@ function(vcpkg_execute_required_process)
RESULT_VARIABLE error_code
WORKING_DIRECTORY ${vcpkg_execute_required_process_WORKING_DIRECTORY})
#debug_message("error_code=${error_code}")
file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}" NATIVE_BUILDTREES_DIR)
if(error_code)
file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-out.log" NATIVE_LOG_OUT)
file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-err.log" NATIVE_LOG_ERR)
message(FATAL_ERROR
" Command failed: ${vcpkg_execute_required_process_COMMAND}\n"
" Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n"
" See logs for more information:\n"
" ${NATIVE_BUILDTREES_DIR}\\${vcpkg_execute_required_process_LOGNAME}-out.log\n"
" ${NATIVE_BUILDTREES_DIR}\\${vcpkg_execute_required_process_LOGNAME}-err.log\n")
" ${NATIVE_LOG_OUT}\n"
" ${NATIVE_LOG_ERR}\n")
endif()
endfunction()

View File

@ -6,4 +6,5 @@ message("VCPKG_TARGET_ARCHITECTURE=${VCPKG_TARGET_ARCHITECTURE}")
message("VCPKG_CMAKE_SYSTEM_NAME=${VCPKG_CMAKE_SYSTEM_NAME}")
message("VCPKG_CMAKE_SYSTEM_VERSION=${VCPKG_CMAKE_SYSTEM_VERSION}")
message("VCPKG_PLATFORM_TOOLSET=${VCPKG_PLATFORM_TOOLSET}")
message("VCPKG_VISUAL_STUDIO_PATH=${VCPKG_VISUAL_STUDIO_PATH}")
message("VCPKG_VISUAL_STUDIO_PATH=${VCPKG_VISUAL_STUDIO_PATH}")
message("VCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")

View File

@ -89,6 +89,7 @@ namespace vcpkg::Build
std::string cmake_system_version;
Optional<std::string> platform_toolset;
Optional<fs::path> visual_studio_path;
Optional<std::string> external_toolchain_file;
};
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset);

View File

@ -26,6 +26,11 @@ namespace vcpkg
std::vector<ToolsetArchOption> supported_architectures;
};
namespace Build
{
struct PreBuildInfo;
}
struct VcpkgPaths
{
static Expected<VcpkgPaths> create(const fs::path& vcpkg_root_dir);
@ -69,8 +74,7 @@ namespace vcpkg
/// <remarks>
/// Valid version strings are "v120", "v140", "v141", and "". Empty string gets the latest.
/// </remarks>
const Toolset& get_toolset(const Optional<std::string>& toolset_version,
const Optional<fs::path>& visual_studio_path) const;
const Toolset& get_toolset(const Build::PreBuildInfo& prebuildinfo) const;
Files::Filesystem& get_filesystem() const;

View File

@ -72,7 +72,8 @@ namespace vcpkg::Files
{
std::vector<fs::path> ret;
fs::stdfs::recursive_directory_iterator b(dir), e{};
std::error_code ec;
fs::stdfs::recursive_directory_iterator b(dir, ec), e{};
for (; b != e; ++b)
{
ret.push_back(b->path());

View File

@ -51,11 +51,21 @@ namespace vcpkg::System
CPUArchitecture get_host_processor()
{
#if defined(_WIN32)
auto w6432 = get_environment_variable("PROCESSOR_ARCHITEW6432");
if (const auto p = w6432.get()) return to_cpu_architecture(*p).value_or_exit(VCPKG_LINE_INFO);
const auto procarch = get_environment_variable("PROCESSOR_ARCHITECTURE").value_or_exit(VCPKG_LINE_INFO);
return to_cpu_architecture(procarch).value_or_exit(VCPKG_LINE_INFO);
#else
#if defined(__x86_64__) || defined(_M_X64)
return CPUArchitecture::X64;
#elif defined(__x86__) || defined(_M_X86)
return CPUArchitecture::X86;
#else
#error "Unknown host architecture"
#endif
#endif
}
std::vector<CPUArchitecture> get_supported_host_architectures()

View File

@ -203,6 +203,10 @@ namespace vcpkg::Build
std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset)
{
if (pre_build_info.external_toolchain_file)
return Strings::format(
R"("%s" %s 2>&1)", toolset.vcvarsall.u8string(), Strings::join(" ", toolset.vcvarsall_options));
const char* tonull = " >nul";
if (GlobalState::debugging)
{
@ -299,8 +303,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);
const std::string cmd_launch_cmake = System::make_cmake_cmd(
cmake_exe_path,
ports_cmake_script_path,
@ -555,6 +558,13 @@ namespace vcpkg::Build
continue;
}
if (variable_name == "VCPKG_CHAINLOAD_TOOLCHAIN_FILE")
{
pre_build_info.external_toolchain_file =
variable_value.empty() ? nullopt : Optional<std::string>{variable_value};
continue;
}
Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown variable name %s", line);
}

View File

@ -20,7 +20,7 @@ namespace vcpkg::Commands::Env
args.parse_arguments(COMMAND_STRUCTURE);
const auto pre_build_info = Build::PreBuildInfo::from_triplet_file(paths, default_triplet);
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);
System::cmd_execute_clean(Build::make_build_env_cmd(pre_build_info, toolset) + " && cmd");
Checks::exit_success(VCPKG_LINE_INFO);

View File

@ -290,7 +290,7 @@ namespace vcpkg::Export
{OPTION_IFW_INSTALLER_FILE_PATH, "Specify the file path for the exported installer"},
}};
const CommandStructure vcpkg::Export::COMMAND_STRUCTURE = {
const CommandStructure COMMAND_STRUCTURE = {
Help::create_example_string("export zlib zlib:x64-windows boost --nuget"),
0,
SIZE_MAX,

View File

@ -561,7 +561,7 @@ namespace vcpkg::Install
static void print_cmake_information(const BinaryParagraph& bpgh, const VcpkgPaths& paths)
{
static const std::regex cmake_library_regex("^add_library\\(([^\\s\\$\\)]+)\\s");
static const std::regex cmake_library_regex(R"(\badd_library\(([^\s\)]+)\s)", std::regex_constants::ECMAScript);
auto& fs = paths.get_filesystem();

View File

@ -726,7 +726,7 @@ namespace vcpkg::PostBuildLint
const auto& fs = paths.get_filesystem();
// for dumpbin
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);
const fs::path package_dir = paths.package_dir(spec);
size_t error_count = 0;

View File

@ -4,6 +4,7 @@
#include <vcpkg/base/files.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/util.h>
#include <vcpkg/build.h>
#include <vcpkg/metrics.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/vcpkgpaths.h>
@ -115,11 +116,13 @@ namespace vcpkg
static constexpr std::array<int, 3> EXPECTED_VERSION = {3, 9, 5};
static const std::string VERSION_CHECK_ARGUMENTS = "--version";
const fs::path downloaded_copy = downloads_folder / "cmake-3.9.5-win32-x86" / "bin" / "cmake.exe";
const std::vector<fs::path> from_path = Files::find_from_PATH("cmake");
std::vector<fs::path> candidate_paths;
const fs::path downloaded_copy = downloads_folder / "cmake-3.9.5-win32-x86" / "bin" / "cmake.exe";
#if defined(_WIN32)
candidate_paths.push_back(downloaded_copy);
#endif
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
#if defined(_WIN32)
candidate_paths.push_back(System::get_program_files_platform_bitness() / "CMake" / "bin" / "cmake.exe");
@ -161,11 +164,13 @@ namespace vcpkg
static constexpr std::array<int, 3> EXPECTED_VERSION = {2, 15, 0};
static const std::string VERSION_CHECK_ARGUMENTS = "--version";
const fs::path downloaded_copy = downloads_folder / "MinGit-2.15.0-32-bit" / "cmd" / "git.exe";
const std::vector<fs::path> from_path = Files::find_from_PATH("git");
const fs::path downloaded_copy = downloads_folder / "MinGit-2.15.0-32-bit" / "cmd" / "git.exe";
std::vector<fs::path> candidate_paths;
#if defined(_WIN32)
candidate_paths.push_back(downloaded_copy);
#endif
candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
#if defined(_WIN32)
candidate_paths.push_back(System::get_program_files_platform_bitness() / "git" / "cmd" / "git.exe");
@ -499,16 +504,36 @@ namespace vcpkg
return found_toolsets;
}
const Toolset& VcpkgPaths::get_toolset(const Optional<std::string>& toolset_version,
const Optional<fs::path>& visual_studio_path) const
const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const
{
if (prebuildinfo.external_toolchain_file)
{
static Toolset external_toolset = []() -> Toolset {
Toolset ret;
ret.dumpbin = "";
ret.supported_architectures = {
ToolsetArchOption{"", System::get_host_processor(), System::get_host_processor()}};
#if defined(_WIN32)
ret.vcvarsall = "cmd";
ret.vcvarsall_options = {"/c", "echo done"};
#else
ret.vcvarsall = "true";
ret.vcvarsall_options = {};
#endif
ret.version = "external";
ret.visual_studio_root_path = "";
return ret;
}();
return external_toolset;
}
// Invariant: toolsets are non-empty and sorted with newest at back()
const std::vector<Toolset>& vs_toolsets =
this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
std::vector<const Toolset*> candidates = Util::element_pointers(vs_toolsets);
const auto tsv = toolset_version.get();
const auto vsp = visual_studio_path.get();
const auto tsv = prebuildinfo.platform_toolset.get();
const auto vsp = prebuildinfo.visual_studio_path.get();
if (tsv && vsp)
{

View File

@ -11,6 +11,51 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vcpkgmetricsuploader", "vcp
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vcpkgtest", "vcpkgtest\vcpkgtest.vcxproj", "{F27B8DB0-1279-4AF8-A2E3-1D49C4F0220D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{F5893B21-EA71-4432-84D6-5FB0E0461A2A}"
ProjectSection(SolutionItems) = preProject
..\scripts\bootstrap.ps1 = ..\scripts\bootstrap.ps1
..\scripts\fetchDependency.ps1 = ..\scripts\fetchDependency.ps1
..\scripts\findAnyMSBuildWithCppPlatformToolset.ps1 = ..\scripts\findAnyMSBuildWithCppPlatformToolset.ps1
..\scripts\findFileRecursivelyUp.ps1 = ..\scripts\findFileRecursivelyUp.ps1
..\scripts\findVisualStudioInstallationInstances.ps1 = ..\scripts\findVisualStudioInstallationInstances.ps1
..\scripts\get_triplet_environment.cmake = ..\scripts\get_triplet_environment.cmake
..\scripts\getProgramFiles32bit.ps1 = ..\scripts\getProgramFiles32bit.ps1
..\scripts\getProgramFilesPlatformBitness.ps1 = ..\scripts\getProgramFilesPlatformBitness.ps1
..\scripts\getWindowsSDK.ps1 = ..\scripts\getWindowsSDK.ps1
..\scripts\internalCI.ps1 = ..\scripts\internalCI.ps1
..\scripts\ports.cmake = ..\scripts\ports.cmake
..\scripts\SHA256Hash.ps1 = ..\scripts\SHA256Hash.ps1
..\scripts\VcpkgPowershellUtils.ps1 = ..\scripts\VcpkgPowershellUtils.ps1
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cmake", "cmake", "{A0122231-04D5-420B-81CA-7960946E5E65}"
ProjectSection(SolutionItems) = preProject
..\scripts\cmake\vcpkg_acquire_msys.cmake = ..\scripts\cmake\vcpkg_acquire_msys.cmake
..\scripts\cmake\vcpkg_apply_patches.cmake = ..\scripts\cmake\vcpkg_apply_patches.cmake
..\scripts\cmake\vcpkg_build_cmake.cmake = ..\scripts\cmake\vcpkg_build_cmake.cmake
..\scripts\cmake\vcpkg_build_msbuild.cmake = ..\scripts\cmake\vcpkg_build_msbuild.cmake
..\scripts\cmake\vcpkg_build_qmake.cmake = ..\scripts\cmake\vcpkg_build_qmake.cmake
..\scripts\cmake\vcpkg_common_functions.cmake = ..\scripts\cmake\vcpkg_common_functions.cmake
..\scripts\cmake\vcpkg_configure_cmake.cmake = ..\scripts\cmake\vcpkg_configure_cmake.cmake
..\scripts\cmake\vcpkg_configure_meson.cmake = ..\scripts\cmake\vcpkg_configure_meson.cmake
..\scripts\cmake\vcpkg_configure_qmake.cmake = ..\scripts\cmake\vcpkg_configure_qmake.cmake
..\scripts\cmake\vcpkg_copy_pdbs.cmake = ..\scripts\cmake\vcpkg_copy_pdbs.cmake
..\scripts\cmake\vcpkg_copy_tool_dependencies.cmake = ..\scripts\cmake\vcpkg_copy_tool_dependencies.cmake
..\scripts\cmake\vcpkg_download_distfile.cmake = ..\scripts\cmake\vcpkg_download_distfile.cmake
..\scripts\cmake\vcpkg_execute_required_process.cmake = ..\scripts\cmake\vcpkg_execute_required_process.cmake
..\scripts\cmake\vcpkg_execute_required_process_repeat.cmake = ..\scripts\cmake\vcpkg_execute_required_process_repeat.cmake
..\scripts\cmake\vcpkg_extract_source_archive.cmake = ..\scripts\cmake\vcpkg_extract_source_archive.cmake
..\scripts\cmake\vcpkg_find_acquire_program.cmake = ..\scripts\cmake\vcpkg_find_acquire_program.cmake
..\scripts\cmake\vcpkg_fixup_cmake_targets.cmake = ..\scripts\cmake\vcpkg_fixup_cmake_targets.cmake
..\scripts\cmake\vcpkg_from_bitbucket.cmake = ..\scripts\cmake\vcpkg_from_bitbucket.cmake
..\scripts\cmake\vcpkg_from_github.cmake = ..\scripts\cmake\vcpkg_from_github.cmake
..\scripts\cmake\vcpkg_get_program_files_32_bit.cmake = ..\scripts\cmake\vcpkg_get_program_files_32_bit.cmake
..\scripts\cmake\vcpkg_get_program_files_platform_bitness.cmake = ..\scripts\cmake\vcpkg_get_program_files_platform_bitness.cmake
..\scripts\cmake\vcpkg_get_windows_sdk.cmake = ..\scripts\cmake\vcpkg_get_windows_sdk.cmake
..\scripts\cmake\vcpkg_install_cmake.cmake = ..\scripts\cmake\vcpkg_install_cmake.cmake
..\scripts\cmake\vcpkg_install_meson.cmake = ..\scripts\cmake\vcpkg_install_meson.cmake
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -55,4 +100,10 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A0122231-04D5-420B-81CA-7960946E5E65} = {F5893B21-EA71-4432-84D6-5FB0E0461A2A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DEDCC7AF-0FE6-4387-9FFE-495D6C1AEE1B}
EndGlobalSection
EndGlobal