mirror of https://github.com/microsoft/vcpkg.git
first check-in.
This commit is contained in:
parent
d3498a8943
commit
e5a6c7a7a6
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <vcpkg/dependencies.h>
|
||||
#include <vcpkg/vcpkgpaths.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace vcpkg::Export::Chocolatey
|
||||
{
|
||||
void do_export(const std::vector<Dependencies::ExportPlanAction>& export_plan,
|
||||
const VcpkgPaths& paths);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -239,6 +239,7 @@
|
|||
<ClCompile Include="..\src\vcpkg\commands.xvsinstances.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\dependencies.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\export.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\export.chocolatey.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\globalstate.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\help.cpp" />
|
||||
<ClCompile Include="..\src\vcpkg\input.cpp" />
|
||||
|
|
|
|||
|
|
@ -96,6 +96,9 @@
|
|||
<ClCompile Include="..\src\vcpkg\export.cpp">
|
||||
<Filter>Source Files\vcpkg</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\vcpkg\export.chocolatey.cpp">
|
||||
<Filter>Source Files\vcpkg</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\vcpkg\globalstate.cpp">
|
||||
<Filter>Source Files\vcpkg</Filter>
|
||||
</ClCompile>
|
||||
|
|
|
|||
Loading…
Reference in New Issue