From patchwork Fri Jun 16 00:16:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 108776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1014724vqr; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OB+3KI8gnO+NpeSVCePY2uLHVM/Tr2Hx9rzWwSwJJVFV2gZxWJTJmBH2S/h+tF1RrOvKm X-Received: by 2002:ad4:4ee9:0:b0:626:199e:1b96 with SMTP id dv9-20020ad44ee9000000b00626199e1b96mr639089qvb.64.1686877590501; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686877590; cv=none; d=google.com; s=arc-20160816; b=iUzWWI6LNEeRzu+EGQYyRKyMoeYjPbZij3W4cH/UR7psGgBqYL5qezuxWRmt+TfZvU /Fto5pqVeBlbVjRTTZp80dqSubui17oZThpMxLdfPec8Adv+42Fuk6UhrKW6kyvSS0Dn nOyEuFgUhd1KmSvgReL78AfN2kkMjzVUwxxzC08/Kh/wLM4Ev1NjaYsYhngRLTG6oLSz D53oEkgyUBZ54lY2M16RAYf8OKOLozWw+tb+TwOjQ7fK/jS+AuklA8Cesu6EntL+CE+p htwFs4gR7gfrRNmKTNB82SQeo9Yy14LwGmHg7EHCHQeKu1rZ6WZtJtetMxPY6Yaf4nk4 htaQ== 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=AEKl23U6D8iZUiMGbnFeXiLZouURaclE6xOG8ePhz7s=; b=Dekj5QHwEdqRDXlAVF1vd0JvEFIPjL3pv5kDdnp+ox1etyp91lfatPT/9TZDzVGHla UaFL1dY9jnbITMHhcOY3XPMRa/hLzQtRIcHZAfKdc2GvfRkuTabfKvP51GkUx7P9OpBB WNaE05nqMRPJgIv7Xkh99f9rXTb/iTVNxJVv01fshqOIX9CQS9Egx0wsnCzBiPhEsdPj rebewCfO9hCwmeFV/o+7FSkUjkDvJ72OkzmSlwi7s4okr/QgprbpM0YVPbQGV+FuAlBV w9zBuswXW/x+HXJy/PaFgwpKUAxhk3uQAX9YgVWvsmFBh0MntuhnlC8P24KHZ4JSoWUz OnjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ES+EVWrn; 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 az9-20020a056a02004900b0053fbb2ddb4csi14353532pgb.36.2023.06.15.18.06.07; Thu, 15 Jun 2023 18:06:30 -0700 (PDT) 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=ES+EVWrn; 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 S240791AbjFPASa (ORCPT + 99 others); Thu, 15 Jun 2023 20:18:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241119AbjFPASR (ORCPT ); Thu, 15 Jun 2023 20:18:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B8D2962; Thu, 15 Jun 2023 17:17:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A3F09628A3; Fri, 16 Jun 2023 00:17:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09FCCC433C8; Fri, 16 Jun 2023 00:17:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874655; bh=iTX/Tcy5uIzvUJfO9A3D/AYRTPs+VCsc4/kXRmaB9Ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ES+EVWrnknZ8OqSaMlle32nh0KsO+2uIP/IbiHmnD26SD+GiR3e+Wdj8GR4bpY6qo 73zdhxQnNdXZQ5c0LP+uNPrmmtzvdv4WaMSm8JDgtvADsd25Oti6RG/snw/jsZWgvt GKBMINCiQejkb45HlZOx8nJWAtu9DtYuORZtGmw39ucs4n36oBViwy3LSif1dorT/S 36R5eSs77I38dH5TDQB8sWljzsUuii/2PNGIET5KwWaVnhQ6aWM+BscB8gKAyaMKIb 1/oKQvA4oUyaiYl1UT/KdrhqXp4NNWriCZfdx4iQbudYn4av2t4TJEwMeZuy1GxTk/ lJhZK59GaknWw== From: Miguel Ojeda To: Masahiro Yamada , Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , linux-kbuild@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 09/11] kbuild: rust_is_available: handle failures calling `$RUSTC`/`$BINDGEN` Date: Fri, 16 Jun 2023 02:16:29 +0200 Message-ID: <20230616001631.463536-10-ojeda@kernel.org> In-Reply-To: <20230616001631.463536-1-ojeda@kernel.org> References: <20230616001631.463536-1-ojeda@kernel.org> MIME-Version: 1.0 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,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768819355992772799?= X-GMAIL-MSGID: =?utf-8?q?1768819355992772799?= The script already checks if `$RUSTC` and `$BINDGEN` exists via `command`, but the environment variables may point to a non-executable file, or the programs may fail for some other reason. While the script successfully exits with a failure as it should, the error given can be quite confusing depending on the shell and the behavior of its `command`. For instance, with `dash`: $ RUSTC=./mm BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " Thus detect failure exit codes when calling `$RUSTC` and `$BINDGEN` and print a better message, in a similar way to what we do when extracting the `libclang` version found by `bindgen`. Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQYk6s11MASRHW6oxtkqF00EJVqhHOP=5rynWt-QDUsXw@mail.gmail.com/ Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Nathan Chancellor --- scripts/rust_is_available.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index b7e0781fdea9..da8296cd9b8d 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -81,8 +81,20 @@ fi # Check that the Rust compiler version is suitable. # # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. +rust_compiler_output=$( \ + LC_ALL=C "$RUSTC" --version 2>/dev/null +) || rust_compiler_code=$? +if [ -n "$rust_compiler_code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$RUSTC' to check the Rust compiler version failed with" + echo >&2 "*** code $rust_compiler_code. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$rust_compiler_output" + echo >&2 "***" + exit 1 +fi rust_compiler_version=$( \ - LC_ALL=C "$RUSTC" --version 2>/dev/null \ + echo "$rust_compiler_output" \ | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_compiler_min_version=$($min_tool_version rustc) @@ -108,8 +120,20 @@ fi # Check that the Rust bindings generator is suitable. # # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. +rust_bindings_generator_output=$( \ + LC_ALL=C "$BINDGEN" --version 2>/dev/null +) || rust_bindings_generator_code=$? +if [ -n "$rust_bindings_generator_code" ]; then + echo >&2 "***" + echo >&2 "*** Running '$BINDGEN' to check the Rust bindings generator version failed with" + echo >&2 "*** code $rust_bindings_generator_code. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$rust_bindings_generator_output" + echo >&2 "***" + exit 1 +fi rust_bindings_generator_version=$( \ - LC_ALL=C "$BINDGEN" --version 2>/dev/null \ + echo "$rust_bindings_generator_output" \ | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_bindings_generator_min_version=$($min_tool_version bindgen)