Skip to content

Commit 7f278db

Browse files
committed
バージョン文字列にgitのハッシュを追記するスクリプトを追加
1 parent 252e05e commit 7f278db

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

Document/HowToBuild.txt

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
6565
となっている部分をインストールされている.NETのバージョンに変更するか、v4.5のTargeting Packをインストールする
6666

67+
・gitコマンドのある環境では、versionhashgen.batを実行すればバージョン情報にコミットハッシュを埋め込むことができる
68+
versionhash.shはMSYS2などのシェル環境用
69+
6770
・Lua5.2を組み込んだビルドもできる("EpgTimerSrv\EpgTimerSrv.sln"の[Release-withlua])
6871
以下のファイルが必要
6972
・https://www.lua.org/ のlua-5.2.4.tar.gzのsrcフォルダの中身を"EpgTimerSrv\EpgTimerSrv\lua"に既存ファイルも含めて上書き

versionhash.sh

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
cd "$(dirname "$0")"
4+
if [ "$1" = clean ]; then
5+
target=Common/CommonResource.h
6+
grep -q '^#define EDCB_VERSION_EXTRA ' $target
7+
if [ $? -eq 0 ]; then
8+
grep -v '^#define EDCB_VERSION_EXTRA ' $target | sed 's/$/\r/' >$target.new
9+
mv $target.new $target
10+
fi
11+
12+
target=EpgTimer/EpgTimer/AppVersion.cs
13+
grep -q '^ *const string VERSION_EXTRA = "";' $target
14+
if [ $? -ne 0 ]; then
15+
grep -v '^ *\(}\|const string VERSION_EXTRA =\)' $target | sed 's/$/\r/' >$target.new
16+
echo -e " const string VERSION_EXTRA = \"\";\r\n }\r\n}\r" >>$target.new
17+
mv $target.new $target
18+
fi
19+
elif [ "$1" = gen ]; then
20+
git_hash=$(git rev-parse --short=7 HEAD)
21+
if [ $? -eq 0 ]; then
22+
target=Common/CommonResource.h
23+
grep -qF "$git_hash" $target
24+
if [ $? -ne 0 ]; then
25+
echo -e "#define EDCB_VERSION_EXTRA \"[$git_hash]\"\r" >$target.new
26+
grep -v '^#define EDCB_VERSION_EXTRA ' $target | sed 's/$/\r/' >>$target.new
27+
mv $target.new $target
28+
fi
29+
30+
target=EpgTimer/EpgTimer/AppVersion.cs
31+
grep -qF "$git_hash" $target
32+
if [ $? -ne 0 ]; then
33+
grep -v '^ *\(}\|const string VERSION_EXTRA =\)' $target | sed 's/$/\r/' >$target.new
34+
echo -e " const string VERSION_EXTRA = \"[$git_hash]\";\r\n }\r\n}\r" >>$target.new
35+
mv $target.new $target
36+
fi
37+
fi
38+
elif [ "$1" = edittag ]; then
39+
target=Common/CommonResource.h
40+
if [ -z "$2" ]; then
41+
sed "0,/^\\/*#define EDCB_VERSION_TAG / s|^/*\\(#define EDCB_VERSION_TAG \\).*|//\\1\"\"|" $target | sed 's/$/\r/' >$target.new
42+
else
43+
sed "0,/^\\/*#define EDCB_VERSION_TAG / s|^/*\\(#define EDCB_VERSION_TAG \\).*|\\1\"$2\"|" $target | sed 's/$/\r/' >$target.new
44+
fi
45+
mv $target.new $target
46+
47+
target=EpgTimer/EpgTimer/AppVersion.cs
48+
sed "s|^\\( *const string VERSION_TAG = \\).*|\\1\"$2\";|" $target | sed 's/$/\r/' >$target.new
49+
mv $target.new $target
50+
else
51+
echo 'Usage: versionhash.sh clean|gen|edittag [<tag>]'
52+
exit 2
53+
fi

versionhashclean.bat

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@echo off
2+
pushd "%~dp0"
3+
set target=Common\CommonResource.h
4+
findstr /bc:"#define EDCB_VERSION_EXTRA " %target% >nul
5+
if %errorlevel% equ 0 (
6+
findstr /vbc:"#define EDCB_VERSION_EXTRA " %target% >%target%.new
7+
move /y %target%.new %target%
8+
)
9+
10+
set target=EpgTimer\EpgTimer\AppVersion.cs
11+
findstr /brc:" *const string VERSION_EXTRA = \"\";" %target% >nul
12+
if %errorlevel% neq 0 (
13+
findstr /vbrc:" *}" /c:" *const string VERSION_EXTRA =" %target% >%target%.new
14+
echo const string VERSION_EXTRA = "";>>%target%.new
15+
echo }>>%target%.new
16+
echo }>>%target%.new
17+
move /y %target%.new %target%
18+
)
19+
popd

versionhashgen.bat

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
pushd "%~dp0"
3+
for /f "usebackq tokens=*" %%i in (`git rev-parse --short=7 HEAD`) do set git_hash=%%i
4+
if "%git_hash%" == "" goto label9
5+
6+
set target=Common\CommonResource.h
7+
find "%git_hash%" %target% >nul
8+
if %errorlevel% neq 0 (
9+
echo #define EDCB_VERSION_EXTRA "[%git_hash%]">%target%.new
10+
findstr /vbc:"#define EDCB_VERSION_EXTRA " %target% >>%target%.new
11+
move /y %target%.new %target%
12+
)
13+
14+
set target=EpgTimer\EpgTimer\AppVersion.cs
15+
find "%git_hash%" %target% >nul
16+
if %errorlevel% neq 0 (
17+
findstr /vbrc:" *}" /c:" *const string VERSION_EXTRA =" %target% >%target%.new
18+
echo const string VERSION_EXTRA = "[%git_hash%]";>>%target%.new
19+
echo }>>%target%.new
20+
echo }>>%target%.new
21+
move /y %target%.new %target%
22+
)
23+
:label9
24+
popd

0 commit comments

Comments
 (0)