Skip to content

Commit

Permalink
Merge pull request #399 from m-tmatma/feature/use-predefined-program-…
Browse files Browse the repository at this point in the history
…files-env

Program Files や Program Files (x86) のパスを決め打ちせずに環境変数を参照する
  • Loading branch information
m-tmatma authored Sep 5, 2018
2 parents 51b2ed7 + 0d32d1a commit bcfe60b
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 16 deletions.
12 changes: 8 additions & 4 deletions build-chm.bat
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
set HHC=C:\Program Files (x86)\HTML Help Workshop\hhc.exe
call %~dp0tools\hhc\find-hhc.bat
if "%CMD_HHC%" == "" (
echo hhc.exe was not found.
exit /b 1
)

@rem hhc.exe returns 1 on success, and returns 0 on failure
"%HHC%" help\macro\macro.HHP
"%CMD_HHC%" help\macro\macro.HHP
if %errorlevel% equ 0 (echo error && exit /b 1)

"%HHC%" help\plugin\plugin.hhp
"%CMD_HHC%" help\plugin\plugin.hhp
if %errorlevel% equ 0 (echo error && exit /b 1)

"%HHC%" help\sakura\sakura.hhp
"%CMD_HHC%" help\sakura\sakura.hhp
if %errorlevel% equ 0 (echo error && exit /b 1)

exit /b 0
8 changes: 7 additions & 1 deletion build-installer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ if "%configuration%" == "Release" (
exit /b 1
)

call %~dp0tools\ISCC\find-ISCC.bat
if "%CMD_ISCC%" == "" (
echo ISCC.exe was not found.
exit /b 1
)

set INSTALLER_WORK=installer\sakura
set INSTALLER_OUTPUT=installer\Output-%platform%

Expand All @@ -46,7 +52,7 @@ copy /Y /B %platform%\%configuration%\*.exe %INSTALLER_WORK%\
copy /Y /B %platform%\%configuration%\*.dll %INSTALLER_WORK%\

set SAKURA_ISS=installer\sakura-%platform%.iss
"C:\Program Files (x86)\Inno Setup 5\ISCC.exe" %SAKURA_ISS% || (echo error && exit /b 1)
"%CMD_ISCC%" %SAKURA_ISS% || (echo error && exit /b 1)
exit /b 0

@rem ------------------------------------------------------------------------------
Expand Down
13 changes: 8 additions & 5 deletions build-sln.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ if "%configuration%" == "Release" (
call :showhelp %0
exit /b 1
)
call %~dp0tools\msbuild\find-msbuild.bat
if "%CMD_MSBUILD%" == "" (
echo msbuild.exe was not found.
exit /b 1
)

set SLN_FILE=sakura.sln

@rem https://www.appveyor.com/docs/environment-variables/

if "%APPVEYOR%"=="True" (
set EXTRA_CMD=/verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
set EXTRA_CMD=/verbosity:minimal /logger:"%ProgramFiles%\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
) else (
set EXTRA_CMD=
)
Expand All @@ -34,10 +39,8 @@ set LOG_FILE=msbuild-%platform%-%configuration%.log
@rem https://msdn.microsoft.com/ja-jp/library/ms171470.aspx
set LOG_OPTION=/flp:logfile=%LOG_FILE%

set MSBUILD_EXE="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"

@echo %MSBUILD_EXE% %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Clean","Rebuild" %EXTRA_CMD% %LOG_OPTION%
%MSBUILD_EXE% %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Clean","Rebuild" %EXTRA_CMD% %LOG_OPTION%
@echo "%CMD_MSBUILD%" %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Clean","Rebuild" %EXTRA_CMD% %LOG_OPTION%
"%CMD_MSBUILD%" %SLN_FILE% /p:Platform=%platform% /p:Configuration=%configuration% /t:"Clean","Rebuild" %EXTRA_CMD% %LOG_OPTION%
if %errorlevel% neq 0 (echo error && exit /b 1)

@echo call parse-buildlog.bat %LOG_FILE%
Expand Down
13 changes: 9 additions & 4 deletions run-cppcheck.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ if "%configuration%" == "Release" (
exit /b 1
)

set CPPCHECK_EXE=C:\Program Files\Cppcheck\cppcheck.exe
call %~dp0tools\CppCheck\find-CppCheck.bat
if "%CMD_CPPCHECK%" == "" (
echo cppcheck.exe was not found. so skip to run it.
exit /b 0
)

set CPPCHECK_OUT=cppcheck-%platform%-%configuration%.xml
set CPPCHECK_LOG=cppcheck-%platform%-%configuration%.log

Expand Down Expand Up @@ -53,9 +58,9 @@ set CPPCHECK_PARAMS=%CPPCHECK_PARAMS% -j %NUMBER_OF_PROCESSORS%
set CPPCHECK_PARAMS=%CPPCHECK_PARAMS% %~dp0sakura_core

set ERROR_RESULT=0
if exist "%CPPCHECK_EXE%" (
@echo "%CPPCHECK_EXE%" %CPPCHECK_PARAMS%
"%CPPCHECK_EXE%" %CPPCHECK_PARAMS% > %CPPCHECK_LOG% || set ERROR_RESULT=1
if exist "%CMD_CPPCHECK%" (
@echo "%CMD_CPPCHECK%" %CPPCHECK_PARAMS%
"%CMD_CPPCHECK%" %CPPCHECK_PARAMS% > %CPPCHECK_LOG% || set ERROR_RESULT=1
@echo.
@echo The log files are %CPPCHECK_LOG% and %CPPCHECK_OUT%
@echo cppcheck success
Expand Down
32 changes: 32 additions & 0 deletions tools/CppCheck/find-CppCheck.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@rem see readme.md
@echo off
set CMD_CPPCHECK=
set PATH_CPPCHECK_1=
set PATH_CPPCHECK_2=
set PATH_CPPCHECK_3=

if not "%ProgramFiles%" == "" set "PATH_CPPCHECK_1=%ProgramFiles%\Cppcheck\cppcheck.exe"
if not "%ProgramFiles(x86)%" == "" set "PATH_CPPCHECK_2=%ProgramFiles(x86)%\Cppcheck\cppcheck.exe"
if not "%ProgramW6432%" == "" set "PATH_CPPCHECK_3=%ProgramW6432%\Cppcheck\cppcheck.exe"

set RESULT_PATH_CPPCHECK_1=--
set RESULT_PATH_CPPCHECK_2=--
set RESULT_PATH_CPPCHECK_3=--

if exist "%PATH_CPPCHECK_1%" (
set RESULT_PATH_CPPCHECK_1=OK
set "CMD_CPPCHECK=%PATH_CPPCHECK_1%"
) else if exist "%PATH_CPPCHECK_2%" (
set RESULT_PATH_CPPCHECK_2=OK
set "CMD_CPPCHECK=%PATH_CPPCHECK_2%"
) else if exist "%PATH_CPPCHECK_3%" (
set RESULT_PATH_CPPCHECK_3=OK
set "CMD_CPPCHECK=%PATH_CPPCHECK_3%"
)

@echo %RESULT_PATH_CPPCHECK_1% %PATH_CPPCHECK_1%
@echo %RESULT_PATH_CPPCHECK_2% %PATH_CPPCHECK_2%
@echo %RESULT_PATH_CPPCHECK_3% %PATH_CPPCHECK_3%
@echo.
@echo CMD_CPPCHECK "%CMD_CPPCHECK%"
@echo.
23 changes: 23 additions & 0 deletions tools/CppCheck/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- TOC -->

- [cppcheck のパスを見つけるバッチファイル](#cppcheck-のパスを見つけるバッチファイル)
- [ロジック](#ロジック)
- [バッチファイルでのはまりポイント](#バッチファイルでのはまりポイント)

<!-- /TOC -->

# cppcheck のパスを見つけるバッチファイル

cppcheck.exe のパスを見つけて 環境変数 `CMD_CPPCHECK` に設定する

## ロジック

以下の順番でパスを検索して、見つかったパスを環境変数 `CMD_CPPCHECK` にセットする。

- %ProgramFiles%\Cppcheck\cppcheck.exe
- %ProgramFiles(x86)%\Cppcheck\cppcheck.exe
- %ProgramW6432%\Cppcheck\cppcheck.exe

## バッチファイルでのはまりポイント

[hhc.exe の readme](../hhc/readme.md) を参照
32 changes: 32 additions & 0 deletions tools/ISCC/find-ISCC.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@rem see readme.md
@echo off
set CMD_ISCC=
set PATH_ISCC_1=
set PATH_ISCC_2=
set PATH_ISCC_3=

if not "%ProgramFiles%" == "" set "PATH_ISCC_1=%ProgramFiles%\Inno Setup 5\ISCC.exe"
if not "%ProgramFiles(x86)%" == "" set "PATH_ISCC_2=%ProgramFiles(x86)%\Inno Setup 5\ISCC.exe"
if not "%ProgramW6432%" == "" set "PATH_ISCC_3=%ProgramW6432%\Inno Setup 5\ISCC.exe"

set RESULT_PATH_ISCC_1=--
set RESULT_PATH_ISCC_2=--
set RESULT_PATH_ISCC_3=--

if exist "%PATH_ISCC_1%" (
set RESULT_PATH_ISCC_1=OK
set "CMD_ISCC=%PATH_ISCC_1%"
) else if exist "%PATH_ISCC_2%" (
set RESULT_PATH_ISCC_2=OK
set "CMD_ISCC=%PATH_ISCC_2%"
) else if exist "%PATH_ISCC_3%" (
set RESULT_PATH_ISCC_3=OK
set "CMD_ISCC=%PATH_ISCC_3%"
)

@echo %RESULT_PATH_ISCC_1% %PATH_ISCC_1%
@echo %RESULT_PATH_ISCC_2% %PATH_ISCC_2%
@echo %RESULT_PATH_ISCC_3% %PATH_ISCC_3%
@echo.
@echo CMD_ISCC "%CMD_ISCC%"
@echo.
23 changes: 23 additions & 0 deletions tools/ISCC/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- TOC -->

- [Inno Setup Compiler のパスを見つけるバッチファイル](#inno-setup-compiler-のパスを見つけるバッチファイル)
- [ロジック](#ロジック)
- [バッチファイルでのはまりポイント](#バッチファイルでのはまりポイント)

<!-- /TOC -->

# Inno Setup Compiler のパスを見つけるバッチファイル

ISCC.exe のパスを見つけて 環境変数 `CMD_ISCC` に設定する

## ロジック

以下の順番でパスを検索して、見つかったパスを環境変数 `CMD_ISCC` にセットする。

- %ProgramFiles%\Inno Setup 5\ISCC.exe
- %ProgramFiles(x86)%\Inno Setup 5\ISCC.exe
- %ProgramW6432%\Inno Setup 5\ISCC.exe

## バッチファイルでのはまりポイント

[hhc.exe の readme](../hhc/readme.md) を参照
32 changes: 32 additions & 0 deletions tools/hhc/find-hhc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@rem see readme.md
@echo off
set CMD_HHC=
set PATH_HHC_1=
set PATH_HHC_2=
set PATH_HHC_3=

if not "%ProgramFiles%" == "" set "PATH_HHC_1=%ProgramFiles%\HTML Help Workshop\hhc.exe"
if not "%ProgramFiles(x86)%" == "" set "PATH_HHC_2=%ProgramFiles(x86)%\HTML Help Workshop\hhc.exe"
if not "%ProgramW6432%" == "" set "PATH_HHC_3=%ProgramW6432%\HTML Help Workshop\hhc.exe"

set RESULT_PATH_HHC_1=--
set RESULT_PATH_HHC_2=--
set RESULT_PATH_HHC_3=--

if exist "%PATH_HHC_1%" (
set RESULT_PATH_HHC_1=OK
set "CMD_HHC=%PATH_HHC_1%"
) else if exist "%PATH_HHC_2%" (
set RESULT_PATH_HHC_2=OK
set "CMD_HHC=%PATH_HHC_2%"
) else if exist "%PATH_HHC_3%" (
set RESULT_PATH_HHC_3=OK
set "CMD_HHC=%PATH_HHC_3%"
)

@echo %RESULT_PATH_HHC_1% %PATH_HHC_1%
@echo %RESULT_PATH_HHC_2% %PATH_HHC_2%
@echo %RESULT_PATH_HHC_3% %PATH_HHC_3%
@echo.
@echo CMD_HHC "%CMD_HHC%"
@echo.
55 changes: 55 additions & 0 deletions tools/hhc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!-- TOC -->

- [HTML Help Compiler のパスを見つけるバッチファイル](#html-help-compiler-のパスを見つけるバッチファイル)
- [ロジック](#ロジック)
- [バッチファイルでのはまりポイント](#バッチファイルでのはまりポイント)

<!-- /TOC -->

# HTML Help Compiler のパスを見つけるバッチファイル

hhc.exe のパスを見つけて 環境変数 `CMD_HHC` に設定する

## ロジック

以下の順番でパスを検索して、見つかったパスを環境変数 `CMD_HHC` にセットする。

- %ProgramFiles%\HTML Help Workshop\hhc.exe
- %ProgramFiles(x86)%\HTML Help Workshop\hhc.exe
- %ProgramW6432%\HTML Help Workshop\hhc.exe

## バッチファイルでのはまりポイント

たとえば以下のようなバッチファイルでの記述の場合

```
if not "%ProgramFiles(x86)%" == "" set HHC_PATH2=%ProgramFiles(x86)%\HTML Help Workshop\hhc.exe
if exist "%HHC_PATH2%" (
set CMD_HHC=%HHC_PATH2%
)
```

以下のような意味不明のエラーメッセージが出る

```
\HTML の使い方が誤っています。
```

上記のバッチファイルは実行時に以下のような内容になる。

```
if exist "C:\Program Files (x86)\HTML Help Workshop\hhc.exe" (
set CMD_HHC=C:\Program Files (x86)\HTML Help Workshop\hhc.exe
)
```

if の構文の `(``C:\Program Files (x86)\HTML Help Workshop\hhc.exe``)` と対応すると
解釈されるので `\HTML` が if の条件が成立したときのコマンドと認識されるのでエラーになる。

このエラーを回避するために以下のように、代入文の変数名 ~ 値の部分全体をダブルクオートで囲む。

```
if exist "%HHC_PATH2%" (
set "CMD_HHC=%HHC_PATH2%"
)
```
32 changes: 32 additions & 0 deletions tools/msbuild/find-msbuild.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@rem see readme.md
@echo off
set CMD_MSBUILD=
set PATH_MSBUILD_1=
set PATH_MSBUILD_2=
set PATH_MSBUILD_3=

if not "%ProgramFiles%" == "" set "PATH_MSBUILD_1=%ProgramFiles%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
if not "%ProgramFiles(x86)%" == "" set "PATH_MSBUILD_2=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
if not "%ProgramW6432%" == "" set "PATH_MSBUILD_3=%ProgramW6432%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"

set RESULT_PATH_MSBUILD_1=--
set RESULT_PATH_MSBUILD_2=--
set RESULT_PATH_MSBUILD_3=--

if exist "%PATH_MSBUILD_1%" (
set RESULT_PATH_MSBUILD_1=OK
set "CMD_MSBUILD=%PATH_MSBUILD_1%"
) else if exist "%PATH_MSBUILD_2%" (
set RESULT_PATH_MSBUILD_2=OK
set "CMD_MSBUILD=%PATH_MSBUILD_2%"
) else if exist "%PATH_MSBUILD_3%" (
set RESULT_PATH_MSBUILD_3=OK
set "CMD_MSBUILD=%PATH_MSBUILD_3%"
)

@echo %RESULT_PATH_MSBUILD_1% %PATH_MSBUILD_1%
@echo %RESULT_PATH_MSBUILD_2% %PATH_MSBUILD_2%
@echo %RESULT_PATH_MSBUILD_3% %PATH_MSBUILD_3%
@echo.
@echo CMD_MSBUILD "%CMD_MSBUILD%"
@echo.
23 changes: 23 additions & 0 deletions tools/msbuild/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- TOC -->

- [msbuild のパスを見つけるバッチファイル](#msbuild-のパスを見つけるバッチファイル)
- [ロジック](#ロジック)
- [バッチファイルでのはまりポイント](#バッチファイルでのはまりポイント)

<!-- /TOC -->

# msbuild のパスを見つけるバッチファイル

msbuild.exe のパスを見つけて 環境変数 `CMD_MSBUILD` に設定する

## ロジック

以下の順番でパスを検索して、見つかったパスを環境変数 `CMD_MSBUILD` にセットする。

- %ProgramFiles%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
- %ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
- %ProgramW6432%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe

## バッチファイルでのはまりポイント

[hhc.exe の readme](../hhc/readme.md) を参照
Loading

0 comments on commit bcfe60b

Please sign in to comment.