Skip to content

Commit

Permalink
tools/find-tools.batにpython検出機能を追加する
Browse files Browse the repository at this point in the history
  • Loading branch information
berryzplus committed Jul 19, 2020
1 parent 4042535 commit 90bfe56
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
8 changes: 7 additions & 1 deletion build-chm.bat
Expand Up @@ -4,6 +4,12 @@ if not defined CMD_HHC (
exit /b 1
)

if not defined CMD_PYTHON call %~dp0tools\find-tools.bat
if not defined CMD_PYTHON (
@echo py.exe was not found.
exit /b 1
)

set SRC_HELP=%~dp0help
set TMP_HELP=%~dp0temphelp

Expand All @@ -13,7 +19,7 @@ set HH_INPUT=sakura_core\sakura.hh
set HH_OUTPUT=help\sakura\sakura.hh

if exist "%HH_OUTPUT%" del /F "%HH_OUTPUT%"
python "%HH_SCRIPT%" "%HH_INPUT%" "%HH_OUTPUT%" || (echo error && exit /b 1)
%CMD_PYTHON% "%HH_SCRIPT%" "%HH_INPUT%" "%HH_OUTPUT%" || (echo error && exit /b 1)

if exist "%TMP_HELP%" rmdir /s /q "%TMP_HELP%"
xcopy /i /k /s "%SRC_HELP%" "%TMP_HELP%"
Expand Down
6 changes: 3 additions & 3 deletions calc-hash-res.bat
Expand Up @@ -17,11 +17,11 @@ if not exist "%SRCDIR%" (
exit /b 1
)

where python --version 1>nul 2>&1
if errorlevel 1 (
if not defined CMD_PYTHON call %~dp0tools\find-tools.bat
if not defined CMD_PYTHON (
@echo NOTE: No python command
) else (
python calc-hash.py %OUTHASHFILE% %SRCDIR% .res
%CMD_PYTHON% calc-hash.py %OUTHASHFILE% %SRCDIR% .res
)
exit /b 0

Expand Down
6 changes: 3 additions & 3 deletions calc-hash.bat
Expand Up @@ -17,11 +17,11 @@ if not exist "%SRCDIR%" (
exit /b 1
)

where python --version 1>nul 2>&1
if errorlevel 1 (
if not defined CMD_PYTHON call %~dp0tools\find-tools.bat
if not defined CMD_PYTHON (
@echo NOTE: No python command
) else (
python calc-hash.py %OUTHASHFILE% %SRCDIR%
%CMD_PYTHON% calc-hash.py %OUTHASHFILE% %SRCDIR%
)
exit /b 0

Expand Down
8 changes: 4 additions & 4 deletions parse-buildlog.bat
Expand Up @@ -15,12 +15,12 @@ if not exist "%LOGFILE%" (
)

set ERROR_RESULT=0
where python --version 1>nul 2>&1
if errorlevel 1 (
if not defined CMD_PYTHON call %~dp0tools\find-tools.bat
if not defined CMD_PYTHON (
@echo NOTE: No python command
) else (
python appveyor_env.py
python parse-buildlog.py %LOGFILE% || set ERROR_RESULT=1
%CMD_PYTHON% appveyor_env.py
%CMD_PYTHON% parse-buildlog.py %LOGFILE% || set ERROR_RESULT=1
)
exit /b %ERROR_RESULT%

Expand Down
38 changes: 38 additions & 0 deletions tools/find-tools.bat
Expand Up @@ -14,6 +14,7 @@ if "%1" equ "clear" (
set CMD_CMAKE=
set CMD_NINJA=
set CMD_LEPROC=
set CMD_PYTHON=
set NUM_VSVERSION=
set CMAKE_G_PARAM=
set FIND_TOOLS_CALLED=
Expand All @@ -39,6 +40,7 @@ if not defined CMD_MSBUILD call :msbuild 2> nul
if not defined CMD_CMAKE call :cmake 2> nul
if not defined CMD_NINJA call :cmake 2> nul
if not defined CMD_LEPROC call :leproc 2> nul
if not defined CMD_PYTHON call :python 2> nul
echo ^|- CMD_GIT=%CMD_GIT%
echo ^|- CMD_7Z=%CMD_7Z%
echo ^|- CMD_HHC=%CMD_HHC%
Expand All @@ -50,6 +52,7 @@ echo ^|- CMD_MSBUILD=%CMD_MSBUILD%
echo ^|- CMD_CMAKE=%CMD_CMAKE%
echo ^|- CMD_NINJA=%CMD_NINJA%
echo ^|- CMD_LEPROC=%CMD_LEPROC%
echo ^|- CMD_PYTHON=%CMD_PYTHON%
echo ^|- CMAKE_G_PARAM=%CMAKE_G_PARAM%
endlocal ^
&& set "CMD_GIT=%CMD_GIT%" ^
Expand All @@ -63,6 +66,7 @@ endlocal ^
&& set "CMD_CMAKE=%CMD_CMAKE%" ^
&& set "CMD_NINJA=%CMD_NINJA%" ^
&& set "CMD_LEPROC=%CMD_LEPROC%" ^
&& set "CMD_PYTHON=%CMD_PYTHON%" ^
&& set "NUM_VSVERSION=%NUM_VSVERSION%" ^
&& set "CMAKE_G_PARAM=%CMAKE_G_PARAM%" ^
&& echo end
Expand Down Expand Up @@ -270,3 +274,37 @@ for /f "usebackq delims=" %%a in (`where $PATH2:LEProc.exe`) do (
exit /b
)
exit /b

:python
call :find_py
call :check_python_version
if defined CMD_PYTHON (
exit /b 0
)

set PATH2=%PATH%
for /f "usebackq delims=" %%a in (`where $PATH2:python.exe`) do (
set "CMD_PYTHON=%%a"
call :check_python_version
exit /b 0
)
call :check_python_version
exit /b 0

:find_py
set PATH2=%PATH%
for /f "usebackq delims=" %%a in (`where $PATH2:py.exe`) do (
set "CMD_PYTHON=%%a"
exit /b 0
)
exit /b 0

:check_python_version
set PYTHON_VERSION=
for /F "usebackq tokens=2*" %%v in (`"%CMD_PYTHON%" --version`) do (
set PYTHON_VERSION=%%v
)
if not defined PYTHON_VERSION (
set CMD_PYTHON=
)
exit /b 0
12 changes: 12 additions & 0 deletions tools/find-tools.md
Expand Up @@ -22,6 +22,7 @@
| vswhere | CMD_VSWHERE | Microsoft Visual Studio\Installer | vswhere.exe |
| MSBuild | CMD_MSBUILD | 特殊 | MSBuild.exe |
| Locale Emulator | CMD_LEPROC | なし | LEProc.exe |
| python | CMD_PYTHON | なし | py.exe(python.exe) |

## MSBuild以外の探索手順
MSBuild以外の探索手順は同一であり、7-Zipを例に説明する。
Expand Down Expand Up @@ -76,6 +77,17 @@ MSBuild以外の探索手順は同一であり、7-Zipを例に説明する。
* https://github.com/Microsoft/vswhere
* https://github.com/Microsoft/vswhere/wiki/Find-MSBuild

## python

ビルドバッチで利用するpythonインタープリターの存在確認をします。
適切なpythonインタープリターが見つかると、環境変数 `CMD_PYTHON` が定義されます。
適切なpythonインタープリターが見つからない場合、`CMD_PYTHON` は定義されません。
pythonインタープリターはビルド要件ではないのでpythonを利用するバッチには `CMD_PYTHON` チェックを挟む必要があります。

1. python Launcher(py.exe)が存在していたら、それを使う。
1. パスが通っているpython.exeで`python.exe --version`してバージョンが取れたら、それを使う。


## zipの処理に7zではなくPowerShellを強制する
事前に環境変数の`FORCE_POWERSHELL_ZIP`を1にセットすることで、7zの検索をスキップできます。
[PowerShellによるzipの処理](zip/readme.md)が正しく行われるかを7zがインストール済みの環境で検証する際に活用できます。[build.md](../build.md#powershell-によるzipファイルの圧縮解凍内容確認の強制)も参照してください。

0 comments on commit 90bfe56

Please sign in to comment.