diff --git a/azure-pipelines/e2e-projects/export-project/vcpkg.json b/azure-pipelines/e2e-projects/export-project/vcpkg.json new file mode 100644 index 000000000..c51d51076 --- /dev/null +++ b/azure-pipelines/e2e-projects/export-project/vcpkg.json @@ -0,0 +1,12 @@ +{ + "name": "my-project", + "version-string": "0.1.0", + "dependencies": [ + { + "name": "zlib" + }, + { + "name": "fmt" + } + ] +} diff --git a/azure-pipelines/end-to-end-tests-dir/commands.export.ps1 b/azure-pipelines/end-to-end-tests-dir/commands.export.ps1 new file mode 100644 index 000000000..e5c8c0d26 --- /dev/null +++ b/azure-pipelines/end-to-end-tests-dir/commands.export.ps1 @@ -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 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." +} + + diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index d7a137b1b..098c749a6 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -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") diff --git a/locales/messages.json b/locales/messages.json index 26cc220c0..99952bc76 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -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", diff --git a/src/vcpkg/commands.export.cpp b/src/vcpkg/commands.export.cpp index d98335590..cda604eba 100644 --- a/src/vcpkg/commands.export.cpp +++ b/src/vcpkg/commands.export.cpp @@ -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 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); }