Message ID | 20230307120736.75492-1-nmi@metaspace.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2398343wrd; Tue, 7 Mar 2023 04:24:47 -0800 (PST) X-Google-Smtp-Source: AK7set9eEUJpJJZBxuQ9QRC0LABZraFIPGC10kJyEkEH1qmViI9l4Q16Jq0atFEiDl7s0Ce1kc/R X-Received: by 2002:a05:6a20:8f2a:b0:cc:50cd:e0bc with SMTP id b42-20020a056a208f2a00b000cc50cde0bcmr13222926pzk.10.1678191887333; Tue, 07 Mar 2023 04:24:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678191887; cv=none; d=google.com; s=arc-20160816; b=SAtyUey1bSXpUeWLCSZX0ZyQbLG6JkGUd+9vpKlWcnIj/w2RN23fB1xEmyQoOQgDZn +H0HnkBjAnMojXHBuDk4XbLzoLqTBbDNXCZaJuo6yhFn+w1CGnTtfOywwKPKb2mdQzbu JTCrCq6t0shQiE5ROy94LqTs0wTl8uAXRKDj05DPLBhRMCbpcVcx8lk98ZQf801YWl+Q S2+1aOxKUFK+sx+ctauzeEAzzWmG2yeMnaQdmwvKOedfm5ep+nuMVzvVX2SjigGVDB0n HzMJ1vIEWJSbqyHYaSW8Kfag22Iv+OQJvJfED3px+8X4knVqCg4eSm7tyKHN92W5JbE7 DQNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=N8+KuBNUOvMkQ5tG78D1gymPnKoB/geR+L27cmc6zCU=; b=oVFToT6hIVuGihg2X2bBBKssoA0lPP/4+QLs/aEJM0CiMmW8teNGFpWqfrf1Gbqvsi tEvFhyoSqjJZMDc3HNkZJhgsXuTh01eBFBUmD+RH1F59IzXW12yd8k4eEbBtvtxLS3aL kQhmpKDDr/4ltJvzn4xyL9gKslsXZKWTJkYPHWipkZkX0wwe7jVlbV4Mkj+Q4V2GrmMx xopaZXGzofDaOAulItlpulwd7P65EXicbf+iRVXAQ4CLb9+G81rEwCk1ZN0tYsTEmNXD yITPEGpNTSypu72+JTad1YfjSX+6QEsrTVOPW5gey2cotIa6foDP6x3D5CRi8249IrGo 0Liw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=JZiHCHIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 17-20020a630011000000b004fc274006d9si12046640pga.368.2023.03.07.04.24.34; Tue, 07 Mar 2023 04:24:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=JZiHCHIF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231293AbjCGMIH (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 7 Mar 2023 07:08:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbjCGMIF (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 7 Mar 2023 07:08:05 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A018B37F28 for <linux-kernel@vger.kernel.org>; Tue, 7 Mar 2023 04:08:03 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id az36so7611939wmb.1 for <linux-kernel@vger.kernel.org>; Tue, 07 Mar 2023 04:08:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20210112.gappssmtp.com; s=20210112; t=1678190882; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=N8+KuBNUOvMkQ5tG78D1gymPnKoB/geR+L27cmc6zCU=; b=JZiHCHIFrKxIz+YAYok47ojhjGpd5HwreP81Bh/lztS9vQDw3MXjwvGiui7nRTyoaQ PRCXJJ2z/aVQNYI+CoywYgwTyaUqJY1EX433/qaD0v6YMv0OzGDgneR3iiLpl3zWZltx S5EWYYG6935vjVpUmlqFRQwVVtx3wvWt+dXqrm50NxWKMSp5GKqKQtwjDA2Sbuc2aqyZ AO7mUNqW3+gBhC1eNajMLFKpMMW+TN1wNX9uruW+dxJrI+sTQ41XnkCgmmaDtxINXnE/ 4SWn6tOI3YOiJb8NRC3tKMAMgJH6khkfYce0wUmpT9PF0zqjG6DW9fzEJKwSSnQRN2XU bI/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678190882; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=N8+KuBNUOvMkQ5tG78D1gymPnKoB/geR+L27cmc6zCU=; b=vuNgYmUmwG7udQ/YI2Unrd+aNhHjx4s+XFMX1v+Aaz9QaJnYFzbywiCGxznGZ/Rtzp hAZ9IAfNUvLlCYrcx+uKApUBBzqhHkayz/9jOqTJAt6h2t1iZSVWPgJgf37rRWwmAylj PJAbSEnVXPBDJsa+7CfSv8kTepv8EWOEQv6a0CH/Pf2PGmrVr0tfHtLJAHmG5tBf3nw8 qEqeO5Gni4ZSbiU6pXLGFzGDgSx2ZTucRfCEByRr8hjNDUilOq8sSJTcH3cdnhVZVKP8 eCmk0+KLfIQz5u8rbTTzi5WzNrz7YzKVEj86azNUziqhEcZfHKtr4Rb5IsEH88FD43Dr ybig== X-Gm-Message-State: AO0yUKUSYFHPok4w1iB4wlwHgX2tuFAbNxjuiRoIcnYAVWxhMIJ0rYeY HX1geY+lw+clAW/1fOgE0fwmMg== X-Received: by 2002:a05:600c:4688:b0:3eb:42fc:fb30 with SMTP id p8-20020a05600c468800b003eb42fcfb30mr12992036wmo.32.1678190882157; Tue, 07 Mar 2023 04:08:02 -0800 (PST) Received: from localhost ([147.161.155.97]) by smtp.gmail.com with ESMTPSA id v38-20020a05600c4da600b003eb68bb61c8sm12351014wmp.3.2023.03.07.04.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 04:08:01 -0800 (PST) From: Andreas Hindborg <nmi@metaspace.dk> To: rust-for-linux@vger.kernel.org Cc: Andreas Hindborg <a.hindborg@samsung.com>, Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, linux-kernel@vger.kernel.org (open list) Subject: [PATCH] scripts: rust-analyzer: Skip crate module directories Date: Tue, 7 Mar 2023 13:07:36 +0100 Message-Id: <20230307120736.75492-1-nmi@metaspace.dk> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759711736339314764?= X-GMAIL-MSGID: =?utf-8?q?1759711736339314764?= |
Series |
scripts: rust-analyzer: Skip crate module directories
|
|
Commit Message
Andreas Hindborg
March 7, 2023, 12:07 p.m. UTC
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(-)
base-commit: 8c20eb7e6a27b2c493b0bbb435e75cae7135634f
Comments
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
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
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
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
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
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
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)