Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

バージョン情報をリファクタリングする #1738

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-sakura.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
steps:
## see https://github.com/actions/checkout
- uses: actions/checkout@v2
with:
fetch-depth: 0

## see https://github.com/microsoft/setup-msbuild
- name: Add msbuild to PATH
Expand Down
5 changes: 3 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ platform:
- Win32
- x64

# set clone depth
clone_depth: 5
# comment-out clone_depth to fetch entire repository.
## set clone depth
#clone_depth: 5

# see "Skip commits" at https://www.appveyor.com/docs/how-to/filtering-commits/#commit-files-github-and-bitbucket-only
skip_commits:
Expand Down
6 changes: 5 additions & 1 deletion ci/azure-pipelines/template.job.build-on-msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
clean: all # what to clean each time; if not mentioned, does not clean
fetchDepth: 5 # the depth of commits to ask Git to fetch; defaults to no limit

- bash: |
BUILD_VERSION=`git log --oneline --no-merges | wc -l`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コミット数のカウントには git rev-list --count --no-merges @ が使えます。(githash.bat についても同様)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git rev-list --count --no-merges @ が使えます。

これだとwc -lfind /C " "と併用せずに数えられますね。
ありがとうございます。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。これならMinGWビルドのコミットカウントを別にする必要もなさそうです。
これはこれとして別PRで対応しようと思います。

echo "##vso[task.setvariable variable=BUILD_VERSION]$BUILD_VERSION"
displayName: compute BUILD_VERSION

# show environmental variables for debug.
- script: set
Expand Down
43 changes: 43 additions & 0 deletions sakura/githash.bat
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,46 @@ exit /b 0
for /f "usebackq" %%s in (`"%CMD_GIT%" describe --tags --contains 2^>nul`) do (
set GIT_TAG_NAME=%%s
)

:: Gitリポジトリの累積コミット数(取れない場合は0)
call :set_build_version
) else (
set GIT_SHORT_COMMIT_HASH=
set GIT_COMMIT_HASH=
set GIT_REMOTE_ORIGIN_URL=
set GIT_TAG_NAME=
set BUILD_VERSION=0
)

:: ビルド環境の名前が未定義なら local とする
if not defined BUILD_ENV_NAME (
set BUILD_ENV_NAME=Local
)

@rem get back to the original directory
popd

exit /b 0

:set_build_version
if not "%GIT_ENABLED%" == "1" exit /b 0
if defined BUILD_VERSION exit /b 0

:: gitがPATHに存在するかチェックする
set HAS_GIT_IN_PATH=0
for /f "usebackq" %%a in (`where $PATH:git`) do (
set HAS_GIT_IN_PATH=1
)
This conversation was marked as resolved.
Show resolved Hide resolved

if "%HAS_GIT_IN_PATH%" == "1" (
for /f "usebackq" %%s in (`git log --oneline --no-merges ^| find /C " "`) do (
This conversation was marked as resolved.
Show resolved Hide resolved
set BUILD_VERSION=%%s
)
) else (
set BUILD_VERSION=0
)
exit /b 0

:set_repo_and_pr_variables
if defined APPVEYOR_REPO_NAME (
set CI_REPO_NAME=%APPVEYOR_REPO_NAME%
Expand Down Expand Up @@ -142,6 +170,7 @@ exit /b 0
:set_ci_build_url
call :set_ci_build_url_for_appveyor
call :set_ci_build_url_for_azurepipelines
call :set_ci_build_url_for_githubactions
exit /b 0

:set_ci_build_url_for_appveyor
Expand All @@ -150,16 +179,24 @@ exit /b 0
if not defined APPVEYOR_ACCOUNT_NAME exit /b 0
if not defined APPVEYOR_PROJECT_SLUG exit /b 0
if not defined APPVEYOR_BUILD_VERSION exit /b 0
set BUILD_ENV_NAME=Appveyor
set CI_BUILD_URL=%APPVEYOR_URL%/project/%APPVEYOR_ACCOUNT_NAME%/%APPVEYOR_PROJECT_SLUG%/build/%APPVEYOR_BUILD_VERSION%
exit /b 0

:set_ci_build_url_for_azurepipelines
if not defined SYSTEM_TEAMFOUNDATIONSERVERURI exit /b 0
if not defined SYSTEM_TEAMPROJECT exit /b 0
if not defined BUILD_BUILDID exit /b 0
set BUILD_ENV_NAME=AZP
set CI_BUILD_URL=%SYSTEM_TEAMFOUNDATIONSERVERURI%%SYSTEM_TEAMPROJECT%/_build/results?buildId=%BUILD_BUILDID%
exit /b 0

:set_ci_build_url_for_githubactions
if not defined GITHUB_ACTIONS exit /b 0
if not "%GITHUB_ACTIONS%" == "true" exit /b 0
set BUILD_ENV_NAME=GHA
exit /b 0

:update_output_githash
@rem update githash.h if necessary
set GITHASH_H=%OUT_DIR%\githash.h
Expand Down Expand Up @@ -207,6 +244,9 @@ exit /b 0
@echo APPVEYOR_URL : %APPVEYOR_URL%
@echo APPVEYOR_PROJECT_SLUG : %APPVEYOR_PROJECT_SLUG%
@echo.
@echo BUILD_ENV_NAME : %BUILD_ENV_NAME%
@echo BUILD_VERSION : %BUILD_VERSION%
@echo.

if exist "%GITHASH_H%" del "%GITHASH_H%"
move /y "%GITHASH_H_TMP%" "%GITHASH_H%"
Expand Down Expand Up @@ -327,4 +367,7 @@ exit /b 0
echo // APPVEYOR specific variables end
echo //

echo #define BUILD_ENV_NAME "%BUILD_ENV_NAME%"
echo #define BUILD_VERSION %BUILD_VERSION%

exit /b 0
9 changes: 8 additions & 1 deletion sakura_core/_main/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
#include "StdAfx.h"
#include "_main/global.h"

#include "_main/CNormalProcess.h"
#include "basis/CErrorInfo.h"
#include "config/app_constants.h"
#include "window/CEditWnd.h"
#include "CNormalProcess.h"
#include "version.h"

#ifdef DEV_VERSION
#pragma message("-------------------------------------------------------------------------------------")
#pragma message("--- This is a Dev version and under development. Be careful to use this version. ---")
#pragma message("-------------------------------------------------------------------------------------")
#endif

/*!
アプリ名を取得します。
Expand Down
3 changes: 0 additions & 3 deletions sakura_core/config/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,4 @@ static const bool UNICODE_BOOL=true;
#define DBG_NEW new
#endif

#if _WIN64
#define ALPHA_VERSION
#endif
#endif /* SAKURA_BUILD_CONFIG_DB7D8D47_EA6A_4ABF_A081_A31875D78808_H_ */
24 changes: 4 additions & 20 deletions sakura_core/dlg/CDlgAbout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ BOOL CDlgAbout::OnInitDialog( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
// 2010.04.15 Moca コンパイラ情報を分離/WINヘッダ,N_SHAREDATA_VERSION追加

// 以下の形式で出力
//サクラエディタ Ver. 2.4.1.0 32bit DEBUG dev
//(GitHash xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
//サクラエディタ開発版(64bitデバッグ) Ver. 2.4.1.1234 GHA (xxxxxxxx)
//(GitURL https://github.com/sakura/sakura-editor.git)
//
// Share Ver: 96
Expand All @@ -184,28 +183,14 @@ BOOL CDlgAbout::OnInitDialog( HWND hwndDlg, WPARAM wParam, LPARAM lParam )

// 1行目
// バージョン情報
cmemMsg.AppendString(LS(STR_DLGABOUT_APPNAME)); // e.g. "サクラエディタ", "Sakura Editor"
cmemMsg.AppendString(L" ");

DWORD dwVersionMS, dwVersionLS;
GetAppVersionInfo( NULL, VS_VERSION_INFO, &dwVersionMS, &dwVersionLS );

cmemMsg.AppendStringF(
L"v%d.%d.%d.%d",
L"%s Ver. %d.%d.%d.%d " LTEXT(BUILD_ENV_NAME) LTEXT(VERSION_HASH) L"\r\n",
LS(STR_GSTR_APPNAME),
HIWORD(dwVersionMS), LOWORD(dwVersionMS), HIWORD(dwVersionLS), LOWORD(dwVersionLS) // e.g. {2, 3, 2, 0}
);
cmemMsg.AppendString( L" " _T(VER_PLATFORM) );
cmemMsg.AppendString( _T(SPACE_WHEN_DEBUG) _T(VER_CONFIG) );
#ifdef DEV_VERSION
cmemMsg.AppendString( _T(DEV_VERSION_STR_WITH_SPACE) );
#endif
#ifdef ALPHA_VERSION
cmemMsg.AppendString( L" " _T(ALPHA_VERSION_STR));
#endif
#ifdef GIT_TAG_NAME
cmemMsg.AppendString( L" (tag " _T(GIT_TAG_NAME) L")" );
#endif
cmemMsg.AppendString( L"\r\n" );

// 2行目
#ifdef GIT_COMMIT_HASH
Expand All @@ -221,9 +206,8 @@ BOOL CDlgAbout::OnInitDialog( HWND hwndDlg, WPARAM wParam, LPARAM lParam )
cmemMsg.AppendString( L"\r\n" );

// コンパイル情報
cmemMsg.AppendString( L" Compile Info: " );
cmemMsg.AppendStringF(
_T(COMPILER_TYPE) _T(TARGET_M_SUFFIX) L"%d " TSTR_TARGET_MODE L" WIN%03x/I%03x/C%03x/N%03x\r\n",
L" Compile Info: " _T(COMPILER_TYPE) _T(TARGET_M_SUFFIX) L"%d " TSTR_TARGET_MODE L" WIN%03x/I%03x/C%03x/N%03x\r\n",
COMPILER_VER, WINVER, _WIN32_IE, MY_WIN32_WINDOWS, MY_WIN32_WINNT
);

Expand Down
32 changes: 17 additions & 15 deletions sakura_core/sakura_rc.rc2
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
// このファイルにはリソースエディタで編集できない要素を配置します.
// このファイルのエンコーディング/改行コードは UTF-16LE(BOM)/CRLF です.

#define _APP_NAME_1 "sakura"
#define _APP_NAME_1 "サクラエディタ"

#ifdef _DEBUG
#define _APP_NAME_2 "(デバッグ版)"
#ifdef DEV_VERSION
#define _APP_NAME_2 "開発版"
#else
#define _APP_NAME_2 ""
#endif

#ifdef DEV_VERSION
#define _APP_NAME_3 "(dev Version)"
#ifdef _WIN64
#define _APP_NAME_3 "64bit"
#else
#define _APP_NAME_3 ""
#define _APP_NAME_3 "32bit"
#endif

#ifdef ALPHA_VERSION
#define _APP_NAME_4 "(Alpha Version)"
#ifdef _DEBUG
#define _APP_NAME_4 "デバッグ"
#else
#define _APP_NAME_4 ""
#endif

#if defined(_WIN64) || defined(_DEBUG)
#define _GSTR_APPNAME _APP_NAME_1 _APP_NAME_2 "(" _APP_NAME_3 _APP_NAME_4 ")"
#else
#define _GSTR_APPNAME _APP_NAME_1 _APP_NAME_2 _APP_NAME_3 _APP_NAME_4
#endif

#define S_COPYRIGHT "Copyright (C) 1998-2021 by Norio Nakatani & Collaborators"
#define FL_VER PR_VER
#define FL_VER_STR PR_VER_STR

/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -90,8 +92,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION FL_VER
PRODUCTVERSION PR_VER
FILEVERSION FILE_VERSION
PRODUCTVERSION PRODUCT_VERSION
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x01L
Expand All @@ -109,13 +111,13 @@ BEGIN
VALUE "Comments", "このソフトはフリーソフトです。\0"
VALUE "CompanyName", "Project: Sakura-Editor\0"
VALUE "FileDescription", "サクラエディタ\0"
VALUE "FileVersion", FL_VER_STR
VALUE "FileVersion", VERSION_STR
VALUE "InternalName", "sakura\0"
VALUE "LegalCopyright", S_COPYRIGHT
VALUE "LegalTrademarks", " \0"
VALUE "OriginalFilename", "sakura.exe\0"
VALUE "ProductName", "サクラエディタ\0"
VALUE "ProductVersion", RESOURCE_VERSION_STRING(PR_VER_STR) // e.g. "2.3.2.0 (4a0de579) UNICODE 64bit DEBUG"
VALUE "ProductName", _GSTR_APPNAME "\0"
VALUE "ProductVersion", VERSION_STR VERSION_HASH // e.g. "2.4.1.0 (4a0de579)"
END
END
BLOCK "VarFileInfo"
Expand Down
86 changes: 11 additions & 75 deletions sakura_core/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,87 +30,23 @@
#include "githash.h"

// バージョン定義 //
// ver a.b.c.d
// 例: ver 2.3.2.0
// a => 2
// b => 3
// c => 2
// d => 0
#define VER_A 2 // a of ver a.b.c.d
#define VER_B 4 // b of ver a.b.c.d
#define VER_C 2 // c of ver a.b.c.d
#ifdef CI_BUILD_NUMBER_INT
#define VER_D CI_BUILD_NUMBER_INT // d of ver a.b.c.d
#else
#define VER_D 0 // d of ver a.b.c.d
#endif
#define VER_A 2 // メジャーバージョン(2固定)
#define VER_B 4 // マイナーバージョン(4以降はGitHub版)
#define VER_C 2 // 連番(マージの通し番号)
#define VER_D BUILD_VERSION // Gitの累積コミット数

#define TO_STR(arg) #arg
#define MAKE_VERSION_STR(a, b, c, d, sep) TO_STR(a) sep TO_STR(b) sep TO_STR(c) sep TO_STR(d)
#define MAKE_VERSION_STR_PERIOD(a, b, c, d) MAKE_VERSION_STR(a, b, c, d, ".")
#define MAKE_VERSION_COMMA(a, b, c, d) a, b, c, d

#define PR_VER_STR MAKE_VERSION_STR_PERIOD(VER_A, VER_B, VER_C, VER_D)
#define PR_VER MAKE_VERSION_COMMA(VER_A, VER_B, VER_C, VER_D)

#define VER_CHARSET "UNICODE"

#ifdef _WIN64
#define VER_PLATFORM "64bit"
#else
#define VER_PLATFORM "32bit"
#endif

#ifdef _DEBUG
#define VER_CONFIG "DEBUG"
#else
#define VER_CONFIG ""
#endif
#define _MAKE_VERSION(a, b, c, d) a, b, c, d
#define _MAKE_VERSION_STR(a, b, c, d, sep) TO_STR(a) sep TO_STR(b) sep TO_STR(c) sep TO_STR(d)

#ifdef _DEBUG
#define SPACE_WHEN_DEBUG " "
#else
#define SPACE_WHEN_DEBUG ""
#endif

#if defined(ALPHA_VERSION)
#pragma message("----------------------------------------------------------------------------------------")
#pragma message("--- This is an alpha version and under development. Be careful to use this version. ---")
#pragma message("----------------------------------------------------------------------------------------")
#endif

#ifdef ALPHA_VERSION
#define ALPHA_VERSION_STR "Alpha Version"
#define ALPHA_VERSION_STR_WITH_SPACE " " ALPHA_VERSION_STR
#else
#define ALPHA_VERSION_STR_WITH_SPACE ""
#endif

#ifdef DEV_VERSION
#define DEV_VERSION_STR_WITH_SPACE " dev"
#else
#define DEV_VERSION_STR_WITH_SPACE ""
#endif
#define PRODUCT_VERSION _MAKE_VERSION(VER_A, VER_B, VER_C, 0)
#define FILE_VERSION _MAKE_VERSION(VER_A, VER_B, VER_C, VER_D)
#define VERSION_STR _MAKE_VERSION_STR(VER_A, VER_B, VER_C, VER_D, ".")

// バージョン情報埋め込み用 Git ハッシュ文字列 (存在しない場合には空文字列)
#ifdef GIT_SHORT_COMMIT_HASH
#define VER_GIT_SHORTHASH " (" GIT_SHORT_COMMIT_HASH ")"
#define VERSION_HASH " (" GIT_SHORT_COMMIT_HASH ")"
#else
#define VER_GIT_SHORTHASH ""
#define VERSION_HASH " (Undefined)"
#endif

// リソース埋め込み用バージョン文字列 //
// e.g. "2.3.2.0 (4a0de579) UNICODE 64bit dev DEBUG" … (開発版) デバッグビルド時の例 //
// e.g. "2.3.2.0 (4a0de579) UNICODE 64bit dev" … (開発版) リリースビルド時の例 //
// e.g. "2.3.2.0 UNICODE 64bit dev" … (開発版) Git 情報無い場合の例 //
// e.g. "2.3.2.0 (4a0de579) UNICODE 64bit DEBUG" … (タグ付き) デバッグビルド時の例 //
// e.g. "2.3.2.0 (4a0de579) UNICODE 64bit" … (タグ付き) リリースビルド時の例 //
#define RESOURCE_VERSION_STRING(_VersionString) \
_VersionString \
VER_GIT_SHORTHASH \
" " VER_CHARSET \
" " VER_PLATFORM \
DEV_VERSION_STR_WITH_SPACE \
SPACE_WHEN_DEBUG \
VER_CONFIG ALPHA_VERSION_STR_WITH_SPACE
#endif /* SAKURA_VERSION_F8EBA970_BB7A_43D9_B89A_04FB0B586A8A_H_ */
Loading