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

This commit is contained in:
Robert Schumacher 2017-09-21 02:27:00 -07:00 committed by Konstantin Podsvirov
parent ba0cc3f1d7
commit 5199507a58
2 changed files with 160 additions and 253 deletions

View File

@ -257,7 +257,8 @@ namespace vcpkg::Commands::Export
if (!raw && !nuget && !ifw && !zip && !seven_zip && !dry_run) 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); System::print(EXAMPLE);
Checks::exit_fail(VCPKG_LINE_INFO); 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); 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 // create the plan
const StatusParagraphs status_db = database_load_check(paths); 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); spec_exported_dir_path = IFW::export_real_package(raw_exported_dir_path, action, fs);
} }
const InstallDir dirs = InstallDir::from_destination_root( const InstallDir dirs = InstallDir::from_destination_root(spec_exported_dir_path,
spec_exported_dir_path, action.spec.triplet().to_string(),
action.spec.triplet().to_string(), spec_exported_dir_path / "vcpkg" / "info" /
spec_exported_dir_path / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list")); (binary_paragraph.fullstem() + ".list"));
Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); 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); System::println(System::Color::success, "Exporting package %s... done", display_name);
@ -391,9 +393,9 @@ namespace vcpkg::Commands::Export
if (ifw) if (ifw)
{ {
// Unigue packages // Unique packages
IFW::export_unique_packages(raw_exported_dir_path, unique_packages, fs); 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); IFW::export_unique_triplets(raw_exported_dir_path, unique_triplets, fs);
// Integration // Integration
IFW::export_integration(raw_exported_dir_path, fs); IFW::export_integration(raw_exported_dir_path, fs);

View File

@ -6,7 +6,9 @@ namespace vcpkg::Commands::Export::IFW
{ {
using Dependencies::ExportPlanAction; 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; 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; action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_paragraph;
// Prepare meta dir // 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(); const fs::path package_xml_dir_path = package_xml_file_path.parent_path();
fs.create_directories(package_xml_dir_path, ec); fs.create_directories(package_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); !ec,
std::vector<std::string> lines; "Could not create directory for package file %s",
std::string line; std::string skip = " "; package_xml_file_path.generic_string());
line = "<?xml version=\"1.0\"?>";
lines.push_back(line); line.clear(); fs.write_contents(package_xml_file_path,
line += "<Package>"; Strings::format(R"###(
lines.push_back(line); line = skip; <?xml version=\"1.0\"?>
line += "<DisplayName>"; <Package>
line += action.spec.to_string(); <DisplayName>%s</DisplayName>
line += "</DisplayName>"; <Version>%s</Version>
lines.push_back(line); line = skip; <ReleaseDate>2017-08-31</ReleaseDate>
line += "<Version>"; <AutoDependsOn>packages.%s:,triplets.%s:</AutoDependsOn>
line += binary_paragraph.version; // TODO: Check IFW version format <Virtual>true</Virtual>
line += "</Version>"; <Checkable>true</Checkable>
lines.push_back(line); line = skip; </Package>
line += "<ReleaseDate>"; )###",
line += "2017-08-31"; // TODO: Get real package release date action.spec.to_string(),
line += "</ReleaseDate>"; binary_paragraph.version,
//if (!binary_paragraph.depends.empty()) action.spec.name(),
//{ action.spec.triplet().canonical_name()));
// 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);
// Return dir path for export package data // 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,
std::error_code ec; Files::Filesystem& fs)
{
std::error_code ec;
// packages // packages
fs::path package_xml_file_path = raw_exported_dir_path / "packages" / "meta" / "package.xml"; 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::path package_xml_dir_path = package_xml_file_path.parent_path();
fs.create_directories(package_xml_dir_path, ec); fs.create_directories(package_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); !ec,
std::vector<std::string> lines; "Could not create directory for package file %s",
std::string line; std::string skip = " "; package_xml_file_path.generic_string());
line = "<?xml version=\"1.0\"?>"; fs.write_contents(package_xml_file_path, R"###(
lines.push_back(line); line.clear(); <?xml version=\"1.0\"?>
line += "<Package>"; <Package>
lines.push_back(line); line = skip; <DisplayName>Packages</DisplayName>
line += "<DisplayName>"; <Version>1.0.0</Version>
line += "Packages"; <ReleaseDate>2017-08-31</ReleaseDate>
line += "</DisplayName>"; <Checkable>true</Checkable>
lines.push_back(line); line = skip; </Package>
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);
for (auto package = unique_packages.begin(); package != unique_packages.end(); ++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 = const BinaryParagraph& binary_paragraph =
action.any_paragraph.binary_control_file.value_or_exit(VCPKG_LINE_INFO).core_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(); package_xml_dir_path = package_xml_file_path.parent_path();
fs.create_directories(package_xml_dir_path, ec); fs.create_directories(package_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); !ec,
lines.clear(); "Could not create directory for package file %s",
line.clear(); package_xml_file_path.generic_string());
skip = " ";
line = "<?xml version=\"1.0\"?>"; auto deps = Strings::join(
lines.push_back(line); line.clear(); ",", binary_paragraph.depends, [](const std::string& dep) { return "packages." + dep + ":"; });
line += "<Package>";
lines.push_back(line); line = skip; if (!deps.empty()) deps = "\n " + deps;
line += "<DisplayName>";
line += action.spec.name(); fs.write_contents(package_xml_file_path,
line += "</DisplayName>"; Strings::format(R"###(
lines.push_back(line); line = skip; <?xml version=\"1.0\"?>
line += "<Description>"; <Package>
line += binary_paragraph.description; <DisplayName>%s</DisplayName>
line += "</Description>"; <Description>%s</Description>
lines.push_back(line); line = skip; <Version>%s</Version>
line += "<Version>"; <ReleaseDate>2017-08-31</ReleaseDate>%s
line += binary_paragraph.version; // TODO: Check IFW version format <Checkable>true</Checkable>
line += "</Version>"; </Package>
lines.push_back(line); line = skip; )###",
line += "<ReleaseDate>"; action.spec.name(),
line += "2017-08-31"; // TODO: Get real package release date binary_paragraph.description,
line += "</ReleaseDate>"; binary_paragraph.version,
if (!binary_paragraph.depends.empty()) deps));
{
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);
} }
} }
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; 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_file_path = raw_exported_dir_path / "triplets" / "meta" / "package.xml";
fs::path package_xml_dir_path = package_xml_file_path.parent_path(); fs::path package_xml_dir_path = package_xml_file_path.parent_path();
fs.create_directories(package_xml_dir_path, ec); fs.create_directories(package_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); !ec,
std::vector<std::string> lines; "Could not create directory for package file %s",
std::string line; std::string skip = " "; package_xml_file_path.generic_string());
line = "<?xml version=\"1.0\"?>"; fs.write_contents(package_xml_file_path, R"###(
lines.push_back(line); line.clear(); <?xml version=\"1.0\"?>
line += "<Package>"; <Package>
lines.push_back(line); line = skip; <DisplayName>Triplets</DisplayName>
line += "<DisplayName>"; <Version>1.0.0</Version>
line += "Triplets"; <ReleaseDate>2017-08-31</ReleaseDate>
line += "</DisplayName>"; <Checkable>true</Checkable>
lines.push_back(line); line = skip; </Package>
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);
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(); package_xml_dir_path = package_xml_file_path.parent_path();
fs.create_directories(package_xml_dir_path, ec); fs.create_directories(package_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); !ec,
lines.clear(); "Could not create directory for package file %s",
line.clear(); package_xml_file_path.generic_string());
skip = " "; fs.write_contents(package_xml_file_path, Strings::format(R"###(
line = "<?xml version=\"1.0\"?>"; <?xml version=\"1.0\"?>
lines.push_back(line); line.clear(); <Package>
line += "<Package>"; <DisplayName>%s</DisplayName>
lines.push_back(line); line = skip; <Version>1.0.0</Version>
line += "<DisplayName>"; <ReleaseDate>2017-08-31</ReleaseDate>
line += triplet; <Checkable>true</Checkable>
line += "</DisplayName>"; </Package>
lines.push_back(line); line = skip; )###", triplet));
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);
} }
} }
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; 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_file_path = raw_exported_dir_path / "integration" / "meta" / "package.xml";
fs::path package_xml_dir_path = package_xml_file_path.parent_path(); fs::path package_xml_dir_path = package_xml_file_path.parent_path();
fs.create_directories(package_xml_dir_path, ec); fs.create_directories(package_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for package file %s", package_xml_file_path.generic_string()); !ec,
std::vector<std::string> lines; "Could not create directory for package file %s",
std::string line; std::string skip = " "; package_xml_file_path.generic_string());
line = "<?xml version=\"1.0\"?>";
lines.push_back(line); line.clear(); fs.write_contents(package_xml_file_path, R"###(
line += "<Package>"; <?xml version=\"1.0\"?>
lines.push_back(line); line = skip; <Package>
line += "<DisplayName>"; <DisplayName>Integration</DisplayName>
line += "Integration"; <Version>1.0.0</Version>
line += "</DisplayName>"; <ReleaseDate>2017-08-31</ReleaseDate>
lines.push_back(line); line = skip; <Checkable>true</Checkable>
line = "<Version>"; </Package>
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);
} }
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; 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_file_path = raw_exported_dir_path / "config.xml";
fs::path config_xml_dir_path = config_xml_file_path.parent_path(); fs::path config_xml_dir_path = config_xml_file_path.parent_path();
fs.create_directories(config_xml_dir_path, ec); fs.create_directories(config_xml_dir_path, ec);
Checks::check_exit( Checks::check_exit(VCPKG_LINE_INFO,
VCPKG_LINE_INFO, !ec, "Could not create directory for configuration file %s", config_xml_file_path.generic_string()); !ec,
std::vector<std::string> lines; "Could not create directory for configuration file %s",
std::string line; std::string skip = " "; config_xml_file_path.generic_string());
line = "<?xml version=\"1.0\"?>"; std::string formatted_repo_url;
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>";
if (!ifw_repository_url.empty()) if (!ifw_repository_url.empty())
{ {
lines.push_back(line); line = skip; formatted_repo_url = Strings::format(R"###(
line += "<RemoteRepositories>"; <RemoteRepositories>
lines.push_back(line); line = skip + skip; <Repository>
line += "<Repository>"; <Url>%s</Url>
lines.push_back(line); line = skip + skip + skip; </Repository>
line += "<Url>"; </RemoteRepositories>
line += ifw_repository_url; )###",
line += "</Url>"; formatted_repo_url);
lines.push_back(line); line = skip + skip;
line += "</Repository>";
lines.push_back(line); line = skip;
line += "</RemoteRepositories>";
} }
lines.push_back(line); line.clear();
line = "</Installer>"; fs.write_contents(config_xml_file_path, Strings::format(R"###(
lines.push_back(line); line.clear(); <?xml version=\"1.0\"?>
fs.write_lines(config_xml_file_path, lines); <Installer>
<Name>vcpkg</Name>
<Version>1.0.0</Version>
<ReleaseDate>2017-08-31</ReleaseDate>
<TargetDir>@RootDir@/src/vcpkg</TargetDir>%s
</Installer>
)###", formatted_repo_url));
} }
} }