From aef838536ea3a08e3c1030ead553ca6456cc7fe3 Mon Sep 17 00:00:00 2001 From: ras0219 Date: Mon, 22 Jun 2020 14:14:36 -0700 Subject: [vcpkg] Track compiler information in ABI (#11654) * [vcpkg] Refactor out abi_tags_from_pre_build_info() * [vcpkg] Track Windows toolchain file in triplet hash * [vcpkg] Improve error messages when constructing PreBuildInfo * [vcpkg] Extract InstallPlanAction::BuildAbiInfo * [vcpkg] Extract Build::EnvCache and private-impl VcpkgPaths * [vcpkg] Enable compiler hash detection when binarycaching is enabled * [vcpkg] Downgrade warning about missing ABI keys When binarycaching is not enabled, this warning is spurious and provides no user value. * [vcpkg] Cleanup * [vcpkg] Refactor compiler tracking into triplet abi computation Move several static global caches into VcpkgPaths/EnvCache. Add feature flag 'compilertracking' to enable the new feature. * [vcpkg] Refactor out PreBuildInfo::using_vcvars() Move VcpkgTripletVar into build.cpp because it is not used outside that file. * [vcpkg] Address some code analysis warnings Co-authored-by: Robert Schumacher --- toolsrc/include/vcpkg/base/expected.h | 2 +- toolsrc/include/vcpkg/base/pragmas.h | 6 +- toolsrc/include/vcpkg/base/util.h | 5 ++ toolsrc/include/vcpkg/binarycaching.h | 2 + toolsrc/include/vcpkg/build.h | 94 +++++++++++++++++-------------- toolsrc/include/vcpkg/dependencies.h | 5 +- toolsrc/include/vcpkg/export.prefab.h | 4 +- toolsrc/include/vcpkg/vcpkgcmdarguments.h | 2 + toolsrc/include/vcpkg/vcpkgpaths.h | 32 ++++++----- 9 files changed, 88 insertions(+), 64 deletions(-) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg/base/expected.h b/toolsrc/include/vcpkg/base/expected.h index 88b09fdb2..ff60149ac 100644 --- a/toolsrc/include/vcpkg/base/expected.h +++ b/toolsrc/include/vcpkg/base/expected.h @@ -10,7 +10,7 @@ namespace vcpkg template struct ErrorHolder { - ErrorHolder() : m_is_error(false) {} + ErrorHolder() : m_is_error(false), m_err{} {} template ErrorHolder(U&& err) : m_is_error(true), m_err(std::forward(err)) { diff --git a/toolsrc/include/vcpkg/base/pragmas.h b/toolsrc/include/vcpkg/base/pragmas.h index 97d01955e..73f14c4b2 100644 --- a/toolsrc/include/vcpkg/base/pragmas.h +++ b/toolsrc/include/vcpkg/base/pragmas.h @@ -19,8 +19,10 @@ #include #endif -#ifndef _Analysis_assume_ -#define _Analysis_assume_(...) +#if defined(_MSC_VER) +#define ASSUME(expr) __assume(expr) +#else +#define ASSUME(expr) #endif #ifdef _MSC_VER diff --git a/toolsrc/include/vcpkg/base/util.h b/toolsrc/include/vcpkg/base/util.h index 849781b95..89f2c51d6 100644 --- a/toolsrc/include/vcpkg/base/util.h +++ b/toolsrc/include/vcpkg/base/util.h @@ -22,6 +22,11 @@ namespace vcpkg::Util { augend->insert(augend->end(), addend.begin(), addend.end()); } + template + bool contains(const Vec& container, const Key& item) + { + return std::find(container.begin(), container.end(), item) != container.end(); + } } namespace Sets diff --git a/toolsrc/include/vcpkg/binarycaching.h b/toolsrc/include/vcpkg/binarycaching.h index 69e3287d6..88f529c22 100644 --- a/toolsrc/include/vcpkg/binarycaching.h +++ b/toolsrc/include/vcpkg/binarycaching.h @@ -36,6 +36,8 @@ namespace vcpkg bool purge_tombstones) = 0; }; + IBinaryProvider& null_binary_provider(); + ExpectedS> create_binary_provider_from_configs(const VcpkgPaths& paths, View args); ExpectedS> create_binary_provider_from_configs_pure(const std::string& env_string, diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 864317fb9..68cfd7d23 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,11 @@ namespace vcpkg::Dependencies struct ActionPlan; } +namespace vcpkg::System +{ + struct Environment; +} + namespace vcpkg::Build { namespace Command @@ -34,7 +40,6 @@ namespace vcpkg::Build void perform_and_exit_ex(const FullPackageSpec& full_spec, const SourceControlFileLocation& scfl, const PortFileProvider::PathsPortFileProvider& provider, - const bool binary_caching_enabled, IBinaryProvider& binaryprovider, const VcpkgPaths& paths); @@ -90,12 +95,6 @@ namespace vcpkg::Build }; const std::string& to_string(DownloadTool tool); - enum class BinaryCaching - { - NO = 0, - YES - }; - enum class FailOnTombstone { NO = 0, @@ -117,7 +116,6 @@ namespace vcpkg::Build CleanPackages clean_packages; CleanDownloads clean_downloads; DownloadTool download_tool; - BinaryCaching binary_caching; FailOnTombstone fail_on_tombstone; PurgeDecompressFailure purge_decompress_failure; }; @@ -149,14 +147,14 @@ namespace vcpkg::Build /// /// Settings from the triplet file which impact the build environment and post-build checks /// - struct PreBuildInfo + struct PreBuildInfo : Util::ResourceBase { PreBuildInfo(const VcpkgPaths& paths, Triplet triplet, const std::unordered_map& cmakevars); - bool load_vcvars_env; - std::string triplet_abi_tag; + Triplet triplet; + bool load_vcvars_env = false; std::string target_architecture; std::string cmake_system_name; std::string cmake_system_version; @@ -165,38 +163,16 @@ namespace vcpkg::Build Optional external_toolchain_file; Optional build_type; Optional public_abi_override; - Optional port; std::vector passthrough_env_vars; - }; - std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); + fs::path toolchain_file() const; + bool using_vcvars() const; - enum class VcpkgTripletVar - { - TARGET_ARCHITECTURE = 0, - CMAKE_SYSTEM_NAME, - CMAKE_SYSTEM_VERSION, - PLATFORM_TOOLSET, - VISUAL_STUDIO_PATH, - CHAINLOAD_TOOLCHAIN_FILE, - BUILD_TYPE, - ENV_PASSTHROUGH, - PUBLIC_ABI_OVERRIDE, - LOAD_VCVARS_ENV, + private: + const VcpkgPaths& m_paths; }; - const std::unordered_map VCPKG_OPTIONS = { - {"VCPKG_TARGET_ARCHITECTURE", VcpkgTripletVar::TARGET_ARCHITECTURE}, - {"VCPKG_CMAKE_SYSTEM_NAME", VcpkgTripletVar::CMAKE_SYSTEM_NAME}, - {"VCPKG_CMAKE_SYSTEM_VERSION", VcpkgTripletVar::CMAKE_SYSTEM_VERSION}, - {"VCPKG_PLATFORM_TOOLSET", VcpkgTripletVar::PLATFORM_TOOLSET}, - {"VCPKG_VISUAL_STUDIO_PATH", VcpkgTripletVar::VISUAL_STUDIO_PATH}, - {"VCPKG_CHAINLOAD_TOOLCHAIN_FILE", VcpkgTripletVar::CHAINLOAD_TOOLCHAIN_FILE}, - {"VCPKG_BUILD_TYPE", VcpkgTripletVar::BUILD_TYPE}, - {"VCPKG_ENV_PASSTHROUGH", VcpkgTripletVar::ENV_PASSTHROUGH}, - {"VCPKG_PUBLIC_ABI_OVERRIDE", VcpkgTripletVar::PUBLIC_ABI_OVERRIDE}, - {"VCPKG_LOAD_VCVARS_ENV", VcpkgTripletVar::LOAD_VCVARS_ENV}, - }; + std::string make_build_env_cmd(const PreBuildInfo& pre_build_info, const Toolset& toolset); struct ExtendedBuildResult { @@ -238,8 +214,7 @@ namespace vcpkg::Build BuildPolicy::ALLOW_OBSOLETE_MSVCRT, BuildPolicy::ALLOW_RESTRICTED_HEADERS, BuildPolicy::SKIP_DUMPBIN_CHECKS, - BuildPolicy::SKIP_ARCHITECTURE_CHECK - }; + BuildPolicy::SKIP_ARCHITECTURE_CHECK}; const std::string& to_string(BuildPolicy policy); CStringView to_cmake_variable(BuildPolicy policy); @@ -300,12 +275,45 @@ namespace vcpkg::Build fs::path tag_file; }; + struct AbiInfo + { + std::unique_ptr pre_build_info; + const Toolset* toolset; + std::string package_abi; + Optional abi_tag_file; + }; + void compute_all_abis(const VcpkgPaths& paths, Dependencies::ActionPlan& action_plan, const CMakeVars::CMakeVarProvider& var_provider, const StatusParagraphs& status_db); - Optional compute_abi_tag(const VcpkgPaths& paths, - const Dependencies::InstallPlanAction& config, - Span dependency_abis); + struct EnvCache + { + explicit EnvCache(bool compiler_tracking) : m_compiler_tracking(compiler_tracking) {} + + const System::Environment& get_action_env(const VcpkgPaths& paths, const AbiInfo& abi_info); + const std::string& get_triplet_info(const VcpkgPaths& paths, const AbiInfo& abi_info); + + private: + struct TripletMapEntry + { + std::string hash; + Cache compiler_hashes; + }; + Cache m_triplet_cache; + Cache m_toolchain_cache; + +#if defined(_WIN32) + struct EnvMapEntry + { + std::unordered_map env_map; + Cache cmd_cache; + }; + + Cache, EnvMapEntry> envs; +#endif + + bool m_compiler_tracking; + }; } diff --git a/toolsrc/include/vcpkg/dependencies.h b/toolsrc/include/vcpkg/dependencies.h index d2eca4408..7b1696dc3 100644 --- a/toolsrc/include/vcpkg/dependencies.h +++ b/toolsrc/include/vcpkg/dependencies.h @@ -55,6 +55,7 @@ namespace vcpkg::Dependencies std::string displayname() const; const std::string& public_abi() const; + const Build::PreBuildInfo& pre_build_info(LineInfo linfo) const; PackageSpec spec; @@ -69,9 +70,7 @@ namespace vcpkg::Dependencies std::vector package_dependencies; std::vector feature_list; - Optional> pre_build_info; - Optional package_abi; - Optional abi_tag_file; + Optional abi_info; }; enum class RemovePlanType diff --git a/toolsrc/include/vcpkg/export.prefab.h b/toolsrc/include/vcpkg/export.prefab.h index 56a5ba371..cf9f940f9 100644 --- a/toolsrc/include/vcpkg/export.prefab.h +++ b/toolsrc/include/vcpkg/export.prefab.h @@ -18,8 +18,8 @@ namespace vcpkg::Export::Prefab Optional maybe_version; Optional maybe_min_sdk; Optional maybe_target_sdk; - bool enable_maven; - bool enable_debug; + bool enable_maven = false; + bool enable_debug = false; }; struct NdkVersion { diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h index e4ed0471b..378aa9703 100644 --- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h +++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h @@ -130,7 +130,9 @@ namespace vcpkg // feature flags Optional feature_packages = nullopt; Optional binary_caching = nullopt; + Optional compiler_tracking = nullopt; bool binary_caching_enabled() const { return binary_caching.value_or(false); } + bool compiler_tracking_enabled() const { return compiler_tracking.value_or(false); } std::string command; std::vector command_arguments; diff --git a/toolsrc/include/vcpkg/vcpkgpaths.h b/toolsrc/include/vcpkg/vcpkgpaths.h index 38a9d4e4d..c4c420820 100644 --- a/toolsrc/include/vcpkg/vcpkgpaths.h +++ b/toolsrc/include/vcpkg/vcpkgpaths.h @@ -6,9 +6,10 @@ #include #include -#include #include #include +#include +#include namespace vcpkg { @@ -46,9 +47,20 @@ namespace vcpkg namespace Build { struct PreBuildInfo; + struct AbiInfo; } - struct VcpkgPaths + namespace System + { + struct Environment; + } + + namespace details + { + struct VcpkgPathsImpl; + } + + struct VcpkgPaths : Util::MoveOnlyBase { struct TripletFile { @@ -59,6 +71,7 @@ namespace vcpkg }; VcpkgPaths(Files::Filesystem& filesystem, const VcpkgCmdArguments& args); + ~VcpkgPaths() noexcept; fs::path package_dir(const PackageSpec& spec) const; fs::path build_info_file_path(const PackageSpec& spec) const; @@ -105,17 +118,10 @@ namespace vcpkg Files::Filesystem& get_filesystem() const; - private: - Lazy> available_triplets; - Lazy> toolsets; - Lazy> toolsets_vs2013; - - fs::path default_vs_path; - std::vector triplets_dirs; + const System::Environment& get_action_env(const Build::AbiInfo& abi_info) const; + const std::string& get_triplet_info(const Build::AbiInfo& abi_info) const; - Files::Filesystem* fsPtr; - - mutable std::unique_ptr m_tool_cache; - mutable vcpkg::Cache m_triplets_cache; + private: + std::unique_ptr m_pimpl; }; } -- cgit v1.2.3