[vcpkg-export-ifw] Use template approach for xml instead of line-by-line
MODIFY
src/commands_export.cpp
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,
+ 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"));
+ 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);

MODIFY
src/commands_export_ifw.cpp
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,62 +16,43 @@ 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<std::string> lines;
- std::string line; std::string skip = " ";
- line = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Package>";
- lines.push_back(line); line = skip;
- line += "<DisplayName>";
- line += action.spec.to_string();
- line += "</DisplayName>";
- lines.push_back(line); line = skip;
- line += "<Version>";
- line += binary_paragraph.version; // TODO: Check IFW version format
- line += "</Version>";
- lines.push_back(line); line = skip;
- line += "<ReleaseDate>";
- line += "2017-08-31"; // TODO: Get real package release date
- line += "</ReleaseDate>";
- //if (!binary_paragraph.depends.empty())
- //{
- // lines.push_back(line); line = skip;
- // line += "<Dependencies>";
- //// 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 += "</Dependencies>";
- //}
- lines.push_back(line); line = skip;
- line += "<AutoDependOn>";
- line += Strings::format("packages.%s:,triplets.%s:", action.spec.name(), action.spec.triplet().canonical_name());
- line += "</AutoDependOn>";
- lines.push_back(line); line = skip;
- line += "<Virtual>";
- line += "true"; // NOTE: hide real package
- line += "</Virtual>";
- lines.push_back(line); line = skip;
- line += "<Checkable>";
- line += "true";
- line += "</Checkable>";
- lines.push_back(line); line.clear();
- line = "</Package>";
- 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"###(
+<?xml version=\"1.0\"?>
+<Package>
+ <DisplayName>%s</DisplayName>
+ <Version>%s</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>
+ <AutoDependsOn>packages.%s:,triplets.%s:</AutoDependsOn>
+ <Virtual>true</Virtual>
+ <Checkable>true</Checkable>
+</Package>
+)###",
+ 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<std::string, const ExportPlanAction*> unique_packages, Files::Filesystem& fs)
+ void export_unique_packages(const fs::path& raw_exported_dir_path,
+ std::map<std::string, const ExportPlanAction*> unique_packages,
+ Files::Filesystem& fs)
{
std::error_code ec;
@@ -78,33 +61,19 @@ namespace vcpkg::Commands::Export::IFW
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<std::string> lines;
- std::string line; std::string skip = " ";
- line = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Package>";
- lines.push_back(line); line = skip;
- line += "<DisplayName>";
- line += "Packages";
- line += "</DisplayName>";
- lines.push_back(line); line = skip;
- line = "<Version>";
- line += "1.0.0"; // TODO: Get real packages package version
- line += "</Version>";
- lines.push_back(line); line = skip;
- line += "<ReleaseDate>";
- line += "2017-08-31"; // TODO: Get real package release date
- line += "</ReleaseDate>";
- lines.push_back(line); line = skip;
- line += "<Checkable>";
- line += "true";
- line += "</Checkable>";
- lines.push_back(line); line.clear();
- line = "</Package>";
- 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"###(
+<?xml version=\"1.0\"?>
+<Package>
+ <DisplayName>Packages</DisplayName>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>
+ <Checkable>true</Checkable>
+</Package>
+)###");
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 = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Package>";
- lines.push_back(line); line = skip;
- line += "<DisplayName>";
- line += action.spec.name();
- line += "</DisplayName>";
- lines.push_back(line); line = skip;
- line += "<Description>";
- line += binary_paragraph.description;
- line += "</Description>";
- lines.push_back(line); line = skip;
- line += "<Version>";
- line += binary_paragraph.version; // TODO: Check IFW version format
- line += "</Version>";
- lines.push_back(line); line = skip;
- line += "<ReleaseDate>";
- line += "2017-08-31"; // TODO: Get real package release date
- line += "</ReleaseDate>";
- if (!binary_paragraph.depends.empty())
- {
- lines.push_back(line); line = skip;
- line += "<Dependencies>";
- 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 += "</Dependencies>";
- }
- lines.push_back(line); line = skip;
- line += "<Checkable>";
- line += "true";
- line += "</Checkable>";
- lines.push_back(line); line.clear();
- line = "</Package>";
- 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"###(
+<?xml version=\"1.0\"?>
+<Package>
+ <DisplayName>%s</DisplayName>
+ <Description>%s</Description>
+ <Version>%s</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>%s
+ <Checkable>true</Checkable>
+</Package>
+)###",
+ action.spec.name(),
+ binary_paragraph.description,
+ binary_paragraph.version,
+ deps));
}
}
- void export_unique_triplets(const fs::path &raw_exported_dir_path, std::set<std::string> unique_triplets, Files::Filesystem& fs)
+ void export_unique_triplets(const fs::path& raw_exported_dir_path,
+ std::set<std::string> unique_triplets,
+ Files::Filesystem& fs)
{
std::error_code ec;
@@ -170,67 +124,39 @@ 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<std::string> lines;
- std::string line; std::string skip = " ";
- line = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Package>";
- lines.push_back(line); line = skip;
- line += "<DisplayName>";
- line += "Triplets";
- line += "</DisplayName>";
- lines.push_back(line); line = skip;
- line = "<Version>";
- line += "1.0.0"; // TODO: Get real triplits package version
- line += "</Version>";
- lines.push_back(line); line = skip;
- line += "<ReleaseDate>";
- line += "2017-08-31"; // TODO: Get real package release date
- line += "</ReleaseDate>";
- lines.push_back(line); line = skip;
- line += "<Checkable>";
- line += "true";
- line += "</Checkable>";
- lines.push_back(line); line.clear();
- line = "</Package>";
- 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"###(
+<?xml version=\"1.0\"?>
+<Package>
+ <DisplayName>Triplets</DisplayName>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>
+ <Checkable>true</Checkable>
+</Package>
+)###");
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 = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Package>";
- lines.push_back(line); line = skip;
- line += "<DisplayName>";
- line += triplet;
- line += "</DisplayName>";
- lines.push_back(line); line = skip;
- line += "<Version>";
- line += "1.0.0"; // TODO: Get real package version
- line += "</Version>";
- lines.push_back(line); line = skip;
- line += "<ReleaseDate>";
- line += "2017-08-31"; // TODO: Get real package release date
- line += "</ReleaseDate>";
- lines.push_back(line); line = skip;
- line += "<Checkable>";
- line += "true";
- line += "</Checkable>";
- lines.push_back(line); line.clear();
- line = "</Package>";
- 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"###(
+<?xml version=\"1.0\"?>
+<Package>
+ <DisplayName>%s</DisplayName>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>
+ <Checkable>true</Checkable>
+</Package>
+)###", triplet));
}
}
@@ -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<std::string> lines;
- std::string line; std::string skip = " ";
- line = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Package>";
- lines.push_back(line); line = skip;
- line += "<DisplayName>";
- line += "Integration";
- line += "</DisplayName>";
- lines.push_back(line); line = skip;
- line = "<Version>";
- line += "1.0.0"; // TODO: Get real integration package version
- line += "</Version>";
- lines.push_back(line); line = skip;
- line += "<ReleaseDate>";
- line += "2017-08-31"; // TODO: Get real package release date
- line += "</ReleaseDate>";
- lines.push_back(line); line.clear();
- line = "</Package>";
- 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"###(
+<?xml version=\"1.0\"?>
+<Package>
+ <DisplayName>Integration</DisplayName>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>
+ <Checkable>true</Checkable>
+</Package>
+)###");
}
- 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<std::string> lines;
- std::string line; std::string skip = " ";
- line = "<?xml version=\"1.0\"?>";
- lines.push_back(line); line.clear();
- line += "<Installer>";
- lines.push_back(line); line = skip;
- line += "<Name>";
- line += "vcpkg";
- line += "</Name>";
- lines.push_back(line); line = skip;
- line += "<Version>";
- line += "1.0.0"; // TODO: Get real vcpkg installer version
- line += "</Version>";
- //lines.push_back(line); line = skip;
- //line += "<AllowAllInNameAndVersion>true</AllowAllInNameAndVersion>";
- lines.push_back(line); line = skip;
- line += "<TargetDir>";
- line += "@RootDir@/src/vcpkg";
- line += "</TargetDir>";
+ 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 += "<RemoteRepositories>";
- lines.push_back(line); line = skip + skip;
- line += "<Repository>";
- lines.push_back(line); line = skip + skip + skip;
- line += "<Url>";
- line += ifw_repository_url;
- line += "</Url>";
- lines.push_back(line); line = skip + skip;
- line += "</Repository>";
- lines.push_back(line); line = skip;
- line += "</RemoteRepositories>";
+ formatted_repo_url = Strings::format(R"###(
+ <RemoteRepositories>
+ <Repository>
+ <Url>%s</Url>
+ </Repository>
+ </RemoteRepositories>
+)###",
+ formatted_repo_url);
}
- lines.push_back(line); line.clear();
- line = "</Installer>";
- lines.push_back(line); line.clear();
- fs.write_lines(config_xml_file_path, lines);
+
+ fs.write_contents(config_xml_file_path, Strings::format(R"###(
+<?xml version=\"1.0\"?>
+<Installer>
+ <Name>vcpkg</Name>
+ <Version>1.0.0</Version>
+ <ReleaseDate>2017-08-31</ReleaseDate>
+ <TargetDir>@RootDir@/src/vcpkg</TargetDir>%s
+</Installer>
+)###", formatted_repo_url));
}
}

[vcpkg-export-ifw] Use template approach for xml instead of line-by-line