Skip to content

Commit

Permalink
Merge pull request sakura-editor#653 from KageShiron/fix/find-batch
Browse files Browse the repository at this point in the history
ビルドツールの検索を改善
  • Loading branch information
KageShiron authored Jan 16, 2019
2 parents eea847b + e8c6ec5 commit b971b2e
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 363 deletions.
4 changes: 2 additions & 2 deletions build-chm.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
call %~dp0tools\hhc\find-hhc.bat
if "%CMD_HHC%" == "" (
if not defined CMD_HHC call %~dp0tools\find-tools.bat
if not defined CMD_HHC (
echo hhc.exe was not found.
exit /b 1
)
Expand Down
4 changes: 2 additions & 2 deletions build-installer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ if "%configuration%" == "Release" (
exit /b 1
)

call %~dp0tools\ISCC\find-ISCC.bat
if "%CMD_ISCC%" == "" (
if not defined CMD_ISCC call %~dp0tools\find-tools.bat
if not defined CMD_ISCC (
echo ISCC.exe was not found.
exit /b 1
)
Expand Down
4 changes: 2 additions & 2 deletions build-sln.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ if "%configuration%" == "Release" (
call :showhelp %0
exit /b 1
)
call %~dp0tools\msbuild\find-msbuild.bat
if "%CMD_MSBUILD%" == "" (
if not defined CMD_MSBUILD call %~dp0tools\find-tools.bat
if not defined CMD_MSBUILD (
echo msbuild.exe was not found.
exit /b 1
)
Expand Down
4 changes: 2 additions & 2 deletions run-cppcheck.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ if "%configuration%" == "Release" (
exit /b 1
)

call %~dp0tools\CppCheck\find-CppCheck.bat
if "%CMD_CPPCHECK%" == "" (
call %~dp0tools\find-tools.bat
if not defined CMD_CPPCHECK (
echo cppcheck.exe was not found. so skip to run it.
exit /b 0
)
Expand Down
3 changes: 1 addition & 2 deletions run-doxygen.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
call sakura\githash.bat "%~dp0sakura_core"
call tools\hhc\find-hhc.bat
call tools\doxygen\find-doxygen.bat
call tools\find-tools.bat

if exist html rmdir /s /q html

Expand Down
32 changes: 0 additions & 32 deletions tools/CppCheck/find-CppCheck.bat

This file was deleted.

23 changes: 0 additions & 23 deletions tools/CppCheck/readme.md

This file was deleted.

32 changes: 0 additions & 32 deletions tools/ISCC/find-ISCC.bat

This file was deleted.

23 changes: 0 additions & 23 deletions tools/ISCC/readme.md

This file was deleted.

32 changes: 0 additions & 32 deletions tools/doxygen/find-doxygen.bat

This file was deleted.

17 changes: 0 additions & 17 deletions tools/doxygen/readme.md

This file was deleted.

89 changes: 89 additions & 0 deletions tools/find-tools.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@echo off
setlocal

if defined FIND_TOOLS_CALLED (
echo find-tools.bat already called
exit /b
)

echo find-tools.bat
if not defined CMD_7Z call :7z 2> nul
if not defined CMD_HHC call :hhc 2> nul
if not defined CMD_ISCC call :iscc 2> nul
if not defined CMD_CPPCHECK call :cppcheck 2> nul
if not defined CMD_DOXYGEN call :doxygen 2> nul
if not defined CMD_MSBUILD call :msbuild 2> nul
echo ^|- CMD_7Z=%CMD_7Z%
echo ^|- CMD_HHC=%CMD_HHC%
echo ^|- CMD_ISCC=%CMD_ISCC%
echo ^|- CMD_CPPCHECK=%CMD_CPPCHECK%
echo ^|- CMD_DOXYGEN=%CMD_DOXYGEN%
echo ^|- CMD_MSBUILD=%CMD_MSBUILD%
endlocal && set "CMD_7Z=%CMD_7Z%" && set "CMD_HHC=%CMD_HHC%" && set "CMD_ISCC=%CMD_ISCC%" && set "CMD_CPPCHECK=%CMD_CPPCHECK%" && set "CMD_DOXYGEN=%CMD_DOXYGEN%"&& set "CMD_MSBUILD=%CMD_MSBUILD%"
set FIND_TOOLS_CALLED=1
exit /b

:7z
if "%FORCE_POWERSHELL_ZIP%" == "1" (
exit /b
)
set APPDIR=7-Zip
set PATH2=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
for /f "usebackq delims=" %%a in (`where $PATH2:7z`) do (
set "CMD_7Z=%%a"
exit /b
)
exit /b

:hhc
set APPDIR=HTML Help Workshop
set PATH2=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
for /f "usebackq delims=" %%a in (`where $PATH2:hhc.exe`) do (
set "CMD_HHC=%%a"
exit /b
)
exit /b

:iscc
set APPDIR=Inno Setup 5
set PATH2=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
for /f "usebackq delims=" %%a in (`where $PATH2:ISCC.exe`) do (
set "CMD_ISCC=%%a"
exit /b
)
exit /b

:cppcheck
set APPDIR=cppcheck
set PATH2=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
for /f "usebackq delims=" %%a in (`where $PATH2:cppcheck.exe`) do (
set "CMD_CPPCHECK=%%a"
exit /b
)
exit /b

:doxygen
set APPDIR=doxygen\bin
set PATH2=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
for /f "usebackq delims=" %%a in (`where $PATH2:doxygen.exe`) do (
set "CMD_DOXYGEN=%%a"
exit /b
)
exit /b

:: ref https://github.com/Microsoft/vswhere
:msbuild
for /f "usebackq delims=" %%a in (`where MSBuild.exe`) do (
set "CMD_MSBUILD=%%a"
exit /b
)

setlocal
set APPDIR=Microsoft Visual Studio\Installer
PATH=%PATH%;%ProgramFiles%\%APPDIR%\;%ProgramFiles(x86)%\%APPDIR%\;%ProgramW6432%\%APPDIR%\;
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
endlocal && set "CMD_MSBUILD=%%i\MSBuild\15.0\Bin\MSBuild.exe"
exit /b
)
endlocal
exit /b
46 changes: 46 additions & 0 deletions tools/find-tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
- [ビルド関連ツールのパスを探す](#%E3%83%93%E3%83%AB%E3%83%89%E9%96%A2%E9%80%A3%E3%83%84%E3%83%BC%E3%83%AB%E3%81%AE%E3%83%91%E3%82%B9%E3%82%92%E6%8E%A2%E3%81%99)
- [外部ツールの一覧](#%E5%A4%96%E9%83%A8%E3%83%84%E3%83%BC%E3%83%AB%E3%81%AE%E4%B8%80%E8%A6%A7)
- [MSBuild以外の探索手順](#msbuild%E4%BB%A5%E5%A4%96%E3%81%AE%E6%8E%A2%E7%B4%A2%E6%89%8B%E9%A0%86)
- [MSBuild](#msbuild)
- [参照](#%E5%8F%82%E7%85%A7)
- [zipの処理に7zではなくPowerShellを強制する](#zip%E3%81%AE%E5%87%A6%E7%90%86%E3%81%AB7z%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%8Fpowershell%E3%82%92%E5%BC%B7%E5%88%B6%E3%81%99%E3%82%8B)

# ビルド関連ツールのパスを探す
外部ツールの実行ファイルの位置を探し、見つかれば環境変数にセットします。現在パスが通っている場所と、インストーラがデフォルトでインストールする場所が検索されます。詳細は[MSBuild以外の探索手順](#msbuild%E4%BB%A5%E5%A4%96%E3%81%AE%E6%8E%A2%E7%B4%A2%E6%89%8B%E9%A0%86)の項目を参照してください。

外部ツールのインストール時にデフォルトパスにインストールしていない場合や別の実行ファイルを使いたい場合、実行前にパスを通しておくかCMD_7Zなどの対応する環境変数に絶対パスをセットしておいてください。

## 外部ツールの一覧
| ツール名 | 環境変数 | デフォルトパス | ファイル名 |
| ------------------ | ------------ | ------------------ | ------------ |
| 7-Zip | CMD_7Z | 7-Zip | 7z |
| HTML Help Workshop | CMD_HHC | HTML Help Workshop | hhc.exe |
| Inno Setup 5 | CMD_ISCC | Inno Setup 5 | ISCC.exe |
| cppcheck | CMD_CPPCHECK | cppcheck | cppcheck.exe |
| doxygen | CMD_DOXYGEN | doxygen\bin | doxygen.exe |
| MSBuild | CMD_MSBUILD | 特殊 | MSBuild.exe |

## MSBuild以外の探索手順
MSBuild以外の探索手順は同一であり、7-Zipを例に説明する。

1. CMD_7Zがセットされていればそれを使う
2. パスが通っていればそれを使う
3. 以下のディレクトリ内の「デフォルトパス」を順に探索し、実行ファイルが見つかればそれを使う
* %ProgramFiles%
* %ProgramFiles(x86)%
* %ProgramW6432%
4. 1~3で見つからなければCMD_7Zには何もセットしない

## MSBuild
1. CMD_MSBUILDがセットされていればそれを使う
2. パスが通っていればそれを使う
3. Visual Studio 2017以降にあるMicrosoft Visual Studio\Installer\vswhere.exeを利用し、msbuild.exeを探す。
4. 1~3で見つからなければCMD_MSBUILDには何もセットしない

### 参照
* https://github.com/Microsoft/vswhere
* https://github.com/Microsoft/vswhere/wiki/Find-MSBuild

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

This file was deleted.

Loading

0 comments on commit b971b2e

Please sign in to comment.