diff options
| author | seanyen <seanyen@microsoft.com> | 2019-06-11 18:09:55 -0700 |
|---|---|---|
| committer | Sean Yen <seanyen@corp.microsoft.com> | 2019-06-19 16:36:47 -0700 |
| commit | e5a6c7a7a61a14e546c7c2f51bbe8595d6624ff0 (patch) | |
| tree | f5c9b0eeb2f1a9a70830c90a81a75946cf2655eb /toolsrc/src | |
| parent | d3498a8943b8af2fd37b287c766acff8d6623463 (diff) | |
| download | vcpkg-e5a6c7a7a61a14e546c7c2f51bbe8595d6624ff0.tar.gz vcpkg-e5a6c7a7a61a14e546c7c2f51bbe8595d6624ff0.zip | |
first check-in.
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/export.chocolatey.cpp | 82 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/export.cpp | 16 |
2 files changed, 95 insertions, 3 deletions
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 <vcpkg/base/system.print.h>
+#include <vcpkg/base/system.process.h>
+#include <vcpkg/commands.h>
+#include <vcpkg/export.h>
+#include <vcpkg/export.chocolatey.h>
+#include <vcpkg/install.h>
+
+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>
+ <metadata>
+ <id>@PACKAGE_ID@</id>
+ <version>@PACKAGE_VERSION@</version>
+ <description><![CDATA[
+ @PACKAGE_DESCRIPTION@
+ ]]></description>
+ </metadata>
+ <files>
+ <file src="@EXPORTED_ROOT_DIR@\installed\**" target="installed" />
+ </files>
+</package>
+)";
+
+ 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<ExportPlanAction>& 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 <vcpkg/dependencies.h> #include <vcpkg/export.h> #include <vcpkg/export.ifw.h> +#include <vcpkg/export.chocolatey.h> #include <vcpkg/help.h> #include <vcpkg/input.h> #include <vcpkg/install.h> @@ -256,6 +257,7 @@ namespace vcpkg::Export bool ifw = false; bool zip = false; bool seven_zip = false; + bool chocolatey = false; Optional<std::string> 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<CommandSwitch, 6> EXPORT_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 7> 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<CommandSetting, 8> 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); } } |
