From nobody Tue Jun 23 06:12:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03458C433EF for ; Wed, 9 Mar 2022 19:43:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237985AbiCITod (ORCPT ); Wed, 9 Mar 2022 14:44:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237984AbiCITob (ORCPT ); Wed, 9 Mar 2022 14:44:31 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F5BE1216A9; Wed, 9 Mar 2022 11:43:32 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E26E11692; Wed, 9 Mar 2022 11:43:31 -0800 (PST) Received: from e121896.arm.com (unknown [10.57.41.86]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 694133FA27; Wed, 9 Mar 2022 11:43:30 -0800 (PST) From: James Clark To: acme@kernel.org, linux-perf-users@vger.kernel.org Cc: James Clark , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org Subject: [PATCH 1/1] perf tools: Use Python devtools for version autodetection rather than runtime Date: Wed, 9 Mar 2022 19:43:13 +0000 Message-Id: <20220309194313.3350126-2-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220309194313.3350126-1-james.clark@arm.com> References: <20220309194313.3350126-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This fixes the issue where the build will fail if only the Python2 runtime is installed but the Python3 devtools are installed. Currently the workaround is 'make PYTHON=3Dpython3'. Fix it by autodetecting Python based on whether python[x]-config exists rather than just python[x] because both are needed for the build. Then -config is stripped to find the Python runtime. Testing =3D=3D=3D=3D=3D=3D=3D * Auto detect links with Python3 when the v3 devtools are installed and only Python 2 runtime is installed * Auto detect links with Python2 when both devtools are installed * Sensible warning is printed if no Python devtools are installed * 'make PYTHON=3Dx' still automatically sets PYTHON_CONFIG=3Dx-config * 'make PYTHON=3Dx' fails if x-config doesn't exist * 'make PYTHON=3Dpython3' overrides Python2 devtools * 'make PYTHON=3Dpython2' overrides Python3 devtools * 'make PYTHON_CONFIG=3Dx-config' works * 'make PYTHON=3Dx PYTHON_CONFIG=3Dx' works * 'make PYTHON=3Dmissing' reports an error * 'make PYTHON_CONFIG=3Dmissing' reports an error Fixes: 79373082fa9d ("perf python: Autodetect python3 binary") Signed-off-by: James Clark --- tools/perf/Makefile.config | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 96ad944ca6a8..b3fbb746e7f0 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -239,18 +239,33 @@ ifdef PARSER_DEBUG endif =20 # Try different combinations to accommodate systems that only have -# python[2][-config] in weird combinations but always preferring -# python2 and python2-config as per pep-0394. If python2 or python -# aren't found, then python3 is used. -PYTHON_AUTO :=3D python -PYTHON_AUTO :=3D $(if $(call get-executable,python3),python3,$(PYTHON_AUTO= )) -PYTHON_AUTO :=3D $(if $(call get-executable,python),python,$(PYTHON_AUTO)) -PYTHON_AUTO :=3D $(if $(call get-executable,python2),python2,$(PYTHON_AUTO= )) -override PYTHON :=3D $(call get-executable-or-default,PYTHON,$(PYTHON_AUTO= )) -PYTHON_AUTO_CONFIG :=3D \ - $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-con= fig) -override PYTHON_CONFIG :=3D \ - $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON_AUTO_CONFIG)) +# python[2][3]-config in weird combinations in the following order of +# priority from lowest to highest: +# * python3-config +# * python-config +# * python2-config as per pep-0394. +# * $(PYTHON)-config (If PYTHON is user supplied but PYTHON_CONFIG isn't) +# +PYTHON_AUTO :=3D python-config +PYTHON_AUTO :=3D $(if $(call get-executable,python3-config),python3-config= ,$(PYTHON_AUTO)) +PYTHON_AUTO :=3D $(if $(call get-executable,python-config),python-config,$= (PYTHON_AUTO)) +PYTHON_AUTO :=3D $(if $(call get-executable,python2-config),python2-config= ,$(PYTHON_AUTO)) + +# If PYTHON is defined but PYTHON_CONFIG isn't, then take $(PYTHON)-config= as if it was the user +# supplied value for PYTHON_CONFIG. Because it's "user supplied", error ou= t if it doesn't exist. +ifdef PYTHON + ifndef PYTHON_CONFIG + PYTHON_CONFIG_AUTO :=3D $(call get-executable,$(PYTHON)-config) + PYTHON_CONFIG :=3D $(if $(PYTHON_CONFIG_AUTO),$(PYTHON_CONFIG_AUTO),\ + $(call $(error $(PYTHON)-config not found))) + endif +endif + +# Select either auto detected python and python-config or use user supplie= d values if they are +# defined. get-executable-or-default fails with an error if the first argu= ment is supplied but +# doesn't exist. +override PYTHON_CONFIG :=3D $(call get-executable-or-default,PYTHON_CONFIG= ,$(PYTHON_AUTO)) +override PYTHON :=3D $(call get-executable-or-default,PYTHON,$(subst -conf= ig,,$(PYTHON_AUTO))) =20 grep-libs =3D $(filter -l%,$(1)) strip-libs =3D $(filter-out -l%,$(1)) --=20 2.28.0