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

Add license reporting and "vcpkg license-report" command. #1514

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
d9215bf
Overhaul StatusParagraph parsing to make status parsing testable.
BillyONeal Sep 6, 2024
21f1d2e
Use PackageSpec's to_string in formatting.
BillyONeal Sep 28, 2024
0da1366
Avoid potential null derefs in create_dependency_graph_snapshot.
BillyONeal Sep 28, 2024
ee6dc8e
Fix read operations like list on readonly filesystems.
BillyONeal Sep 6, 2024
a48c10d
Extract some more contractual-constants file names.
BillyONeal Oct 1, 2024
ddfcadd
Add "maybe_" operations to JSON to avoid assert anti-patterns.
BillyONeal Oct 1, 2024
12371d9
Use Json::Value::maybe_* and fix some string/stringview ping pong in …
BillyONeal Oct 1, 2024
721175c
Consistently use {}s in statusparagraphs.cpp
BillyONeal Oct 7, 2024
db320df
Implement re-parsing the license out of the installed SBOM.
BillyONeal Oct 7, 2024
e3bd557
Remove formatting concern PrintUsage from BuildPackageOptions because…
BillyONeal Oct 7, 2024
0875ad6
Improve console output when installing packages by deduplicating 'alr…
BillyONeal Oct 11, 2024
4d15956
Add a message to `vcpkg install` where the licenses of the packages i…
BillyONeal Oct 11, 2024
a0ac8fe
Fix linux and macos build.
BillyONeal Oct 18, 2024
ca8a4e2
Merge remote-tracking branch 'origin/main' into license-printing
BillyONeal Oct 23, 2024
c20ed47
Merge remote-tracking branch 'origin/main' into license-printing
BillyONeal Oct 24, 2024
43bf3d1
Fix issues found in extractions.
BillyONeal Oct 24, 2024
755eb2e
Merge remote-tracking branch 'origin/main' into license-printing
BillyONeal Nov 8, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
8 changes: 8 additions & 0 deletions azure-pipelines/e2e-ports/vcpkg-license-bsd-on-mit/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "vcpkg-license-bsd-on-mit",
"version": "0",
"license": "BSD-3-Clause",
"dependencies": [
"vcpkg-license-mit"
]
}
1 change: 1 addition & 0 deletions azure-pipelines/e2e-ports/vcpkg-license-bsd/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
5 changes: 5 additions & 0 deletions azure-pipelines/e2e-ports/vcpkg-license-bsd/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "vcpkg-license-bsd",
"version": "0",
"license": "BSD-3-Clause"
}
1 change: 1 addition & 0 deletions azure-pipelines/e2e-ports/vcpkg-license-mit/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
5 changes: 5 additions & 0 deletions azure-pipelines/e2e-ports/vcpkg-license-mit/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "vcpkg-license-mit",
"version": "0",
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
5 changes: 5 additions & 0 deletions azure-pipelines/e2e-ports/vcpkg-license-null/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "vcpkg-license-null",
"version": "0",
"license": null
}
7 changes: 4 additions & 3 deletions azure-pipelines/end-to-end-tests-dir/build-test-ports.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ The following packages are already installed:

$output = Run-VcpkgAndCaptureOutput @commonArgs --overlay-ports="$PSScriptRoot/../e2e-ports" install vcpkg-internal-e2e-test-port3 --head
Throw-IfFailed
if ($output -notmatch 'vcpkg-internal-e2e-test-port3:[^ ]+ is already installed -- not building from HEAD') {
throw 'Wrong already installed message for --head'
}
Throw-IfNonContains -Actual $output -Expected @"
The following packages are already installed, but were requested at --head version. Their installed contents will not be changed. To get updated versions, remove these packages first:
vcpkg-internal-e2e-test-port3:
"@

Refresh-TestRoot
$output = Run-VcpkgAndCaptureOutput @commonArgs --x-builtin-ports-root="$PSScriptRoot/../e2e-ports" install vcpkg-bad-spdx-license
Expand Down
90 changes: 90 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/license-report.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

[string]$output = Run-VcpkgAndCaptureOutput @commonArgs license-report "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports"
Throw-IfFailed
Throw-IfNonEqual -Actual $output -Expected @"
There are no installed packages, and thus no licenses of installed packages. Did you mean to install something first?

"@

$output = Run-VcpkgAndCaptureOutput @commonArgs install "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports" vcpkg-license-bsd vcpkg-license-mit
Throw-IfFailed
Throw-IfNonContains -Actual $output -Expected @"
Packages installed in this vcpkg installation declare the following licenses:
BSD-3-Clause
MIT
"@

$output = Run-VcpkgAndCaptureOutput @commonArgs license-report "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports"
Throw-IfFailed
Throw-IfNonEqual -Actual $output -Expected @"
Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Installed packages declare the following licenses:
BSD-3-Clause
MIT

"@

# Note that the MIT license already is not displayed
$output = Run-VcpkgAndCaptureOutput @commonArgs install "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports" vcpkg-license-bsd-on-mit
Throw-IfFailed
Throw-IfNonContains -Actual $output -Expected @"
Packages installed in this vcpkg installation declare the following licenses:
BSD-3-Clause
"@

$output = Run-VcpkgAndCaptureOutput @commonArgs license-report "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports"
Throw-IfFailed
Throw-IfNonEqual -Actual $output -Expected @"
Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Installed packages declare the following licenses:
BSD-3-Clause
MIT

"@

# Empty port == no license field set at all
$output = Run-VcpkgAndCaptureOutput @commonArgs install "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports" vcpkg-empty-port
Throw-IfFailed
Throw-IfNonContains -Actual $output -Expected @"
Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Some packages did not declare an SPDX license. Check the ``copyright`` file for each package for more information about their licensing.
"@

$output = Run-VcpkgAndCaptureOutput @commonArgs license-report "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports"
Throw-IfFailed
Throw-IfNonEqual -Actual $output -Expected @"
Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Some packages did not declare an SPDX license. Check the ``copyright`` file for each package for more information about their licensing.
Installed packages declare the following licenses:
BSD-3-Clause
MIT

"@

Run-Vcpkg @commonArgs remove "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports" vcpkg-license-bsd
Throw-IfFailed

# bsd-on-mit is still here so no change
$output = Run-VcpkgAndCaptureOutput @commonArgs license-report "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports"
Throw-IfFailed
Throw-IfNonEqual -Actual $output -Expected @"
Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Some packages did not declare an SPDX license. Check the ``copyright`` file for each package for more information about their licensing.
Installed packages declare the following licenses:
BSD-3-Clause
MIT

"@

Run-Vcpkg @commonArgs remove "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports" vcpkg-license-bsd-on-mit vcpkg-license-mit
Throw-IfFailed

# Only unknown left
$output = Run-VcpkgAndCaptureOutput @commonArgs license-report "--x-builtin-ports-root=$PSScriptRoot/../e2e-ports"
Throw-IfFailed
Throw-IfNonEqual -Actual $output -Expected @"
Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Some packages did not declare an SPDX license. Check the ``copyright`` file for each package for more information about their licensing.

"@
6 changes: 3 additions & 3 deletions azure-pipelines/end-to-end-tests-dir/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Throw-IfNotFailed
if ($output -notmatch @"
warning: In octopus, 1.0 is completely new version, so the "port-version" field should be removed. Remove "port-version", commit that change, and try again. To skip this check, rerun with --skip-version-format-check .
"@) {
throw "Expected detecting present port-version when a new version is added as bad"
throw "Expected detecting present port-version when a new version is added as bad"
}

Run-Vcpkg @portsRedirectArgsOK x-add-version octopus --skip-version-format-check
Expand All @@ -105,7 +105,7 @@ Throw-IfNotFailed
if ($output -notmatch @"
warning: In octopus, 2.0 is completely new version, so the "port-version" field should be removed. Remove "port-version", commit that change, and try again. To skip this check, rerun with --skip-version-format-check .
"@) {
throw "Expected detecting present port-version when a new version is added as bad"
throw "Expected detecting present port-version when a new version is added as bad"
}

Run-Vcpkg @portsRedirectArgsOK x-add-version octopus --skip-version-format-check
Expand All @@ -121,7 +121,7 @@ Throw-IfNotFailed
if ($output -notmatch @"
warning: In octopus, the current "port-version" for 2.0 is 1, so the next added "port-version" should be 2, but the port declares "port-version" 3. Change "port-version" to 2, commit that change, and try again. To skip this check, rerun with --skip-version-format-check .
"@) {
throw "Expected detecting present port-version when a new version is added as bad"
throw "Expected detecting present port-version when a new version is added as bad"
}

Run-Vcpkg @portsRedirectArgsOK x-add-version octopus --skip-version-format-check
Expand Down
2 changes: 2 additions & 0 deletions include/vcpkg/base/contractual-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ namespace vcpkg
inline constexpr StringLiteral FilePortfileDotCMake = "portfile.cmake";
inline constexpr StringLiteral FileShare = "share";
inline constexpr StringLiteral FileStatus = "status";
inline constexpr StringLiteral FileStatusNew = "status-new";
inline constexpr StringLiteral FileStatusOld = "status-old";
inline constexpr StringLiteral FileTools = "tools";
inline constexpr StringLiteral FileUpdates = "updates";
inline constexpr StringLiteral FileUsage = "usage";
Expand Down
39 changes: 32 additions & 7 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,7 @@ DECLARE_MESSAGE(AllFormatArgsUnbalancedBraces,
(msg::value),
"example of {value} is 'foo bar {'",
"unbalanced brace in format string \"{value}\"")
DECLARE_MESSAGE(AllPackagesAreUpdated, (), "", "All installed packages are up-to-date.")
DECLARE_MESSAGE(AlreadyInstalled, (msg::spec), "", "{spec} is already installed")
DECLARE_MESSAGE(AlreadyInstalledNotHead,
(msg::spec),
"'HEAD' means the most recent version of source code",
"{spec} is already installed -- not building from HEAD")
DECLARE_MESSAGE(AllPackagesAreUpdated, (), "", "No action taken because all installed packages are up-to-date.")
DECLARE_MESSAGE(AManifest, (), "", "a manifest")
DECLARE_MESSAGE(AMaximumOfOneAssetReadUrlCanBeSpecified, (), "", "a maximum of one asset read url can be specified.")
DECLARE_MESSAGE(AMaximumOfOneAssetWriteUrlCanBeSpecified, (), "", "a maximum of one asset write url can be specified.")
Expand Down Expand Up @@ -735,6 +730,7 @@ DECLARE_MESSAGE(CmdInstallExample1,
"This is a command line, only the <> parts should be localized",
"vcpkg install <port name> <port name>...")
DECLARE_MESSAGE(CmdIntegrateSynopsis, (), "", "Integrates vcpkg with machines, projects, or shells")
DECLARE_MESSAGE(CmdLicenseReportSynopsis, (), "", "Displays the declared licenses of all ports in the installed tree")
DECLARE_MESSAGE(CmdListExample2,
(),
"This is a command line, only the <filter> part should be localized",
Expand Down Expand Up @@ -1168,10 +1164,10 @@ DECLARE_MESSAGE(ExpectedCharacterHere,
DECLARE_MESSAGE(ExpectedDefaultFeaturesList, (), "", "expected ',' or end of text in default features list")
DECLARE_MESSAGE(ExpectedDependenciesList, (), "", "expected ',' or end of text in dependencies list")
DECLARE_MESSAGE(ExpectedDigitsAfterDecimal, (), "", "Expected digits after the decimal point")
DECLARE_MESSAGE(ExpectedExplicitTriplet, (), "", "expected an explicit triplet")
DECLARE_MESSAGE(ExpectedFailOrSkip, (), "", "expected 'fail', 'skip', or 'pass' here")
DECLARE_MESSAGE(ExpectedFeatureListTerminal, (), "", "expected ',' or ']' in feature list")
DECLARE_MESSAGE(ExpectedFeatureName, (), "", "expected feature name (must be lowercase, digits, '-')")
DECLARE_MESSAGE(ExpectedExplicitTriplet, (), "", "expected an explicit triplet")
DECLARE_MESSAGE(ExpectedInstallStateField,
(),
"The values in ''s are locale-invariant",
Expand Down Expand Up @@ -1734,6 +1730,11 @@ DECLARE_MESSAGE(InstallCopiedFile,
"{path_source} -> {path_destination} done")
DECLARE_MESSAGE(InstalledBy, (msg::path), "", "Installed by {path}")
DECLARE_MESSAGE(InstalledPackages, (), "", "The following packages are already installed:")
DECLARE_MESSAGE(InstalledPackagesHead,
(),
"",
"The following packages are already installed, but were requested at --head version. Their installed "
"contents will not be changed. To get updated versions, remove these packages first:")
DECLARE_MESSAGE(InstalledRequestedPackages, (), "", "All requested packages are currently installed.")
DECLARE_MESSAGE(InstallFailed, (msg::path, msg::error_msg), "", "failed: {path}: {error_msg}")
DECLARE_MESSAGE(InstallingMavenFileFailure,
Expand Down Expand Up @@ -2147,6 +2148,11 @@ DECLARE_MESSAGE(NoInstalledPackages,
(),
"The name 'search' is the name of a command that is not localized.",
"No packages are installed. Did you mean `search`?")
DECLARE_MESSAGE(NoInstalledPackagesLicenseReport,
(),
"",
"There are no installed packages, and thus no licenses of installed packages. Did you mean to install "
"something first?")
DECLARE_MESSAGE(NonExactlyArgs,
(msg::command_name, msg::expected, msg::actual),
"{expected} and {actual} are integers",
Expand Down Expand Up @@ -2214,6 +2220,21 @@ DECLARE_MESSAGE(OverwritingFile, (msg::path), "", "File {path} was already prese
DECLARE_MESSAGE(PackageAbi, (msg::spec, msg::package_abi), "", "{spec} package ABI: {package_abi}")
DECLARE_MESSAGE(PackageAlreadyRemoved, (msg::spec), "", "unable to remove {spec}: already removed")
DECLARE_MESSAGE(PackageDiscoveryHeader, (), "", "Package Discovery")
DECLARE_MESSAGE(PackageLicenseSpdx, (), "", "Installed packages declare the following licenses:")
DECLARE_MESSAGE(PackageLicenseSpdxThisInstall,
(),
"",
"Packages installed in this vcpkg installation declare the following licenses:")
DECLARE_MESSAGE(PackageLicenseUnknown,
(),
"",
"Some packages did not declare an SPDX license. Check the `copyright` file for each package for more "
"information about their licensing.")
DECLARE_MESSAGE(PackageLicenseWarning,
(),
"",
"Installed contents are licensed to you by owners. Microsoft is not responsible for, nor does it grant "
"any licenses to, third-party packages.")
DECLARE_MESSAGE(PackageManipulationHeader, (), "", "Package Manipulation")
DECLARE_MESSAGE(PackageInfoHelp, (), "", "Display detailed information on packages")
DECLARE_MESSAGE(PackageFailedtWhileExtracting,
Expand Down Expand Up @@ -2719,6 +2740,10 @@ DECLARE_MESSAGE(ToRemovePackages,
"",
"To only remove outdated packages, run\n{command_name} remove --outdated")
DECLARE_MESSAGE(TotalInstallTime, (msg::elapsed), "", "Total install time: {elapsed}")
DECLARE_MESSAGE(TotalInstallTimeSuccess,
(msg::elapsed),
"",
"All requested installations completed successfully in: {elapsed}")
DECLARE_MESSAGE(ToUpdatePackages,
(msg::command_name),
"",
Expand Down
15 changes: 12 additions & 3 deletions include/vcpkg/commands.install.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ namespace vcpkg
PackageSpec m_spec;
};

struct LicenseReport
{
bool any_unknown_licenses = false;
std::set<std::string> named_licenses;
void print_license_report(const msg::MessageT<>& named_license_heading) const;
};

struct InstallSummary
{
std::vector<SpecSummary> results;
ElapsedTime timing;
LicenseReport license_report;
bool failed = false;

LocalizedString format() const;
LocalizedString format_results() const;
void print_failed() const;
std::string xunit_results() const;
bool failed() const;
void print_complete_message() const;
};

struct InstallDir
Expand Down
10 changes: 10 additions & 0 deletions include/vcpkg/commands.license-report.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <vcpkg/fwd/vcpkgcmdarguments.h>
#include <vcpkg/fwd/vcpkgpaths.h>

namespace vcpkg
{
extern const CommandMetadata CommandLicenseReportMetadata;
void command_license_report_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
}
5 changes: 4 additions & 1 deletion include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ namespace vcpkg
struct FormattedPlan
{
bool has_removals = false;
LocalizedString text;
LocalizedString warning_text;
LocalizedString normal_text;

LocalizedString all_text() const;
};

FormattedPlan format_plan(const ActionPlan& action_plan, const Path& builtin_ports_dir);
Expand Down
3 changes: 3 additions & 0 deletions include/vcpkg/spdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <vcpkg/fwd/dependencies.h>

#include <vcpkg/base/optional.h>
#include <vcpkg/base/span.h>

#include <string>
Expand All @@ -29,5 +30,7 @@ namespace vcpkg
std::string document_namespace,
std::vector<Json::Object>&& resource_docs);

Optional<std::string> read_spdx_license(StringView text, StringView origin);

Json::Object run_resource_heuristics(StringView contents, StringView portRawVersion);
}
8 changes: 6 additions & 2 deletions include/vcpkg/vcpkglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

namespace vcpkg
{
StatusParagraphs database_load_check(const Filesystem& fs, const InstalledPaths& installed);
StatusParagraphs database_load(const ReadOnlyFilesystem& fs, const InstalledPaths& installed);
StatusParagraphs database_load_collapse(const Filesystem& fs, const InstalledPaths& installed);

void write_update(const Filesystem& fs, const InstalledPaths& installed, const StatusParagraph& p);

Expand All @@ -24,9 +25,12 @@ namespace vcpkg
};

std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db);
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const Filesystem& fs,
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files(const ReadOnlyFilesystem& fs,
const InstalledPaths& installed,
const StatusParagraphs& status_db);
std::vector<StatusParagraphAndAssociatedFiles> get_installed_files_and_upgrade(const Filesystem& fs,
const InstalledPaths& installed,
const StatusParagraphs& status_db);

std::string shorten_text(StringView desc, const size_t length);
} // namespace vcpkg
Loading
Loading