diff --git a/toolsrc/include/vcpkg/base/files.h b/toolsrc/include/vcpkg/base/files.h index 0fba3a55fa1535..7b8e8c12a864ef 100644 --- a/toolsrc/include/vcpkg/base/files.h +++ b/toolsrc/include/vcpkg/base/files.h @@ -111,6 +111,8 @@ namespace vcpkg::Files { std::string read_contents(const fs::path& file_path, LineInfo linfo) const; virtual Expected read_contents(const fs::path& file_path) const = 0; + /// Read text lines from a file + /// Lines will have up to one trailing carriage-return character stripped (CRLF) virtual Expected> read_lines(const fs::path& file_path) const = 0; virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0; virtual std::vector get_files_recursive(const fs::path& dir) const = 0; diff --git a/toolsrc/include/vcpkg/install.h b/toolsrc/include/vcpkg/install.h index ad91bbb378281c..9a438b0392ca2e 100644 --- a/toolsrc/include/vcpkg/install.h +++ b/toolsrc/include/vcpkg/install.h @@ -70,7 +70,13 @@ namespace vcpkg::Install std::vector get_all_port_names(const VcpkgPaths& paths); - void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, const InstallDir& dirs); + void install_package_and_write_listfile(const VcpkgPaths& paths, const PackageSpec& spec, const InstallDir& dirs); + + void install_files_and_write_listfile(Files::Filesystem& fs, + const fs::path& source_dir, + const std::vector& files, + const InstallDir& destination_dir); + InstallResult install_package(const VcpkgPaths& paths, const BinaryControlFile& binary_paragraph, StatusParagraphs* status_db); diff --git a/toolsrc/src/vcpkg/commands.exportifw.cpp b/toolsrc/src/vcpkg/commands.exportifw.cpp index 33b6acf0b7662a..db0987512d8974 100644 --- a/toolsrc/src/vcpkg/commands.exportifw.cpp +++ b/toolsrc/src/vcpkg/commands.exportifw.cpp @@ -476,7 +476,7 @@ namespace vcpkg::Export::IFW ifw_package_dir_path / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list")); - Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); + Install::install_package_and_write_listfile(paths, action.spec, dirs); } System::printf("Exporting packages %s... done\n", ifw_packages_dir_path.generic_u8string()); diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index 81bdeacd76a95a..8d98a4d3f78c3b 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -200,7 +200,7 @@ if (Test-Path $installedDir) action.spec.triplet().to_string(), per_package_dir_path / "installed" / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list")); - Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); + Install::install_package_and_write_listfile(paths, action.spec, dirs); const std::string nuspec_file_content = create_nuspec_file_contents( per_package_dir_path.string(), binary_paragraph, packages_version, chocolatey_options); diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index be968e4c94a402..ae0fa38d4a038d 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -3,9 +3,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -306,9 +306,6 @@ namespace vcpkg::Export static constexpr StringLiteral OPTION_PREFAB_ENABLE_MAVEN = "--prefab-maven"; static constexpr StringLiteral OPTION_PREFAB_ENABLE_DEBUG = "--prefab-debug"; - - - static constexpr std::array EXPORT_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually export"}, {OPTION_RAW, "Export to an uncompressed directory"}, @@ -336,7 +333,7 @@ namespace vcpkg::Export "Specify the maintainer for the exported Chocolatey package (experimental feature)"}, {OPTION_CHOCOLATEY_VERSION_SUFFIX, "Specify the version suffix to add for the exported Chocolatey package (experimental feature)"}, - {OPTION_PREFAB_GROUP_ID, "GroupId uniquely identifies your project according maven specifications"}, + {OPTION_PREFAB_GROUP_ID, "GroupId uniquely identifies your project according maven specifications"}, {OPTION_PREFAB_ARTIFACT_ID, "Artifact Id is the name of the project according maven specifications"}, {OPTION_PREFAB_VERSION, "Version is the name of the project according maven specifications"}, {OPTION_PREFAB_SDK_MIN_VERSION, "Android minimum supported sdk version"}, @@ -389,10 +386,12 @@ namespace vcpkg::Export }); } - if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey && !ret.prefab) + if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey && + !ret.prefab) { - System::print2(System::Color::error, - "Must provide at least one export type: --raw --nuget --ifw --zip --7zip --chocolatey --prefab\n"); + System::print2( + System::Color::error, + "Must provide at least one export type: --raw --nuget --ifw --zip --7zip --chocolatey --prefab\n"); System::print2(COMMAND_STRUCTURE.example_text); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -512,7 +511,18 @@ namespace vcpkg::Export action.spec.triplet().to_string(), raw_exported_dir_path / "installed" / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list")); - Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); + auto lines = fs.read_lines(paths.listfile_path(binary_paragraph)).value_or_exit(VCPKG_LINE_INFO); + std::vector files; + for (auto&& suffix : lines) + { + if (suffix.empty()) continue; + if (suffix.back() == '/') suffix.pop_back(); + if (suffix == action.spec.triplet().to_string()) continue; + files.push_back(paths.installed / fs::u8path(suffix)); + } + + Install::install_files_and_write_listfile( + fs, paths.installed / action.spec.triplet().to_string(), files, dirs); } // Copy files needed for integration @@ -641,7 +651,8 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console Chocolatey::do_export(export_plan, paths, opts.chocolatey_options); } - if(opts.prefab){ + if (opts.prefab) + { Prefab::do_export(export_plan, paths, opts.prefab_options, default_triplet); } diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 951e4027869128..cb17e5b4a8c0c1 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -42,30 +42,37 @@ namespace vcpkg::Install const fs::path& InstallDir::listfile() const { return this->m_listfile; } + void install_package_and_write_listfile(const VcpkgPaths& paths, + const PackageSpec& spec, + const InstallDir& destination_dir) + { + auto& fs = paths.get_filesystem(); + auto source_dir = paths.package_dir(spec); + Checks::check_exit( + VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.u8string()); + auto files = fs.get_files_recursive(source_dir); + install_files_and_write_listfile(fs, source_dir, files, destination_dir); + } void install_files_and_write_listfile(Files::Filesystem& fs, const fs::path& source_dir, + const std::vector& files, const InstallDir& destination_dir) { std::vector output; std::error_code ec; - const size_t prefix_length = source_dir.native().size(); + const size_t prefix_length = source_dir.generic_u8string().size(); const fs::path& destination = destination_dir.destination(); const std::string& destination_subdirectory = destination_dir.destination_subdirectory(); const fs::path& listfile = destination_dir.listfile(); - Checks::check_exit( - VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.generic_string()); fs.create_directories(destination, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create destination directory %s", destination.u8string()); const fs::path listfile_parent = listfile.parent_path(); fs.create_directories(listfile_parent, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.generic_string()); + Checks::check_exit(VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.u8string()); output.push_back(Strings::format(R"(%s/)", destination_subdirectory)); - auto files = fs.get_files_recursive(source_dir); for (auto&& file : files) { const auto status = fs.symlink_status(file, ec); @@ -75,7 +82,7 @@ namespace vcpkg::Install continue; } - const std::string filename = file.filename().u8string(); + const std::string filename = file.filename().generic_u8string(); if (fs::is_regular_file(status) && (Strings::case_insensitive_ascii_equals(filename, "CONTROL") || Strings::case_insensitive_ascii_equals(filename, "BUILD_INFO"))) { @@ -278,7 +285,7 @@ namespace vcpkg::Install const InstallDir install_dir = InstallDir::from_destination_root( paths.installed, triplet.to_string(), paths.listfile_path(bcf.core_paragraph)); - install_files_and_write_listfile(paths.get_filesystem(), package_dir, install_dir); + install_package_and_write_listfile(paths, bcf.core_paragraph.spec, install_dir); source_paragraph.state = InstallState::INSTALLED; write_update(paths, source_paragraph);