Received: from list by lists.gnu.org with archive (Exim 4.71) id 1g2bpR-0006U3-F0 for mharc-grub-devel@gnu.org; Wed, 19 Sep 2018 08:43:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2bpN-0006Sy-Gd for grub-devel@gnu.org; Wed, 19 Sep 2018 08:43:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2bpK-00059L-5Z for grub-devel@gnu.org; Wed, 19 Sep 2018 08:43:33 -0400 Received: from dibed.net-space.pl ([84.10.22.86]:43386) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.71) (envelope-from ) id 1g2bpI-00055v-8V for grub-devel@gnu.org; Wed, 19 Sep 2018 08:43:30 -0400 Received: (from localhost user: 'dkiper' uid#4000 fake: STDIN (dkiper@dibed.net-space.pl)) by router-fw-old.i.net-space.pl id S1870379AbeISMnW (ORCPT ); Wed, 19 Sep 2018 14:43:22 +0200 Date: Wed, 19 Sep 2018 14:43:22 +0200 From: Daniel Kiper To: Adam Williamson Cc: The development of GNU GRUB , Daniel Kiper Subject: Re: Patch: allow the 'python' used to run gentpl.py to be configured Message-ID: <20180919124322.GA7003@router-fw-old.i.net-space.pl> References: <20180706172545.GA14342@router-fw-old.local.net-space.pl> <167358216f61c5136d6d6db4fa074f0d171683ae.camel@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <167358216f61c5136d6d6db4fa074f0d171683ae.camel@redhat.com> User-Agent: Mutt/1.3.28i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 84.10.22.86 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 12:43:36 -0000 On Tue, Jul 17, 2018 at 12:35:42PM -0700, Adam Williamson wrote: > On Fri, 2018-07-06 at 13:19 -0700, Adam Williamson wrote: > > On Fri, 2018-07-06 at 19:25 +0200, Daniel Kiper wrote: > > > On Wed, Jul 04, 2018 at 10:08:53AM -0700, Adam Williamson wrote: > > > > gentpl.py is python2/3-agnostic, but there's no way to cause it > > > > to be run with any interpreter other than 'python', it's just > > > > hard-coded into Makefile.common that way. Adjust that to allow > > > > a make variable PYTHONBIN to be set to the desired interpreter. > > > > This will make it easier in situations where we specifically > > > > want to build with 'python2' or 'python3' or whatever. > > > > > > > > Signed-off-by: Adam Williamson > > > > > > Thanks for the patch. However, I think that the configure should find > > > correct python binary and set PYTHON variable (instead of PYTHONBIN) > > > in the Makefile (good example is BUILD_CC variable in Makefile.in). > > > > That's possible, but it depends what you mean by "correct", doesn't it? > > There could be many python interpreters installed on a system; which > > are we to assume is "correct"? > > > > We could make it configurable with some sort of default heuristic, I > > guess, I was just going for a simple patch approximately in line with > > what was done for autogen.sh for now. (And I wouldn't want to reinvent > > python interpreter discovery, which has been invented enough times > > already; if we were to go that route it'd probably make sense to use an > > existing autoconf extension or something). > > So I've just been looking into this, and it's actually very easy to do > using AM_PATH_PYTHON, provided by autoconf. However, there's a rather > funny wrinkle for grub's particular build process. AM_PATH_PYTHON has a > documented behaviour where, if the 'PYTHON' env var is set when > autoconf is run, it will *only* consider the value that env var is set > to as a candidate for the Python interpreter - it won't do its usual > attempt to discover one. And grub's autogen.sh already uses the PYTHON > env var - setting it if it was not set already - and then calls > autoreconf! > > So the practical effect of just applying this patch would be that only > 'python', or whatever the env var PYTHON is set to when running > autogen.sh, would be considered, when using autogen.sh. All the > 'discovery' bits of AM_PATH_PYTHON wouldn't be used: if you just call > 'autogen.sh' without setting PYTHON, but your Python binary is called > 'python3' or 'python2.7' or whatever, it won't work. > > This seems a bit funny, but I'm not sure if it's really a > *problem*...because autogen.sh *itself* will only work if whatever > value PYTHON is set to is a working Python interpreter, anyway. We > could in fact argue that the consequence is quite nice as it makes > everything sort of consistent: whatever PYTHON is set to will be the > interpreter used both by autogen.sh and for running gentpl.py. But I > figured I should point it out. > > With that in mind, I'm attaching the updated patch in git format. > Thanks! > From 5fc0bb5f16a4189aa9581ebca4ea3abbc5c96593 Mon Sep 17 00:00:00 2001 > From: Adam Williamson > Date: Wed, 4 Jul 2018 09:55:52 -0700 > Subject: [PATCH] Use AM_PATH_PYTHON to determine interpreter for gentpl.py > > gentpl.py is python2/3-agnostic, but there's no way to cause it > to be run with any interpreter other than 'python', it's just > hard-coded into Makefile.common that way. Adjust that to use > AM_PATH_PYTHON (provided by automake) to find an interpreter > and run gentpl.py with that instead. This makes grub buildable > when `python` does not exist (but rather `python3` or `python2` > or `python2.7`, etc.) Minimum version is set to 2.6 as this is > the first version with `__future__.print_function` available. > > Note, AM_PATH_PYTHON respects the PYTHON environment variable > and will treat its value as the *only* candidate for a valid > interpreter if it is set - when PYTHON is set, AM_PATH_PYTHON > will not try to find any alternative interpreter, it will only > check whether the interpreter set as the value of PYTHON meets > the requirements and use it if so or fail if not. This means > that when using grub's `autogen.sh`, as it too uses the value > of the PYTHON environment variable (and if it is not set, just > sets it to 'python') you cannot rely on AM_PATH_PYTHON > interpreter discovery. If your desired Python interpreter is > not just 'python', you must set the PYTHON environment variable, > e.g. 'PYTHON=/usr/local/bin/python3 ./autogen.sh'. The specified > interpreter will then be used both by autogen.sh itself and by > the autotools-driven build scripts. > > Signed-off-by: Adam Williamson Reviewed-by: Daniel Kiper Daniel