From 4da95d667c8600c80b4b5731631ebb7bcbc91f1b Mon Sep 17 00:00:00 2001 From: Curtis J Bezault Date: Tue, 20 Aug 2019 08:47:26 -0700 Subject: [vcpkg]Port toolchains (#7687) * checkpoint commit * Only set VCPKG_ENV_OVERRIDES_FILE if it exists * First pass at working port-toolchain * Update VERSION.txt * Return rvalue * Fix compilation error * Some fixes are requested by @ubsan * Fix another compilation error --- toolsrc/src/vcpkg/build.cpp | 84 +++++++++++++++++++++++++------------- toolsrc/src/vcpkg/dependencies.cpp | 2 +- 2 files changed, 56 insertions(+), 30 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 2114b7415..aeb01b27d 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -311,8 +311,8 @@ namespace vcpkg::Build const std::set& feature_list, const Triplet& triplet) { - return Util::fmap(get_dependencies(scf, feature_list, triplet), - [&](const Features& feat) { return feat.name; }); + return Util::sort_unique_erase( + Util::fmap(get_dependencies(scf, feature_list, triplet), [&](const Features& feat) { return feat.name; })); } static std::vector compute_required_feature_specs(const BuildPackageConfig& config, @@ -397,7 +397,6 @@ namespace vcpkg::Build {"CURRENT_PORT_DIR", config.port_dir}, {"TARGET_TRIPLET", triplet.canonical_name()}, {"TARGET_TRIPLET_FILE", paths.get_triplet_file_path(triplet).u8string()}, - {"ENV_OVERRIDES_FILE", config.port_dir / "environment-overrides.cmake"}, {"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()}, {"VCPKG_USE_HEAD_VERSION", Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"}, {"DOWNLOADS", paths.downloads}, @@ -413,6 +412,33 @@ namespace vcpkg::Build variables.push_back({"GIT", git_exe_path}); } + const Files::Filesystem& fs = paths.get_filesystem(); + if (fs.is_regular_file(config.port_dir / "environment-overrides.cmake")) + { + variables.emplace_back("VCPKG_ENV_OVERRIDES_FILE", config.port_dir / "environment-overrides.cmake"); + } + + std::vector dependencies = + filter_dependencies_to_specs(config.scfl.source_control_file->core_paragraph->depends, triplet); + + std::vector port_toolchains; + for (const FeatureSpec& dependency : dependencies) + { + const fs::path port_toolchain_path = paths.installed / dependency.triplet().canonical_name() / "share" / + dependency.spec().name() / "port-toolchain.cmake"; + + if (fs.is_regular_file(port_toolchain_path)) + { + System::print2(port_toolchain_path.u8string()); + port_toolchains.emplace_back(port_toolchain_path.u8string()); + } + } + + if (!port_toolchains.empty()) + { + variables.emplace_back("VCPKG_PORT_TOOLCHAINS", Strings::join(";", port_toolchains)); + } + return variables; } @@ -620,58 +646,53 @@ namespace vcpkg::Build const int max_port_file_count = 100; // the order of recursive_directory_iterator is undefined so save the names to sort - std::vector> hashes_files; + std::vector port_files; for (auto& port_file : fs::stdfs::recursive_directory_iterator(config.port_dir)) { if (fs::is_regular_file(fs.status(VCPKG_LINE_INFO, port_file))) { - hashes_files.emplace_back(vcpkg::Hash::get_file_hash(fs, port_file, "SHA1"), - port_file.path().filename().u8string()); + port_files.emplace_back(port_file.path().filename().u8string(), + vcpkg::Hash::get_file_hash(fs, port_file, "SHA1")); - if (hashes_files.size() > max_port_file_count) + if (port_files.size() > max_port_file_count) { - abi_tag_entries.emplace_back(AbiEntry{"no_hash_max_portfile", ""}); + abi_tag_entries.emplace_back("no_hash_max_portfile", ""); break; } } } - if (hashes_files.size() <= max_port_file_count) + if (port_files.size() <= max_port_file_count) { - Util::sort(hashes_files); + Util::sort(port_files, [](const AbiEntry& l, const AbiEntry& r) { + return l.value < r.value || (l.value == r.value && l.key < r.key); + }); - for (auto& hash_file : hashes_files) - { - // We've already sorted by hash so it's safe to write down the - // filename, which will be consistent across machines. - abi_tag_entries.emplace_back(AbiEntry{std::move(hash_file.second), std::move(hash_file.first)}); - } + std::move(port_files.begin(), port_files.end(), std::back_inserter(abi_tag_entries)); } - abi_tag_entries.emplace_back(AbiEntry{"cmake", paths.get_tool_version(Tools::CMAKE)}); + abi_tag_entries.emplace_back("cmake", paths.get_tool_version(Tools::CMAKE)); #if defined(_WIN32) - abi_tag_entries.emplace_back(AbiEntry{"powershell", paths.get_tool_version("powershell-core")}); + abi_tag_entries.emplace_back("powershell", paths.get_tool_version("powershell-core")); #endif - abi_tag_entries.emplace_back(AbiEntry{ + abi_tag_entries.emplace_back( "vcpkg_fixup_cmake_targets", - vcpkg::Hash::get_file_hash(fs, paths.scripts / "cmake" / "vcpkg_fixup_cmake_targets.cmake", "SHA1")}); - - abi_tag_entries.emplace_back(AbiEntry{"triplet", pre_build_info.triplet_abi_tag}); + vcpkg::Hash::get_file_hash(fs, paths.scripts / "cmake" / "vcpkg_fixup_cmake_targets.cmake", "SHA1")); - const std::string features = Strings::join(";", config.feature_list); - abi_tag_entries.emplace_back(AbiEntry{"features", features}); + abi_tag_entries.emplace_back("triplet", pre_build_info.triplet_abi_tag); + abi_tag_entries.emplace_back("features", Strings::join(";", config.feature_list)); if (pre_build_info.public_abi_override) { - abi_tag_entries.emplace_back(AbiEntry{ + abi_tag_entries.emplace_back( "public_abi_override", - Hash::get_string_hash(pre_build_info.public_abi_override.value_or_exit(VCPKG_LINE_INFO), "SHA1")}); + Hash::get_string_hash(pre_build_info.public_abi_override.value_or_exit(VCPKG_LINE_INFO), "SHA1")); } if (config.build_package_options.use_head_version == UseHeadVersion::YES) - abi_tag_entries.emplace_back(AbiEntry{"head", ""}); + abi_tag_entries.emplace_back("head", ""); const std::string full_abi_info = Strings::join("", abi_tag_entries, [](const AbiEntry& p) { return p.key + " " + p.value + "\n"; }); @@ -765,6 +786,7 @@ namespace vcpkg::Build const std::string& name = config.scf.core_paragraph->name; std::vector required_fspecs = compute_required_feature_specs(config, status_db); + std::vector required_fspecs_copy = required_fspecs; // extract out the actual package ids auto dep_pspecs = Util::fmap(required_fspecs, [](FeatureSpec const& fspec) { return fspec.spec(); }); @@ -1027,8 +1049,12 @@ namespace vcpkg::Build if (port) { - args.emplace_back("CMAKE_ENV_OVERRIDES_FILE", - port.value_or_exit(VCPKG_LINE_INFO).source_location / "environment-overrides.cmake"); + const SourceControlFileLocation& scfl = port.value_or_exit(VCPKG_LINE_INFO); + + if (paths.get_filesystem().is_regular_file(scfl.source_location / "environment-overrides.cmake")) + { + args.emplace_back("VCPKG_ENV_OVERRIDES_FILE", scfl.source_location / "environment-overrides.cmake"); + } } const auto cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path, ports_cmake_script_path, args); diff --git a/toolsrc/src/vcpkg/dependencies.cpp b/toolsrc/src/vcpkg/dependencies.cpp index ab14934a2..7c3f2df4c 100644 --- a/toolsrc/src/vcpkg/dependencies.cpp +++ b/toolsrc/src/vcpkg/dependencies.cpp @@ -674,7 +674,7 @@ namespace vcpkg::Dependencies } // The feature was not previously installed. Mark the cluster - //(aka the entire port) to be removed before re-adding it. + // (aka the entire port) to be removed before re-adding it. mark_minus(cluster, graph, graph_plan, prevent_default_features); return follow_plus_dependencies(feature, cluster, graph, graph_plan, prevent_default_features); -- cgit v1.2.3 From 94ef325828961dc5c9f721a0eb9fcc5ba8a2b765 Mon Sep 17 00:00:00 2001 From: Curtis J Bezault Date: Wed, 21 Aug 2019 14:23:15 -0700 Subject: [vcpkg] Fix gcc-9 warning (#7816) * drop one usage of span in export. Span is not appropriate for rvalues * Add back reference * Fix @ubsan 's comments --- toolsrc/src/vcpkg/export.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index 8f5034eee..5ceb47adf 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -339,26 +339,27 @@ namespace vcpkg::Export struct OptionPair { - const std::string& name; + const StringLiteral& name; Optional& out_opt; }; - const auto options_implies = - [&](const std::string& main_opt_name, bool main_opt, Span implying_opts) { - if (main_opt) - { - for (auto&& opt : implying_opts) - opt.out_opt = maybe_lookup(options.settings, opt.name); - } - else - { - for (auto&& opt : implying_opts) - Checks::check_exit(VCPKG_LINE_INFO, - !maybe_lookup(options.settings, opt.name), - "%s is only valid with %s", - opt.name, - main_opt_name); - } - }; + const auto options_implies = [&](const StringLiteral& main_opt_name, + bool is_main_opt, + const std::initializer_list& implying_opts) { + if (is_main_opt) + { + for (auto&& opt : implying_opts) + opt.out_opt = maybe_lookup(options.settings, opt.name); + } + else + { + for (auto&& opt : implying_opts) + Checks::check_exit(VCPKG_LINE_INFO, + !maybe_lookup(options.settings, opt.name), + "%s is only valid with %s", + opt.name, + main_opt_name); + } + }; #if defined(_MSC_VER) && _MSC_VER <= 1900 // there's a bug in VS 2015 that causes a bunch of "unreferenced local variable" warnings -- cgit v1.2.3 From cc35672763a340b4d6d836a2b9e4ec0e3d703e50 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Tue, 20 Aug 2019 18:43:51 -0700 Subject: =?UTF-8?q?(#7798)=20[vcpkg]=20Fix=20the=20build=20on=20FreeBSD=20?= =?UTF-8?q?=F0=9F=98=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a `#else` line to `toolsrc/src/vcpkg/base/files.cpp`. On Linux and macOS, there are specific ways to copy from file descriptor to file descriptor, but on FreeBSD there isn't (as far as I could tell). This change does a copy using the POSIX standard `read` and `write` calls. (This change was to `RealFilesystem::rename_or_copy`). We expect to have people on FreeBSD install CMake themselves, and use `./bootstrap.sh -useSystemBinaries`, in order to build vcpkg. Since CMake 3.15.2 exists in the FreeBSD 12 (latest stable) package manager, it's trivial to install it. --- toolsrc/src/vcpkg/base/files.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp index bbf37fd25..5ebe8d834 100644 --- a/toolsrc/src/vcpkg/base/files.cpp +++ b/toolsrc/src/vcpkg/base/files.cpp @@ -8,9 +8,8 @@ #include #include -#if defined(__linux__) || defined(__APPLE__) +#if !defined(_WIN32) #include -#include #include #include #include @@ -396,7 +395,7 @@ namespace vcpkg::Files { this->rename(oldpath, newpath, ec); Util::unused(temp_suffix); -#if defined(__linux__) || defined(__APPLE__) +#if !defined(_WIN32) if (ec) { auto dst = newpath; @@ -419,6 +418,33 @@ namespace vcpkg::Files auto written_bytes = sendfile(o_fd, i_fd, &bytes, info.st_size); #elif defined(__APPLE__) auto written_bytes = fcopyfile(i_fd, o_fd, 0, COPYFILE_ALL); +#else + ssize_t written_bytes = 0; + { + constexpr std::size_t buffer_length = 4096; + auto buffer = std::make_unique(buffer_length); + while (auto read_bytes = read(i_fd, buffer.get(), buffer_length)) + { + if (read_bytes == -1) + { + written_bytes = -1; + break; + } + auto remaining = read_bytes; + while (remaining > 0) { + auto read_result = write(o_fd, buffer.get(), remaining); + if (read_result == -1) + { + written_bytes = -1; + // break two loops + goto copy_failure; + } + remaining -= read_result; + } + } + + copy_failure: ; + } #endif if (written_bytes == -1) { -- cgit v1.2.3