diff options
| author | Jan HrubĂ˝ <jhruby.web@gmail.com> | 2017-03-13 08:56:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-13 08:56:05 +0100 |
| commit | 665f4118f603c5858217ed7a2f2f824b18ff4fc5 (patch) | |
| tree | f0167041edf71e90f2331b5025f603392a8de67a /toolsrc/src/commands_import.cpp | |
| parent | 1bec0fcb73073b5b1719f454c368a63f1bff625e (diff) | |
| parent | 1c9873a0daf625f67474aaf3e163c592c27ecb65 (diff) | |
| download | vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.tar.gz vcpkg-665f4118f603c5858217ed7a2f2f824b18ff4fc5.zip | |
Merge pull request #1 from Microsoft/master
pull
Diffstat (limited to 'toolsrc/src/commands_import.cpp')
| -rw-r--r-- | toolsrc/src/commands_import.cpp | 77 |
1 files changed, 66 insertions, 11 deletions
diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp index b1eae277c..11924b4b2 100644 --- a/toolsrc/src/commands_import.cpp +++ b/toolsrc/src/commands_import.cpp @@ -1,30 +1,85 @@ +#include "pch.h" #include "vcpkg_Commands.h" -#include "vcpkg.h" -#include "vcpkg_System.h" +#include "Paragraphs.h" +#include "StatusParagraph.h" +#include "vcpkg_Files.h" -namespace vcpkg +namespace vcpkg::Commands::Import { - void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + struct Binaries { - if (args.command_arguments.size() != 3) + std::vector<fs::path> dlls; + std::vector<fs::path> libs; + }; + + static Binaries find_binaries_in_dir(const fs::path& path) + { + Files::check_is_directory(path); + + Binaries binaries; + binaries.dlls = Files::recursive_find_files_with_extension_in_dir(path, ".dll"); + binaries.libs = Files::recursive_find_files_with_extension_in_dir(path, ".lib"); + return binaries; + } + + static void copy_files_into_directory(const std::vector<fs::path>& files, const fs::path& destination_folder) + { + fs::create_directory(destination_folder); + + for (auto const& src_path : files) { - System::println(System::color::error, "Error: %s requires 3 parameters", args.command); - print_example(Strings::format(R"(%s C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)", args.command).c_str()); - exit(EXIT_FAILURE); + fs::path dest_path = destination_folder / src_path.filename(); + fs::copy(src_path, dest_path, fs::copy_options::overwrite_existing); } + } + + static void place_library_files_in(const fs::path& include_directory, const fs::path& project_directory, const fs::path& destination_path) + { + Files::check_is_directory(include_directory); + Files::check_is_directory(project_directory); + Files::check_is_directory(destination_path); + Binaries debug_binaries = find_binaries_in_dir(project_directory / "Debug"); + Binaries release_binaries = find_binaries_in_dir(project_directory / "Release"); + + fs::path destination_include_directory = destination_path / "include"; + fs::copy(include_directory, destination_include_directory, fs::copy_options::recursive | fs::copy_options::overwrite_existing); + + copy_files_into_directory(release_binaries.dlls, destination_path / "bin"); + copy_files_into_directory(release_binaries.libs, destination_path / "lib"); + + fs::create_directory(destination_path / "debug"); + copy_files_into_directory(debug_binaries.dlls, destination_path / "debug" / "bin"); + copy_files_into_directory(debug_binaries.libs, destination_path / "debug" / "lib"); + } + + static void do_import(const vcpkg_paths& paths, const fs::path& include_directory, const fs::path& project_directory, const BinaryParagraph& control_file_data) + { + fs::path library_destination_path = paths.package_dir(control_file_data.spec); + fs::create_directory(library_destination_path); + place_library_files_in(include_directory, project_directory, library_destination_path); + + fs::path control_file_path = library_destination_path / "CONTROL"; + std::ofstream(control_file_path) << control_file_data; + } + + void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths) + { + static const std::string example = Commands::Help::create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)"); + args.check_exact_arg_count(3, example); + args.check_and_get_optional_command_arguments({}); const fs::path control_file_path(args.command_arguments[0]); const fs::path include_directory(args.command_arguments[1]); const fs::path project_directory(args.command_arguments[2]); - auto pghs = get_paragraphs(control_file_path); - Checks::check_throw(pghs.size() == 1, "Invalid control file for package"); + auto pghs = Paragraphs::get_paragraphs(control_file_path); + Checks::check_exit(pghs.size() == 1, "Invalid control file %s for package", control_file_path.generic_string()); StatusParagraph spgh; spgh.package = BinaryParagraph(pghs[0]); auto& control_file_data = spgh.package; - vcpkg::binary_import(paths, include_directory, project_directory, control_file_data); + do_import(paths, include_directory, project_directory, control_file_data); exit(EXIT_SUCCESS); } } |
