From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4010:c07::22a; helo=mail-lf0-x22a.google.com; envelope-from=arvindprasanna@gmail.com; receiver=edk2-devel@lists.01.org Received: from mail-lf0-x22a.google.com (mail-lf0-x22a.google.com [IPv6:2a00:1450:4010:c07::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 2AEF4224872B2 for ; Mon, 12 Mar 2018 22:35:24 -0700 (PDT) Received: by mail-lf0-x22a.google.com with SMTP id f75-v6so26838253lfg.6 for ; Mon, 12 Mar 2018 22:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=76y/2HYDJ2jUSVjmdyyXchZzRSMhe1wDg2qEZ5fTgCE=; b=Q9I/lpLKLGHVNgghgbOXVKpWRag7RN1JnmZ9pa0CYmRvnn04lpaevahldGcV9NI9YM aVGiuzx6bjcAg3Ex/XDl/+XAYxvV9Z2KFhFCa9TnCXr2WLX4zkDvkYg8Tz2tiJy2JRj2 L9/3MsJHDDJevtRbxSUrooqr7cVI26uWw/uNkCT7WMSjIB/5rzT/d269kq2V3Y44hFXs rja4NzaI6SMsS9V1YEZ50tQIBRarsX7b9o1ZvFhV6TXJrywgd9VC9hGCvlk40IYzG+6u dc/sSul/YIKu9K/229C8/AuDHmCghq70HvI0RbWcmRKITuMjAzE/PyjwnAcRRCrkIeVb OBjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=76y/2HYDJ2jUSVjmdyyXchZzRSMhe1wDg2qEZ5fTgCE=; b=VkxwpSOnHr1cu86hd0GDm+A9pChvBAZ/Ro2+gaTBy68fL6OQYXCB3+QkvasuCDAIIX 6IbH4hsc7c1TIZN1XsmYwwj6klxL4hiMhtx6hkn0YsRrDHjG4qUlecVJE+PHVhTGomE2 8YrDD5c3BchBXvLhk/tJkoAdLLjMKSzmFh4sJWYjBlb4HA/xbcp+OXsbqL6nW9dZNad1 RZ416Z6AHsXFp+PYWqSDRnc7mV5l6JtgSBFoob6clpsmpq37bjR+i+m0n+yunWVFSBaj hRl0obimNsNb//AyIYNpqu3dZFtBGaxp/g78bU1CN3IWlwuLa3hvSE+26QJNM/cMh5a1 lB0A== X-Gm-Message-State: AElRT7Fz35W1DqH4ZtP6aRIfXN0kawR0pB7OBdHi4qWsO5f6dA5iz0ob 29n+vvk4+A7fCYqDOzfQEH6lq/+b5Fv/9KZ5F+g= X-Google-Smtp-Source: AG47ELsrRHx6+xZHj/I1WD+tED3v6+peqnz0wQ6crLw3WitK6miAsKOFYaKoJRaZt00VpRzxSdf8kl85vr+GSD6RYp8= X-Received: by 2002:a19:5c84:: with SMTP id u4-v6mr6266108lfi.14.1520919703830; Mon, 12 Mar 2018 22:41:43 -0700 (PDT) MIME-Version: 1.0 Received: by 10.179.75.154 with HTTP; Mon, 12 Mar 2018 22:41:42 -0700 (PDT) In-Reply-To: References: <1520669933-8602-1-git-send-email-arvindprasanna@gmail.com> <4A89E2EF3DFEDB4C8BFDE51014F606A14E1E5764@SHSMSX104.ccr.corp.intel.com> From: Arvind Prasanna Date: Tue, 13 Mar 2018 01:41:42 -0400 Message-ID: To: "Gao, Liming" Cc: "Zhu, Yonghong" , "edk2-devel@lists.01.org" X-Content-Filtered-By: Mailman/MimeDel 2.1.23 Subject: Re: [PATCH] edksetup.sh: Update help section regarding positional X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Mar 2018 05:35:26 -0000 Content-Type: text/plain; charset="UTF-8" I am not sure why git send mail did not include my patch in the chain but here is my version 2: 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 Changes in v2: - Fixed a typo. - Minor rewording. --- edksetup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/edksetup.sh b/edksetup.sh index 93d6525..e85fbf2 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 script has no set positional parameters." } function SetWorkspace() Thanks! -Arvind. On Mon, Mar 12, 2018 at 1:17 PM, Arvind Prasanna wrote: > Hi Liming Gao: > > Here is a simple example that highlights the issue: > > > $ ls -l > total 8 > drwxrwxr-x 49 arvind arvind 4096 Mar 12 12:35 edk2 > -rwxrwxr-x 1 arvind arvind 113 Mar 12 12:37 sourcing_script.sh > > $ cat sourcing_script.sh > > #!/bin/bash > echo "I have been passed $# arguments" > EDK2_PATH=${PWD}/../edk2 > cd ${EDK2_PATH} > source edksetup.sh > > > Case 1) Let us call sourcing_script.sh with no arguments > > $ ./sourcing_script.sh > I have been passed 0 arguments > Loading previous configuration from /home/arvind/edk2/Conf/BuildEnv.sh > WORKSPACE: /home/arvind/edk2 > EDK_TOOLS_PATH: /home/arvind/edk2/BaseTools > CONF_PATH: /home/arvind/edk2/Conf > > Everything looks good. > > > Case 2) Let us call sourcing_script.sh with say two arguments > > $ ./sourcing_script.sh arg1 arg2 > I have been passed 2 arguments > Usage: edksetup.sh [Options] > > The system environment variable, WORKSPACE, is always set to the current > working directory. > > Options: > --help, -h, -? Print this help screen and exit. > > --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the > template files from the BaseTools/Conf directory. > > Please note: This script must be 'sourced' so the environment can be > changed. > . edksetup.sh > source edksetup.sh > > > This is the case I intend to bring out. I have not passed any arguments > (intentionally) to edksetup.sh. but it always defaults to the help case > with the current edksetup.sh script. > > In edksetup.sh in line 120, it counts the number of positional parameters > "I=$#" and then does a switch-case on these arguments. In case 2, these > arguments are "arg1" and "arg2" which has nothing to do with edksetup.sh. > > If I were to clear all the positional arguments passed to > sourcing_script.sh, using "shift $#" prior to sourcing edk2setup.sh, it > works as expected. I do not want to fix anything in the code as this might > not be a common case but I would like to let the user know that all the > positional parameters that exist in the caller script will affect sourcing > edksetup.sh. > > > > This is how I would recommend the help section be with my patch: > > $ ./sourcing_script.sh arg1 arg2 > I have been passed 2 arguments > Usage: edksetup.sh [Options] > > The system environment variable, WORKSPACE, is always set to the current > working directory. > > Options: > --help, -h, -? Print this help screen and exit. > > --reconfig Overwrite the WORKSPACE/Conf/*.txt files with the > template files from the BaseTools/Conf directory. > > Please note: This script must be 'sourced' so the environment can be > changed. > . edksetup.sh > source edksetup.sh > If this script is being sourced from another script, please ensure that the > sourcing/calling script has no set postional parameters. > > Please let me know your feedback. > > Thanks! > > - Arvind. > > P.S. I just realized my patch has a typo in the word "positional". I will > fix it. > > On Mon, Mar 12, 2018 at 10:55 AM, Gao, Liming > wrote: > >> Arvind: >> >> Could you give one example to explain this usage? >> >> >> >> ---------- Forwarded message ---------- >> From: *Arvind Prasanna* >> Date: Sat, Mar 10, 2018 at 3:18 AM >> Subject: [PATCH] edksetup.sh: Update help section regarding positional >> To: edk2-devel@lists.01.org >> Cc: Arvind Prasanna >> >> >> 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 >> --- >> 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 >> >> >> > >