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 1 commit
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
45 changes: 41 additions & 4 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,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::value), "{value} is a 40-digit hexadecimal SHA", "new SHA: {value}");
Expand Down Expand Up @@ -512,11 +520,40 @@ 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 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),
"{actual} is the currently used license",
"The port \"{package_name}\" uses the deprecated license expression \"{actual}\".");
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(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
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;
};
}
35 changes: 35 additions & 0 deletions include/vcpkg/portlint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#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>

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
};

Status check_used_version_scheme(SourceControlFile& scf, Fix fix);

Status check_license_expression(SourceControlFile& scf, Fix fix);

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 @@ -131,6 +131,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
10 changes: 9 additions & 1 deletion locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"AddVersionCommitChangesReminder": "Did you remember to commit your changes?",
"AddVersionCommitResultReminder": "Don't forget to commit the result!",
"AddVersionDetectLocalChangesError": "skipping detection of local changes due to unexpected format in git status output",
"AddVersionDisableCheck": "Use --{option} to disable this check.",
"AddVersionFileNotFound": "couldn't find required file {path}",
"AddVersionFormatPortSuggestion": "Run `{command_line}` to format the file",
"AddVersionIgnoringOptionAll": "ignoring --{option} since a port name argument was provided",
"AddVersionLintPort": "You can run `./vcpkg x-lint-port --fix {package_name}` to fix these issues.",
"AddVersionLoadPortFailed": "can't load port {package_name}",
"AddVersionNewFile": "(new file)",
"AddVersionNewShaIs": "new SHA: {value}",
Expand All @@ -24,7 +26,6 @@
"AddVersionPortFilesShaChanged": "checked-in files for {package_name} have changed but the version was not updated",
"AddVersionPortFilesShaUnchanged": "checked-in files for {package_name} are unchanged from version {version}",
"AddVersionPortHasImproperFormat": "{package_name} is not properly formatted",
"AddVersionSuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".\nUse --{option} to disable this check.",
"AddVersionUnableToParseVersionsFile": "unable to parse versions file {path}",
"AddVersionUncommittedChanges": "there are uncommitted changes for {package_name}",
"AddVersionUpdateVersionReminder": "Did you remember to update the version or port version?",
Expand Down Expand Up @@ -271,6 +272,13 @@
"LicenseExpressionImbalancedParens": "There was a close parenthesis without an opening parenthesis.",
"LicenseExpressionUnknownException": "Unknown license exception identifier '{value}'. Known values are listed at https://spdx.org/licenses/exceptions-index.html",
"LicenseExpressionUnknownLicense": "Unknown license identifier '{value}'. Known values are listed at https://spdx.org/licenses/",
"LintDeprecatedFunction": "The deprecated function \"{actual}\" is used inside the port \"{package_name}\". Use the function \"{expected}\" instead.",
"LintDeprecatedLicenseExpressionWithReplacement": "The port \"{package_name}\" uses the deprecated license expression \"{actual}\". You shoud use the non deprecated version \"{new_value}\".",
"LintDeprecatedLicenseExpressionWithoutReplacement": "The port \"{package_name}\" uses the deprecated license expression \"{actual}\".",
"LintMissingLicenseExpression": "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.",
"LintPortErrors": "The port \"{package_name}\" should be fixed. See warning(s) above.",
"LintPortErrorsFixed": "Problems in the port \"{package_name}\" have been fixed.",
"LintSuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".",
"ListOfValidFieldsForControlFiles": "This is the list of valid fields for CONTROL files (case-sensitive):",
"LoadingCommunityTriplet": "-- [COMMUNITY] Loading triplet configuration from: {path}",
"LoadingDependencyInformation": "Loading dependency information for {count} packages...",
Expand Down
20 changes: 18 additions & 2 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
"AddVersionCommitChangesReminder": "Did you remember to commit your changes?",
"AddVersionCommitResultReminder": "Don't forget to commit the result!",
"AddVersionDetectLocalChangesError": "skipping detection of local changes due to unexpected format in git status output",
"AddVersionDisableCheck": "Use --{option} to disable this check.",
"_AddVersionDisableCheck.comment": "The -- before {option} must be preserved as they're part of the help message for the user. An example of {option} is editable.",
"AddVersionFileNotFound": "couldn't find required file {path}",
"_AddVersionFileNotFound.comment": "An example of {path} is /foo/bar.",
"AddVersionFormatPortSuggestion": "Run `{command_line}` to format the file",
"_AddVersionFormatPortSuggestion.comment": "An example of {command_line} is vcpkg install zlib.",
"AddVersionIgnoringOptionAll": "ignoring --{option} since a port name argument was provided",
"_AddVersionIgnoringOptionAll.comment": "The -- before {option} must be preserved as they're part of the help message for the user. An example of {option} is editable.",
"AddVersionLintPort": "You can run `./vcpkg x-lint-port --fix {package_name}` to fix these issues.",
"_AddVersionLintPort.comment": "An example of {package_name} is zlib.",
"AddVersionLoadPortFailed": "can't load port {package_name}",
"_AddVersionLoadPortFailed.comment": "An example of {package_name} is zlib.",
"AddVersionNewFile": "(new file)",
Expand All @@ -42,8 +46,6 @@
"_AddVersionPortFilesShaUnchanged.comment": "An example of {package_name} is zlib. An example of {version} is 1.3.8.",
"AddVersionPortHasImproperFormat": "{package_name} is not properly formatted",
"_AddVersionPortHasImproperFormat.comment": "An example of {package_name} is zlib.",
"AddVersionSuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".\nUse --{option} to disable this check.",
"_AddVersionSuggestNewVersionScheme.comment": "The -- before {option} must be preserved as they're part of the help message for the user. An example of {new_scheme} is version. An example of {old_scheme} is version-string. An example of {package_name} is zlib. An example of {option} is editable.",
"AddVersionUnableToParseVersionsFile": "unable to parse versions file {path}",
"_AddVersionUnableToParseVersionsFile.comment": "An example of {path} is /foo/bar.",
"AddVersionUncommittedChanges": "there are uncommitted changes for {package_name}",
Expand Down Expand Up @@ -446,6 +448,20 @@
"_LicenseExpressionUnknownException.comment": "Example of {value} is 'unknownexception'",
"LicenseExpressionUnknownLicense": "Unknown license identifier '{value}'. Known values are listed at https://spdx.org/licenses/",
"_LicenseExpressionUnknownLicense.comment": "Example of {value} is 'unknownlicense'",
"LintDeprecatedFunction": "The deprecated function \"{actual}\" is used inside the port \"{package_name}\". Use the function \"{expected}\" instead.",
"_LintDeprecatedFunction.comment": "{actual} is the currently used deprecated function, {expected} is the function that should be used An example of {package_name} is zlib.",
"LintDeprecatedLicenseExpressionWithReplacement": "The port \"{package_name}\" uses the deprecated license expression \"{actual}\". You shoud use the non deprecated version \"{new_value}\".",
"_LintDeprecatedLicenseExpressionWithReplacement.comment": "{actual} is the currently used license and {new_value} is the license expression that should be used An example of {package_name} is zlib.",
"LintDeprecatedLicenseExpressionWithoutReplacement": "The port \"{package_name}\" uses the deprecated license expression \"{actual}\".",
"_LintDeprecatedLicenseExpressionWithoutReplacement.comment": "{actual} is the currently used license An example of {package_name} is zlib.",
"LintMissingLicenseExpression": "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.",
"_LintMissingLicenseExpression.comment": "An example of {package_name} is zlib.",
"LintPortErrors": "The port \"{package_name}\" should be fixed. See warning(s) above.",
"_LintPortErrors.comment": "An example of {package_name} is zlib.",
"LintPortErrorsFixed": "Problems in the port \"{package_name}\" have been fixed.",
"_LintPortErrorsFixed.comment": "An example of {package_name} is zlib.",
"LintSuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".",
"_LintSuggestNewVersionScheme.comment": "An example of {new_scheme} is version. An example of {old_scheme} is version-string. An example of {package_name} is zlib.",
"ListOfValidFieldsForControlFiles": "This is the list of valid fields for CONTROL files (case-sensitive):",
"LoadingCommunityTriplet": "-- [COMMUNITY] Loading triplet configuration from: {path}",
"_LoadingCommunityTriplet.comment": "'-- [COMMUNITY]' at the beginning must be preserved An example of {path} is /foo/bar.",
Expand Down
14 changes: 11 additions & 3 deletions src/vcpkg/base/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,12 @@ namespace vcpkg
REGISTER_MESSAGE(AddVersionCommitChangesReminder);
REGISTER_MESSAGE(AddVersionCommitResultReminder);
REGISTER_MESSAGE(AddVersionDetectLocalChangesError);
REGISTER_MESSAGE(AddVersionDisableCheck);
REGISTER_MESSAGE(AddVersionFileNotFound);
REGISTER_MESSAGE(AddVersionFormatPortSuggestion);
REGISTER_MESSAGE(AddVersionIgnoringOptionAll);
REGISTER_MESSAGE(AddVersionLoadPortFailed);
REGISTER_MESSAGE(AddVersionLintPort);
REGISTER_MESSAGE(AddVersionNewFile);
REGISTER_MESSAGE(AddVersionNewShaIs);
REGISTER_MESSAGE(AddVersionNoFilesUpdated);
Expand All @@ -408,7 +410,6 @@ namespace vcpkg
REGISTER_MESSAGE(AddVersionPortFilesShaChanged);
REGISTER_MESSAGE(AddVersionPortFilesShaUnchanged);
REGISTER_MESSAGE(AddVersionPortHasImproperFormat);
REGISTER_MESSAGE(AddVersionSuggestNewVersionScheme);
REGISTER_MESSAGE(AddVersionUnableToParseVersionsFile);
REGISTER_MESSAGE(AddVersionUncommittedChanges);
REGISTER_MESSAGE(AddVersionUpdateVersionReminder);
Expand Down Expand Up @@ -466,8 +467,8 @@ namespace vcpkg
REGISTER_MESSAGE(CMakeToolChainFile);
REGISTER_MESSAGE(CommandFailed);
REGISTER_MESSAGE(CompressFolderFailed);
REGISTER_MESSAGE(ConstraintViolation);
REGISTER_MESSAGE(ConflictingValuesForOption);
REGISTER_MESSAGE(ConstraintViolation);
REGISTER_MESSAGE(ControlAndManifestFilesPresent);
REGISTER_MESSAGE(CopyrightIsDir);
REGISTER_MESSAGE(CorruptedDatabase);
Expand Down Expand Up @@ -648,6 +649,13 @@ namespace vcpkg
REGISTER_MESSAGE(LicenseExpressionImbalancedParens);
REGISTER_MESSAGE(LicenseExpressionUnknownException);
REGISTER_MESSAGE(LicenseExpressionUnknownLicense);
REGISTER_MESSAGE(LintDeprecatedFunction);
REGISTER_MESSAGE(LintDeprecatedLicenseExpressionWithoutReplacement);
REGISTER_MESSAGE(LintDeprecatedLicenseExpressionWithReplacement);
REGISTER_MESSAGE(LintMissingLicenseExpression);
REGISTER_MESSAGE(LintSuggestNewVersionScheme);
REGISTER_MESSAGE(LintPortErrors);
REGISTER_MESSAGE(LintPortErrorsFixed);
REGISTER_MESSAGE(ListOfValidFieldsForControlFiles);
REGISTER_MESSAGE(LoadingCommunityTriplet);
REGISTER_MESSAGE(LoadingDependencyInformation);
Expand All @@ -661,8 +669,8 @@ namespace vcpkg
REGISTER_MESSAGE(MissingDependency);
REGISTER_MESSAGE(MissingExtension);
REGISTER_MESSAGE(MissingOption);
REGISTER_MESSAGE(MissmatchedBinParagraphs);
REGISTER_MESSAGE(MissingPortSuggestPullRequest);
REGISTER_MESSAGE(MissmatchedBinParagraphs);
REGISTER_MESSAGE(MonoInstructions);
REGISTER_MESSAGE(MsiexecFailedToExtract);
REGISTER_MESSAGE(MultiArch);
Expand Down
Loading