Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Export Command] Enabling Manifest Mode #1136

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions azure-pipelines/e2e-projects/export-project/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "my-project",
"version-string": "0.1.0",
"dependencies": [
{
"name": "zlib"
},
{
"name": "fmt"
}
]
}
67 changes: 67 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/commands.export.ps1
Original file line number Diff line number Diff line change
@@ -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."
}


4 changes: 4 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,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")
Expand Down
1 change: 1 addition & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,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",
Expand Down
40 changes: 32 additions & 8 deletions src/vcpkg/commands.export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; })
Comment on lines +394 to +421
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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; })
auto output_dir_arg = Util::lookup_value(options.settings, OPTION_OUTPUT_DIR);
if (paths.manifest_mode_enabled())
{
if (!output_dir_arg)
{
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 = output_dir_arg.map([&](const Path& p) { return paths.original_cwd / p; }).value_or(paths.root);

.value_or(paths.root)
: ret.output_dir;

if (ret.all_installed)
{
auto installed_ipv = get_installed_ports(status_db);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down