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

Make tidy not traverse untracked directories #112921

Closed
wants to merge 1 commit into from
Closed

Make tidy not traverse untracked directories #112921

wants to merge 1 commit into from

Conversation

Milo123459
Copy link
Contributor

Fixes #69291
(untested, still needs some work)

Not sure if this is the best way to do it either. Could anyone give some advice?

@rustbot
Copy link
Collaborator

rustbot commented Jun 22, 2023

r? @clubby789

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 22, 2023
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Getting action download info
Download action repository 'actions/checkout@v3' (SHA:c85c95e3d7251135ab7dc9ce3241c5835cc595a9)
Download action repository 'rust-lang/simpleinfra@master' (SHA:3999262f9f9933e66da0e5e168b90798c32a320e)
Download action repository 'actions/upload-artifact@v3' (SHA:0b7f8abb1508181956e8e162db84b466c27e18ce)
Complete job name: PR - mingw-check-tidy
git config --global core.autocrlf false
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
  CI_JOB_NAME: mingw-check-tidy
---
Building wheels for collected packages: reuse
  Building wheel for reuse (pyproject.toml): started
  Building wheel for reuse (pyproject.toml): finished with status 'done'
  Created wheel for reuse: filename=reuse-1.1.0-cp310-cp310-manylinux_2_35_x86_64.whl size=180116 sha256=351235b2326fb4db7a18e257e13ce7896c5f77339521e2c2612e71e154800a19
  Stored in directory: /tmp/pip-ephem-wheel-cache-eio97r82/wheels/c2/3c/b9/1120c2ab4bd82694f7e6f0537dc5b9a085c13e2c69a8d0c76d
Installing collected packages: boolean-py, binaryornot, setuptools, reuse, python-debian, markupsafe, license-expression, jinja2, chardet
  Attempting uninstall: setuptools
    Found existing installation: setuptools 59.6.0
    Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
---
Successfully tagged rust-ci:latest
Built container sha256:1f0fc30b39e0eb87b04c8f6a5ab4b9e4c68cacc46e75c03e94bb554317f9246c
Uploading finished image to https://ci-caches.rust-lang.org/docker/6c79211b759db8881e4e083f32c23f7a9fde027e88ac4e65b52f7f5e0405fbb6bd8d3cd81afe7617920fe598db5be42068b29a40aff8b5cde467364f4587bbd8

<botocore.awsrequest.AWSRequest object at 0x7f9afe4594d0>
gzip: stdout: Broken pipe
xargs: docker: terminated by signal 13
[CI_JOB_NAME=mingw-check-tidy]
[CI_JOB_NAME=mingw-check-tidy]
---
   Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
error[E0308]: mismatched types
  --> src/tools/tidy/src/walk.rs:42:54
   |
42 |                 skip.remove(skip.iter().position(|x| **x = line))
   |                                                      ^^^^^^^^^^ expected `bool`, found `()`
error[E0308]: mismatched types
  --> src/tools/tidy/src/walk.rs:42:29
   |
   |
42 |                 skip.remove(skip.iter().position(|x| **x = line))
   |                      ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `Option<usize>`
   |                      arguments to this method are incorrect
   |
   = note: expected type `usize`
              found enum `Option<usize>`
              found enum `Option<usize>`
note: method defined here
  --> /rustc/eff24c06d8f4397802b546aa2e52450e1022fc02/library/alloc/src/vec/mod.rs:1496:12

error[E0308]: mismatched types
  --> src/tools/tidy/src/walk.rs:42:17
   |
41 | /             if skip.contains(&line) {
42 | |                 skip.remove(skip.iter().position(|x| **x = line))
   | |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&str`
   | |_____________- expected this to be `()`
   |
help: consider using a semicolon here
   |
   |
42 |                 skip.remove(skip.iter().position(|x| **x = line));
help: consider using a semicolon here
   |
43 |             };
   |              +

@Milo123459 Milo123459 marked this pull request as draft June 22, 2023 16:05
@clubby789
Copy link
Contributor

clubby789 commented Jun 22, 2023

I don't think we want to be running this command on every invocation of filter_dirs, since the output isn't going to change. Maybe this could be done in a OnceLock or similar

String::from_utf8_lossy(&output.stdout).split('\n').into_iter().collect();
for line in stdout {
if skip.contains(&line) {
skip.remove(skip.iter().position(|x| **x = line))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just add each line of stdout to skip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue (unless I'm interpreting it wrong) says that you need to remove these elements from the skip array. But, that could be wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for this is probably to run git ls-files . --exclude-standard --others and skip files that it outputs in the default filter_dirs function

The existing skip array defines directories that we wish to skip. We want to extend this with any untracked directories - all directories in skip are tracked, so right now this wouldn't do anything even without the compile errors

@@ -31,6 +32,17 @@ pub fn filter_dirs(path: &Path) -> bool {
"src/bootstrap/target",
"vendor",
];
let command =
Command::new("git").args(["ls-files", ".", "--exclude-standard", "--others"]).output();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work properly if tidy is run from a subdirectory. Maybe this could be combined with git rev-parse --show-toplevel?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, ls-files will return each untracked file in a directory rather than the directory itself. I think --directory is the flag you want to prevent recursing into untracked dirs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the command that was posted in the linked issue, so I wasn't sure. I'll look into it.

Command::new("git").args(["ls-files", ".", "--exclude-standard", "--others"]).output();
if let Ok(output) = command {
let stdout: Vec<&str> =
String::from_utf8_lossy(&output.stdout).split('\n').into_iter().collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need to collect when you iterate over it below

@Milo123459
Copy link
Contributor Author

I don't think we want to be running this command on every invocation, since the output isn't going to change. Maybe this could be done in a OnceLock or similar

I think in that case, if done in a OnceLock, would it not be beneficial to just put the entire array in a const or something?

@clubby789
Copy link
Contributor

Untracked directories can't be known at compile time, as they may change after tidy is compiled.

@clubby789 clubby789 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2023
@bors
Copy link
Contributor

bors commented Jul 5, 2023

☔ The latest upstream changes (presumably #113370) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@Milo123459 any updates on this?

@Milo123459
Copy link
Contributor Author

dont have the time for this pr rn, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tidy should not traverse untracked directories
6 participants