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 command lint-port #720

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9d0b2dd
Add command `lint-port`
autoantwort Sep 28, 2022
c5d5557
CR
autoantwort Sep 29, 2022
32ef8e0
fix bug
autoantwort Sep 30, 2022
689e47d
Adopt tests
autoantwort Sep 30, 2022
7a5a5bd
Merge branch 'main' into feature/lint-port
autoantwort Oct 25, 2022
4cae60d
Merge branch 'main' into feature/lint-port
autoantwort Nov 2, 2022
bfe12fe
Fix warning
autoantwort Nov 2, 2022
1bad290
Fix test
autoantwort Nov 2, 2022
d3668f3
Fix e2e tests
autoantwort Nov 2, 2022
c48fb10
Fix windows
autoantwort Nov 2, 2022
23a7459
Ignore more wrong ports
autoantwort Nov 5, 2022
6795b99
Merge branch 'main' into feature/lint-port
autoantwort Nov 10, 2022
a890651
Merge branch 'main' into feature/lint-port
autoantwort Nov 12, 2022
b0b4495
Apply format diff
autoantwort Nov 13, 2022
38b2a69
Merge branch 'main' into feature/lint-port
autoantwort Nov 25, 2022
686a36f
Make code more unit testable
autoantwort Nov 25, 2022
04ba447
Add helpers to MessageSink
autoantwort Nov 26, 2022
ea500f5
Apply code review and add tests
autoantwort Nov 26, 2022
8f56f8e
Replace usages of vcpkg_extract_source_archive_ex
autoantwort Nov 27, 2022
9e85bdd
format diff
autoantwort Nov 27, 2022
a8b28ea
Also replace REF with SOURCE_BASE in vcpkg_extract_source_archive
autoantwort Nov 29, 2022
7f2c55a
Fix Bug
autoantwort Nov 29, 2022
4e17669
Merge branch 'main' into feature/lint-port
autoantwort Dec 9, 2022
d967f73
Apply diff
autoantwort Dec 12, 2022
054858c
PACKAGE_NAME must also be used if the package name casing is different
autoantwort Dec 17, 2022
2b95b50
Format
autoantwort Dec 19, 2022
c320e6c
Revert "PACKAGE_NAME must also be used if the package name casing is …
autoantwort Dec 20, 2022
ed44a8d
Use functions to simplify code
autoantwort Dec 21, 2022
9eaf07d
Also check for vcpkg_check_features without FEATURES keyword
autoantwort Dec 21, 2022
d2d792d
Merge branch 'main' into feature/lint-port
autoantwort Jan 11, 2023
dbfd782
Add message file changes
autoantwort Jan 11, 2023
2ab739f
Merge branch 'main' into feature/lint-port
autoantwort Jan 13, 2023
68e6756
Fix command name
autoantwort Jan 29, 2023
a6f2608
Merge branch 'main' into feature/lint-port
autoantwort Feb 9, 2023
53df38b
Merge branch 'main' into feature/lint-port
autoantwort Feb 28, 2023
ee0fda1
Merge branch 'main' into feature/lint-port
autoantwort Mar 14, 2023
83b13a9
Improve performance
autoantwort Mar 14, 2023
89208e9
Merge branch 'main' into feature/lint-port
autoantwort Mar 19, 2023
0c5c4f1
Merge branch 'main' into feature/lint-port
autoantwort Apr 6, 2023
4cdcb30
Add missing include
autoantwort Apr 6, 2023
14f1b1f
Use right command arguments
autoantwort Apr 12, 2023
f596c5a
Merge branch 'main' into feature/lint-port
autoantwort Apr 26, 2023
53e95f4
Merge branch 'main' into feature/lint-port
autoantwort May 2, 2023
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
6 changes: 4 additions & 2 deletions azure-pipelines/end-to-end-tests-dir/format-manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $testProjects | % {
Write-Trace "test that format-manifest on $full produces $expectedPath"
[string]$expected = Get-Content $expectedPath -Raw
Copy-Item $asItem $tempItemPath
Run-Vcpkg format-manifest $tempItemPath
Run-Vcpkg format-manifest $tempItemPath | Out-Null
$actual = Get-Content $tempItemPath -Raw
if ($expected -ne $actual) {
throw "Expected formatting $full to produce $expectedPath but was $tempItemPath"
Expand All @@ -20,10 +20,12 @@ $testProjects | % {

Write-Trace "test re-serializing every manifest"
$manifestDir = "$TestingRoot/manifest-dir"

Copy-Item -Path "$env:VCPKG_ROOT/ports" -Destination $manifestDir -recurse -Force -Filter vcpkg.json
@("libuvc", "mlpack", "qt5-virtualkeyboard", "qtwebengine", "vamp-sdk") | % { Remove-Item -Recurse "$manifestDir/$_" }
& git init $manifestDir && git -C $manifestDir add . && git -C $manifestDir -c user.name='vcpkg-test' -c user.email='[email protected]' commit -m "baseline"
Throw-IfFailed
Run-Vcpkg format-manifest --all --x-builtin-ports-root=$manifestDir/ports
Run-Vcpkg format-manifest --all --x-builtin-ports-root=$manifestDir
Throw-IfFailed
$diff = (& git -C $manifestDir diff) | Out-String
if ($diff.length -gt 0) {
Expand Down
14 changes: 7 additions & 7 deletions azure-pipelines/end-to-end-tests-dir/versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ Throw-IfNotFailed

$CurrentTest = "x-add-version cat"
# Do not fail if there's nothing to update
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version cat
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version --skip-license-check cat
Throw-IfFailed

$CurrentTest = "x-add-version dog"
# Local version is not in baseline and versions file
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version dog
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version --skip-license-check dog
Throw-IfFailed

$CurrentTest = "x-add-version duck"
# Missing versions file
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version duck
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version --skip-license-check duck
Throw-IfFailed

$CurrentTest = "x-add-version ferret"
# Missing versions file and missing baseline entry
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version ferret
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version --skip-license-check ferret
Throw-IfFailed

$CurrentTest = "x-add-version fish (must fail)"
# Discrepancy between local SHA and SHA in fish.json. Requires --overwrite-version.
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version fish
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version --skip-license-check fish
Throw-IfNotFailed
$CurrentTest = "x-add-version fish --overwrite-version"
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version fish --overwrite-version --skip-version-format-check
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version fish --overwrite-version --skip-version-format-check --skip-license-check
Throw-IfFailed

$CurrentTest = "x-add-version mouse"
# Missing baseline entry
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version mouse
Run-Vcpkg @portsRedirectArgsIncomplete x-add-version --skip-license-check mouse
Throw-IfFailed
# Validate changes
Run-Vcpkg @portsRedirectArgsIncomplete x-ci-verify-versions --verbose
Expand Down
88 changes: 84 additions & 4 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,32 @@ namespace vcpkg
this->print(c, msg::format(m, args...).append_raw('\n'));
}

void println_warning(const LocalizedString& s);
template<class Message, class... Ts>
typename Message::is_message_type println_warning(Message m, Ts... args)
{
println_warning(format(m, args...));
}

void println_error(const LocalizedString& s);
template<class Message, class... Ts>
typename Message::is_message_type println_error(Message m, Ts... args)
{
println_error(format(m, args...));
}

template<class Message, class... Ts, class = typename Message::is_message_type>
LocalizedString format_warning(Message m, Ts... args)
{
return format(msg::msgWarningMessage).append(m, args...);
}

template<class Message, class... Ts, class = typename Message::is_message_type>
LocalizedString format_error(Message m, Ts... args)
{
return format(msg::msgErrorMessage).append(m, args...);
}

MessageSink(const MessageSink&) = delete;
MessageSink& operator=(const MessageSink&) = delete;

Expand Down Expand Up @@ -480,12 +506,20 @@ namespace vcpkg
(),
"",
"skipping detection of local changes due to unexpected format in git status output");
DECLARE_MESSAGE(AddVersionDisableCheck,
(msg::option),
"The -- before {option} must be preserved as they're part of the help message for the user.",
"Use --{option} to disable this check.");
DECLARE_MESSAGE(AddVersionFileNotFound, (msg::path), "", "couldn't find required file {path}");
DECLARE_MESSAGE(AddVersionFormatPortSuggestion, (msg::command_line), "", "Run `{command_line}` to format the file");
DECLARE_MESSAGE(AddVersionIgnoringOptionAll,
(msg::option),
"The -- before {option} must be preserved as they're part of the help message for the user.",
"ignoring --{option} since a port name argument was provided");
DECLARE_MESSAGE(AddVersionLintPort,
(msg::package_name),
"",
"You can run `./vcpkg x-lint-port --fix {package_name}` to fix these issues.");
DECLARE_MESSAGE(AddVersionLoadPortFailed, (msg::package_name), "", "can't load port {package_name}");
DECLARE_MESSAGE(AddVersionNewFile, (), "", "(new file)");
DECLARE_MESSAGE(AddVersionNewShaIs, (msg::commit_sha), "", "new SHA: {commit_sha}");
Expand All @@ -512,11 +546,49 @@ namespace vcpkg
(msg::package_name),
"",
"{package_name} is not properly formatted");
DECLARE_MESSAGE(AddVersionSuggestNewVersionScheme,
(msg::new_scheme, msg::old_scheme, msg::package_name, msg::option),
"The -- before {option} must be preserved as they're part of the help message for the user.",
DECLARE_MESSAGE(
LintDeprecatedFunction,
(msg::package_name, msg::actual, msg::expected),
"{actual} is the currently used deprecated function, {expected} is the function that should be used",
"The deprecated function \"{actual}\" is used inside the port \"{package_name}\". Use the function "
"\"{expected}\" instead.");

DECLARE_MESSAGE(
LintDeprecatedLicenseExpressionWithReplacement,
(msg::package_name, msg::actual, msg::new_value),
"{actual} is the currently used license expression and {new_value} is the license expression that should be "
"used",
"The port \"{package_name}\" uses the deprecated license expression \"{actual}\". You shoud use the non "
"deprecated version \"{new_value}\".");
DECLARE_MESSAGE(
LintDeprecatedLicenseExpressionWithoutReplacement,
(msg::package_name, msg::actual, msg::new_value),
"{actual} is the currently used license, {new_value} is the suggested WITH expression",
"The port \"{package_name}\" uses the deprecated license expression \"{actual}\". "
"Use license expression including main license, \"WITH\" operator, and identifier: \"{new_value}\"");
DECLARE_MESSAGE(LintMissingLicenseExpression,
(msg::package_name),
"",
"There is no license expression in port \"{package_name}\". You could use "
"https://tools.spdx.org/app/check_license/ to determine the right license expression.");
DECLARE_MESSAGE(LintSuggestNewVersionScheme,
(msg::new_scheme, msg::old_scheme, msg::package_name),
"",
"Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port "
"\"{package_name}\".\nUse --{option} to disable this check.");
"\"{package_name}\".");
DECLARE_MESSAGE(LintVcpkgCheckFeatures,
(msg::package_name),
"",
"Calling `vcpkg_check_features` without the `FEATURES` keyword has been deprecated. Please add the "
"`FEATURES` keyword to the call inside the port {package_name}.");
DECLARE_MESSAGE(LintPortErrorsFixed,
(msg::package_name),
"",
"Problems in the port \"{package_name}\" have been fixed.");
DECLARE_MESSAGE(LintPortErrors,
(msg::package_name),
"",
"The port \"{package_name}\" should be fixed. See warning(s) above.");
DECLARE_MESSAGE(AddVersionUnableToParseVersionsFile, (msg::path), "", "unable to parse versions file {path}");
DECLARE_MESSAGE(AddVersionUncommittedChanges,
(msg::package_name),
Expand Down Expand Up @@ -894,6 +966,8 @@ namespace vcpkg
DECLARE_MESSAGE(CmdAddVersionOptOverwriteVersion, (), "", "Overwrite `git-tree` of an existing version.");
DECLARE_MESSAGE(CmdAddVersionOptSkipFormatChk, (), "", "Skips the formatting check of vcpkg.json files.");
DECLARE_MESSAGE(CmdAddVersionOptSkipVersionFormatChk, (), "", "Skips the version format check.");
DECLARE_MESSAGE(CmdAddVersionOptSkipLicenseChk, (), "", "Skips the license expression check.");
DECLARE_MESSAGE(CmdAddVersionOptSkipPortfileChk, (), "", "Skips the portfile.cmake check.");
DECLARE_MESSAGE(CmdAddVersionOptVerbose, (), "", "Print success messages instead of just errors.");
DECLARE_MESSAGE(CmdContactOptSurvey, (), "", "Launch default browser to the current vcpkg survey");
DECLARE_MESSAGE(CmdDependInfoOptDepth, (), "", "Show recursion depth in output");
Expand Down Expand Up @@ -979,6 +1053,12 @@ namespace vcpkg
"When generating the message map, include comments (the default)");
DECLARE_MESSAGE(CmdInfoOptInstalled, (), "", "(experimental) Report on installed packages instead of available");
DECLARE_MESSAGE(CmdInfoOptTransitive, (), "", "(experimental) Also report on dependencies of installed packages");
DECLARE_MESSAGE(CmdLintPortOptAllPorts, (), "", "Checks all ports.");
DECLARE_MESSAGE(CmdLintPortOptFix, (), "", "Tries to fix all problems that were found.");
DECLARE_MESSAGE(CmdLintPortOptIncreaseVersion,
(),
"",
"Increase the port-version of a port if a problem was fixed.");
DECLARE_MESSAGE(CmdNewOptApplication, (), "", "Create an application manifest (don't require name or version).");
DECLARE_MESSAGE(CmdNewOptSingleFile, (), "", "Embed vcpkg-configuration.json into vcpkg.json.");
DECLARE_MESSAGE(CmdNewOptVersionDate, (), "", "Interpret --version as an ISO 8601 date. (YYYY-MM-DD)");
Expand Down
13 changes: 13 additions & 0 deletions include/vcpkg/commands.lint-port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands::LintPort
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct LintPortCommand : PathsCommand
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
53 changes: 53 additions & 0 deletions include/vcpkg/portlint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <vcpkg/base/fwd/files.h>
#include <vcpkg/base/fwd/stringview.h>

#include <vcpkg/fwd/packagespec.h>
#include <vcpkg/fwd/triplet.h>
#include <vcpkg/fwd/vcpkgpaths.h>

#include <vcpkg/sourceparagraph.h>

#include <set>

namespace vcpkg::Lint
{
enum class Status : int
{
Ok = 0b0,
Problem = 0b01,
Fixed = 0b10,
PartiallyFixed = 0b11
};
autoantwort marked this conversation as resolved.
Show resolved Hide resolved

Status& operator|=(Status& self, Status s);

enum class Fix
{
NO = 0, // A warning message is printed for every found problem
YES // The problem is fixed in place (SourceControlFile) and no message is printed
};

std::string get_recommended_license_expression(std::string original_license);

VersionScheme get_recommended_version_scheme(StringView raw_version, VersionScheme original_scheme);

Status check_used_version_scheme(SourceControlFile& scf, Fix fix);

Status check_license_expression(SourceControlFile& scf, Fix fix);

struct FixedPortfile
{
Status status;
std::string new_portfile_content; // empty if Fix::NO
std::set<StringLiteral> added_host_deps; // host-dependencies that need to be added, empty if Fix::NO
};

FixedPortfile check_portfile_deprecated_functions(std::string&& portfile_content,
StringView origin,
Fix fix,
MessageSink& warningsSink);

Status check_portfile_deprecated_functions(Filesystem& fs, SourceControlFileAndLocation& scf, Fix fix);
}
2 changes: 2 additions & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ namespace vcpkg
}
VersionSpec to_version_spec() const { return {core_paragraph->name, core_paragraph->to_version()}; }

std::unique_ptr<ParseControlErrorInfo> canonicalize();

friend bool operator==(const SourceControlFile& lhs, const SourceControlFile& rhs);
friend bool operator!=(const SourceControlFile& lhs, const SourceControlFile& rhs) { return !(lhs == rhs); }
};
Expand Down
Loading