Repository navigation
ci: Rust tests run when a file they read outside rs changes #9271
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
+160
−102
Merged
Changes from all commits
Commits
Show all changes
3 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
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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,51 @@ | ||
| #!/usr/bin/env bash | ||
| # Print each path outside its crate that a Rust source under rs/ reads, one | ||
| # `<crate dir> <glob> <file>:<line>` per line, naming the literal behind it. A glob's `*`, like a format interpolation such | ||
| # as `{name}`, stays within a path segment, `**` crosses them, and a plain path | ||
| # also covers what lies beneath it. | ||
| # | ||
| # A read is an `include_*!` or `#[path]` literal, relative to its file, or, in a | ||
| # file that mentions CARGO_MANIFEST_DIR, a literal that climbs out with `../`, | ||
| # relative to its crate. A `#[path]` to a `mod.rs` reads its directory, where its | ||
| # own modules live. The CARGO_MANIFEST_DIR rule spans the whole file rather than | ||
| # the statement that joins the literal, so a read built across statements is | ||
| # never missed; the cost is that any `../` string in such a file, such as a | ||
| # path-traversal test input, also counts, and the source column points at it. sh/rs/select.sh selects the reading crate from these, and | ||
| # sh/rs/select.test.py checks that sh/dispatch.sh's `rs` scope covers those | ||
| # outside rs/. The interop clients under test/ are moq-cli examples that only | ||
| # the interop harness runs, so their scripts stay out. | ||
| set -euo pipefail | ||
|
|
||
| cd "$(git rev-parse --show-toplevel)" | ||
|
|
||
| crates=$(git ls-files --cached --others --exclude-standard -- ':(glob)rs/**/Cargo.toml' | sed 's|/Cargo\.toml$||') | ||
| # grep exits 1 when no source climbs, which leaves nothing to print. | ||
| files=$(grep -rlE --include='*.rs' --exclude-dir=target '"(\{\}/|/)?\.\./' rs) || [[ $? == 1 ]] | ||
| [[ -n "$files" ]] || exit 0 | ||
|
|
||
| # One argument per file; no path under rs/ holds whitespace. | ||
| # shellcheck disable=SC2086 | ||
| jq -nrR --arg crates "$crates" ' | ||
| def resolve: reduce split("/")[] as $s ([]; | ||
| if $s == ".." then .[:-1] elif $s == "." or $s == "" then . else . + [$s] end) | join("/"); | ||
| ($crates | split("\n") | map(select(. != ""))) as $crates | ||
| | [inputs | {file: input_filename, line: .}] | ||
| | group_by(.file)[] | ||
| | .[0].file as $file | ||
| | (map(.line) | join("\n")) as $text | ||
| | ($file | split("/")[:-1] | join("/")) as $dir | ||
| | ([$crates[] | select(. as $c | $file | startswith($c + "/"))] | max_by(length)) as $crate | ||
| | ($text | test("CARGO_MANIFEST_DIR")) as $manifest | ||
| | $text | ||
| | match("(include(?:_str|_bytes)?!\\s*\\(\\s*|#\\[path\\s*=\\s*)?\"((?:\\{\\}/|/)?\\.\\./[^\"]*)\""; "g") | ||
| | "\($file):\($text[:.offset] | split("\n") | length)" as $source | ||
| | .captures as [$from, $name] | ||
| | if $from.string != null then "\($dir)/\($name.string)" | ||
| elif $manifest then "\($crate)/\($name.string | ltrimstr("{}"))" | ||
| else empty end | ||
| | gsub("\\{[^}]*\\}"; "*") | ||
| | resolve | ||
| | if ($from.string // "") | startswith("#") then sub("/mod\\.rs$"; "") else . end | ||
| | select(startswith($crate + "/") | not) | ||
| | "\($crate) \(.) \($source)" | ||
| ' $files | LC_ALL=C sort -u | ||
Oops, something went wrong.
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.