[Export Command] Enabling Manifest Mode (#1136)

* initial implementation

* avoid value or exit and reuse MissinOption message

* improve messaging

* reduce redundancy

* add end2end test file

* add test cases for raw based exports in manifest mode
This commit is contained in:
Javier Matos Denizac 2023-08-10 13:06:37 -07:00 коммит произвёл GitHub
Родитель b03c2b2203
Коммит c94e4034e9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 116 добавлений и 8 удалений

Просмотреть файл

@ -0,0 +1,12 @@
{
"name": "my-project",
"version-string": "0.1.0",
"dependencies": [
{
"name": "zlib"
},
{
"name": "fmt"
}
]
}

Просмотреть файл

@ -0,0 +1,67 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1
$manifestPath = "$PSScriptRoot/../e2e-projects/export-project"
$outputDir = "$manifestPath/output"
Run-Vcpkg install --x-manifest-root=$manifestPath
Throw-IfFailed
Run-Vcpkg export --zip --x-manifest-root=$manifestPath --output-dir=$outputDir
Throw-IfFailed
Run-Vcpkg export --nuget --x-manifest-root=$manifestPath --output-dir=$outputDir
Throw-IfFailed
Run-Vcpkg export --7zip --x-manifest-root=$manifestPath --output-dir=$outputDir
Throw-IfFailed
# Check existence of zip file(s)
$zipFilesExist = Test-Path "$outputDir/*.zip"
if (-Not $zipFilesExist)
{
throw "No zip files found in $outputDir"
}
# Check existence of nuget file(s)
$nugetFilesExist = Test-Path "$outputDir/*.nupkg"
if (-Not $nugetFilesExist)
{
throw "No nuget files found in $outputDir"
}
# Check existence of 7zip file(s)
$sevenZipFilesExist = Test-Path "$outputDir/*.7z"
if (-Not $sevenZipFilesExist)
{
throw "No 7zip files found in $outputDir"
}
# Cleanup exported packages
Get-ChildItem -Path $manifestPath | Where-Object { $_.Name -ne "vcpkg.json" -and $_.Name -ne "vcpkg_installed" } | Remove-Item -Recurse -Force
# Test export with invalid <port:triplet> argument
$out = Run-VcpkgAndCaptureOutput export zlib:x64-windows --zip --x-manifest-root=$manifestPath --output-dir=$manifestPath
Throw-IfNotFailed
if ($out -notmatch "unexpected argument: zlib:x64-windows")
{
throw "Expected to fail and print warning about unexpected argument"
}
# Test export with missing --output-dir argument
$out = Run-VcpkgAndCaptureOutput export --zip --x-manifest-root=$manifestPath
Throw-IfNotFailed
if ($out -notmatch "This command requires --output-dir")
{
throw "Expected to fail and print warning about missing argument"
}
# Test export with empty export plan
Remove-Item -Path "$manifestPath/vcpkg_installed" -Recurse -Force
$out = Run-VcpkgAndCaptureOutput export --zip --x-manifest-root=$manifestPath --output-dir=$manifestPath
Throw-IfNotFailed
if ($out -notmatch "Refusing to create an export of zero packages. Install packages before exporting.")
{
throw "Expected to fail and print warning about empty export plan."
}

Просмотреть файл

@ -496,6 +496,10 @@ DECLARE_MESSAGE(CmdDependInfoOptSort,
DECLARE_MESSAGE(CmdEditOptAll, (), "", "Open editor into the port as well as the port-specific buildtree subfolder")
DECLARE_MESSAGE(CmdEditOptBuildTrees, (), "", "Open editor into the port-specific buildtree subfolder")
DECLARE_MESSAGE(CmdEnvOptions, (msg::path, msg::env_var), "", "Add installed {path} to {env_var}")
DECLARE_MESSAGE(CmdExportEmptyPlan,
(),
"",
"Refusing to create an export of zero packages. Install packages before exporting.")
DECLARE_MESSAGE(CmdExportOpt7Zip, (), "", "Export to a 7zip (.7z) file")
DECLARE_MESSAGE(CmdExportOptChocolatey, (), "", "Export a Chocolatey package (experimental feature)")
DECLARE_MESSAGE(CmdExportOptDebug, (), "", "Enable prefab debug")

Просмотреть файл

@ -289,6 +289,7 @@
"CmdEditOptBuildTrees": "Open editor into the port-specific buildtree subfolder",
"CmdEnvOptions": "Add installed {path} to {env_var}",
"_CmdEnvOptions.comment": "An example of {path} is /foo/bar. An example of {env_var} is VCPKG_DEFAULT_TRIPLET.",
"CmdExportEmptyPlan": "Refusing to create an export of zero packages. Install packages before exporting.",
"CmdExportOpt7Zip": "Export to a 7zip (.7z) file",
"CmdExportOptChocolatey": "Export a Chocolatey package (experimental feature)",
"CmdExportOptDebug": "Enable prefab debug",

Просмотреть файл

@ -389,11 +389,39 @@ namespace vcpkg::Export
ret.prefab_options.enable_maven = Util::Sets::contains(options.switches, OPTION_PREFAB_ENABLE_MAVEN);
ret.prefab_options.enable_debug = Util::Sets::contains(options.switches, OPTION_PREFAB_ENABLE_DEBUG);
ret.maybe_output = Util::lookup_value_copy(options.settings, OPTION_OUTPUT);
ret.output_dir = Util::lookup_value(options.settings, OPTION_OUTPUT_DIR)
.map([&](const Path& p) { return paths.original_cwd / p; })
.value_or(paths.root);
ret.all_installed = Util::Sets::contains(options.switches, OPTION_ALL_INSTALLED);
if (paths.manifest_mode_enabled())
{
auto output_dir_opt = Util::lookup_value(options.settings, OPTION_OUTPUT_DIR);
// --output-dir is required in manifest mode
if (auto d = output_dir_opt.get())
{
ret.output_dir = paths.original_cwd / *d;
}
else
{
msg::println_error(msgMissingOption, msg::option = "output-dir");
Checks::exit_fail(VCPKG_LINE_INFO);
}
// Force enable --all-installed in manifest mode
ret.all_installed = true;
// In manifest mode the entire installed directory is exported
if (!options.command_arguments.empty())
{
msg::println_error(msgUnexpectedArgument, msg::option = options.command_arguments[0]);
Checks::exit_fail(VCPKG_LINE_INFO);
}
}
ret.output_dir = ret.output_dir.empty() ? Util::lookup_value(options.settings, OPTION_OUTPUT_DIR)
.map([&](const Path& p) { return paths.original_cwd / p; })
.value_or(paths.root)
: ret.output_dir;
if (ret.all_installed)
{
auto installed_ipv = get_installed_ports(status_db);
@ -593,10 +621,6 @@ namespace vcpkg::Export
Triplet host_triplet)
{
(void)host_triplet;
if (paths.manifest_mode_enabled())
{
Checks::msg_exit_maybe_upgrade(VCPKG_LINE_INFO, msgExportUnsupportedInManifest);
}
const StatusParagraphs status_db = database_load_check(paths.get_filesystem(), paths.installed());
const auto opts = handle_export_command_arguments(paths, args, default_triplet, status_db);
@ -610,7 +634,7 @@ namespace vcpkg::Export
std::vector<ExportPlanAction> export_plan = create_export_plan(opts.specs, status_db);
if (export_plan.empty())
{
Debug::print("Export plan cannot be empty.");
msg::println_error(msgCmdExportEmptyPlan);
Checks::exit_fail(VCPKG_LINE_INFO);
}