diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-04-01 02:08:48 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-04-01 02:08:48 -0700 |
| commit | bb865fb312d9f603a18a40768ae357da0421905d (patch) | |
| tree | 1bb1e4336afcf7962646e7087b235c3992fb634a | |
| parent | 05c9f77a4ae72b8339b027ccbe5a769fc627fe87 (diff) | |
| download | vcpkg-bb865fb312d9f603a18a40768ae357da0421905d.tar.gz vcpkg-bb865fb312d9f603a18a40768ae357da0421905d.zip | |
[vcpkg] Merge search for dumpbin and toolchain (they are the same).
| -rw-r--r-- | toolsrc/include/cstring_view.h | 1 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_paths.h | 11 | ||||
| -rw-r--r-- | toolsrc/src/PostBuildLint.cpp | 13 | ||||
| -rw-r--r-- | toolsrc/src/commands_build.cpp | 6 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_paths.cpp | 81 |
5 files changed, 43 insertions, 69 deletions
diff --git a/toolsrc/include/cstring_view.h b/toolsrc/include/cstring_view.h index 88728992b..92f1a6fa5 100644 --- a/toolsrc/include/cstring_view.h +++ b/toolsrc/include/cstring_view.h @@ -6,6 +6,7 @@ namespace vcpkg template<class CharType> struct basic_cstring_view { + constexpr basic_cstring_view() : cstr(nullptr) {} constexpr basic_cstring_view(const CharType* cstr) : cstr(cstr) {} basic_cstring_view(const std::basic_string<CharType>& str) : cstr(str.c_str()) {} diff --git a/toolsrc/include/vcpkg_paths.h b/toolsrc/include/vcpkg_paths.h index 9577abd01..474f47255 100644 --- a/toolsrc/include/vcpkg_paths.h +++ b/toolsrc/include/vcpkg_paths.h @@ -7,10 +7,11 @@ namespace vcpkg { - struct vcvarsall_and_platform_toolset + struct toolset_t { - fs::path path; - std::wstring platform_toolset; + fs::path dumpbin; + fs::path vcvarsall; + cwstring_view version; }; struct vcpkg_paths @@ -46,12 +47,12 @@ namespace vcpkg const fs::path& get_cmake_exe() const; const fs::path& get_git_exe() const; const fs::path& get_nuget_exe() const; - const fs::path& get_dumpbin_exe() const; - const vcvarsall_and_platform_toolset& get_vcvarsall_bat() const; + const toolset_t& get_toolset() const; private: lazy<fs::path> cmake_exe; lazy<fs::path> git_exe; lazy<fs::path> nuget_exe; + lazy<toolset_t> toolset; }; } diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 81f712368..a1e9fda51 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -621,7 +621,8 @@ namespace vcpkg::PostBuildLint static size_t perform_all_checks_and_return_error_count(const package_spec& spec, const vcpkg_paths& paths) { - const fs::path dumpbin_exe = paths.get_dumpbin_exe(); + // for dumpbin + const toolset_t& toolset = paths.get_toolset(); BuildInfo build_info = read_build_info(paths.build_info_file_path(spec)); const fs::path package_dir = paths.package_dir(spec); @@ -675,11 +676,11 @@ namespace vcpkg::PostBuildLint dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend()); dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend()); - error_count += check_exports_of_dlls(dlls, dumpbin_exe); - error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, dumpbin_exe); + error_count += check_exports_of_dlls(dlls, toolset.dumpbin); + error_count += check_uwp_bit_of_dlls(spec.target_triplet().system(), dlls, toolset.dumpbin); error_count += check_dll_architecture(spec.target_triplet().architecture(), dlls); - error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe); + error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin); break; } case LinkageType::backing_enum_t::STATIC: @@ -692,9 +693,9 @@ namespace vcpkg::PostBuildLint if (!contains_and_enabled(build_info.policies, BuildPolicies::ONLY_RELEASE_CRT)) { - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage), debug_libs, dumpbin_exe); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage), debug_libs, toolset.dumpbin); } - error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage), release_libs, dumpbin_exe); + error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage), release_libs, toolset.dumpbin); break; } case LinkageType::backing_enum_t::NULLVALUE: diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index 301612831..8791ef1c1 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -42,8 +42,8 @@ namespace vcpkg::Commands::Build const fs::path& git_exe_path = paths.get_git_exe(); const fs::path ports_cmake_script_path = paths.ports_cmake; - const vcvarsall_and_platform_toolset vcvarsall_bat = paths.get_vcvarsall_bat(); - const std::wstring cmd_set_environment = Strings::wformat(LR"("%s" %s >nul 2>&1)", vcvarsall_bat.path.native(), Strings::utf8_to_utf16(target_triplet.architecture())); + const toolset_t& toolset = paths.get_toolset(); + const std::wstring cmd_set_environment = Strings::wformat(LR"("%s" %s >nul 2>&1)", toolset.vcvarsall.native(), Strings::utf8_to_utf16(target_triplet.architecture())); const std::wstring cmd_launch_cmake = make_cmake_cmd(cmake_exe_path, ports_cmake_script_path, { @@ -51,7 +51,7 @@ namespace vcpkg::Commands::Build { L"PORT", source_paragraph.name }, { L"CURRENT_PORT_DIR", port_dir / "/." }, { L"TARGET_TRIPLET", target_triplet.canonical_name() }, - { L"VCPKG_PLATFORM_TOOLSET", vcvarsall_bat.platform_toolset }, + { L"VCPKG_PLATFORM_TOOLSET", toolset.version }, { L"GIT", git_exe_path } }); diff --git a/toolsrc/src/vcpkg_paths.cpp b/toolsrc/src/vcpkg_paths.cpp index 03b739b29..dd26e89e4 100644 --- a/toolsrc/src/vcpkg_paths.cpp +++ b/toolsrc/src/vcpkg_paths.cpp @@ -269,23 +269,33 @@ namespace vcpkg return vs2015_path; } - static fs::path find_dumpbin_exe(const vcpkg_paths& paths) + static toolset_t find_toolset_instance(const vcpkg_paths& paths) { const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths); + // Note: this will contain a mix of vcvarsall.bat locations and dumpbin.exe locations. std::vector<fs::path> paths_examined; // VS2017 - for (const std::string& instance : vs2017_installation_instances) + for (const fs::path& instance : vs2017_installation_instances) { - const fs::path msvc_path = Strings::format(R"(%s\VC\Tools\MSVC)", instance); + const fs::path vc_dir = instance / "VC"; + + // Skip any instances that do not have vcvarsall. + const fs::path vcvarsall_bat = vc_dir / "Auxiliary" / "Build" / "vcvarsall.bat"; + paths_examined.push_back(vcvarsall_bat); + if (!fs::exists(vcvarsall_bat)) + continue; + + // Locate the "best" MSVC toolchain version + const fs::path msvc_path = vc_dir / "Tools" / "MSVC"; std::vector<fs::path> msvc_subdirectories; - Files::non_recursive_find_matching_paths_in_dir(msvc_path, [&](const fs::path& current) + Files::non_recursive_find_matching_paths_in_dir(msvc_path, [](const fs::path& current) { return fs::is_directory(current); }, &msvc_subdirectories); // Sort them so that latest comes first - std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [&](const fs::path& left, const fs::path& right) + std::sort(msvc_subdirectories.begin(), msvc_subdirectories.end(), [](const fs::path& left, const fs::path& right) { return left.filename() > right.filename(); }); @@ -296,7 +306,7 @@ namespace vcpkg paths_examined.push_back(dumpbin_path); if (fs::exists(dumpbin_path)) { - return dumpbin_path; + return { dumpbin_path, vcvarsall_bat , L"v141" }; } } } @@ -305,70 +315,31 @@ namespace vcpkg const optional<fs::path>& vs_2015_installation_instance = get_VS2015_installation_instance(); if (auto v = vs_2015_installation_instance.get()) { - const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe"; - paths_examined.push_back(vs2015_dumpbin_exe); - if (fs::exists(vs2015_dumpbin_exe)) - { - return vs2015_dumpbin_exe; - } - } - - System::println(System::color::error, "Could not detect dumpbin.exe."); - System::println("The following paths were examined:"); - for (const fs::path& path : paths_examined) - { - System::println(" %s", path.generic_string()); - } - Checks::exit_fail(VCPKG_LINE_INFO); - } - - const fs::path& vcpkg_paths::get_dumpbin_exe() const - { - static const fs::path dumpbin_exe = find_dumpbin_exe(*this); - return dumpbin_exe; - } - - static vcvarsall_and_platform_toolset find_vcvarsall_bat(const vcpkg_paths& paths) - { - const std::vector<std::string> vs2017_installation_instances = get_VS2017_installation_instances(paths); - std::vector<fs::path> paths_examined; - - // VS2017 - for (const fs::path& instance : vs2017_installation_instances) - { - const fs::path vcvarsall_bat = instance / "VC" / "Auxiliary" / "Build" / "vcvarsall.bat"; - paths_examined.push_back(vcvarsall_bat); - if (fs::exists(vcvarsall_bat)) - { - return { vcvarsall_bat , L"v141" }; - } - } - - // VS2015 - const optional<fs::path>& vs_2015_installation_instance = get_VS2015_installation_instance(); - if (auto v = vs_2015_installation_instance.get()) - { const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat"; paths_examined.push_back(vs2015_vcvarsall_bat); if (fs::exists(vs2015_vcvarsall_bat)) { - return { vs2015_vcvarsall_bat, L"v140" }; + const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe"; + paths_examined.push_back(vs2015_dumpbin_exe); + if (fs::exists(vs2015_dumpbin_exe)) + { + return { vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140" }; + } } } - System::println(System::color::error, "Could not detect vcvarsall.bat."); + System::println(System::color::error, "Could not locate a complete toolset."); System::println("The following paths were examined:"); for (const fs::path& path : paths_examined) { - System::println(" %s", path.generic_string()); + System::println(" %s", path.u8string()); } Checks::exit_fail(VCPKG_LINE_INFO); } - const vcvarsall_and_platform_toolset& vcpkg_paths::get_vcvarsall_bat() const + const toolset_t& vcpkg_paths::get_toolset() const { - static const vcvarsall_and_platform_toolset vcvarsall_bat = find_vcvarsall_bat(*this); - return vcvarsall_bat; + return this->toolset.get_lazy([this]() { return find_toolset_instance(*this); }); } } |
