Skip to content

Commit d549344

Browse files
bonzinijljusten
authored andcommitted
edksetup.sh: Ensure that WORKSPACE points to the top of an edk2 checkout
Since WORKSPACE should point at the EDK2 tree, the right place to check its validity is edksetup.sh, not BaseTools/BuildEnv. This patch makes sure that BuildEnv is always invoked with a valid WORKSPACE. This lets us show better error messages, and ensures that we never dirty the user's environment. BuildEnv will maintain backwards-compatibility and, should the variable be missing, it will be able to set a default WORKSPACE. Only the sanity checks will be of lower quality. Note that the error message in SetupEnv will never be shown if SetWorkspace sets WORKSPACE=`pwd`. Suggested-by: Laszlo Ersek <[email protected]> Contributed-under: TianoCore Contribution Agreement 1.0 Reviewed-by: Jordan Justen <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15701 6f19259b-4bc3-4df7-8a09-765794883524
1 parent 7bc1421 commit d549344

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

edksetup.sh

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,57 @@ function HelpMsg()
3333
return 1
3434
}
3535

36+
function SetWorkspace()
37+
{
38+
#
39+
# If WORKSPACE is already set, then we can return right now
40+
#
41+
if [ -n "$WORKSPACE" ]
42+
then
43+
return 0
44+
fi
45+
46+
if [ ! ${BASH_SOURCE[0]} -ef ./edksetup.sh ]
47+
then
48+
echo Run this script from the base of your tree. For example:
49+
echo " cd /Path/To/Edk/Root"
50+
echo " . edksetup.sh"
51+
return 1
52+
fi
53+
54+
#
55+
# Check for BaseTools/BuildEnv before dirtying the user's environment.
56+
#
57+
if [ ! -f BaseTools/BuildEnv ] && [ -z "$EDK_TOOLS_PATH" ]
58+
then
59+
echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
60+
echo Please point EDK_TOOLS_PATH at the directory that contains
61+
echo the EDK2 BuildEnv script.
62+
return 1
63+
fi
64+
65+
#
66+
# Set $WORKSPACE
67+
#
68+
export WORKSPACE=`pwd`
69+
70+
return 0
71+
}
72+
3673
function SetupEnv()
3774
{
3875
if [ -n "$EDK_TOOLS_PATH" ]
3976
then
4077
. $EDK_TOOLS_PATH/BuildEnv $*
41-
elif [ -n "$WORKSPACE" ]
78+
elif [ -f "$WORKSPACE/BaseTools/BuildEnv" ]
4279
then
4380
. $WORKSPACE/BaseTools/BuildEnv $*
4481
else
45-
. BaseTools/BuildEnv $*
82+
echo BaseTools not found in your tree, and EDK_TOOLS_PATH is not set.
83+
echo Please check that WORKSPACE is not set incorrectly in your
84+
echo shell, or point EDK_TOOLS_PATH at the directory that contains
85+
echo the EDK2 BuildEnv script.
86+
return 1
4687
fi
4788
}
4889

@@ -56,6 +97,7 @@ function SourceEnv()
5697
then
5798
HelpMsg
5899
else
100+
SetWorkspace &&
59101
SetupEnv "$*"
60102
fi
61103
}

0 commit comments

Comments
 (0)