diff --git a/toolsrc/src/commands_export.cpp b/toolsrc/src/commands_export.cpp index 139f19026c..c143fb9c7e 100644 --- a/toolsrc/src/commands_export.cpp +++ b/toolsrc/src/commands_export.cpp @@ -257,7 +257,8 @@ namespace vcpkg::Commands::Export if (!raw && !nuget && !ifw && !zip && !seven_zip && !dry_run) { - System::println(System::Color::error, "Must provide at least one export type: --raw --nuget --ifw --zip --7zip"); + System::println(System::Color::error, + "Must provide at least one export type: --raw --nuget --ifw --zip --7zip"); System::print(EXAMPLE); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -271,7 +272,8 @@ namespace vcpkg::Commands::Export auto maybe_ifw_repository_url = maybe_lookup(options.settings, OPTION_IFW_REPOSITORY_URL); - Checks::check_exit(VCPKG_LINE_INFO, !maybe_ifw_repository_url || ifw, "--ifw-repository-url is only valid with --ifw"); + Checks::check_exit( + VCPKG_LINE_INFO, !maybe_ifw_repository_url || ifw, "--ifw-repository-url is only valid with --ifw"); // create the plan const StatusParagraphs status_db = database_load_check(paths); @@ -354,10 +356,10 @@ namespace vcpkg::Commands::Export spec_exported_dir_path = IFW::export_real_package(raw_exported_dir_path, action, fs); } - const InstallDir dirs = InstallDir::from_destination_root( - spec_exported_dir_path, - action.spec.triplet().to_string(), - spec_exported_dir_path / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list")); + const InstallDir dirs = InstallDir::from_destination_root(spec_exported_dir_path, + action.spec.triplet().to_string(), + spec_exported_dir_path / "vcpkg" / "info" / + (binary_paragraph.fullstem() + ".list")); Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); System::println(System::Color::success, "Exporting package %s... done", display_name); @@ -391,9 +393,9 @@ namespace vcpkg::Commands::Export if (ifw) { - // Unigue packages + // Unique packages IFW::export_unique_packages(raw_exported_dir_path, unique_packages, fs); - // Unigue triplets + // Unique triplets IFW::export_unique_triplets(raw_exported_dir_path, unique_triplets, fs); // Integration IFW::export_integration(raw_exported_dir_path, fs); diff --git a/toolsrc/src/commands_export_ifw.cpp b/toolsrc/src/commands_export_ifw.cpp index ceedac9a35..4b5bdb902d 100644 --- a/toolsrc/src/commands_export_ifw.cpp +++ b/toolsrc/src/commands_export_ifw.cpp @@ -6,7 +6,9 @@ namespace vcpkg::Commands::Export::IFW { using Dependencies::ExportPlanAction; - fs::path export_real_package(const fs::path &raw_exported_dir_path, const ExportPlanAction& action, Files::Filesystem& fs) + fs::path export_real_package(const fs::path& raw_exported_dir_path, + const ExportPlanAction& action, + Files::Filesystem& fs) { std::error_code ec; @@ -14,97 +16,64 @@ namespace vcpkg::Commands::Export::IFW action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph; // Prepare meta dir - const fs::path package_xml_file_path = raw_exported_dir_path / Strings::format("packages.%s.%s", action.spec.name(), action.spec.triplet().canonical_name()) / "meta" / "package.xml"; + const fs::path package_xml_file_path = + raw_exported_dir_path / + Strings::format("packages.%s.%s", action.spec.name(), action.spec.triplet().canonical_name()) / "meta" / + "package.xml"; const fs::path package_xml_dir_path = package_xml_file_path.parent_path(); fs.create_directories(package_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); - std::vector lines; - std::string line; std::string skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += action.spec.to_string(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += binary_paragraph.version; // TODO: Check IFW version format - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "2017-08-31"; // TODO: Get real package release date - line += ""; - //if (!binary_paragraph.depends.empty()) - //{ - // lines.push_back(line); line = skip; - // line += ""; - //// line += Strings::format("triplets.%s:", action.spec.triplet().canonical_name()); - // line += Strings::format("packages.%s.%s:", binary_paragraph.depends[0], action.spec.triplet().canonical_name()); - // for (size_t i = 1; i < binary_paragraph.depends.size(); ++i) - // { - // line += Strings::format(",packages.%s.%s:", binary_paragraph.depends[i], action.spec.triplet().canonical_name()); - // } - // line += ""; - //} - lines.push_back(line); line = skip; - line += ""; - line += Strings::format("packages.%s:,triplets.%s:", action.spec.name(), action.spec.triplet().canonical_name()); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "true"; // NOTE: hide real package - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "true"; - line += ""; - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(package_xml_file_path, lines); + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for package file %s", + package_xml_file_path.generic_string()); + + fs.write_contents(package_xml_file_path, + Strings::format(R"###( + + + %s + %s + 2017-08-31 + packages.%s:,triplets.%s: + true + true + +)###", + action.spec.to_string(), + binary_paragraph.version, + action.spec.name(), + action.spec.triplet().canonical_name())); // Return dir path for export package data - return raw_exported_dir_path / Strings::format("packages.%s.%s", action.spec.name(), action.spec.triplet().canonical_name()) / "data" / "installed"; + return raw_exported_dir_path / + Strings::format("packages.%s.%s", action.spec.name(), action.spec.triplet().canonical_name()) / "data" / + "installed"; } - void export_unique_packages(const fs::path &raw_exported_dir_path, std::map unique_packages, Files::Filesystem& fs) - { - std::error_code ec; - + void export_unique_packages(const fs::path& raw_exported_dir_path, + std::map unique_packages, + Files::Filesystem& fs) + { + std::error_code ec; + // packages fs::path package_xml_file_path = raw_exported_dir_path / "packages" / "meta" / "package.xml"; fs::path package_xml_dir_path = package_xml_file_path.parent_path(); fs.create_directories(package_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); - std::vector lines; - std::string line; std::string skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "Packages"; - line += ""; - lines.push_back(line); line = skip; - line = ""; - line += "1.0.0"; // TODO: Get real packages package version - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "2017-08-31"; // TODO: Get real package release date - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "true"; - line += ""; - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(package_xml_file_path, lines); + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for package file %s", + package_xml_file_path.generic_string()); + fs.write_contents(package_xml_file_path, R"###( + + + Packages + 1.0.0 + 2017-08-31 + true + +)###"); for (auto package = unique_packages.begin(); package != unique_packages.end(); ++package) { @@ -112,56 +81,41 @@ namespace vcpkg::Commands::Export::IFW const BinaryParagraph& binary_paragraph = action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph; - package_xml_file_path = raw_exported_dir_path / Strings::format("packages.%s", package->first) / "meta" / "package.xml"; + package_xml_file_path = + raw_exported_dir_path / Strings::format("packages.%s", package->first) / "meta" / "package.xml"; package_xml_dir_path = package_xml_file_path.parent_path(); fs.create_directories(package_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); - lines.clear(); - line.clear(); - skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += action.spec.name(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += binary_paragraph.description; - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += binary_paragraph.version; // TODO: Check IFW version format - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "2017-08-31"; // TODO: Get real package release date - line += ""; - if (!binary_paragraph.depends.empty()) - { - lines.push_back(line); line = skip; - line += ""; - line += Strings::format("packages.%s:", binary_paragraph.depends[0]); - for (size_t i = 1; i < binary_paragraph.depends.size(); ++i) - { - line += Strings::format(",packages.%s:", binary_paragraph.depends[i]); - } - line += ""; - } - lines.push_back(line); line = skip; - line += ""; - line += "true"; - line += ""; - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(package_xml_file_path, lines); + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for package file %s", + package_xml_file_path.generic_string()); + + auto deps = Strings::join( + ",", binary_paragraph.depends, [](const std::string& dep) { return "packages." + dep + ":"; }); + + if (!deps.empty()) deps = "\n " + deps; + + fs.write_contents(package_xml_file_path, + Strings::format(R"###( + + + %s + %s + %s + 2017-08-31%s + true + +)###", + action.spec.name(), + binary_paragraph.description, + binary_paragraph.version, + deps)); } } - void export_unique_triplets(const fs::path &raw_exported_dir_path, std::set unique_triplets, Files::Filesystem& fs) + void export_unique_triplets(const fs::path& raw_exported_dir_path, + std::set unique_triplets, + Files::Filesystem& fs) { std::error_code ec; @@ -170,71 +124,43 @@ namespace vcpkg::Commands::Export::IFW fs::path package_xml_file_path = raw_exported_dir_path / "triplets" / "meta" / "package.xml"; fs::path package_xml_dir_path = package_xml_file_path.parent_path(); fs.create_directories(package_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); - std::vector lines; - std::string line; std::string skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "Triplets"; - line += ""; - lines.push_back(line); line = skip; - line = ""; - line += "1.0.0"; // TODO: Get real triplits package version - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "2017-08-31"; // TODO: Get real package release date - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "true"; - line += ""; - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(package_xml_file_path, lines); + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for package file %s", + package_xml_file_path.generic_string()); + fs.write_contents(package_xml_file_path, R"###( + + + Triplets + 1.0.0 + 2017-08-31 + true + +)###"); - for (const std::string &triplet : unique_triplets) + for (const std::string& triplet : unique_triplets) { - package_xml_file_path = raw_exported_dir_path / Strings::format("triplets.%s", triplet) / "meta" / "package.xml"; + package_xml_file_path = + raw_exported_dir_path / Strings::format("triplets.%s", triplet) / "meta" / "package.xml"; package_xml_dir_path = package_xml_file_path.parent_path(); fs.create_directories(package_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); - lines.clear(); - line.clear(); - skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += triplet; - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "1.0.0"; // TODO: Get real package version - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "2017-08-31"; // TODO: Get real package release date - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "true"; - line += ""; - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(package_xml_file_path, lines); + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for package file %s", + package_xml_file_path.generic_string()); + fs.write_contents(package_xml_file_path, Strings::format(R"###( + + + %s + 1.0.0 + 2017-08-31 + true + +)###", triplet)); } } - void export_integration(const fs::path &raw_exported_dir_path, Files::Filesystem& fs) + void export_integration(const fs::path& raw_exported_dir_path, Files::Filesystem& fs) { std::error_code ec; @@ -242,32 +168,25 @@ namespace vcpkg::Commands::Export::IFW fs::path package_xml_file_path = raw_exported_dir_path / "integration" / "meta" / "package.xml"; fs::path package_xml_dir_path = package_xml_file_path.parent_path(); fs.create_directories(package_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); - std::vector lines; - std::string line; std::string skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "Integration"; - line += ""; - lines.push_back(line); line = skip; - line = ""; - line += "1.0.0"; // TODO: Get real integration package version - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "2017-08-31"; // TODO: Get real package release date - line += ""; - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(package_xml_file_path, lines); + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for package file %s", + package_xml_file_path.generic_string()); + + fs.write_contents(package_xml_file_path, R"###( + + + Integration + 1.0.0 + 2017-08-31 + true + +)###"); } - void export_config(const fs::path &raw_exported_dir_path, const std::string ifw_repository_url, Files::Filesystem& fs) + void export_config(const fs::path& raw_exported_dir_path, + const std::string ifw_repository_url, + Files::Filesystem& fs) { std::error_code ec; @@ -275,45 +194,31 @@ namespace vcpkg::Commands::Export::IFW fs::path config_xml_file_path = raw_exported_dir_path / "config.xml"; fs::path config_xml_dir_path = config_xml_file_path.parent_path(); fs.create_directories(config_xml_dir_path, ec); - Checks::check_exit( - VCPKG_LINE_INFO, !ec, "Could not create directory for configuration file %s", config_xml_file_path.generic_string()); - std::vector lines; - std::string line; std::string skip = " "; - line = ""; - lines.push_back(line); line.clear(); - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "vcpkg"; - line += ""; - lines.push_back(line); line = skip; - line += ""; - line += "1.0.0"; // TODO: Get real vcpkg installer version - line += ""; - //lines.push_back(line); line = skip; - //line += "true"; - lines.push_back(line); line = skip; - line += ""; - line += "@RootDir@/src/vcpkg"; - line += ""; + Checks::check_exit(VCPKG_LINE_INFO, + !ec, + "Could not create directory for configuration file %s", + config_xml_file_path.generic_string()); + std::string formatted_repo_url; if (!ifw_repository_url.empty()) { - lines.push_back(line); line = skip; - line += ""; - lines.push_back(line); line = skip + skip; - line += ""; - lines.push_back(line); line = skip + skip + skip; - line += ""; - line += ifw_repository_url; - line += ""; - lines.push_back(line); line = skip + skip; - line += ""; - lines.push_back(line); line = skip; - line += ""; + formatted_repo_url = Strings::format(R"###( + + + %s + + +)###", + formatted_repo_url); } - lines.push_back(line); line.clear(); - line = ""; - lines.push_back(line); line.clear(); - fs.write_lines(config_xml_file_path, lines); + + fs.write_contents(config_xml_file_path, Strings::format(R"###( + + + vcpkg + 1.0.0 + 2017-08-31 + @RootDir@/src/vcpkg%s + +)###", formatted_repo_url)); } }