[edk2] [PATCH] edksetup.sh: Update help section regarding positional

Arvind Prasanna posted 1 patch 6 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/1520698318-9232-1-git-send-email-arvindprasanna@gmail.com
edksetup.sh | 2 ++
1 file changed, 2 insertions(+)
[edk2] [PATCH] edksetup.sh: Update help section regarding positional
Posted by Arvind Prasanna 6 years, 2 months ago
It is possible to source edksetup.sh from another script. If the
calling/sourcing script has any positional parameters set, those are
incorrectly accounted for in edksetup.sh while sourcing it resulting in
the the help section always being shown. This patch updates the help
section advising the user about these set positional parameters so they
can be unset prior to sourcing edksetup.sh.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Arvind Prasanna <arvindprasanna@gmail.com>
---
 edksetup.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/edksetup.sh b/edksetup.sh
index 93d6525..a3d5560 100755
--- a/edksetup.sh
+++ b/edksetup.sh
@@ -42,6 +42,8 @@ function HelpMsg()
   echo Please note: This script must be \'sourced\' so the environment can be changed.
   echo ". $SCRIPTNAME"
   echo "source $SCRIPTNAME"
+  echo "If this script is being sourced from another script, please ensure that the"
+  echo "sourcing/calling script has no set postional parameters."
 }
 
 function SetWorkspace()
-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] edksetup.sh: Update help section regarding positional
Posted by Leif Lindholm 6 years, 2 months ago
Hi Arvind,

On Sat, Mar 10, 2018 at 11:11:58AM -0500, Arvind Prasanna wrote:
> It is possible to source edksetup.sh from another script. If the
> calling/sourcing script has any positional parameters set, those are
> incorrectly accounted for in edksetup.sh while sourcing it resulting in
> the the help section always being shown. This patch updates the help
> section advising the user about these set positional parameters so they
> can be unset prior to sourcing edksetup.sh.

This is really just one of the unpleasantries of sourcing shell
scripts.

Since the current script could only ever work with bash anyway (and
not sh, dash, ...) I don't know that we could do much better - and
there's nothing about the problem that is specific to this script.

As an aside, since we _know_ this only works on bash, you can also
make use of the bash side effect that if you pass any arguments to the
sourced script, it gets its own copies of $#, $0, $1 and so on.

For ancient backwards compatility, the parameter BaseTools is ignored
if provided on the command line. So you could always just use
  edksetup.sh BaseTools

Alternatively, you can use
  edksetup.sh --reconfig
which also ensures you are always using the latest toolchain
templates.

Regards,

Leif

> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Arvind Prasanna <arvindprasanna@gmail.com>
> ---
>  edksetup.sh | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/edksetup.sh b/edksetup.sh
> index 93d6525..a3d5560 100755
> --- a/edksetup.sh
> +++ b/edksetup.sh
> @@ -42,6 +42,8 @@ function HelpMsg()
>    echo Please note: This script must be \'sourced\' so the environment can be changed.
>    echo ". $SCRIPTNAME"
>    echo "source $SCRIPTNAME"
> +  echo "If this script is being sourced from another script, please ensure that the"
> +  echo "sourcing/calling script has no set postional parameters."
>  }
>  
>  function SetWorkspace()
> -- 
> 2.7.4
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] edksetup.sh: Update help section regarding positional
Posted by Arvind Prasanna 6 years, 2 months ago
Hi Leif:

Thank you for your feedback. I concur with you that it is a bash side
effect, desired or undesired :) . I ran into this issue with positional
parameters and thought a small message would be helpful to users. I will no
longer pursue this issue.

Thanks,

Arvind.



On Wed, Mar 14, 2018 at 7:25 AM, Leif Lindholm <leif.lindholm@linaro.org>
wrote:

> Hi Arvind,
>
> On Sat, Mar 10, 2018 at 11:11:58AM -0500, Arvind Prasanna wrote:
> > It is possible to source edksetup.sh from another script. If the
> > calling/sourcing script has any positional parameters set, those are
> > incorrectly accounted for in edksetup.sh while sourcing it resulting in
> > the the help section always being shown. This patch updates the help
> > section advising the user about these set positional parameters so they
> > can be unset prior to sourcing edksetup.sh.
>
> This is really just one of the unpleasantries of sourcing shell
> scripts.
>
> Since the current script could only ever work with bash anyway (and
> not sh, dash, ...) I don't know that we could do much better - and
> there's nothing about the problem that is specific to this script.
>
> As an aside, since we _know_ this only works on bash, you can also
> make use of the bash side effect that if you pass any arguments to the
> sourced script, it gets its own copies of $#, $0, $1 and so on.
>
> For ancient backwards compatility, the parameter BaseTools is ignored
> if provided on the command line. So you could always just use
>   edksetup.sh BaseTools
>
> Alternatively, you can use
>   edksetup.sh --reconfig
> which also ensures you are always using the latest toolchain
> templates.
>
> Regards,
>
> Leif
>
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Arvind Prasanna <arvindprasanna@gmail.com>
> > ---
> >  edksetup.sh | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/edksetup.sh b/edksetup.sh
> > index 93d6525..a3d5560 100755
> > --- a/edksetup.sh
> > +++ b/edksetup.sh
> > @@ -42,6 +42,8 @@ function HelpMsg()
> >    echo Please note: This script must be \'sourced\' so the environment
> can be changed.
> >    echo ". $SCRIPTNAME"
> >    echo "source $SCRIPTNAME"
> > +  echo "If this script is being sourced from another script, please
> ensure that the"
> > +  echo "sourcing/calling script has no set postional parameters."
> >  }
> >
> >  function SetWorkspace()
> > --
> > 2.7.4
> >
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
>
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel