From e5a6c7a7a61a14e546c7c2f51bbe8595d6624ff0 Mon Sep 17 00:00:00 2001 From: seanyen Date: Tue, 11 Jun 2019 18:09:55 -0700 Subject: first check-in. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 82 +++++++++++++++++++++++++++++++++ toolsrc/src/vcpkg/export.cpp | 16 +++++-- 2 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 toolsrc/src/vcpkg/export.chocolatey.cpp (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp new file mode 100644 index 000000000..88fb15c23 --- /dev/null +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -0,0 +1,82 @@ +#include "pch.h" + +#include +#include +#include +#include +#include +#include + +namespace vcpkg::Export::Chocolatey +{ + using Dependencies::ExportPlanAction; + using Dependencies::ExportPlanType; + using Install::InstallDir; + + static std::string create_nuspec_file_contents(const std::string& exported_root_dir, + const BinaryParagraph& binary_paragraph) + { + static constexpr auto CONTENT_TEMPLATE = R"( + + + @PACKAGE_ID@ + @PACKAGE_VERSION@ + + + + + + +)"; + + std::string nuspec_file_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", binary_paragraph.spec.name()); + nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_VERSION@", binary_paragraph.version); + nuspec_file_content = + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DESCRIPTION@", binary_paragraph.description); + nuspec_file_content = + Strings::replace_all(std::move(nuspec_file_content), "@EXPORTED_ROOT_DIR@", exported_root_dir); + return nuspec_file_content; + } + + void do_export(const std::vector& export_plan, + const VcpkgPaths& paths) + { + Files::Filesystem& fs = paths.get_filesystem(); + const fs::path export_to_path = paths.root; + const fs::path raw_exported_dir_path = export_to_path / "test-chocolatey"; + + std::error_code ec; + fs.remove_all(raw_exported_dir_path, ec); + fs.create_directory(raw_exported_dir_path, ec); + + // execute the plan + for (const ExportPlanAction& action : export_plan) + { + if (action.plan_type != ExportPlanType::ALREADY_BUILT) + { + Checks::unreachable(VCPKG_LINE_INFO); + } + + const std::string display_name = action.spec.to_string(); + System::print2("Exporting package ", display_name, "...\n"); + + const fs::path per_package_dir_path = raw_exported_dir_path / action.spec.name(); + + const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO); + + const InstallDir dirs = InstallDir::from_destination_root( + per_package_dir_path / "installed", + action.spec.triplet().to_string(), + per_package_dir_path / "installed" / "vcpkg" / "info" / (binary_paragraph.fullstem() + ".list")); + + Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); + + const std::string nuspec_file_content = + create_nuspec_file_contents(raw_exported_dir_path.string(), binary_paragraph); + const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); + fs.write_contents(nuspec_file_path, nuspec_file_content); + } + } +} diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index 23fc7441a..3a40befc7 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -256,6 +257,7 @@ namespace vcpkg::Export bool ifw = false; bool zip = false; bool seven_zip = false; + bool chocolatey = false; Optional maybe_output; @@ -280,14 +282,16 @@ namespace vcpkg::Export static constexpr StringLiteral OPTION_IFW_REPOSITORY_DIR_PATH = "--ifw-repository-directory-path"; static constexpr StringLiteral OPTION_IFW_CONFIG_FILE_PATH = "--ifw-configuration-file-path"; static constexpr StringLiteral OPTION_IFW_INSTALLER_FILE_PATH = "--ifw-installer-file-path"; + static constexpr StringLiteral OPTION_CHOCOLATEY = "--chocolatey"; - static constexpr std::array EXPORT_SWITCHES = {{ + static constexpr std::array EXPORT_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually export"}, {OPTION_RAW, "Export to an uncompressed directory"}, {OPTION_NUGET, "Export a NuGet package"}, {OPTION_IFW, "Export to an IFW-based installer"}, {OPTION_ZIP, "Export to a zip file"}, {OPTION_SEVEN_ZIP, "Export to a 7zip (.7z) file"}, + {OPTION_CHOCOLATEY, "Export a Chocolatey package"}, }}; static constexpr std::array EXPORT_SETTINGS = {{ @@ -326,13 +330,14 @@ namespace vcpkg::Export ret.ifw = options.switches.find(OPTION_IFW) != options.switches.cend(); ret.zip = options.switches.find(OPTION_ZIP) != options.switches.cend(); ret.seven_zip = options.switches.find(OPTION_SEVEN_ZIP) != options.switches.cend(); + ret.chocolatey = options.switches.find(OPTION_CHOCOLATEY) != options.switches.cend(); ret.maybe_output = maybe_lookup(options.settings, OPTION_OUTPUT); - if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run) + if (!ret.raw && !ret.nuget && !ret.ifw && !ret.zip && !ret.seven_zip && !ret.dry_run && !ret.chocolatey) { System::print2(System::Color::error, - "Must provide at least one export type: --raw --nuget --ifw --zip --7zip\n"); + "Must provide at least one export type: --raw --nuget --ifw --zip --7zip --chocolatey\n"); System::print2(COMMAND_STRUCTURE.example_text); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -544,6 +549,11 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console print_next_step_info("@RootDir@/src/vcpkg"); } + if (opts.chocolatey) + { + Chocolatey::do_export(export_plan, paths); + } + Checks::exit_success(VCPKG_LINE_INFO); } } -- cgit v1.2.3 From 31482e4d09bce785dbe2e999c3c009d854734224 Mon Sep 17 00:00:00 2001 From: seanyen Date: Tue, 11 Jun 2019 23:54:54 -0700 Subject: add nuget packaging logic. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index 88fb15c23..aa10ec71d 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -21,6 +21,7 @@ namespace vcpkg::Export::Chocolatey @PACKAGE_ID@ @PACKAGE_VERSION@ + @PACKAGE_MAINTAINER@ @@ -30,9 +31,16 @@ namespace vcpkg::Export::Chocolatey )"; - + std::string maintainer = binary_paragraph.maintainer; + if (maintainer.empty()) + { + maintainer = binary_paragraph.spec.name(); + } std::string nuspec_file_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", binary_paragraph.spec.name()); - nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_VERSION@", binary_paragraph.version); + nuspec_file_content = + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_VERSION@", binary_paragraph.version); + nuspec_file_content = + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_MAINTAINER@", maintainer); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DESCRIPTION@", binary_paragraph.description); nuspec_file_content = @@ -45,7 +53,8 @@ namespace vcpkg::Export::Chocolatey { Files::Filesystem& fs = paths.get_filesystem(); const fs::path export_to_path = paths.root; - const fs::path raw_exported_dir_path = export_to_path / "test-chocolatey"; + const fs::path raw_exported_dir_path = export_to_path / "chocolatey"; + const fs::path& nuget_exe = paths.get_tool_exe(Tools::NUGET); std::error_code ec; fs.remove_all(raw_exported_dir_path, ec); @@ -74,9 +83,17 @@ namespace vcpkg::Export::Chocolatey Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); const std::string nuspec_file_content = - create_nuspec_file_contents(raw_exported_dir_path.string(), binary_paragraph); + create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph); const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); fs.write_contents(nuspec_file_path, nuspec_file_content); + + const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", + nuget_exe.u8string(), + raw_exported_dir_path.u8string(), + nuspec_file_path.u8string()); + + const int exit_code = System::cmd_execute_clean(cmd_line); + Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed"); } } } -- cgit v1.2.3 From 9a3999d8e29c535ed7fd304a1db5eb2805313416 Mon Sep 17 00:00:00 2001 From: seanyen Date: Wed, 12 Jun 2019 00:29:51 -0700 Subject: add dependencies. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index aa10ec71d..3e6acd34e 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -13,6 +13,19 @@ namespace vcpkg::Export::Chocolatey using Dependencies::ExportPlanType; using Install::InstallDir; + static std::string create_nuspec_dependencies(const BinaryParagraph& binary_paragraph) + { + static constexpr auto CONTENT_TEMPLATE = + R"()"; + + std::string nuspec_dependencies; + for (const std::string& depend: binary_paragraph.depends) + { + nuspec_dependencies += Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", depend); + } + return nuspec_dependencies; + } + static std::string create_nuspec_file_contents(const std::string& exported_root_dir, const BinaryParagraph& binary_paragraph) { @@ -25,6 +38,9 @@ namespace vcpkg::Export::Chocolatey + + @PACKAGE_DEPENDENCIES@ + @@ -45,6 +61,8 @@ namespace vcpkg::Export::Chocolatey Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DESCRIPTION@", binary_paragraph.description); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@EXPORTED_ROOT_DIR@", exported_root_dir); + nuspec_file_content = + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DEPENDENCIES@", create_nuspec_dependencies(binary_paragraph)); return nuspec_file_content; } -- cgit v1.2.3 From c63af255e39c8303b07014456d97985a71ef3174 Mon Sep 17 00:00:00 2001 From: seanyen Date: Wed, 12 Jun 2019 18:20:02 -0700 Subject: add chocolatey install scripts. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 86 +++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index 3e6acd34e..b2bfffd41 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -44,6 +44,7 @@ namespace vcpkg::Export::Chocolatey + )"; @@ -66,12 +67,81 @@ namespace vcpkg::Export::Chocolatey return nuspec_file_content; } + static std::string create_chocolatey_install_contents() + { + static constexpr auto CONTENT_TEMPLATE = R"###( +$ErrorActionPreference = 'Stop'; + +$packageName= $env:ChocolateyPackageName +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$rootDir = "$(Split-Path -parent $toolsDir)" +$installedDir = Join-Path $rootDir 'installed' + +$whereToInstall = (pwd).path +$whereToInstallCache = Join-Path $rootDir 'install.txt' +Set-Content -Path $whereToInstallCache -Value $whereToInstall +Copy-Item $installedDir -destination $whereToInstall -recurse -force +)###"; + return CONTENT_TEMPLATE; + } + + static std::string create_chocolatey_uninstall_contents(const BinaryParagraph& binary_paragraph) + { + static constexpr auto CONTENT_TEMPLATE = R"###( +$ErrorActionPreference = 'Stop'; + +$packageName= $env:ChocolateyPackageName +$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" +$rootDir = "$(Split-Path -parent $toolsDir)" +$listFile = Join-Path $rootDir 'installed\vcpkg\info\@PACKAGE_FULLSTEM@.list' + +$whereToInstall = $null +$whereToInstallCache = Join-Path $rootDir 'install.txt' +Get-Content $whereToInstallCache | Foreach-Object { + $whereToInstall = $_ +} + +$installedDir = Join-Path $whereToInstall 'installed' +Get-Content $listFile | Foreach-Object { + $fileToRemove = Join-Path $installedDir $_ + if (Test-Path $fileToRemove -PathType Leaf) { + Remove-Item $fileToRemove + } +} + +Get-Content $listFile | Foreach-Object { + $fileToRemove = Join-Path $installedDir $_ + if (Test-Path $fileToRemove -PathType Container) { + $folderToDelete = Join-Path $fileToRemove * + if (-Not (Test-Path $folderToDelete)) + { + Remove-Item $fileToRemove + } + } +} + +$listFileToRemove = Join-Path $whereToInstall 'installed\vcpkg\info\@PACKAGE_FULLSTEM@.list' +Remove-Item $listFileToRemove + +if (Test-Path $installedDir) +{ + while ( + $empties = Get-ChildItem $installedDir -recurse -Directory | Where-Object { + $_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0 + } + ) { $empties | Remove-Item } +} +)###"; + std::string chocolatey_uninstall_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_FULLSTEM@", binary_paragraph.fullstem()); + return chocolatey_uninstall_content; + } + void do_export(const std::vector& export_plan, const VcpkgPaths& paths) { Files::Filesystem& fs = paths.get_filesystem(); - const fs::path export_to_path = paths.root; - const fs::path raw_exported_dir_path = export_to_path / "chocolatey"; + const fs::path vcpkg_root_path = paths.root; + const fs::path raw_exported_dir_path = vcpkg_root_path / "chocolatey"; const fs::path& nuget_exe = paths.get_tool_exe(Tools::NUGET); std::error_code ec; @@ -105,9 +175,19 @@ namespace vcpkg::Export::Chocolatey const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); fs.write_contents(nuspec_file_path, nuspec_file_content); + fs.create_directory(per_package_dir_path / "tools", ec); + + const std::string chocolatey_install_content = create_chocolatey_install_contents(); + const fs::path chocolatey_install_file_path = per_package_dir_path / "tools" / "chocolateyInstall.ps1"; + fs.write_contents(chocolatey_install_file_path, chocolatey_install_content); + + const std::string chocolatey_uninstall_content = create_chocolatey_uninstall_contents(binary_paragraph); + const fs::path chocolatey_uninstall_file_path = per_package_dir_path / "tools" / "chocolateyUninstall.ps1"; + fs.write_contents(chocolatey_uninstall_file_path, chocolatey_uninstall_content); + const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", nuget_exe.u8string(), - raw_exported_dir_path.u8string(), + vcpkg_root_path.u8string(), nuspec_file_path.u8string()); const int exit_code = System::cmd_execute_clean(cmd_line); -- cgit v1.2.3 From 11d2fc9f81065cc883a59ea29931d8e1030a3731 Mon Sep 17 00:00:00 2001 From: seanyen Date: Thu, 13 Jun 2019 01:04:19 -0700 Subject: add depends version restrictions. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index b2bfffd41..2c1d1e657 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -13,21 +13,30 @@ namespace vcpkg::Export::Chocolatey using Dependencies::ExportPlanType; using Install::InstallDir; - static std::string create_nuspec_dependencies(const BinaryParagraph& binary_paragraph) + static std::string create_nuspec_dependencies(const BinaryParagraph& binary_paragraph, + const std::map& dependsVersion) { static constexpr auto CONTENT_TEMPLATE = - R"()"; + R"()"; std::string nuspec_dependencies; for (const std::string& depend: binary_paragraph.depends) { - nuspec_dependencies += Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", depend); + auto found = dependsVersion.find(depend); + if (found == dependsVersion.end()) + { + Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot find desired dependency version."); + } + std::string nuspec_dependency = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", depend); + nuspec_dependency = Strings::replace_all(std::move(nuspec_dependency), "@PACKAGE_VERSION@", found->second); + nuspec_dependencies += nuspec_dependency; } return nuspec_dependencies; } static std::string create_nuspec_file_contents(const std::string& exported_root_dir, - const BinaryParagraph& binary_paragraph) + const BinaryParagraph& binary_paragraph, + const std::map& dependsVersion) { static constexpr auto CONTENT_TEMPLATE = R"( @@ -63,7 +72,7 @@ namespace vcpkg::Export::Chocolatey nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@EXPORTED_ROOT_DIR@", exported_root_dir); nuspec_file_content = - Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DEPENDENCIES@", create_nuspec_dependencies(binary_paragraph)); + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DEPENDENCIES@", create_nuspec_dependencies(binary_paragraph, dependsVersion)); return nuspec_file_content; } @@ -149,6 +158,7 @@ if (Test-Path $installedDir) fs.create_directory(raw_exported_dir_path, ec); // execute the plan + std::map dependsVersion; for (const ExportPlanAction& action : export_plan) { if (action.plan_type != ExportPlanType::ALREADY_BUILT) @@ -156,6 +166,12 @@ if (Test-Path $installedDir) Checks::unreachable(VCPKG_LINE_INFO); } + const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO); + dependsVersion.insert(std::make_pair(binary_paragraph.spec.name(), binary_paragraph.version)); + } + + for (const ExportPlanAction& action : export_plan) + { const std::string display_name = action.spec.to_string(); System::print2("Exporting package ", display_name, "...\n"); @@ -171,7 +187,7 @@ if (Test-Path $installedDir) Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); const std::string nuspec_file_content = - create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph); + create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph, dependsVersion); const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); fs.write_contents(nuspec_file_path, nuspec_file_content); -- cgit v1.2.3 From 4c7188919a63dd0f3cdbd559f25571ca079596b7 Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Mon, 17 Jun 2019 17:50:48 -0700 Subject: Add version-suffix and maintainer options. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 45 ++++++++++++++++++++------------- toolsrc/src/vcpkg/export.cpp | 16 ++++++++++-- 2 files changed, 42 insertions(+), 19 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index 2c1d1e657..cf9db6f4c 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -14,7 +14,7 @@ namespace vcpkg::Export::Chocolatey using Install::InstallDir; static std::string create_nuspec_dependencies(const BinaryParagraph& binary_paragraph, - const std::map& dependsVersion) + const std::map& packages_version) { static constexpr auto CONTENT_TEMPLATE = R"()"; @@ -22,8 +22,8 @@ namespace vcpkg::Export::Chocolatey std::string nuspec_dependencies; for (const std::string& depend: binary_paragraph.depends) { - auto found = dependsVersion.find(depend); - if (found == dependsVersion.end()) + auto found = packages_version.find(depend); + if (found == packages_version.end()) { Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot find desired dependency version."); } @@ -36,10 +36,11 @@ namespace vcpkg::Export::Chocolatey static std::string create_nuspec_file_contents(const std::string& exported_root_dir, const BinaryParagraph& binary_paragraph, - const std::map& dependsVersion) + const std::map& packages_version, + const Options& chocolatey_options) { - static constexpr auto CONTENT_TEMPLATE = R"( - + static constexpr auto CONTENT_TEMPLATE = R"( + @PACKAGE_ID@ @PACKAGE_VERSION@ @@ -57,22 +58,22 @@ namespace vcpkg::Export::Chocolatey )"; - std::string maintainer = binary_paragraph.maintainer; - if (maintainer.empty()) + auto package_version = packages_version.find(binary_paragraph.spec.name()); + if (package_version == packages_version.end()) { - maintainer = binary_paragraph.spec.name(); + Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot find desired package version."); } std::string nuspec_file_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", binary_paragraph.spec.name()); nuspec_file_content = - Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_VERSION@", binary_paragraph.version); + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_VERSION@", package_version->second); nuspec_file_content = - Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_MAINTAINER@", maintainer); + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_MAINTAINER@", chocolatey_options.maybe_maintainer.value_or("")); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DESCRIPTION@", binary_paragraph.description); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@EXPORTED_ROOT_DIR@", exported_root_dir); nuspec_file_content = - Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DEPENDENCIES@", create_nuspec_dependencies(binary_paragraph, dependsVersion)); + Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DEPENDENCIES@", create_nuspec_dependencies(binary_paragraph, packages_version)); return nuspec_file_content; } @@ -146,19 +147,23 @@ if (Test-Path $installedDir) } void do_export(const std::vector& export_plan, - const VcpkgPaths& paths) + const VcpkgPaths& paths, + const Options& chocolatey_options) { Files::Filesystem& fs = paths.get_filesystem(); const fs::path vcpkg_root_path = paths.root; const fs::path raw_exported_dir_path = vcpkg_root_path / "chocolatey"; + const fs::path exported_dir_path = vcpkg_root_path / "chocolatey_exports"; const fs::path& nuget_exe = paths.get_tool_exe(Tools::NUGET); std::error_code ec; fs.remove_all(raw_exported_dir_path, ec); fs.create_directory(raw_exported_dir_path, ec); + fs.remove_all(exported_dir_path, ec); + fs.create_directory(exported_dir_path, ec); // execute the plan - std::map dependsVersion; + std::map packages_version; for (const ExportPlanAction& action : export_plan) { if (action.plan_type != ExportPlanType::ALREADY_BUILT) @@ -167,7 +172,13 @@ if (Test-Path $installedDir) } const BinaryParagraph& binary_paragraph = action.core_paragraph().value_or_exit(VCPKG_LINE_INFO); - dependsVersion.insert(std::make_pair(binary_paragraph.spec.name(), binary_paragraph.version)); + auto norm_version = binary_paragraph.version; + + // normalize the version string to be separated by dots to be compliant with Nusepc. + norm_version = Strings::replace_all(std::move(norm_version), "-", "."); + norm_version = Strings::replace_all(std::move(norm_version), "_", "."); + norm_version = norm_version + chocolatey_options.maybe_version_suffix.value_or(""); + packages_version.insert(std::make_pair(binary_paragraph.spec.name(), norm_version)); } for (const ExportPlanAction& action : export_plan) @@ -187,7 +198,7 @@ if (Test-Path $installedDir) Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); const std::string nuspec_file_content = - create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph, dependsVersion); + create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph, packages_version, chocolatey_options); const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); fs.write_contents(nuspec_file_path, nuspec_file_content); @@ -203,7 +214,7 @@ if (Test-Path $installedDir) const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", nuget_exe.u8string(), - vcpkg_root_path.u8string(), + exported_dir_path.u8string(), nuspec_file_path.u8string()); const int exit_code = System::cmd_execute_clean(cmd_line); diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index 3a40befc7..06f4b1868 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -265,6 +265,7 @@ namespace vcpkg::Export Optional maybe_nuget_version; IFW::Options ifw_options; + Chocolatey::Options chocolatey_options; std::vector specs; }; @@ -283,6 +284,8 @@ namespace vcpkg::Export static constexpr StringLiteral OPTION_IFW_CONFIG_FILE_PATH = "--ifw-configuration-file-path"; static constexpr StringLiteral OPTION_IFW_INSTALLER_FILE_PATH = "--ifw-installer-file-path"; static constexpr StringLiteral OPTION_CHOCOLATEY = "--chocolatey"; + static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "--maintainer"; + static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "--version-suffix"; static constexpr std::array EXPORT_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually export"}, @@ -294,7 +297,7 @@ namespace vcpkg::Export {OPTION_CHOCOLATEY, "Export a Chocolatey package"}, }}; - static constexpr std::array EXPORT_SETTINGS = {{ + static constexpr std::array EXPORT_SETTINGS = {{ {OPTION_OUTPUT, "Specify the output name (used to construct filename)"}, {OPTION_NUGET_ID, "Specify the id for the exported NuGet package (overrides --output)"}, {OPTION_NUGET_VERSION, "Specify the version for the exported NuGet package"}, @@ -303,6 +306,8 @@ namespace vcpkg::Export {OPTION_IFW_REPOSITORY_DIR_PATH, "Specify the directory path for the exported repository"}, {OPTION_IFW_CONFIG_FILE_PATH, "Specify the temporary file path for the installer configuration"}, {OPTION_IFW_INSTALLER_FILE_PATH, "Specify the file path for the exported installer"}, + {OPTION_CHOCOLATEY_MAINTAINER, "Specify the maintainer for the exported Chocolatey package"}, + {OPTION_CHOCOLATEY_VERSION_SUFFIX, "Specify the version suffix to add for the exported Chocolatey package"}, }}; const CommandStructure COMMAND_STRUCTURE = { @@ -381,6 +386,13 @@ namespace vcpkg::Export {OPTION_IFW_CONFIG_FILE_PATH, ret.ifw_options.maybe_config_file_path}, {OPTION_IFW_INSTALLER_FILE_PATH, ret.ifw_options.maybe_installer_file_path}, }); + + options_implies(OPTION_CHOCOLATEY, + ret.chocolatey, + { + {OPTION_CHOCOLATEY_MAINTAINER, ret.chocolatey_options.maybe_maintainer}, + {OPTION_CHOCOLATEY_VERSION_SUFFIX, ret.chocolatey_options.maybe_version_suffix}, + }); return ret; } @@ -551,7 +563,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console if (opts.chocolatey) { - Chocolatey::do_export(export_plan, paths); + Chocolatey::do_export(export_plan, paths, opts.chocolatey_options); } Checks::exit_success(VCPKG_LINE_INFO); -- cgit v1.2.3 From f54151fff6ce32b24ef18be0a55113132345c859 Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Wed, 19 Jun 2019 16:25:21 -0700 Subject: make options to be experimental. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 2 ++ toolsrc/src/vcpkg/export.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index cf9db6f4c..a433cc84b 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -150,6 +150,8 @@ if (Test-Path $installedDir) const VcpkgPaths& paths, const Options& chocolatey_options) { + Checks::check_exit(VCPKG_LINE_INFO, chocolatey_options.maybe_maintainer.has_value(), "--x-maintainer option is required."); + Files::Filesystem& fs = paths.get_filesystem(); const fs::path vcpkg_root_path = paths.root; const fs::path raw_exported_dir_path = vcpkg_root_path / "chocolatey"; diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index 06f4b1868..607066164 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -283,9 +283,9 @@ namespace vcpkg::Export static constexpr StringLiteral OPTION_IFW_REPOSITORY_DIR_PATH = "--ifw-repository-directory-path"; static constexpr StringLiteral OPTION_IFW_CONFIG_FILE_PATH = "--ifw-configuration-file-path"; static constexpr StringLiteral OPTION_IFW_INSTALLER_FILE_PATH = "--ifw-installer-file-path"; - static constexpr StringLiteral OPTION_CHOCOLATEY = "--chocolatey"; - static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "--maintainer"; - static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "--version-suffix"; + static constexpr StringLiteral OPTION_CHOCOLATEY = "--x-chocolatey"; + static constexpr StringLiteral OPTION_CHOCOLATEY_MAINTAINER = "--x-maintainer"; + static constexpr StringLiteral OPTION_CHOCOLATEY_VERSION_SUFFIX = "--x-version-suffix"; static constexpr std::array EXPORT_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually export"}, @@ -294,7 +294,7 @@ namespace vcpkg::Export {OPTION_IFW, "Export to an IFW-based installer"}, {OPTION_ZIP, "Export to a zip file"}, {OPTION_SEVEN_ZIP, "Export to a 7zip (.7z) file"}, - {OPTION_CHOCOLATEY, "Export a Chocolatey package"}, + {OPTION_CHOCOLATEY, "Export a Chocolatey package (experimental feature)"}, }}; static constexpr std::array EXPORT_SETTINGS = {{ @@ -306,8 +306,8 @@ namespace vcpkg::Export {OPTION_IFW_REPOSITORY_DIR_PATH, "Specify the directory path for the exported repository"}, {OPTION_IFW_CONFIG_FILE_PATH, "Specify the temporary file path for the installer configuration"}, {OPTION_IFW_INSTALLER_FILE_PATH, "Specify the file path for the exported installer"}, - {OPTION_CHOCOLATEY_MAINTAINER, "Specify the maintainer for the exported Chocolatey package"}, - {OPTION_CHOCOLATEY_VERSION_SUFFIX, "Specify the version suffix to add for the exported Chocolatey package"}, + {OPTION_CHOCOLATEY_MAINTAINER, "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)"}, }}; const CommandStructure COMMAND_STRUCTURE = { -- cgit v1.2.3 From 62d67d3bf8eeff1afa8009041fd08b8822676b7b Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Wed, 19 Jun 2019 16:39:04 -0700 Subject: rebase and fix build breaks. --- toolsrc/src/vcpkg/export.chocolatey.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index a433cc84b..ef9952bc4 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -202,17 +202,17 @@ if (Test-Path $installedDir) const std::string nuspec_file_content = create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph, packages_version, chocolatey_options); const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); - fs.write_contents(nuspec_file_path, nuspec_file_content); + fs.write_contents(nuspec_file_path, nuspec_file_content, VCPKG_LINE_INFO); fs.create_directory(per_package_dir_path / "tools", ec); const std::string chocolatey_install_content = create_chocolatey_install_contents(); const fs::path chocolatey_install_file_path = per_package_dir_path / "tools" / "chocolateyInstall.ps1"; - fs.write_contents(chocolatey_install_file_path, chocolatey_install_content); + fs.write_contents(chocolatey_install_file_path, chocolatey_install_content, VCPKG_LINE_INFO); const std::string chocolatey_uninstall_content = create_chocolatey_uninstall_contents(binary_paragraph); const fs::path chocolatey_uninstall_file_path = per_package_dir_path / "tools" / "chocolateyUninstall.ps1"; - fs.write_contents(chocolatey_uninstall_file_path, chocolatey_uninstall_content); + fs.write_contents(chocolatey_uninstall_file_path, chocolatey_uninstall_content, VCPKG_LINE_INFO); const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", nuget_exe.u8string(), -- cgit v1.2.3 From 018c265d71a40b316f1fe6d68411bc1804fd401e Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 22 Nov 2019 10:33:45 -0800 Subject: [vcpkg] Fix build breaks and run clang-format --- toolsrc/src/vcpkg/export.chocolatey.cpp | 44 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'toolsrc/src') diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index ef9952bc4..492e5d371 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include #include namespace vcpkg::Export::Chocolatey @@ -16,11 +16,10 @@ namespace vcpkg::Export::Chocolatey static std::string create_nuspec_dependencies(const BinaryParagraph& binary_paragraph, const std::map& packages_version) { - static constexpr auto CONTENT_TEMPLATE = - R"()"; - + static constexpr auto CONTENT_TEMPLATE = R"()"; + std::string nuspec_dependencies; - for (const std::string& depend: binary_paragraph.depends) + for (const std::string& depend : binary_paragraph.depends) { auto found = packages_version.find(depend); if (found == packages_version.end()) @@ -63,17 +62,19 @@ namespace vcpkg::Export::Chocolatey { Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot find desired package version."); } - std::string nuspec_file_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", binary_paragraph.spec.name()); + std::string nuspec_file_content = + Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_ID@", binary_paragraph.spec.name()); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_VERSION@", package_version->second); - nuspec_file_content = - Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_MAINTAINER@", chocolatey_options.maybe_maintainer.value_or("")); + nuspec_file_content = Strings::replace_all( + std::move(nuspec_file_content), "@PACKAGE_MAINTAINER@", chocolatey_options.maybe_maintainer.value_or("")); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DESCRIPTION@", binary_paragraph.description); nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), "@EXPORTED_ROOT_DIR@", exported_root_dir); - nuspec_file_content = - Strings::replace_all(std::move(nuspec_file_content), "@PACKAGE_DEPENDENCIES@", create_nuspec_dependencies(binary_paragraph, packages_version)); + nuspec_file_content = Strings::replace_all(std::move(nuspec_file_content), + "@PACKAGE_DEPENDENCIES@", + create_nuspec_dependencies(binary_paragraph, packages_version)); return nuspec_file_content; } @@ -142,7 +143,8 @@ if (Test-Path $installedDir) ) { $empties | Remove-Item } } )###"; - std::string chocolatey_uninstall_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_FULLSTEM@", binary_paragraph.fullstem()); + std::string chocolatey_uninstall_content = + Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_FULLSTEM@", binary_paragraph.fullstem()); return chocolatey_uninstall_content; } @@ -150,7 +152,8 @@ if (Test-Path $installedDir) const VcpkgPaths& paths, const Options& chocolatey_options) { - Checks::check_exit(VCPKG_LINE_INFO, chocolatey_options.maybe_maintainer.has_value(), "--x-maintainer option is required."); + Checks::check_exit( + VCPKG_LINE_INFO, chocolatey_options.maybe_maintainer.has_value(), "--x-maintainer option is required."); Files::Filesystem& fs = paths.get_filesystem(); const fs::path vcpkg_root_path = paths.root; @@ -159,9 +162,9 @@ if (Test-Path $installedDir) const fs::path& nuget_exe = paths.get_tool_exe(Tools::NUGET); std::error_code ec; - fs.remove_all(raw_exported_dir_path, ec); + fs.remove_all(raw_exported_dir_path, VCPKG_LINE_INFO); fs.create_directory(raw_exported_dir_path, ec); - fs.remove_all(exported_dir_path, ec); + fs.remove_all(exported_dir_path, VCPKG_LINE_INFO); fs.create_directory(exported_dir_path, ec); // execute the plan @@ -199,9 +202,10 @@ if (Test-Path $installedDir) Install::install_files_and_write_listfile(paths.get_filesystem(), paths.package_dir(action.spec), dirs); - const std::string nuspec_file_content = - create_nuspec_file_contents(per_package_dir_path.string(), binary_paragraph, packages_version, chocolatey_options); - const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); + const std::string nuspec_file_content = create_nuspec_file_contents( + per_package_dir_path.string(), binary_paragraph, packages_version, chocolatey_options); + const fs::path nuspec_file_path = + per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec"); fs.write_contents(nuspec_file_path, nuspec_file_content, VCPKG_LINE_INFO); fs.create_directory(per_package_dir_path / "tools", ec); @@ -215,9 +219,9 @@ if (Test-Path $installedDir) fs.write_contents(chocolatey_uninstall_file_path, chocolatey_uninstall_content, VCPKG_LINE_INFO); const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", - nuget_exe.u8string(), - exported_dir_path.u8string(), - nuspec_file_path.u8string()); + nuget_exe.u8string(), + exported_dir_path.u8string(), + nuspec_file_path.u8string()); const int exit_code = System::cmd_execute_clean(cmd_line); Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Error: NuGet package creation failed"); -- cgit v1.2.3