qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] roms/edk2-build.sh: Allow to run edk2-build.sh from command line
Date: Fri, 14 Jun 2019 19:35:06 +0200	[thread overview]
Message-ID: <5ad8f71b-9266-8cab-f50d-37a992e67d91@redhat.com> (raw)
In-Reply-To: <62fae3fa-ba9d-6c38-ac8f-0e453ef396f8@redhat.com>

On 06/14/19 15:55, Philippe Mathieu-Daudé wrote:
> On 6/14/19 3:29 PM, Eric Blake wrote:
>> On 6/14/19 5:16 AM, Philippe Mathieu-Daudé wrote:
>>> Cc'ing Eric :)
>>>
>>
>>>> When running this script out of 'make', we get:
>>>>
>>>>   $ cd roms
>>>>   $ ./edk2-build.sh aarch64 --arch=AARCH64 --platform=ArmVirtPkg/ArmVirtQemu.dsc > /dev/null
>>>>   ./edk2-build.sh: line 46: MAKEFLAGS: unbound variable
>>>>
>>>> Fix this by checking the variable is defined before using it,
>>>> else use a default value.
>>>>
>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>>> ---
>>>>  roms/edk2-build.sh | 8 +++++++-
>>>>  1 file changed, 7 insertions(+), 1 deletion(-)

(1) "allow to run" is not correct English, to my understanding. This
form of "allow" requires an object. You could reformulate the subject
line as "allow edk2-build.sh to be invoked from the command line".


>>>> diff --git a/roms/edk2-build.sh b/roms/edk2-build.sh
>>>> index 4f46f8a6a2..5390228b4e 100755
>>>> --- a/roms/edk2-build.sh
>>>> +++ b/roms/edk2-build.sh
>>
>> This is running under /bin/bash (hmm - not '/bin/env bash' like other
>> scripts in qemu?), so...
>>
>>>> @@ -43,7 +43,13 @@ fi
>>>>  # any), for the edk2 "build" utility.
>>>>  source ../edk2-funcs.sh
>>>>  edk2_toolchain=$(qemu_edk2_get_toolchain "$emulation_target")
>>>> -edk2_thread_count=$(qemu_edk2_get_thread_count "$MAKEFLAGS")
>>>> +if [ -v MAKEFLAGS ]; then
>>
>> the non-portable bashism '[ -v' works. However, it's just as easy to
> 
> Ah, OK.
> 
>> work around this problem portably for all POSIX shells without needing 'if':
>>
>>>> +  edk2_thread_count=$(qemu_edk2_get_thread_count "$MAKEFLAGS")
>>>> +else
>>>> +  # We are not running within 'make', let the edk2 "build" utility to fetch
>>>> +  # the logical CPU count with Python's multiprocessing.cpu_count() method.
>>>> +  edk2_thread_count=0
>>>> +fi

(2) "let" doesn't take the preposition "to". I'd suggest:

  Let the edk2 "build" utility [] fetch ...


>>
>> edk2_thread_count=$(qemu_edk2_get_thread_count "${MAKEFLAGS:-0}")

(3) The expression

  edk2_thread_count=$(qemu_edk2_get_thread_count "${MAKEFLAGS:-0}")

would pass the string "0" as $1 to the qemu_edk2_get_thread_count()
function. That doesn't seem useful (please see the docs on said shell
function).

We could write

  edk2_thread_count=$(qemu_edk2_get_thread_count "${MAKEFLAGS:-}")

instead, to pass "". But that would cause qemu_edk2_get_thread_count()
to print "1", which is not what we want here, AIUI.


I think I prefer the approach with "[ -v". While it's nonportable,
"edk2-build.sh" is already -- consciously -- so: it uses an array
variable, for example.


(4) Phil, did you regression-test this change with plain "make" (i.e.,
no "-j" option)? The behavior shouldn't change for that case (i.e.
qemu_edk2_get_thread_count() should be invoked, and it should print "1").


With (1) and (2) fixed, and (4) confirmed:

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


      reply	other threads:[~2019-06-14 18:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 17:54 [Qemu-devel] [PATCH] roms/edk2-build.sh: Allow to run edk2-build.sh from command line Philippe Mathieu-Daudé
2019-06-14 10:16 ` Philippe Mathieu-Daudé
2019-06-14 13:29   ` Eric Blake
2019-06-14 13:55     ` Philippe Mathieu-Daudé
2019-06-14 17:35       ` Laszlo Ersek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ad8f71b-9266-8cab-f50d-37a992e67d91@redhat.com \
    --to=lersek@redhat.com \
    --cc=eblake@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).