* [PATCH] scripts: rust-analyzer: Skip crate module directories
@ 2023-03-07 12:07 Andreas Hindborg
2023-03-07 12:38 ` Miguel Ojeda
2023-04-06 22:33 ` Miguel Ojeda
0 siblings, 2 replies; 7+ messages in thread
From: Andreas Hindborg @ 2023-03-07 12:07 UTC (permalink / raw)
To: rust-for-linux
Cc: Andreas Hindborg, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
Boqun Feng, Gary Guo, Björn Roy Baron, open list
When generating rust-analyzer configuration, skip module directories. This fixes
an issue that occur if we have
- drivers/block/driver.rs
- drivers/block/driver_mod/mod.rs
If `driver_mod` is a module of the crate `driver`, the directory `driver_mod`
may not contain `Makefile`, and `generate_rust_analyzer.py` will fail.
Signed-off-by: Andreas Hindborg <a.hindborg@samsung.com>
---
scripts/generate_rust_analyzer.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index ecc7ea9a4dcf..e8c643fb2488 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -104,7 +104,7 @@ def generate_crates(srctree, objtree, sysroot_src):
name = path.name.replace(".rs", "")
# Skip those that are not crate roots.
- if f"{name}.o" not in open(path.parent / "Makefile").read():
+ if not (path.parent / "Makefile").is_file() or f"{name}.o" not in open(path.parent / "Makefile").read():
continue
logging.info("Adding %s", name)
base-commit: 8c20eb7e6a27b2c493b0bbb435e75cae7135634f
--
2.39.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] scripts: rust-analyzer: Skip crate module directories
2023-03-07 12:07 [PATCH] scripts: rust-analyzer: Skip crate module directories Andreas Hindborg
@ 2023-03-07 12:38 ` Miguel Ojeda
2023-03-07 12:53 ` Andreas Hindborg
2023-03-07 16:32 ` Gary Guo
2023-04-06 22:33 ` Miguel Ojeda
1 sibling, 2 replies; 7+ messages in thread
From: Miguel Ojeda @ 2023-03-07 12:38 UTC (permalink / raw)
To: Asahi Lina, Andreas Hindborg
Cc: rust-for-linux, Andreas Hindborg, Miguel Ojeda, Alex Gaynor,
Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron,
open list
On Tue, Mar 7, 2023 at 1:08 PM Andreas Hindborg <nmi@metaspace.dk> wrote:
>
> When generating rust-analyzer configuration, skip module directories.
This is https://github.com/Rust-for-Linux/linux/pull/883, also handled
by Vinay's patch
https://lore.kernel.org/rust-for-linux/20230118160220.776302-1-varmavinaym@gmail.com/.
Lina's approach is arguably a bit more idiomatic in Python in that it
is usually encouraged to follow the "Easier to ask for forgiveness
than permission" approach.
Lina, would you like to submit yours? Or do you prefer a `Link: ` /
`Reported-by: ` / `Co-developed-by: ` here?
> If `driver_mod` is a module of the crate `driver`, the directory `driver_mod`
> may not contain `Makefile`, and `generate_rust_analyzer.py` will fail.
By the way, note that in the kernel crate we are avoiding `mod.rs`
files, instead using `name.rs` in the parent folder, in other to make
it easier to find the files. I will add a note about it in the docs.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] scripts: rust-analyzer: Skip crate module directories
2023-03-07 12:38 ` Miguel Ojeda
@ 2023-03-07 12:53 ` Andreas Hindborg
2023-03-07 16:32 ` Gary Guo
1 sibling, 0 replies; 7+ messages in thread
From: Andreas Hindborg @ 2023-03-07 12:53 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Asahi Lina, rust-for-linux, Miguel Ojeda, Alex Gaynor,
Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron,
open list
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> writes:
> On Tue, Mar 7, 2023 at 1:08 PM Andreas Hindborg <nmi@metaspace.dk> wrote:
>>
>> When generating rust-analyzer configuration, skip module directories.
>
> This is https://github.com/Rust-for-Linux/linux/pull/883, also handled
> by Vinay's patch
> https://lore.kernel.org/rust-for-linux/20230118160220.776302-1-varmavinaym@gmail.com/.
Awesome, three solutions to the same problem 😅
>
> Lina's approach is arguably a bit more idiomatic in Python in that it
> is usually encouraged to follow the "Easier to ask for forgiveness
> than permission" approach.
>
> Lina, would you like to submit yours? Or do you prefer a `Link: ` /
> `Reported-by: ` / `Co-developed-by: ` here?
>
>> If `driver_mod` is a module of the crate `driver`, the directory `driver_mod`
>> may not contain `Makefile`, and `generate_rust_analyzer.py` will fail.
>
> By the way, note that in the kernel crate we are avoiding `mod.rs`
> files, instead using `name.rs` in the parent folder, in other to make
> it easier to find the files. I will add a note about it in the docs.
Thanks for pointing that out :)
BR Andreas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] scripts: rust-analyzer: Skip crate module directories
2023-03-07 12:38 ` Miguel Ojeda
2023-03-07 12:53 ` Andreas Hindborg
@ 2023-03-07 16:32 ` Gary Guo
2023-03-07 17:14 ` Miguel Ojeda
1 sibling, 1 reply; 7+ messages in thread
From: Gary Guo @ 2023-03-07 16:32 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Asahi Lina, Andreas Hindborg, rust-for-linux, Andreas Hindborg,
Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
Björn Roy Baron, open list
On Tue, 7 Mar 2023 13:38:10 +0100
Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> On Tue, Mar 7, 2023 at 1:08 PM Andreas Hindborg <nmi@metaspace.dk> wrote:
> >
> > When generating rust-analyzer configuration, skip module directories.
>
> This is https://github.com/Rust-for-Linux/linux/pull/883, also handled
> by Vinay's patch
> https://lore.kernel.org/rust-for-linux/20230118160220.776302-1-varmavinaym@gmail.com/.
>
> Lina's approach is arguably a bit more idiomatic in Python in that it
> is usually encouraged to follow the "Easier to ask for forgiveness
> than permission" approach.
>
> Lina, would you like to submit yours? Or do you prefer a `Link: ` /
> `Reported-by: ` / `Co-developed-by: ` here?
>
> > If `driver_mod` is a module of the crate `driver`, the directory `driver_mod`
> > may not contain `Makefile`, and `generate_rust_analyzer.py` will fail.
>
> By the way, note that in the kernel crate we are avoiding `mod.rs`
> files, instead using `name.rs` in the parent folder, in other to make
> it easier to find the files. I will add a note about it in the docs.
I personally think mod.rs makes it easier for me to find files because
all related stuff are contained inside a single directory, especially
the parent modules and submodules are closed related.
That's just personal opinion though.
Best,
Gary
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] scripts: rust-analyzer: Skip crate module directories
2023-03-07 16:32 ` Gary Guo
@ 2023-03-07 17:14 ` Miguel Ojeda
2023-04-06 22:33 ` Miguel Ojeda
0 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2023-03-07 17:14 UTC (permalink / raw)
To: Gary Guo, Wedson Almeida Filho
Cc: Asahi Lina, Andreas Hindborg, rust-for-linux, Andreas Hindborg,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Björn Roy Baron,
open list
On Tue, Mar 7, 2023 at 5:32 PM Gary Guo <gary@garyguo.net> wrote:
>
> I personally think mod.rs makes it easier for me to find files because
> all related stuff are contained inside a single directory, especially
> the parent modules and submodules are closed related.
>
> That's just personal opinion though.
I don't have a strong opinion either way -- this was originally done
to improve fuzzy searching, see commit 829c2df153d7 ("rust: move `net`
and `sync` modules to uniquely-named files") upstream:
This is so that each file in the module has a unique name instead of the
generic `mod.rs` name. It makes it easier to open files when using fuzzy
finders like `fzf` once names are unique.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] scripts: rust-analyzer: Skip crate module directories
2023-03-07 12:07 [PATCH] scripts: rust-analyzer: Skip crate module directories Andreas Hindborg
2023-03-07 12:38 ` Miguel Ojeda
@ 2023-04-06 22:33 ` Miguel Ojeda
1 sibling, 0 replies; 7+ messages in thread
From: Miguel Ojeda @ 2023-04-06 22:33 UTC (permalink / raw)
To: Andreas Hindborg, Asahi Lina
Cc: rust-for-linux, Andreas Hindborg, Miguel Ojeda, Alex Gaynor,
Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron,
open list
On Tue, Mar 7, 2023 at 1:08 PM Andreas Hindborg <nmi@metaspace.dk> wrote:
>
> When generating rust-analyzer configuration, skip module directories. This fixes
> an issue that occur if we have
>
> - drivers/block/driver.rs
> - drivers/block/driver_mod/mod.rs
>
> If `driver_mod` is a module of the crate `driver`, the directory `driver_mod`
> may not contain `Makefile`, and `generate_rust_analyzer.py` will fail.
I picked Lina's for `rust-fixes` from
https://github.com/Rust-for-Linux/linux/pull/883.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] scripts: rust-analyzer: Skip crate module directories
2023-03-07 17:14 ` Miguel Ojeda
@ 2023-04-06 22:33 ` Miguel Ojeda
0 siblings, 0 replies; 7+ messages in thread
From: Miguel Ojeda @ 2023-04-06 22:33 UTC (permalink / raw)
To: Gary Guo, Wedson Almeida Filho
Cc: Asahi Lina, Andreas Hindborg, rust-for-linux, Andreas Hindborg,
Miguel Ojeda, Alex Gaynor, Boqun Feng, Björn Roy Baron,
open list
On Tue, Mar 7, 2023 at 6:14 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> I don't have a strong opinion either way -- this was originally done
> to improve fuzzy searching, see commit 829c2df153d7 ("rust: move `net`
> and `sync` modules to uniquely-named files") upstream:
>
> This is so that each file in the module has a unique name instead of the
> generic `mod.rs` name. It makes it easier to open files when using fuzzy
> finders like `fzf` once names are unique.
Apparently the "encouraged" way is using `name.rs`:
https://doc.rust-lang.org/stable/reference/items/modules.html#module-source-filenames
https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html#no-more-modrs
Another argument I saw for `name.rs` is that one can easily the name
of the file in editor's tabs/titles, and some of the editors can add
part of the path to disambiguate, which may take more space in the UI.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-06 22:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-07 12:07 [PATCH] scripts: rust-analyzer: Skip crate module directories Andreas Hindborg
2023-03-07 12:38 ` Miguel Ojeda
2023-03-07 12:53 ` Andreas Hindborg
2023-03-07 16:32 ` Gary Guo
2023-03-07 17:14 ` Miguel Ojeda
2023-04-06 22:33 ` Miguel Ojeda
2023-04-06 22:33 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox