Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg] Fix issue #9781 by exporting from the installed directory #11015

Merged
merged 5 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions toolsrc/include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ namespace vcpkg::Files
{
std::string read_contents(const fs::path& file_path, LineInfo linfo) const;
virtual Expected<std::string> read_contents(const fs::path& file_path) const = 0;
/// <summary>Read text lines from a file</summary>
/// <remarks>Lines will have up to one trailing carriage-return character stripped (CRLF)</remarks>
virtual Expected<std::vector<std::string>> 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<fs::path> get_files_recursive(const fs::path& dir) const = 0;
Expand Down
8 changes: 7 additions & 1 deletion toolsrc/include/vcpkg/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ namespace vcpkg::Install

std::vector<std::string> 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<fs::path>& files,
const InstallDir& destination_dir);

InstallResult install_package(const VcpkgPaths& paths,
const BinaryControlFile& binary_paragraph,
StatusParagraphs* status_db);
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg/commands.exportifw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg/export.chocolatey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 21 additions & 10 deletions toolsrc/src/vcpkg/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <vcpkg/commands.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/export.chocolatey.h>
#include <vcpkg/export.prefab.h>
#include <vcpkg/export.h>
#include <vcpkg/export.ifw.h>
#include <vcpkg/export.prefab.h>
#include <vcpkg/help.h>
#include <vcpkg/input.h>
#include <vcpkg/install.h>
Expand Down Expand Up @@ -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<CommandSwitch, 11> EXPORT_SWITCHES = {{
{OPTION_DRY_RUN, "Do not actually export"},
{OPTION_RAW, "Export to an uncompressed directory"},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<fs::path> 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
Expand Down Expand Up @@ -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);
}

Expand Down
27 changes: 17 additions & 10 deletions toolsrc/src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fs::path>& files,
const InstallDir& destination_dir)
{
std::vector<std::string> 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);
Expand All @@ -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")))
{
Expand Down Expand Up @@ -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);
Expand Down