-
Notifications
You must be signed in to change notification settings - Fork 32
RustCheck: new crates checks #589
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| from .. import bash, results, sources | ||
| from . import Check | ||
|
|
||
|
|
||
| class SuboptimalCratesSeparator(results.LineResult, results.Warning): | ||
| """Using ``-`` as name-version separator in ``CRATES`` is suboptimal. | ||
|
|
||
| The ``CRATES`` variable is a space separated list of crates. The eclass | ||
| supports specifying the crate name and version as ``name@version`` and as | ||
| ``name-version``. The latter is suboptimal as it's slower. | ||
|
|
||
| It is recommended to use ``pycargoebuild`` 0.7+ to generate new ``CRATES``. | ||
| """ | ||
|
|
||
| @property | ||
| def desc(self): | ||
| return f"line: {self.lineno}: using - as name-version separator in CRATES is suboptimal, use name@version instead" | ||
|
|
||
|
|
||
| class SuboptimalCratesURICall(results.LineResult, results.Warning): | ||
| """Calling ``cargo_crate_uris`` with ``CRATES`` is suboptimal, use | ||
| ``${CARGO_CRATE_URIS}``. | ||
|
|
||
| Calls to ``$(cargo_crate_uris)`` and ``$(cargo_crate_uris ${CRATES})`` are | ||
| suboptimal, and can be replaces with ``${CARGO_CRATE_URIS}`` which is | ||
| pre-computed, faster and doesn't require sub-shell in global-scope. | ||
| """ | ||
|
|
||
| @property | ||
| def desc(self): | ||
| return f"line: {self.lineno}: calling {self.line!r} is suboptimal, use '${{CARGO_CRATE_URIS}}' for global CRATES instead" | ||
|
|
||
|
|
||
| class RustCheck(Check): | ||
| """Checks for rust related issues.""" | ||
|
|
||
| _source = sources.EbuildParseRepoSource | ||
| known_results = frozenset( | ||
| { | ||
| SuboptimalCratesSeparator, | ||
| SuboptimalCratesURICall, | ||
| } | ||
| ) | ||
|
|
||
| def _verify_crates(self, pkg: bash.ParseTree): | ||
| for node in pkg.global_query(bash.var_assign_query): | ||
| name = pkg.node_str(node.child_by_field_name("name")) | ||
| if name == "CRATES": | ||
| val_node = node.children[-1] | ||
| row, _ = val_node.start_point | ||
| val_str = pkg.node_str(val_node).strip("'\"") | ||
| for lineno, line in enumerate(val_str.splitlines(), start=row + 1): | ||
| for token in line.split(): | ||
| if "@" not in token: | ||
| yield SuboptimalCratesSeparator( | ||
| lineno=lineno, | ||
| line=token, | ||
| pkg=pkg, | ||
| ) | ||
| return | ||
|
|
||
| def _verify_cargo_crate_uris(self, pkg: bash.ParseTree): | ||
| for node, _ in bash.cmd_query.captures(pkg.tree.root_node): | ||
| call_name = pkg.node_str(node.child_by_field_name("name")) | ||
| if call_name == "cargo_crate_uris": | ||
| row, _ = node.start_point | ||
| line = pkg.node_str(node.parent) | ||
| if node.child_count == 1 or ( | ||
| node.child_count == 2 | ||
| and any( | ||
| pkg.node_str(var_node) == "CRATES" | ||
| for var_node, _ in bash.var_query.captures(node.children[1]) | ||
| ) | ||
|
arthurzam marked this conversation as resolved.
|
||
| ): | ||
| yield SuboptimalCratesURICall( | ||
| lineno=row + 1, | ||
| line=line, | ||
| pkg=pkg, | ||
| ) | ||
| break | ||
|
|
||
| def feed(self, pkg: bash.ParseTree): | ||
| if "cargo" not in pkg.inherited: | ||
| return | ||
| yield from self._verify_crates(pkg) | ||
| yield from self._verify_cargo_crate_uris(pkg) | ||
1 change: 1 addition & 0 deletions
1
testdata/data/repos/standalone/RustCheck/SuboptimalCratesSeparator/expected.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"__class__": "SuboptimalCratesSeparator", "category": "RustCheck", "package": "SuboptimalCratesSeparator", "version": "0", "line": "snakeoil-0.10.0", "lineno": 2} |
14 changes: 14 additions & 0 deletions
14
testdata/data/repos/standalone/RustCheck/SuboptimalCratesSeparator/fix.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| diff -Naur standalone/RustCheck/SuboptimalCratesSeparator/SuboptimalCratesSeparator-0.ebuild fixed/RustCheck/SuboptimalCratesSeparator/SuboptimalCratesSeparator-0.ebuild | ||
| --- standalone/RustCheck/SuboptimalCratesSeparator/SuboptimalCratesSeparator-0.ebuild | ||
| +++ fixed/RustCheck/SuboptimalCratesSeparator/SuboptimalCratesSeparator-0.ebuild | ||
| @@ -1,7 +1,7 @@ | ||
| CRATES=" | ||
| - random@0.10.0 snakeoil-0.10.0 | ||
| - pkgcore-0.10.0 | ||
| - pkgcheck-0.10.0 | ||
| + random@0.10.0 snakeoil@0.10.0 | ||
| + pkgcore@0.10.0 | ||
| + pkgcheck@0.10.0 | ||
| " | ||
|
|
||
| inherit cargo |
2 changes: 2 additions & 0 deletions
2
testdata/data/repos/standalone/RustCheck/SuboptimalCratesURICall/expected.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {"__class__": "SuboptimalCratesURICall", "category": "RustCheck", "package": "SuboptimalCratesURICall", "version": "0", "line": "$(cargo_crate_uris)", "lineno": 13} | ||
| {"__class__": "SuboptimalCratesURICall", "category": "RustCheck", "package": "SuboptimalCratesURICall", "version": "1", "line": "$(cargo_crate_uris ${CRATES})", "lineno": 13} |
18 changes: 18 additions & 0 deletions
18
testdata/data/repos/standalone/RustCheck/SuboptimalCratesURICall/fix.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| diff -Naur standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-0.ebuild fixed/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-0.ebuild | ||
| --- standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-0.ebuild | ||
| +++ fixed/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-0.ebuild | ||
| @@ -10,4 +10,4 @@ DESCRIPTION="Ebuild with suboptimal cargo_crate_uris" | ||
| HOMEPAGE="https://github.com/pkgcore/pkgcheck" | ||
| SLOT="0" | ||
| LICENSE="BSD" | ||
| -SRC_URI="$(cargo_crate_uris)" | ||
| +SRC_URI="${CARGO_CRATE_URIS}" | ||
| diff -Naur standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-1.ebuild fixed/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-1.ebuild | ||
| --- standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-1.ebuild | ||
| +++ fixed/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-1.ebuild | ||
| @@ -10,4 +10,4 @@ DESCRIPTION="Ebuild with suboptimal cargo_crate_uris" | ||
| HOMEPAGE="https://github.com/pkgcore/pkgcheck" | ||
| SLOT="0" | ||
| LICENSE="BSD" | ||
| -SRC_URI="$(cargo_crate_uris ${CRATES})" | ||
| +SRC_URI="${CARGO_CRATE_URIS}" |
12 changes: 12 additions & 0 deletions
12
...a/repos/standalone/RustCheck/SuboptimalCratesSeparator/SuboptimalCratesSeparator-0.ebuild
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| CRATES=" | ||
| random@0.10.0 snakeoil-0.10.0 | ||
| pkgcore-0.10.0 | ||
| pkgcheck-0.10.0 | ||
| " | ||
|
|
||
| inherit cargo | ||
|
|
||
| DESCRIPTION="Ebuild with suboptimal CRATES separator" | ||
| HOMEPAGE="https://github.com/pkgcore/pkgcheck" | ||
| SLOT="0" | ||
| LICENSE="BSD" |
13 changes: 13 additions & 0 deletions
13
testdata/repos/standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-0.ebuild
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CRATES=" | ||
| snakeoil@0.10.0 | ||
| pkgcore@0.10.0 | ||
| pkgcheck@0.10.0 | ||
| " | ||
|
|
||
| inherit cargo | ||
|
|
||
| DESCRIPTION="Ebuild with suboptimal cargo_crate_uris" | ||
| HOMEPAGE="https://github.com/pkgcore/pkgcheck" | ||
| SLOT="0" | ||
| LICENSE="BSD" | ||
| SRC_URI="$(cargo_crate_uris)" |
13 changes: 13 additions & 0 deletions
13
testdata/repos/standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-1.ebuild
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CRATES=" | ||
| snakeoil@0.10.0 | ||
| pkgcore@0.10.0 | ||
| pkgcheck@0.10.0 | ||
| " | ||
|
|
||
| inherit cargo | ||
|
|
||
| DESCRIPTION="Ebuild with suboptimal cargo_crate_uris" | ||
| HOMEPAGE="https://github.com/pkgcore/pkgcheck" | ||
| SLOT="0" | ||
| LICENSE="BSD" | ||
| SRC_URI="$(cargo_crate_uris ${CRATES})" |
13 changes: 13 additions & 0 deletions
13
testdata/repos/standalone/RustCheck/SuboptimalCratesURICall/SuboptimalCratesURICall-2.ebuild
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CRATES=" | ||
| snakeoil@0.10.0 | ||
| pkgcore@0.10.0 | ||
| pkgcheck@0.10.0 | ||
| " | ||
|
|
||
| inherit cargo | ||
|
|
||
| DESCRIPTION="Ebuild with suboptimal cargo_crate_uris" | ||
| HOMEPAGE="https://github.com/pkgcore/pkgcheck" | ||
| SLOT="0" | ||
| LICENSE="BSD" | ||
| SRC_URI="$(cargo_crate_uris ${CRATES} something)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # cargo eclass | ||
|
|
||
| CARGO_CRATE_URIS=${CRATES} | ||
|
|
||
| cargo_crate_uris() { :; } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.