From patchwork Tue Oct 25 17:29:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 79255 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp3235484qge; Tue, 25 Oct 2016 10:29:50 -0700 (PDT) X-Received: by 10.98.223.150 with SMTP id d22mr41544572pfl.2.1477416590100; Tue, 25 Oct 2016 10:29:50 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id g17si9624345pgh.51.2016.10.25.10.29.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Oct 2016 10:29:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7196C1A1E57; Tue, 25 Oct 2016 10:29:49 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org 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)" Subject: Re: [edk2] [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: , Cc: tianocore/edk2 , Author , Liming Gao Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel 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