Message ID | 20230109204520.539080-5-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 p1csp2372793wrt; Mon, 9 Jan 2023 12:49:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUObgEtfqY1uT389s3PZOK4SFJ0JRd6RuVf8YQaIFcaKt3rH+DVbipz0qj85ZbKQMUu9Cb X-Received: by 2002:a17:90a:af85:b0:223:f385:bb72 with SMTP id w5-20020a17090aaf8500b00223f385bb72mr67499709pjq.49.1673297395594; Mon, 09 Jan 2023 12:49:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297395; cv=none; d=google.com; s=arc-20160816; b=dzm+gprho7oDrY1Ya8iP6h4LYV/jSfRAW3svIFToT9hjyMWfk2KmVr9/X3bv0Bhqtu 9CQJ5scbaQddVsBCXJZ703oOdSJlD+OtUTucOUUFi338IWMaYKrBzxt6dW5sRweN99kx 4/Q3FbP1lHTNeMm0sIFpg5ImWIum8A2K97kK6+z487gCgTNmk+XGCcz0w9vQbHfakD35 +3gWDtUWabFMzpkzkoAX4bHWK77WKPCJsruEC/1/irO2zQNR0eZqyyjLAVH6nb896g7k 2186jR7oHAHlKAKwNYX4B0Z2h2aoBeZ3aQvNq9vbbhASl6HqPck/SqNCsGrkSXHqLJY0 NS/w== 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=9+W9jj4caIYbq0EH7wrqETCcuCmoDOwqCsIH3zHLq00=; b=oIrVH6u04YeZONabsG1ZQX6I0jyW/X2e4mLHfBq9gyoNh0ZpL5v5StVy3BRCTVZpmp uixEwKpmcODXjLck7Gbfis7gwi9C+XhNhkE7ahLsApLQODw+wKIC06ftY8dtGOubIOpW C7t/dvNtkktbTTOrDTzp1wVxWrOKQpG4QZhix8pHtFk5JBa+MqsvVpoRL7GvPoAsD07R gedNcIhioneIiCRhIe0TFLYoLpxE9d1j+4JxCw6rXiu3cKzePB6a5tpeK/zTy+F+yaQh kmvSSpTAk/CNZR4lQw4MCEpOkhTlTti/LozC1ZXuKWuYN53Nx1OvKBj5j2Ecc5edZvoM 64Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nU3KceGN; 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 s133-20020a632c8b000000b004ad1e82a3e6si8777677pgs.554.2023.01.09.12.49.43; Mon, 09 Jan 2023 12:49:55 -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=nU3KceGN; 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 S234593AbjAIUq0 (ORCPT <rfc822;syz17693488234@gmail.com> + 99 others); Mon, 9 Jan 2023 15:46:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237666AbjAIUqL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Jan 2023 15:46:11 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A06573E3A; Mon, 9 Jan 2023 12:46:05 -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 2979DB80FE1; Mon, 9 Jan 2023 20:46:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F207FC433F0; Mon, 9 Jan 2023 20:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297162; bh=v6aIwGe42UpqRaNoSLoyuLZZtQ4F5eJRx+9gWWQ/eO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nU3KceGNxWBQHIw4s9cYt/+dB4mBbRCcVDxEWhD97wuWQx1pW1cuVmiFxvPG9ovqa LxqUYYF5JfpArpnr/OW8MnFdtsjss8Ty3NY+79and96nOyJw7ZDi0QG1HW99e1fvst Gywb+jPHB/nGT9VLU29DM6/QAjgWK7ILl8TDVMoxnPgBccHuG757H4SivxGK2bBnEa 2WjPHnV4T1u27okoMT6T2s++THucuyYlW1KeKmoel2+tv4sTATR1t1zRIGjjBDDDAh Bzn8HdMYfZXbz6+btbSMvCHuYP3rH08v98r9FFecybgSZWb2IJU7KfqJ+0OynWfB7B ObscqPXnQLETw== 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 5/6] kbuild: rust_is_available: fix confusion when a version appears in the path Date: Mon, 9 Jan 2023 21:45:19 +0100 Message-Id: <20230109204520.539080-5-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?1754579489520084990?= X-GMAIL-MSGID: =?utf-8?q?1754579489520084990?= |
Series |
[1/6] docs: rust: add paragraph about finding a suitable `libclang`
|
|
Commit Message
Miguel Ojeda
Jan. 9, 2023, 8:45 p.m. UTC
`bindgen`'s output for `libclang`'s version check contains paths, which
in turn may contain strings that look like version numbers [1]:
.../6.1.0-dev/.../rust_is_available_bindgen_libclang.h:2:9: warning: clang version 11.1.0 [-W#pragma-messages], err: false
which the script will pick up as the version instead of the latter.
It is also the case that versions may appear after the actual version
(e.g. distribution's version text), which was the reason behind `head` [2]:
.../rust-is-available-bindgen-libclang.h:2:9: warning: clang version 13.0.0 (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false
Thus instead ask for a match after the `clang version` string.
Reported-by: Jordan (@jordanisaacs)
Link: https://github.com/Rust-for-Linux/linux/issues/942 [1]
Link: https://github.com/Rust-for-Linux/linux/pull/789 [2]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
scripts/rust_is_available.sh | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
Comments
On Tue, Jan 10, 2023 at 5:46 AM Miguel Ojeda <ojeda@kernel.org> wrote: > > `bindgen`'s output for `libclang`'s version check contains paths, which > in turn may contain strings that look like version numbers [1]: > > .../6.1.0-dev/.../rust_is_available_bindgen_libclang.h:2:9: warning: clang version 11.1.0 [-W#pragma-messages], err: false > > which the script will pick up as the version instead of the latter. > > It is also the case that versions may appear after the actual version > (e.g. distribution's version text), which was the reason behind `head` [2]: > > .../rust-is-available-bindgen-libclang.h:2:9: warning: clang version 13.0.0 (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false > > Thus instead ask for a match after the `clang version` string. > > Reported-by: Jordan (@jordanisaacs) > Link: https://github.com/Rust-for-Linux/linux/issues/942 [1] > Link: https://github.com/Rust-for-Linux/linux/pull/789 [2] > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> > --- > scripts/rust_is_available.sh | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh > index 0c082a248f15..a86659410e48 100755 > --- a/scripts/rust_is_available.sh > +++ b/scripts/rust_is_available.sh > @@ -141,9 +141,7 @@ fi > # of the `libclang` found by the Rust bindings generator is suitable. > bindgen_libclang_version=$( \ > echo "$bindgen_libclang_output" \ > - | grep -F 'clang version ' \ > - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ > - | head -n 1 \ > + | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' > ) > bindgen_libclang_min_version=$($min_tool_version llvm) > bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) > -- > 2.39.0 > You do not need to fork sed. diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 1f478d7e0f77..ebe427e27379 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -137,14 +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. -bindgen_libclang_version=$( \ - echo "$bindgen_libclang_output" \ - | grep -F 'clang version ' \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ - | head -n 1 \ -) +set -- ${bindgen_libclang_output#**clang version} +bindgen_libclang_cversion=$(get_canonical_version $1) bindgen_libclang_min_version=$($min_tool_version llvm) -bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) bindgen_libclang_min_cversion=$(get_canonical_version $bindgen_libclang_min_version) if [ "$bindgen_libclang_cversion" -lt "$bindgen_libclang_min_cversion" ]; then echo >&2 "***"
On Thu, Jan 12, 2023 at 6:32 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > +set -- ${bindgen_libclang_output#**clang version} > +bindgen_libclang_cversion=$(get_canonical_version $1) > bindgen_libclang_min_version=$($min_tool_version llvm) > -bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) Nice trick :) To be honest, I am not really fond of `set`, and in this case it means the command is not symmetric (we remove the prefix using parameter expansion, and the suffix via positional argument selection), but if you prefer it that way, I think it would be fine. However, why the double asterisk? One already matches any string, including spaces, no? Cheers, Miguel
On Mon, Jan 9, 2023 at 9:46 PM Miguel Ojeda <ojeda@kernel.org> wrote: > > Reported-by: Jordan (@jordanisaacs) Cc'ing Jordan who gave us the email address in GitHub and wants to send a `Tested-by` tag. Cheers, Miguel
On Sat, Jan 14, 2023 at 8:13 AM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Thu, Jan 12, 2023 at 6:32 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > +set -- ${bindgen_libclang_output#**clang version} > > +bindgen_libclang_cversion=$(get_canonical_version $1) > > bindgen_libclang_min_version=$($min_tool_version llvm) > > -bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) > > Nice trick :) To be honest, I am not really fond of `set`, and in this > case it means the command is not symmetric (we remove the prefix using > parameter expansion, and the suffix via positional argument > selection), but if you prefer it that way, I think it would be fine. I just tend to write efficient code. (scripts/{cc,ld,as}-version.sh do not use sed or grep at all.) Especially, I avoid unneeded process forks in the process forks. > However, why the double asterisk? One already matches any string, > including spaces, no? Sorry, it is my mistake. I meant double pound. set -- ${bindgen_libclang_output##*clang version} The double pound strips "the longest matching pattern", just in case "clang version" is contained in the file path. (but if a space is contained in the directory path, it would have failed earlier. > > Cheers, > Miguel -- Best Regards Masahiro Yamada
diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 0c082a248f15..a86659410e48 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -141,9 +141,7 @@ fi # of the `libclang` found by the Rust bindings generator is suitable. bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ - | grep -F 'clang version ' \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ - | head -n 1 \ + | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) bindgen_libclang_min_version=$($min_tool_version llvm) bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version)