Skip to content

Commit

Permalink
[vcpkg] Fix issue microsoft#9781 by exporting from the installed dire…
Browse files Browse the repository at this point in the history
…ctory
  • Loading branch information
ras0219-msft committed Apr 24, 2020
1 parent d0531aa commit 907573c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
6 changes: 6 additions & 0 deletions toolsrc/include/vcpkg/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ 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_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
28 changes: 18 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,15 @@ 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() && suffix.back() == '\r') suffix.pop_back();
files.push_back(paths.installed / suffix);
}

Install::install_files_and_write_listfile(fs, paths.installed, files, dirs);
}

// Copy files needed for integration
Expand Down Expand Up @@ -641,7 +648,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
23 changes: 15 additions & 8 deletions toolsrc/src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ namespace vcpkg::Install
void install_files_and_write_listfile(Files::Filesystem& fs,
const fs::path& source_dir,
const InstallDir& destination_dir)
{
Checks::check_exit(
VCPKG_LINE_INFO, fs.exists(source_dir), "Source directory %s does not exist", source_dir.generic_string());
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());
Expand All @@ -65,7 +73,6 @@ namespace vcpkg::Install
VCPKG_LINE_INFO, !ec, "Could not create directory for listfile %s", listfile.generic_string());

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 Down Expand Up @@ -298,9 +305,9 @@ namespace vcpkg::Install
using Build::ExtendedBuildResult;

static ExtendedBuildResult perform_install_plan_action(const VcpkgPaths& paths,
InstallPlanAction& action,
StatusParagraphs& status_db,
IBinaryProvider* binaries_provider)
InstallPlanAction& action,
StatusParagraphs& status_db,
IBinaryProvider* binaries_provider)
{
const InstallPlanType& plan_type = action.plan_type;
const std::string display_name = action.spec.to_string();
Expand Down Expand Up @@ -731,7 +738,7 @@ namespace vcpkg::Install
{
const auto vs_prompt_view = to_zstring_view(vs_prompt);
System::print2(vcpkg::System::Color::warning,
"warning: vcpkg appears to be in a Visual Studio prompt targeting ",
"warning: vcpkg appears to be in a Visual Studio prompt targeting ",
vs_prompt_view,
" but is installing packages for ",
common_triplet.to_string(),
Expand Down

0 comments on commit 907573c

Please sign in to comment.