Skip to content

Commit

Permalink
BaseTools: Update windows and linux run scripts file to use Python3
Browse files Browse the repository at this point in the history
Modify windows script, PosixLike script, edksetup.sh, edksetup.bat to
use Python3

Cc: Liming Gao <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
  • Loading branch information
yunhuafx authored and Yonghong Zhu committed Oct 13, 2018
1 parent 8be15c6 commit 04c47cd
Show file tree
Hide file tree
Showing 30 changed files with 110 additions and 65 deletions.
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/BPDG
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/Ecc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/GenDepex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/GenFds
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/GenPatchPcdTable
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/GenerateCapsule
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/PatchPcdValue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/Pkcs7Sign
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/Rsa2048Sha256GenerateKeys
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/Rsa2048Sha256Sign
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/TargetTool
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/Trim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/UPT
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
6 changes: 3 additions & 3 deletions BaseTools/BinWrappers/PosixLike/build
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
#python `dirname $0`/RunToolFromSource.py `basename $0` $*

# If a python2 command is available, use it in preference to python
if command -v python2 >/dev/null 2>&1; then
python_exe=python2
# If a PYTHON3 command is available, use it in preference to python
if command -v $PYTHON3 >/dev/null 2>&1; then
python_exe=$PYTHON3
fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
Expand Down
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/BPDG.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@setlocal
@set ToolName=%~n0%
@set PYTHONPATH=%PYTHONPATH%;%BASE_TOOLS_PATH%\Source\Python
@%PYTHON_HOME%\python.exe -m %ToolName%.%ToolName% %*
@%PYTHON3% -m %ToolName%.%ToolName% %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/Ecc.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@setlocal
@set ToolName=%~n0%
@set PYTHONPATH=%PYTHONPATH%;%BASE_TOOLS_PATH%\Source\Python
@%PYTHON_HOME%\python.exe -m %ToolName%.EccMain %*
@%PYTHON3% -m %ToolName%.EccMain %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/GenDepex.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\AutoGen\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\AutoGen\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/GenFds.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@setlocal
@set ToolName=%~n0%
@set PYTHONPATH=%PYTHONPATH%;%BASE_TOOLS_PATH%\Source\Python
@%PYTHON_HOME%\python.exe -m %ToolName%.%ToolName% %*
@%PYTHON3% -m %ToolName%.%ToolName% %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/GenPatchPcdTable.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/GenerateCapsule.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\Capsule\GenerateCapsule.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\Capsule\GenerateCapsule.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/PatchPcdValue.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/Pkcs7Sign.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\Rsa2048Sha256Sign\Rsa2048Sha256GenerateKeys.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\Rsa2048Sha256Sign\Rsa2048Sha256GenerateKeys.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/Rsa2048Sha256Sign.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/TargetTool.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/Trim.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/UPT.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
2 changes: 1 addition & 1 deletion BaseTools/BinWrappers/WindowsLike/build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@setlocal
@set ToolName=%~n0%
@%PYTHON_HOME%\python.exe %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
@%PYTHON3% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
32 changes: 23 additions & 9 deletions BaseTools/toolsetup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,32 @@ goto end
)
)

if not defined PYTHON_HOME (
if defined PYTHONHOME (
set PYTHON_HOME=%PYTHONHOME%
) else (
echo.
echo !!! ERROR !!! Binary python tools are missing. PYTHON_HOME environment variable is not set.
echo PYTHON_HOME is required to build or execute the python tools.
echo.
goto end
set PYTHON3=py -3
:check_python_version
%PYTHON3% --version >NUL 2>&1
if %ERRORLEVEL% NEQ 0 (
if defined PYTHON_HOME (
if EXIST "%PYTHON_HOME%" (
set PYTHON3=%PYTHON_HOME%\python.exe
)
)
)
%PYTHON3% --version >NUL 2>&1
if %ERRORLEVEL% NEQ 0 (
echo.
echo !!! ERROR !!! %PYTHON3% not install.
echo.
goto end
)
FOR /F "TOKENS=1,2" %%i IN ('%PYTHON3% --version') DO set VERSION=%%j
if /I "%VERSION%" LSS "3.6" (
echo.
echo !!! ERROR !!! python version should greater than or equal to version 3.6.
echo.
goto end
)

:check_freezer_path
@REM We have Python, now test for FreezePython application
if not defined PYTHON_FREEZER_PATH (
echo.
Expand Down
31 changes: 31 additions & 0 deletions edksetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,41 @@ function SetupEnv()
fi
}

function SetupPython3()
{
for python in $(whereis python3)
do
python=$(echo $python | grep "[[:digit:]]$" || true)
python_version=${python##*python}
if [ -z "${python_version}" ];then
continue
fi
if [ -z $origin_version ];then
origin_version=$python_version
export PYTHON3=$python
continue
fi
ret=`echo "$origin_version < $python_version" |bc`
if [ "$ret" -eq 1 ]; then
origin_version=$python_version
export PYTHON3=$python
fi
done
if [ -z "$origin_version" ] || [ `echo "$origin_version < 3.6" |bc` -eq 1 ]; then
echo
echo ERROR!!!, python version should greater than or equal to version 3.6.
echo
return 1
fi


}

function SourceEnv()
{
SetWorkspace &&
SetupEnv
SetupPython3
}

I=$#
Expand Down

0 comments on commit 04c47cd

Please sign in to comment.