From: Leif Lindholm <leif.lindholm@linaro.org>
To: "tianocore/edk2"
<reply+0064a185de442789e25ff066b5b3dcd9c47ae4f29fe707d892cf0000000114271ae792a163ce012a7449@reply.github.com>,
"edk2-devel (edk2-devel@lists.01.org)" <edk2-devel@lists.01.org>
Cc: "tianocore/edk2" <edk2@noreply.github.com>,
Author <author@noreply.github.com>,
Liming Gao <liming.gao@intel.com>,
Yonghong Zhu <yonghong.zhu@intel.com>
Subject: Re: [tianocore/edk2] edksetup.sh: rework argument parsing and update usage information (44f7942)
Date: Tue, 25 Oct 2016 18:29:46 +0100 [thread overview]
Message-ID: <CAF7UmSyLk9vvSXaLJ+8ATn0L=g4wkToJ3XeinfuEG39Vfi=pjQ@mail.gmail.com> (raw)
In-Reply-To: <tianocore/edk2/commit/44f79425589ef58cc10e58e1d1d882e02871158d/19559497@github.com>
Hi Dmitry,
On 25 October 2016 at 14:06, Dmitry <notifications@github.com> 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 <leif.lindholm@linaro.org>
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 <leif.lindholm@linaro.org>
---
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
parent reply other threads:[~2016-10-25 17:29 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <tianocore/edk2/commit/44f79425589ef58cc10e58e1d1d882e02871158d/19559497@github.com>]
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-list 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='CAF7UmSyLk9vvSXaLJ+8ATn0L=g4wkToJ3XeinfuEG39Vfi=pjQ@mail.gmail.com' \
--to=devel@edk2.groups.io \
/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