-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Expose compiletest as a library for use in Clippy #103266
Conversation
Let's leave this to a separate PR, since it'll have a fairly distinct set of changes. That said, the broad strokes are going to be to do something similar to the RustcDev component which takes the artifacts built for compile test and copies them into the target directory: https://github.com/rust-lang/rust/blob/master/src/bootstrap/dist.rs#L651-L652 I believe we don't currently produce a stamp file for tools, but it should be possible to make that happen. It'll be a bit tricky to get compiletest shipped as a library in terms of the dependency tree -- we don't currently build it in the compiler directory which means that copying it into the sysroot likely isn't a good idea. But I think the first step is to just try and do that, and we can go from there if it fails; that will mean replicating the stamp file for tools like we do for rustc and replicating those steps. |
30249c2
to
75be411
Compare
I split the commits up differently so the |
☔ The latest upstream changes (presumably #103471) made this pull request unmergeable. Please resolve the merge conflicts. |
75be411
to
3f11dbe
Compare
Can you talk a bit more about why these changes were necessary? We already support failing to compile by default, or successfully compiling with Can you confirm for me that the clippy team is planning to use this changes if they're merged? cc @oli-obk @flip1995 |
3f11dbe
to
b3c473e
Compare
I removed We don't have anything inline in place of I plan to open a PR on the clippy side at least. My impression is that it's likely to be accepted but I'll wait for the others to weigh in there |
I'm in favor of using compiletest from the rust-lang/rust repo, rather than the fork. So I would give my +1 to move forward with this. |
☔ The latest upstream changes (presumably #103727) made this pull request unmergeable. Please resolve the merge conflicts. |
b3c473e
to
0219f07
Compare
☔ The latest upstream changes (presumably #103298) made this pull request unmergeable. Please resolve the merge conflicts. |
0219f07
to
3333422
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few comments on the implementation but overall the changes seem reasonable.
I have a larger question for @Alexendoo: are you planning to use compiletest as a library or as a binary? There's a weird mix of both currently: renaming main to lib, making some things public, but also making the main function public, adding more arguments, and you mentioned packaging as a binary on nightly. We should pick one or the other.
src/tools/compiletest/src/common.rs
Outdated
pub exclude_file: Option<Arc<dyn Fn(&Path) -> bool + Send + Sync>>, | ||
|
||
/// Modify a [Command] just before it's executed | ||
pub modify_command: Option<Arc<dyn Fn(&Path, &mut Command) + Send + Sync>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird. Why would you need to run this before any command? I would expect you to only run it for things like the compiler if you need to change the sysroot.
Ah, looking later I see this is only called for the rustc process. Can you mention that in the doc-comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we don't need it for any command just clippy-driver, I had the hook in a place I think gets called by other things as well like debuggers/run tests (that clippy doesn't happen to use), but I've found a place to move it to that I think is only called for compilation
src/tools/compiletest/src/lib.rs
Outdated
@@ -67,6 +67,7 @@ pub fn parse_config(args: Vec<String>) -> Config { | |||
.optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind") | |||
.optopt("", "run-clang-based-tests-with", "path to Clang executable", "PATH") | |||
.optopt("", "llvm-filecheck", "path to LLVM's FileCheck binary", "DIR") | |||
.reqopt("", "root", "root directory of the project", "PATH") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this should be named "source root" or "source directory"? I guess "src-base" below makes that confusing ... that should be named "suite-path" IMO, but it doesn't have to block this PR. would be nice to fix in a follow up though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Changed it to source root, I'm happy to follow up with another PR that changes src-base also
src/tools/compiletest/src/lib.rs
Outdated
@@ -36,7 +36,7 @@ mod read2; | |||
pub mod runtest; | |||
pub mod util; | |||
|
|||
fn main() { | |||
pub fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems weird to make public? is clippy planning to use exactly this entrypoint? that means it can't use the new hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not, it's only public as main.rs
consists of
fn main() {
compiletest::main();
}
This was to keep the diff smaller, I can move fn main
& others only used by the binary back into main.rs
if that's preferable
Here's the current WIP I have for using it in clippy: https://github.com/Alexendoo/rust-clippy/blob/compiletest/tests/compile-test.rs
(using compiletest = { path = "../rust/src/tools/compiletest" }
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Can we keep the parts clippy isn't using in main.rs so it's easier to understand what parts have to work both in-tree and out of tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved main
and log_config
there, parse_config
is used by some tests though so remains in lib.rs
for expected in &expected_errors { | ||
self.error(&format!( | ||
"{file_name}:{}: found expectation comment `{}`", | ||
expected.line_num, expected.msg, | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird; @flip1995 do you want to actively prevent people from adding //~ ERROR annotations? I mean I guess that's fine, but it would be nice if clippy and rust converged on this eventually, forcefully preventing it seems unfortunate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I was copying how known-bug works, but I could change it to check them if they happen to be present + ignore missing ones
TargetLocation::ThisFile(self.make_exe_name()), | ||
emit_metadata, | ||
AllowUnused::No, | ||
LinkToAux::Yes, | ||
); | ||
// Set the crate name to avoid `file.revision.fixed` inferring the | ||
// invalid name `file.revision` | ||
rustc.arg("--crate-name=fixed"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does "invalid name" mean? Why did this only break now when using clippy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently files with both revisions and // run-rustfix
check test.fixed
instead of test.revision.fixed
, that gets fixed just above here
However rustc
seems to use file_stem
of the path to determine a default crate name if you don't provide your own, so it infers test.revision
here, but considers that invalid:
$ rustc test.revision.fixed
error: invalid character `'.'` in crate name: `test.revision`
error: aborting due to previous error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There don't seem to be any revision + // run-rustfix
tests in the rust suite, but there are some leftovers from a previous one that's no longer used so I'll rm
those
3333422
to
b40547e
Compare
8625f36
to
3aae7cc
Compare
As a library The mention of testing the binary is that I tried the approach from #99968 and believe that a library will be better suited I've removed the flag |
3aae7cc
to
ff54663
Compare
Let's avoid merging this until we work out with @oli-obk whether clippy is going to use this or Oli's new codebase. |
Return multiple resolutions from `def_path_res` Changes `def_path_res` to return all the resolutions matching the path rather than the first one (with a namespace hint that covered some cases). This would fix any issues that come up with multiple versions of the same crate being present as they all have the same crate name It also adds resolution of `impl _ {}` items for local items, and removes struct field resolution as it didn't seem to be used anywhere I tested it on a local crate and it worked for the multiple crate issue, but I couldn't come up with a test that worked well with `// aux-build`, maybe `// aux-crate` after rust-lang/rust#103266 could work but I'm not sure on that either changelog: [`disallowed_methods`], [`disallowed_types`], [`disallowed_macros`]: fix path resolution with multiple versions of the same crate changelog: [`disallowed_methods`]: Resolve methods in `impl`s in the current crate
☔ The latest upstream changes (presumably #104607) made this pull request unmergeable. Please resolve the merge conflicts. |
@Alexendoo it looks like clippy is planning to go with ui_test: rust-lang/rust-clippy#10426 |
Yeah that's the plan, didn't realise this was still open. Thank you for your time on it! |
I tried out the binary approach from #99968, with some tweaks and a few extra flags it worked well for most of our test suite. The
ui-cargo
andui-toml
tests need some very clippy specific bits of setup thoughRather than those clippy specific bits living in compiletest this PR adds two hooks to compiletest's
Config
that clippy will supply. This lets us keep the clippy specifics in the clippy tree to avoid any sync woesSome other changes:
--root
to break the.parent().unwrap().parent().unwrap().parent().unwrap() == rust repo root
assumption--no-expected-comments
as clippy doesn't use//~ ERROR
This doesn't publish the library as a component, as I wasn't sure how to go about that
cc @Mark-Simulacrum
r? @jyn514