From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb0-x22a.google.com (mail-yb0-x22a.google.com [IPv6:2607:f8b0:4002:c09::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7860C1A1E46 for ; Tue, 25 Oct 2016 10:29:48 -0700 (PDT) Received: by mail-yb0-x22a.google.com with SMTP id d128so3690553ybh.2 for ; Tue, 25 Oct 2016 10:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fm5U1CqhrbJdLE56W0VDAgQYh1T8AGJvU/uV7+G7Hno=; b=iZ4jYA0dBn11XowV3QdBC9yDZmRNY9Gi8nME/ZpOxhDldRSsSA3jaxa16qT+g20sKe voLOhQ6vvET/o1yN4mnokS8utO6BvX4LPJTIBXonJtKWt4MT1+P38Z2SxrAX5gZCunhY e/9vxpSM3a+OQyioQAIYIBWFkmBo1d05MqgJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fm5U1CqhrbJdLE56W0VDAgQYh1T8AGJvU/uV7+G7Hno=; b=RP0VEKWtclluxWQjjxH2Al3//8FDZOuNkRgDP0uuVBSJsJTecgQaWsbbzcM/KbGr1r uo6aeloXFiyX5A0WZj92HmKYlf87r8SouYvWbAu62NcC1DxGXO6Pthdug+0lIR4uV0t8 8ksHmNjA5Ql12bbYMwDeNixpf3pKifnhyai77l21gOfecqakJCQfVtdBNMgh5rsUiwsC i5hxzh4K31uy3EWTfQwBpD46rDHgrx4rOGNnbMYN1rA4IupsyfUCumqjrTU6nMute2Bo c+eVPwqYoteFeXpeci/HC5wD9calYjE9entqF8MaYSIiiivj8GN4vRuyV8+OqQkxrWYw 8rxQ== X-Gm-Message-State: ABUngvdyLxKRitQ4D25VjCvHYpXNAvvXmxfRB6ZTpd6PugJbbqwOBtZsaIUGU90ZRluUqlfGsJHbAiFzRHxEkSQN X-Received: by 10.36.87.14 with SMTP id u14mr2553539ita.65.1477416587455; Tue, 25 Oct 2016 10:29:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.110.99 with HTTP; Tue, 25 Oct 2016 10:29:46 -0700 (PDT) In-Reply-To: References: From: Leif Lindholm Date: Tue, 25 Oct 2016 18:29:46 +0100 Message-ID: To: "tianocore/edk2" , "edk2-devel (edk2-devel@lists.01.org)" Cc: "tianocore/edk2" , Author , Liming Gao , Yonghong Zhu Subject: Re: [tianocore/edk2] edksetup.sh: rework argument parsing and update usage information (44f7942) X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Oct 2016 17:29:48 -0000 Content-Type: text/plain; charset=UTF-8 Hi Dmitry, On 25 October 2016 at 14:06, Dmitry wrote: > https://github.com/tianocore/edk2/blob/master/edksetup.sh#L149 > ./edksetup.sh: line 149: return: can only `return' from a function or sourced script We don't use github for bugtracking - reports can be made either to edk2-devel@lists.01.org (added to cc) or on https://bugzilla.tianocore.org/. Yes. edksetup.sh must always be run as a sourced script, via 'source' or '.', as stated in the usage message. But I concede there is a change in behaviour when invoking it incorrectly. And the generated error message could be better. I propose the following update to improve the situation: >>From b24a4ef698ea993535b80dfaee340bd5b70e9f91 Mon Sep 17 00:00:00 2001 From: Leif Lindholm Date: Tue, 25 Oct 2016 18:20:04 +0100 Subject: [PATCH] edksetup.sh: refactor source/execution detection Commit 44f79425589e ("edksetup.sh: rework argument parsing and...") added a return call to the top level of the script, triggering the not entirely user friendly error message "line 149: return: can only `return' from a function or sourced script" when the script is executed rather than sourced. Move the existing test for erroneous invocation first in SetWorkspace() and add a test that exits rather than returns when the script is executed directly. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leif Lindholm --- For further improvements, I could also change the last hardcoded edksetup.sh to $SCRIPTNAME, but preferred minimal changes to the modified code. edksetup.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/edksetup.sh b/edksetup.sh index ec54f9e..634ff99 100755 --- a/edksetup.sh +++ b/edksetup.sh @@ -46,6 +46,14 @@ function HelpMsg() function SetWorkspace() { + if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] + then + echo Run this script from the base of your tree. For example: + echo " cd /Path/To/Edk/Root" + echo " . edksetup.sh" + exit 1 + fi + # # If WORKSPACE is already set, then we can return right now # @@ -54,14 +62,6 @@ function SetWorkspace() return 0 fi - if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ] - then - echo Run this script from the base of your tree. For example: - echo " cd /Path/To/Edk/Root" - echo " . edksetup.sh" - return 1 - fi - # # Check for BaseTools/BuildEnv before dirtying the user's environment. # @@ -117,6 +117,8 @@ function SourceEnv() SetupEnv } +[ "$0" = "./$SCRIPTNAME" ] && HelpMsg && exit 1 + I=$# while [ $I -gt 0 ] do -- 2.9.3