-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feature: Substitute $saved_file in custom check commands #15476
Conversation
Do we want to try moving these changes atop of my changes, maybe? Could simply review, potentially. |
@davidbarsky Since this is a smaller change overall, I hope this is an easier review in the current form. I've amended your commit here, so the attribution is still clear :) |
a7464f6
to
79fa8f6
Compare
☔ The latest upstream changes (presumably #15465) made this pull request unmergeable. Please resolve the merge conflicts. |
79fa8f6
to
f061b31
Compare
f061b31
to
07effec
Compare
I've been using this patch on Fuchsia's codebase (a I think you can close #12882 if this lands. |
☔ The latest upstream changes (presumably #15492) made this pull request unmergeable. Please resolve the merge conflicts. |
07effec
to
b5eafbf
Compare
b5eafbf
to
097033c
Compare
Rebased. We're successfully using this patch internally and would love to see it upstreamed. @Veykril is there anything else you need from me here? |
c61adae
to
ebea717
Compare
} else { | ||
// The custom command has a $saved_file placeholder, | ||
// but we had an IDE event that wasn't a file save. Do nothing. | ||
return None; |
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 means there's going to be no initial check when loading the project, but I don't see any way around it without configuring two check commands.
I guess this is not a problem for you, but Cargo users trying this might still be surprised (ref. #12882).
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 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.
An example this should work for is rust-lang/rust
's cargo wrapper, ./x.py check
.
I reckon: If the command has $saved_file in it, return None. If it doesn't, return Some, as it does not require substitution. That brings back the current behaviour until you start using $saved_file.
☔ The latest upstream changes (presumably #16062) made this pull request unmergeable. Please resolve the merge conflicts. |
008f797
to
d2fbc83
Compare
Sorry to keep pinging this thread but we're in the same spot as @Wilfred. We'd prefer to avoid standing up our own fork of r-a for Fuchsia with just this patch applied and I'd be happy to help get this to a mergeable state if there's actionable work to be done. @Veykril is this gated on review or are there already issues with it you'd like someone to address? |
@P1n3appl3 I'm increasingly of the opinion that the right solution would be building atop of #15892, which feels substantially less like a hack than the approach that @Wilfred commandeered. Would that approach fork work for Fuschia? (It's not clear to me if Fuschia builds with Bazel today or if does its own thing). |
I was worried you'd say that 😛. I agree that #15892 is a less hacky approach and we'd definitely like something like it in the long run, but I was hoping that we could land a simple replacement variable for If merging a stopgap isn't desirable then I'm ok with pulling this change into our rust-analyzer mirror for now and hopefully getting back to using upstream once the more robust solution lands. It felt a bit silly for us and wilfred to separately keep rebasing this patch while we wait, but it's not much code so I'm not too worried about it. To answer your question Fuchsia mostly uses GN/Ninja for rust, though the codebase is generally moving towards bazel. That doesn't really concern us in terms of this issue though because they're all generating rust-project.json and all have the ability to run a check build and/or clippy on a single crate if they're given the info about which file was saved. |
That's certainly fair! I've been meaning to get back to #16135. I'll wire up the flycheck string to actually run flycheck in that PR in the next day or so and ping you once it's ready.
In fairness, it's you, Wilfred, and I rebasing this change, as Wilfred and I work together 😄.
Gotcha! Can GN/Ninja build a crate if they're provided with a target label (to use Bazel/Buck terminology)? Do you currently infer the owning target(s) from the saved file here to build said crate? (I'm asking to ensure that the PR I linked to works for Fuschia.) |
Substitute $saved_file in custom check commands If the custom command has a $saved_file placeholder, and we know the file being saved, replace the placeholder and run a check command. If there's a placeholder and we don't know the saved file, do nothing. This is a simplified version of #15381, which I hope is easier to review.
If the custom command has a $saved_file placeholder, and we know the file being saved, replace the placeholder and then run a check command. If there's a placeholder and we don't know the saved file, do nothing.
155e38b
to
cdbf54f
Compare
@bors r+ |
☀️ Test successful - checks-actions |
The `--compile_one_dependency` flag ([docs](https://bazel.build/docs/user-manual#compile-one-dependency)) changes `bazel build` etc. to accept a file path and build the target corresponding to that file. This is useful for check-on-save with rust-analyzer in combination with the newly-added `$saved_file` command substitution (rust-lang/rust-analyzer#15476). Officially `--compile_one_dependency` only supports the builtin C++ and Java rules, but an [undocumented flag](https://github.com/bazelbuild/bazel/blob/7.1.1/src/main/java/com/google/devtools/build/lib/packages/Attribute.java#L102) can be added to attributes to turn them into sources supporting `--compile_one_dependency`. I'm not sure what the status of this support is, but it appears to work for all bazel versions up to at least 7.1.1, and if support is removed the flag is pretty harmless. Before this change: ``` > bazel build --compile_one_dependency tools/rust_analyzer/main.rs WARNING: Target pattern parsing failed. ERROR: Couldn't find dependency on target '//tools/rust_analyzer:main.rs' ERROR: Couldn't find dependency on target '//tools/rust_analyzer:main.rs' INFO: Elapsed time: 0.956s INFO: 0 processes. ERROR: Build did NOT complete successfully ``` After: ``` > bazel build --compile_one_dependency tools/rust_analyzer/main.rs INFO: Analyzed target //tools/rust_analyzer:gen_rust_project (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //tools/rust_analyzer:gen_rust_project up-to-date: bazel-bin/tools/rust_analyzer/gen_rust_project INFO: Elapsed time: 0.341s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action ``` --------- Co-authored-by: Daniel Wagner-Hall <[email protected]>
If the custom command has a $saved_file placeholder, and we know the file being saved, replace the placeholder and run a check command.
If there's a placeholder and we don't know the saved file, do nothing.
This is a simplified version of #15381, which I hope is easier to review.