Message ID | 20230109204520.539080-6-ojeda@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2372222wrt; Mon, 9 Jan 2023 12:48:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBqE4roqqEoT94wSOQbISU4oTv6ERqHtnY5SXCiI4C0U/Z1sn5jLSNR44xxqEdrccQoe9f X-Received: by 2002:a05:6a20:3c91:b0:ad:5cde:8f05 with SMTP id b17-20020a056a203c9100b000ad5cde8f05mr100370622pzj.37.1673297313679; Mon, 09 Jan 2023 12:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297313; cv=none; d=google.com; s=arc-20160816; b=vHBHkiDszZ2GY02lXbqUm1qj7anrbmuxkkgaNg82e9AhEgduVyqMvECZ0GhRAHPg7d JdPz8L6mzxQzjzHTtk/bA3pJwkYE5G8qjo1IfL5mivSyntdDIirPUcDcG8nfyHIwnL3M 6vSStsvWOyzPJ0pPR3vZ3K3BSFrQ06cOXX0aJgVK8Dt9KEHniU3hvaugVjMyWSjrJDrE q/E4Xe26QHC0P1m0v+sHNWO5wWF0+HB1v6bfVDHn2E7h255pAyL673rJfDUlnVBMjyJU Ryvwz1+p6W0rAbeMBq2FBH62RnXEJ1WABwlqZL/JMtyldJ4Me9cDvc6nORvQZw8ykKzR Nxag== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EtFaJKcTxXKYJFq4R2/6JUojLkJ+YIgcvPt2RKiRmMY=; b=PTz+CoB5DxBHQr9fSYYL/Pj+mZFtNO68BPEwqfUhaDuoMJWHkAM5+K73QCgxqtRyqU WliZT/kN1pqBGJOSe/mRBf/xNBn/6CbbkS9mJAb2IN5KHpmeZRW8z2H4CnWB9CCJ3+zC RV/TboqMVyN4kB5pPkmCgXGGn9YIUJx59Gx8YyznQvU9djF+F7Dcmd5KBS57oFcgVBcd hj9tyLSkBIQEwE+UiEsV1ABVGxjhAIhUDwqxxueI7XS4AMbH7puM7tJB2GCdiSD6fTCT oEbJnW7HEicXpc5uENN3h9gZNVfqsaK1XrofdCRGGHV56+cm9FAB6nzZECb8sZbGO8UB 2Zkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=md6E83gI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u24-20020a63df18000000b00496731929d6si10032367pgg.780.2023.01.09.12.48.20; Mon, 09 Jan 2023 12:48:33 -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=@kernel.org header.s=k20201202 header.b=md6E83gI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237490AbjAIUq3 (ORCPT <rfc822;syz17693488234@gmail.com> + 99 others); Mon, 9 Jan 2023 15:46:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjAIUqM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 15:46:12 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FC6755D7; Mon, 9 Jan 2023 12:46:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 88F6BB80FE9; Mon, 9 Jan 2023 20:46:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B2F0C433EF; Mon, 9 Jan 2023 20:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297166; bh=UwE38YioG9dTqnBwoYpucHihCJ8r0LAOxRgPcDdHqlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=md6E83gIPs0q+cIi9mPU6xAs1exMIZwpNLcjfKZj9ntwkm+sTaENDo6dkGPwVXN6U Xw/8oJ+EYwdci1GfgUC31xhejRtHJo4niR8nZRaLcU63lYtYHW2aPcchBBA+MiinxJ A4vteyRB/s7a8KGj0QknTLQlXG4ZzIfwj9M5Q2ojzSIy6b3QpJqSYhq/n4PdIKTRgy zx7ymJQbnBZb2e3VbPws2+xMh6/gQWxSkubLZcWkTk5GfZ80hQd9dIJeQpxzvS/q6q Xpg9ugardquGSdJlGp1qZTjLyy8kLpKTLvdHHON4ppoE29OE8szZZVBOPLcOeszj5N aV3yOENwkKJkQ== From: Miguel Ojeda <ojeda@kernel.org> To: Masahiro Yamada <masahiroy@kernel.org> Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Nicolas Schier <nicolas@fjasle.eu>, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, 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> Subject: [PATCH 6/6] kbuild: rust_is_available: normalize version matching Date: Mon, 9 Jan 2023 21:45:20 +0100 Message-Id: <20230109204520.539080-6-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-1-ojeda@kernel.org> References: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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?1754579403625551622?= X-GMAIL-MSGID: =?utf-8?q?1754579403625551622?= |
Series |
[1/6] docs: rust: add paragraph about finding a suitable `libclang`
|
|
Commit Message
Miguel Ojeda
Jan. 9, 2023, 8:45 p.m. UTC
In order to match the version string, `sed` is used in a couple
cases, and `grep` and `head` in a couple others.
Make the script more consistent and easier to understand by
using the same method, `sed`, for all of them.
This makes the version matching also a bit more strict for
the changed cases, since the strings `rustc ` and `bindgen `
will now be required, which should be fine since `rustc`
complains if one attempts to call it with another program
name, and `bindgen` uses a hardcoded string.
In addition, clarify why one of the existing `sed` commands
does not provide an address like the others.
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
scripts/rust_is_available.sh | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
Comments
On Tue, Jan 10, 2023 at 5:46 AM Miguel Ojeda <ojeda@kernel.org> wrote: > > In order to match the version string, `sed` is used in a couple > cases, and `grep` and `head` in a couple others. > > Make the script more consistent and easier to understand by > using the same method, `sed`, for all of them. > > This makes the version matching also a bit more strict for > the changed cases, since the strings `rustc ` and `bindgen ` > will now be required, which should be fine since `rustc` > complains if one attempts to call it with another program > name, and `bindgen` uses a hardcoded string. > > In addition, clarify why one of the existing `sed` commands > does not provide an address like the others. > > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Maybe, your purpose is to use sed consistently, but perhaps you can avoid forking sed if you know the format of the first line. BTW, what is missing here is, you do not check if ${RUSTC} is really rustc. I can fool this script to print "arithmetic expression: expecting primary: "100000 * + 100 * + " $ make RUSTC=true rustavailable ./scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " *** *** Please see Documentation/rust/quick-start.rst for details *** on how to setup Rust support. *** make: *** [Makefile:1809: rustavailable] Error 2 scripts/{as,ld}-version.sh tried their best to parse the line with shell syntax only, and print "unknown assembler invoked" if the given tool does not seem to be a supported assembler. > --- > scripts/rust_is_available.sh | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh > index a86659410e48..99811842b61f 100755 > --- a/scripts/rust_is_available.sh > +++ b/scripts/rust_is_available.sh > @@ -66,8 +66,7 @@ fi > # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. > rust_compiler_version=$( \ > LC_ALL=C "$RUSTC" --version 2>/dev/null \ > - | head -n 1 \ > - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ > + | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' > ) > rust_compiler_min_version=$($min_tool_version rustc) > rust_compiler_cversion=$(get_canonical_version $rust_compiler_version) > @@ -94,8 +93,7 @@ fi > # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. > rust_bindings_generator_version=$( \ > LC_ALL=C "$BINDGEN" --version 2>/dev/null \ > - | head -n 1 \ > - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ > + | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' > ) > rust_bindings_generator_min_version=$($min_tool_version bindgen) > rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version) > @@ -139,6 +137,9 @@ fi > > # `bindgen` returned successfully, thus use the output to check that the version > # of the `libclang` found by the Rust bindings generator is suitable. > +# > +# Unlike other version checks, note that this one does not necessarily appear > +# in the first line of the output, thus no `sed` address is provided. > bindgen_libclang_version=$( \ > echo "$bindgen_libclang_output" \ > | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' > -- > 2.39.0 >
On Thu, Jan 12, 2023 at 7:23 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > Maybe, your purpose is to use sed consistently, but > perhaps you can avoid forking sed if you know the > format of the first line. The most unknown format would be the one of the libclang check, where there may be other lines before the one we are interested in. However, the pattern expansion would still match newlines, right? > BTW, what is missing here is, you do not check if > ${RUSTC} is really rustc. > > I can fool this script to print > "arithmetic expression: expecting primary: "100000 * + 100 * + " We can test if nothing was printed by `sed` for that (or do it with shell builtins). Having said that, I would say fooling the script on purpose is an more of an oddity compared to the case `MAKEFLAGS` attempts to cover (please see my reply on the other patch). So if we cover this, then I would say we should really cover the other one. Cheers, Miguel
On Sat, Jan 14, 2023 at 8:15 AM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Thu, Jan 12, 2023 at 7:23 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > Maybe, your purpose is to use sed consistently, but > > perhaps you can avoid forking sed if you know the > > format of the first line. > > The most unknown format would be the one of the libclang check, where > there may be other lines before the one we are interested in. However, > the pattern expansion would still match newlines, right? > > > BTW, what is missing here is, you do not check if > > ${RUSTC} is really rustc. > > > > I can fool this script to print > > "arithmetic expression: expecting primary: "100000 * + 100 * + " > > We can test if nothing was printed by `sed` for that (or do it with > shell builtins). > > Having said that, I would say fooling the script on purpose is an more > of an oddity compared to the case `MAKEFLAGS` attempts to cover > (please see my reply on the other patch). So if we cover this, then I > would say we should really cover the other one. get_canonical_version() in scripts/as-version.sh has a little more trick to avoid "arithmetic expression: expecting primary: "100000 * + 100 * + " but it is up to you. > Cheers, > Miguel
On Sun, Jan 15, 2023 at 11:48 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Sat, Jan 14, 2023 at 8:15 AM Miguel Ojeda > <miguel.ojeda.sandonis@gmail.com> wrote: > > > > On Thu, Jan 12, 2023 at 7:23 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > > > Maybe, your purpose is to use sed consistently, but > > > perhaps you can avoid forking sed if you know the > > > format of the first line. > > > > The most unknown format would be the one of the libclang check, where > > there may be other lines before the one we are interested in. However, > > the pattern expansion would still match newlines, right? > > > > > BTW, what is missing here is, you do not check if > > > ${RUSTC} is really rustc. > > > > > > I can fool this script to print > > > "arithmetic expression: expecting primary: "100000 * + 100 * + " > > > > We can test if nothing was printed by `sed` for that (or do it with > > shell builtins). > > > > Having said that, I would say fooling the script on purpose is an more > > of an oddity compared to the case `MAKEFLAGS` attempts to cover > > (please see my reply on the other patch). So if we cover this, then I > > would say we should really cover the other one. > > > > get_canonical_version() in scripts/as-version.sh has > a little more trick to avoid > "arithmetic expression: expecting primary: "100000 * + 100 * + " > but it is up to you. My code accepts anything that is separated by dots (and non-numerical strings are silently turned into zero). Your code takes exactly the "([0-9]+\.[0-9]+\.[0-9]+)" pattern, so it works very safely. I think using sed is fine.
diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index a86659410e48..99811842b61f 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -66,8 +66,7 @@ fi # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. rust_compiler_version=$( \ LC_ALL=C "$RUSTC" --version 2>/dev/null \ - | head -n 1 \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ + | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_compiler_min_version=$($min_tool_version rustc) rust_compiler_cversion=$(get_canonical_version $rust_compiler_version) @@ -94,8 +93,7 @@ fi # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. rust_bindings_generator_version=$( \ LC_ALL=C "$BINDGEN" --version 2>/dev/null \ - | head -n 1 \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ + | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_bindings_generator_min_version=$($min_tool_version bindgen) rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version) @@ -139,6 +137,9 @@ fi # `bindgen` returned successfully, thus use the output to check that the version # of the `libclang` found by the Rust bindings generator is suitable. +# +# Unlike other version checks, note that this one does not necessarily appear +# in the first line of the output, thus no `sed` address is provided. bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'