diff --git a/CMakeLists.txt b/CMakeLists.txt index aee14d57f..57a8fe351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,21 @@ if(NOT C2A_USE_C99_STDINT) include_directories(Library/stdint_wrapper) endif() +execute_process( + COMMAND git log -1 --format=%H + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_C2A_CORE + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_C2A_CORE_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE +) +add_definitions("-DGIT_REVISION_C2A_CORE=\"${GIT_REVISION_C2A_CORE}\"") +add_definitions("-DGIT_REVISION_C2A_CORE_SHORT=0x${GIT_REVISION_C2A_CORE_SHORT}") + if(BUILD_C2A_AS_CXX) set_source_files_properties(${C2A_SRCS} PROPERTIES LANGUAGE CXX) # C++ endif() diff --git a/Cargo.toml b/Cargo.toml index cfe89d352..691fd5e77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c2a-core" -version = "3.9.0-beta.5" +version = "3.9.0-beta.6" edition = "2021" description = "Core of Command Centric Architecture" diff --git a/Examples/2nd_obc_user/CMakeLists.txt b/Examples/2nd_obc_user/CMakeLists.txt index 4db3a125d..ed9428b31 100644 --- a/Examples/2nd_obc_user/CMakeLists.txt +++ b/Examples/2nd_obc_user/CMakeLists.txt @@ -39,6 +39,21 @@ if(SHOW_DEBUG_PRINT_ON_SILS) message("Show debug print") endif() +execute_process( + COMMAND git log -1 --format=%H + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_C2A_USER + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_C2A_USER_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE +) +add_definitions("-DGIT_REVISION_C2A_USER=\"${GIT_REVISION_C2A_USER}\"") +add_definitions("-DGIT_REVISION_C2A_USER_SHORT=0x${GIT_REVISION_C2A_USER_SHORT}") + add_subdirectory(${C2A_CORE_DIR}) add_subdirectory(${C2A_USER_DIR}/Applications) @@ -89,16 +104,4 @@ else() ) endif() -if(WIN32) - add_custom_command(TARGET ${PROJECT_NAME} - PRE_BUILD - COMMAND git_revision.bat - WORKING_DIRECTORY ${C2A_USER_DIR}/Script) -else() - add_custom_command(TARGET ${PROJECT_NAME} - PRE_BUILD - COMMAND ./git_revision.sh - WORKING_DIRECTORY ${C2A_USER_DIR}/Script) -endif() - include(${C2A_USER_DIR}/common.cmake) diff --git a/Examples/2nd_obc_user/src/src_user/Applications/UserDefined/debug_apps.c b/Examples/2nd_obc_user/src/src_user/Applications/UserDefined/debug_apps.c index 4a8a61f21..9692e4f77 100644 --- a/Examples/2nd_obc_user/src/src_user/Applications/UserDefined/debug_apps.c +++ b/Examples/2nd_obc_user/src/src_user/Applications/UserDefined/debug_apps.c @@ -4,6 +4,7 @@ #include // for NULL #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include "../../Applications/DriverInstances/di_mobc.h" // #include -#include "../../Library/git_revision.h" #include "../../Library/vt100.h" void APP_DBG_flush_screen_(void); diff --git a/Examples/2nd_obc_user/src/src_user/Library/CMakeLists.txt b/Examples/2nd_obc_user/src/src_user/Library/CMakeLists.txt index 82e7c6f03..7b98581d7 100644 --- a/Examples/2nd_obc_user/src/src_user/Library/CMakeLists.txt +++ b/Examples/2nd_obc_user/src/src_user/Library/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.13) project(C2A_USER_LIB) set(C2A_SRCS - git_revision.c print.c vt100.c ) diff --git a/Examples/2nd_obc_user/src/src_user/Library/git_revision.c b/Examples/2nd_obc_user/src/src_user/Library/git_revision.c deleted file mode 100644 index 6ef1c0e56..000000000 --- a/Examples/2nd_obc_user/src/src_user/Library/git_revision.c +++ /dev/null @@ -1,14 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief git revisionをコードに埋め込む - */ - -#include "git_revision.h" - -const char GIT_REV_CORE[41] = "0000000000000000000000000000000000000000"; -const uint32_t GIT_REV_CORE_SHORT = 0x0000000; -const char GIT_REV_USER[41] = "0000000000000000000000000000000000000000"; -const uint32_t GIT_REV_USER_SHORT = 0x0000000; - -#pragma section diff --git a/Examples/2nd_obc_user/src/src_user/Library/git_revision.h b/Examples/2nd_obc_user/src/src_user/Library/git_revision.h deleted file mode 100644 index 9da4eabed..000000000 --- a/Examples/2nd_obc_user/src/src_user/Library/git_revision.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @file - * @brief git revisionをコードに埋め込む - */ -#ifndef GIT_REVISION_H_ -#define GIT_REVISION_H_ - -#include - -extern const char GIT_REV_CORE[41]; -extern const uint32_t GIT_REV_CORE_SHORT; -extern const char GIT_REV_USER[41]; -extern const uint32_t GIT_REV_USER_SHORT; - -#endif // GIT_REVISION_H_ diff --git a/Examples/2nd_obc_user/src/src_user/Script/Git/revision.bat b/Examples/2nd_obc_user/src/src_user/Script/Git/revision.bat new file mode 100644 index 000000000..29978faba --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/Script/Git/revision.bat @@ -0,0 +1,31 @@ +@ECHO OFF +REM generate C header for Git revision + +REM current directoryɈړ(src_user/Script/Git) +cd /d %~dp0 + +REM src_userɈړ +cd ..\.. + +for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_user=%%a +for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_user_short=%%a + +REM cd ..\..\src_core + +REM generate header +REM MEMO: ̃qAhLgǂ̏winecmd.exe(Windows 6.1.7601)ƓȂH +( +echo.#ifndef GIT_REVISION_CONFIG_H_ +echo.#define GIT_REVISION_CONFIG_H_ +echo. +echo./* This file is generated by src_user/Script/Git/revision.bat */ +echo. +call ..\src_core\Script\Git\revision.bat +echo.#define GIT_REVISION_C2A_USER "%git_rev_user%" +echo.#define GIT_REVISION_C2A_USER_SHORT 0x%git_rev_user_short% +echo. +echo.#endif // GIT_REVISION_CONFIG_H_ +) > Settings\git_revision_config.h + +REM current directoryɈړ(src_user/Script/Git) +cd /d %~dp0 diff --git a/Examples/2nd_obc_user/src/src_user/Script/Git/revision.sh b/Examples/2nd_obc_user/src/src_user/Script/Git/revision.sh new file mode 100644 index 000000000..2b1d63ae8 --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/Script/Git/revision.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# generate C header for Git revision + +cd $(dirname $0) # src/src_user/Script/Git +cd ../../ # src/src_user + +# get core revision +git_revs_core=$(../src_core/Script/Git/revision.sh) + +git_rev_user=$(git log --pretty=format:%H -1) +git_rev_user_short=$(git log --pretty=format:%h -1) + +tee Settings/git_revision_config.h << EOS +#ifndef GIT_REVISION_CONFIG_H_ +#define GIT_REVISION_CONFIG_H_ + +/* This file is generated by src_user/Script/Git/revision.sh */ +#define C2A_GIT_REVISION_GENERATED + +${git_revs_core} +#define GIT_REVISION_C2A_USER "${git_rev_user}" +#define GIT_REVISION_C2A_USER_SHORT 0x${git_rev_user_short} + +#endif // GIT_REVISION_CONFIG_H_ +EOS diff --git a/Examples/2nd_obc_user/src/src_user/Script/git_revision.bat b/Examples/2nd_obc_user/src/src_user/Script/git_revision.bat deleted file mode 100644 index 99aab22ee..000000000 --- a/Examples/2nd_obc_user/src/src_user/Script/git_revision.bat +++ /dev/null @@ -1,29 +0,0 @@ -@ECHO OFF - -REM @brief git revision ߍ - -REM current directoryɈړ -cd /d %~dp0 - -for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_user=%%a -for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_user_short=%%a - -cd ..\..\src_core - -for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_core=%%a -for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_core_short=%%a - -cd ..\src_user\Script - -if exist ..\Library\git_revision.c del ..\Library\git_revision.c - -setlocal EnableDelayedExpansion -for /f "delims=" %%a in (git_revision.tmp) do ( - set line=%%a - set line=!line:git_rev_core_hash=%git_rev_core%! - set line=!line:git_rev_core_short_hash=%git_rev_core_short%! - set line=!line:git_rev_user_hash=%git_rev_user%! - set line=!line:git_rev_user_short_hash=%git_rev_user_short%! - echo !line! >> ..\Library\git_revision.c -) -endlocal diff --git a/Examples/2nd_obc_user/src/src_user/Script/git_revision.sh b/Examples/2nd_obc_user/src/src_user/Script/git_revision.sh deleted file mode 100755 index 756a5f338..000000000 --- a/Examples/2nd_obc_user/src/src_user/Script/git_revision.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /bin/sh - -# @brief git revision 埋め込み - -# current directoryに移動 -cd `dirname $0` - -git_rev_user=$(git log --pretty=format:%H -1) -git_rev_user_short=$(git log --pretty=format:%h -1) - -cd ../../src_core - -git_rev_core=$(git log --pretty=format:%H -1) -git_rev_core_short=$(git log --pretty=format:%h -1) - -cd ../src_user/Script - -sed -e s/git_rev_core_hash/${git_rev_core}/ -e s/git_rev_core_short_hash/${git_rev_core_short}/ -e s/git_rev_core_short_hash/${git_rev_core_short}/ -e s/git_rev_user_hash/${git_rev_user}/ -e s/git_rev_user_short_hash/${git_rev_user_short}/ git_revision.tmp > ../Library/git_revision.c diff --git a/Examples/2nd_obc_user/src/src_user/Script/git_revision.tmp b/Examples/2nd_obc_user/src/src_user/Script/git_revision.tmp deleted file mode 100644 index a5a66bbe5..000000000 --- a/Examples/2nd_obc_user/src/src_user/Script/git_revision.tmp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief git revisionをコードに埋め込む - */ - -#include "git_revision.h" - -const char GIT_REV_CORE[41] = "git_rev_core_hash"; -const uint32_t GIT_REV_CORE_SHORT = 0xgit_rev_core_short_hash; -const char GIT_REV_USER[41] = "git_rev_user_hash"; -const uint32_t GIT_REV_USER_SHORT = 0xgit_rev_user_short_hash; - -#pragma section diff --git a/Examples/2nd_obc_user/src/src_user/Settings/git_revision_config.h b/Examples/2nd_obc_user/src/src_user/Settings/git_revision_config.h new file mode 100644 index 000000000..0a17e3fa3 --- /dev/null +++ b/Examples/2nd_obc_user/src/src_user/Settings/git_revision_config.h @@ -0,0 +1,44 @@ +#ifndef GIT_REVISION_CONFIG_H_ +#define GIT_REVISION_CONFIG_H_ + +/** + * このファイルは自動生成される場合と設定だけを書く場合があります. + * C2A core/userのcommit hashはコマンドラインオプションないしこのファイルでdefineされ, + * 実際の埋め込みについてはsrc_core/Librari/git_revision.hとsrc_core/c2a_core_main.cが制御します. + */ + +#if 1 // このuserはCMakeでビルドするのでこれを使う +/*!< @brief CMakeでビルドする時など,コマンドラインオプションからcommit hashを流し込む場合の設定 + * この場合,以下の定数をコマンドラインオプション(-D)などで設定してください + * GIT_REVISION_C2A_CORE C2A coreのcommit hash(文字列) + * GIT_REVISION_C2A_CORE_SHORT C2A coreのcommit hash short(0xから始まる数値) + * GIT_REVISION_C2A_USER C2A userのcommit hash(文字列) + * GIT_REVISION_C2A_USER_SHORT C2A userのcommit hash short(0xから始まる数値) + */ + +#define C2A_GIT_REVISION_FROM_OPTION +#endif // from option + +#if 0 +/*!< @brief このファイルを自動生成する場合 + * src_user/Script/Git/revision.sh/batが以下のような内容でこのファイルを生成します + */ + +/* This file is generated by src_user/Script/Git/revision.sh */ +#define C2A_GIT_REVISION_GENERATED + +#define GIT_REVISION_C2A_CORE "1234567890123456789012345678901234567890" +#define GIT_REVISION_C2A_CORE_SHORT 0x1234567 +#define GIT_REVISION_C2A_USER "1234567890123456789012345678901234567890" +#define GIT_REVISION_C2A_USER_SHORT 0x1234567 +#endif // generated version + +#if 0 +/*!< @brief commit hashを埋め込まない場合の設定 + * 実際には0が埋め込まれます + */ + +#define C2A_GIT_REVISION_IGNORE +#endif + +#endif // GIT_REVISION_CONFIG_H_ diff --git a/Examples/2nd_obc_user/src/src_user/TlmCmd/telemetry_source.h b/Examples/2nd_obc_user/src/src_user/TlmCmd/telemetry_source.h index b6e6bddb9..173c5f985 100644 --- a/Examples/2nd_obc_user/src/src_user/TlmCmd/telemetry_source.h +++ b/Examples/2nd_obc_user/src/src_user/TlmCmd/telemetry_source.h @@ -6,6 +6,7 @@ #define TELEMETRY_SOURCE_H_ #include "string.h" // for memcpy +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include "../Applications/app_headers.h" -#include "../Library/git_revision.h" #include "../Settings/build_settings.h" #endif diff --git a/Examples/2nd_obc_user/src/src_user/c2a_main.c b/Examples/2nd_obc_user/src/src_user/c2a_main.c index 572d664be..403a69a16 100644 --- a/Examples/2nd_obc_user/src/src_user/c2a_main.c +++ b/Examples/2nd_obc_user/src/src_user/c2a_main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -59,6 +60,8 @@ static void C2A_main_(void) // Printf内部で WDT_clear_wdt(); が呼ばれてることに注意! static void C2A_init_(void) { + Printf("C2A_init: user revision = %s\n", GIT_REV_USER); + WDT_init(); TMGR_init(); // Time Manager // AM_initialize_all_apps での時間計測のためにここで初期化 diff --git a/Examples/2nd_obc_user/sync_with_minimum_user.bat b/Examples/2nd_obc_user/sync_with_minimum_user.bat index 5d125aa8a..3d7224bc7 100644 --- a/Examples/2nd_obc_user/sync_with_minimum_user.bat +++ b/Examples/2nd_obc_user/sync_with_minimum_user.bat @@ -19,6 +19,7 @@ call :sync_file ".\src\src_user\IfWrapper\Sils\wdt_sils.cpp" "..\minimum_user\sr call :sync_file ".\src\src_user\IfWrapper\SilsMockup\README.md" "..\minimum_user\src\src_user\IfWrapper\SilsMockup\README.md" call :sync_file ".\src\src_user\IfWrapper\SilsMockup\uart_sils.c" "..\minimum_user\src\src_user\IfWrapper\SilsMockup\uart_sils.c" call :sync_file ".\src\src_user\IfWrapper\SilsMockup\wdt_sils.c" "..\minimum_user\src\src_user\IfWrapper\SilsMockup\wdt_sils.c" +call :sync_file ".\src\src_user\Settings\git_revision_config.h" "..\minimum_user\src\src_user\Settings\git_revision_config.h" call :sync_file ".\src\src_user\Settings\DriverSuper\driver_buffer_define.h" "..\minimum_user\src\src_user\Settings\DriverSuper\driver_buffer_define.h" call :sync_file ".\src\src_user\Settings\TlmCmd\common_cmd_packet_define.c" "..\minimum_user\src\src_user\Settings\TlmCmd\common_cmd_packet_define.c" call :sync_file ".\src\src_user\Settings\TlmCmd\common_tlm_cmd_packet_define.h" "..\minimum_user\src\src_user\Settings\TlmCmd\common_tlm_cmd_packet_define.h" diff --git a/Examples/minimum_user/CMakeLists.txt b/Examples/minimum_user/CMakeLists.txt index c6e996763..d94aa2d06 100644 --- a/Examples/minimum_user/CMakeLists.txt +++ b/Examples/minimum_user/CMakeLists.txt @@ -41,6 +41,21 @@ if(SHOW_DEBUG_PRINT_ON_SILS) message("Show debug print") endif() +execute_process( + COMMAND git log -1 --format=%H + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_C2A_USER + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_REVISION_C2A_USER_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE +) +add_definitions("-DGIT_REVISION_C2A_USER=\"${GIT_REVISION_C2A_USER}\"") +add_definitions("-DGIT_REVISION_C2A_USER_SHORT=0x${GIT_REVISION_C2A_USER_SHORT}") + add_subdirectory(${C2A_CORE_DIR}) add_subdirectory(${C2A_USER_DIR}/Applications) @@ -91,16 +106,4 @@ else() ) endif() -if(WIN32) - add_custom_command(TARGET ${PROJECT_NAME} - PRE_BUILD - COMMAND git_revision.bat - WORKING_DIRECTORY ${C2A_USER_DIR}/Script) -else() - add_custom_command(TARGET ${PROJECT_NAME} - PRE_BUILD - COMMAND ./git_revision.sh - WORKING_DIRECTORY ${C2A_USER_DIR}/Script) -endif() - include(${C2A_USER_DIR}/common.cmake) diff --git a/Examples/minimum_user/src/src_user/Applications/UserDefined/debug_apps.c b/Examples/minimum_user/src/src_user/Applications/UserDefined/debug_apps.c index a05338e20..f0954720d 100644 --- a/Examples/minimum_user/src/src_user/Applications/UserDefined/debug_apps.c +++ b/Examples/minimum_user/src/src_user/Applications/UserDefined/debug_apps.c @@ -4,6 +4,7 @@ #include // for NULL #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include "../../Applications/DriverInstances/di_gs.h" // #include -#include "../../Library/git_revision.h" #include "../../Library/vt100.h" void APP_DBG_flush_screen_(void); diff --git a/Examples/minimum_user/src/src_user/Library/CMakeLists.txt b/Examples/minimum_user/src/src_user/Library/CMakeLists.txt index 82e7c6f03..7b98581d7 100644 --- a/Examples/minimum_user/src/src_user/Library/CMakeLists.txt +++ b/Examples/minimum_user/src/src_user/Library/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.13) project(C2A_USER_LIB) set(C2A_SRCS - git_revision.c print.c vt100.c ) diff --git a/Examples/minimum_user/src/src_user/Library/git_revision.c b/Examples/minimum_user/src/src_user/Library/git_revision.c deleted file mode 100644 index 6ef1c0e56..000000000 --- a/Examples/minimum_user/src/src_user/Library/git_revision.c +++ /dev/null @@ -1,14 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief git revisionをコードに埋め込む - */ - -#include "git_revision.h" - -const char GIT_REV_CORE[41] = "0000000000000000000000000000000000000000"; -const uint32_t GIT_REV_CORE_SHORT = 0x0000000; -const char GIT_REV_USER[41] = "0000000000000000000000000000000000000000"; -const uint32_t GIT_REV_USER_SHORT = 0x0000000; - -#pragma section diff --git a/Examples/minimum_user/src/src_user/Library/git_revision.h b/Examples/minimum_user/src/src_user/Library/git_revision.h deleted file mode 100644 index 9da4eabed..000000000 --- a/Examples/minimum_user/src/src_user/Library/git_revision.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @file - * @brief git revisionをコードに埋め込む - */ -#ifndef GIT_REVISION_H_ -#define GIT_REVISION_H_ - -#include - -extern const char GIT_REV_CORE[41]; -extern const uint32_t GIT_REV_CORE_SHORT; -extern const char GIT_REV_USER[41]; -extern const uint32_t GIT_REV_USER_SHORT; - -#endif // GIT_REVISION_H_ diff --git a/Examples/minimum_user/src/src_user/Script/Git/revision.bat b/Examples/minimum_user/src/src_user/Script/Git/revision.bat new file mode 100644 index 000000000..29978faba --- /dev/null +++ b/Examples/minimum_user/src/src_user/Script/Git/revision.bat @@ -0,0 +1,31 @@ +@ECHO OFF +REM generate C header for Git revision + +REM current directoryɈړ(src_user/Script/Git) +cd /d %~dp0 + +REM src_userɈړ +cd ..\.. + +for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_user=%%a +for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_user_short=%%a + +REM cd ..\..\src_core + +REM generate header +REM MEMO: ̃qAhLgǂ̏winecmd.exe(Windows 6.1.7601)ƓȂH +( +echo.#ifndef GIT_REVISION_CONFIG_H_ +echo.#define GIT_REVISION_CONFIG_H_ +echo. +echo./* This file is generated by src_user/Script/Git/revision.bat */ +echo. +call ..\src_core\Script\Git\revision.bat +echo.#define GIT_REVISION_C2A_USER "%git_rev_user%" +echo.#define GIT_REVISION_C2A_USER_SHORT 0x%git_rev_user_short% +echo. +echo.#endif // GIT_REVISION_CONFIG_H_ +) > Settings\git_revision_config.h + +REM current directoryɈړ(src_user/Script/Git) +cd /d %~dp0 diff --git a/Examples/minimum_user/src/src_user/Script/Git/revision.sh b/Examples/minimum_user/src/src_user/Script/Git/revision.sh new file mode 100755 index 000000000..2b1d63ae8 --- /dev/null +++ b/Examples/minimum_user/src/src_user/Script/Git/revision.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# generate C header for Git revision + +cd $(dirname $0) # src/src_user/Script/Git +cd ../../ # src/src_user + +# get core revision +git_revs_core=$(../src_core/Script/Git/revision.sh) + +git_rev_user=$(git log --pretty=format:%H -1) +git_rev_user_short=$(git log --pretty=format:%h -1) + +tee Settings/git_revision_config.h << EOS +#ifndef GIT_REVISION_CONFIG_H_ +#define GIT_REVISION_CONFIG_H_ + +/* This file is generated by src_user/Script/Git/revision.sh */ +#define C2A_GIT_REVISION_GENERATED + +${git_revs_core} +#define GIT_REVISION_C2A_USER "${git_rev_user}" +#define GIT_REVISION_C2A_USER_SHORT 0x${git_rev_user_short} + +#endif // GIT_REVISION_CONFIG_H_ +EOS diff --git a/Examples/minimum_user/src/src_user/Script/git_revision.bat b/Examples/minimum_user/src/src_user/Script/git_revision.bat deleted file mode 100644 index 99aab22ee..000000000 --- a/Examples/minimum_user/src/src_user/Script/git_revision.bat +++ /dev/null @@ -1,29 +0,0 @@ -@ECHO OFF - -REM @brief git revision ߍ - -REM current directoryɈړ -cd /d %~dp0 - -for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_user=%%a -for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_user_short=%%a - -cd ..\..\src_core - -for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_core=%%a -for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_core_short=%%a - -cd ..\src_user\Script - -if exist ..\Library\git_revision.c del ..\Library\git_revision.c - -setlocal EnableDelayedExpansion -for /f "delims=" %%a in (git_revision.tmp) do ( - set line=%%a - set line=!line:git_rev_core_hash=%git_rev_core%! - set line=!line:git_rev_core_short_hash=%git_rev_core_short%! - set line=!line:git_rev_user_hash=%git_rev_user%! - set line=!line:git_rev_user_short_hash=%git_rev_user_short%! - echo !line! >> ..\Library\git_revision.c -) -endlocal diff --git a/Examples/minimum_user/src/src_user/Script/git_revision.sh b/Examples/minimum_user/src/src_user/Script/git_revision.sh deleted file mode 100755 index 756a5f338..000000000 --- a/Examples/minimum_user/src/src_user/Script/git_revision.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /bin/sh - -# @brief git revision 埋め込み - -# current directoryに移動 -cd `dirname $0` - -git_rev_user=$(git log --pretty=format:%H -1) -git_rev_user_short=$(git log --pretty=format:%h -1) - -cd ../../src_core - -git_rev_core=$(git log --pretty=format:%H -1) -git_rev_core_short=$(git log --pretty=format:%h -1) - -cd ../src_user/Script - -sed -e s/git_rev_core_hash/${git_rev_core}/ -e s/git_rev_core_short_hash/${git_rev_core_short}/ -e s/git_rev_core_short_hash/${git_rev_core_short}/ -e s/git_rev_user_hash/${git_rev_user}/ -e s/git_rev_user_short_hash/${git_rev_user_short}/ git_revision.tmp > ../Library/git_revision.c diff --git a/Examples/minimum_user/src/src_user/Script/git_revision.tmp b/Examples/minimum_user/src/src_user/Script/git_revision.tmp deleted file mode 100644 index a5a66bbe5..000000000 --- a/Examples/minimum_user/src/src_user/Script/git_revision.tmp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma section REPRO -/** - * @file - * @brief git revisionをコードに埋め込む - */ - -#include "git_revision.h" - -const char GIT_REV_CORE[41] = "git_rev_core_hash"; -const uint32_t GIT_REV_CORE_SHORT = 0xgit_rev_core_short_hash; -const char GIT_REV_USER[41] = "git_rev_user_hash"; -const uint32_t GIT_REV_USER_SHORT = 0xgit_rev_user_short_hash; - -#pragma section diff --git a/Examples/minimum_user/src/src_user/Settings/git_revision_config.h b/Examples/minimum_user/src/src_user/Settings/git_revision_config.h new file mode 100644 index 000000000..0a17e3fa3 --- /dev/null +++ b/Examples/minimum_user/src/src_user/Settings/git_revision_config.h @@ -0,0 +1,44 @@ +#ifndef GIT_REVISION_CONFIG_H_ +#define GIT_REVISION_CONFIG_H_ + +/** + * このファイルは自動生成される場合と設定だけを書く場合があります. + * C2A core/userのcommit hashはコマンドラインオプションないしこのファイルでdefineされ, + * 実際の埋め込みについてはsrc_core/Librari/git_revision.hとsrc_core/c2a_core_main.cが制御します. + */ + +#if 1 // このuserはCMakeでビルドするのでこれを使う +/*!< @brief CMakeでビルドする時など,コマンドラインオプションからcommit hashを流し込む場合の設定 + * この場合,以下の定数をコマンドラインオプション(-D)などで設定してください + * GIT_REVISION_C2A_CORE C2A coreのcommit hash(文字列) + * GIT_REVISION_C2A_CORE_SHORT C2A coreのcommit hash short(0xから始まる数値) + * GIT_REVISION_C2A_USER C2A userのcommit hash(文字列) + * GIT_REVISION_C2A_USER_SHORT C2A userのcommit hash short(0xから始まる数値) + */ + +#define C2A_GIT_REVISION_FROM_OPTION +#endif // from option + +#if 0 +/*!< @brief このファイルを自動生成する場合 + * src_user/Script/Git/revision.sh/batが以下のような内容でこのファイルを生成します + */ + +/* This file is generated by src_user/Script/Git/revision.sh */ +#define C2A_GIT_REVISION_GENERATED + +#define GIT_REVISION_C2A_CORE "1234567890123456789012345678901234567890" +#define GIT_REVISION_C2A_CORE_SHORT 0x1234567 +#define GIT_REVISION_C2A_USER "1234567890123456789012345678901234567890" +#define GIT_REVISION_C2A_USER_SHORT 0x1234567 +#endif // generated version + +#if 0 +/*!< @brief commit hashを埋め込まない場合の設定 + * 実際には0が埋め込まれます + */ + +#define C2A_GIT_REVISION_IGNORE +#endif + +#endif // GIT_REVISION_CONFIG_H_ diff --git a/Examples/minimum_user/src/src_user/TlmCmd/telemetry_source.h b/Examples/minimum_user/src/src_user/TlmCmd/telemetry_source.h index 0d50aabd7..6a79dd1d8 100644 --- a/Examples/minimum_user/src/src_user/TlmCmd/telemetry_source.h +++ b/Examples/minimum_user/src/src_user/TlmCmd/telemetry_source.h @@ -6,6 +6,7 @@ #define TELEMETRY_SOURCE_H_ #include "string.h" // for memcpy +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include "../Applications/app_headers.h" -#include "../Library/git_revision.h" #include "../Drivers/Aocs/aobc_telemetry_buffer.h" #include "../Drivers/Com/gs_validate.h" #include "../Settings/build_settings.h" diff --git a/Examples/minimum_user/src/src_user/c2a_main.c b/Examples/minimum_user/src/src_user/c2a_main.c index 572d664be..403a69a16 100644 --- a/Examples/minimum_user/src/src_user/c2a_main.c +++ b/Examples/minimum_user/src/src_user/c2a_main.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -59,6 +60,8 @@ static void C2A_main_(void) // Printf内部で WDT_clear_wdt(); が呼ばれてることに注意! static void C2A_init_(void) { + Printf("C2A_init: user revision = %s\n", GIT_REV_USER); + WDT_init(); TMGR_init(); // Time Manager // AM_initialize_all_apps での時間計測のためにここで初期化 diff --git a/Library/git_revision.h b/Library/git_revision.h new file mode 100644 index 000000000..9222ff323 --- /dev/null +++ b/Library/git_revision.h @@ -0,0 +1,63 @@ +/** + * @file git_revision.h + * @brief git revisionをコードに埋め込むための準備をする + */ +#ifndef GIT_REVISION_H_ +#define GIT_REVISION_H_ + +#include + +#include //!< 設定ないしcommit hashを読み込む + +/*!< @brief コンパイルオプションないしuserの設定で定義されたcommit hashを読み込んで埋め込みます + * git revisionの埋め込みは,以下の定数を通して行われます(経緯: #82). + * GIT_REVISION_C2A_CORE C2A coreのcommit hash(文字列) + * GIT_REVISION_C2A_CORE_SHORT C2A coreのcommit hash short(0xから始まる数値) + * GIT_REVISION_C2A_USER C2A userのcommit hash(文字列) + * GIT_REVISION_C2A_USER_SHORT C2A userのcommit hash short(0xから始まる数値) + * これらの定数は,Cコンパイラの引数からdefine(-Dなど)してもよいですし, + * src_user/Settings/git_revision_config.hでdefineしてもよいです. + */ + +/** + * @note CMakeを使う場合はコマンドラインオプションからのdefineを推奨します. + * この場合,src_user/Settings/git_revision_config.hでC2A_GIT_REVISION_FROM_OPTIONをdefineしてください(他には何も要りません). + */ + +/** + * @note コマンドラインオプションからのdefineが開発環境の都合などにより困難な場合は, + * src_user/Script/Git/revision.sh/batをビルドパイプライン上で実行するようにします. + * このスクリプトは上記の定数群をdefineしたsrc_user/Settings/git_revision_config.hを自動生成します. + * この場合,src_user/Settings/git_revision_config.hはcommit・ビルドの度に変更されるため,gitignoreしておいた方がよいでしょう. + */ + +/** + * @note ビルドパイプラインをうまく組めないなど,上記2つの手段が使えない,かつ,revisionを埋め込まなくてもよい場合は, + * src_user/Settings/git_revision_config.hでC2A_GIT_REVISION_IGNOREをdefineしてください. + * こうすると,0が埋め込まれます. + */ + +#ifdef C2A_GIT_REVISION_IGNORE +// commit hashを埋め込まない場合 + +#define GIT_REVISION_C2A_CORE "0000000000000000000000000000000000000000" +#define GIT_REVISION_C2A_CORE_SHORT 0x0000000 +#define GIT_REVISION_C2A_USER "0000000000000000000000000000000000000000" +#define GIT_REVISION_C2A_USER_SHORT 0x0000000 + +#else + +// commit hashを埋め込むはずなのにsrc_user/Settings/git_revision_config.hで設定されていない +#if !defined(C2A_GIT_REVISION_FROM_OPTION) && !defined(C2A_GIT_REVISION_GENERATED) +#error "please specify git revision config in src_user/Settings/git_revision_config.h" +#endif // error + +#endif // C2A_GIT_REVISION_IGNORE + +// これをc2a_core_main.cで埋め込む +extern const char GIT_REV_CORE[41]; +extern const uint32_t GIT_REV_CORE_SHORT; +extern const char GIT_REV_USER[41]; +extern const uint32_t GIT_REV_USER_SHORT; + +#endif // GIT_REVISION_H_ diff --git a/Script/Git/revision.bat b/Script/Git/revision.bat new file mode 100644 index 000000000..eaf2b3f54 --- /dev/null +++ b/Script/Git/revision.bat @@ -0,0 +1,11 @@ +@ECHO OFF +REM print C2A core Git revision as C header + +REM current directory(src_core/Script/Git)Ɉړ +cd /d %~dp0 + +for /f "usebackq" %%a in (`"git log --pretty=format:%%H -1"`) do set git_rev_core=%%a +for /f "usebackq" %%a in (`"git log --pretty=format:%%h -1"`) do set git_rev_core_short=%%a + +echo #define GIT_REVISION_C2A_CORE "%git_rev_core%" +echo #define GIT_REVISION_C2A_CORE_SHORT "%git_rev_core_short%" diff --git a/Script/Git/revision.sh b/Script/Git/revision.sh new file mode 100755 index 000000000..23c4b70a4 --- /dev/null +++ b/Script/Git/revision.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# print C2A core Git revision as C header + +cd $(dirname $0) # src_core/Script/Git +#cd ../../ # src_core + +git_rev_core=$(git log --pretty=format:%H -1) +git_rev_core_short=$(git log --pretty=format:%h -1) + +cat << EOS +#define GIT_REVISION_C2A_CORE "${git_rev_core}" +#define GIT_REVISION_C2A_CORE_SHORT 0x${git_rev_core_short} +EOS diff --git a/Script/GitHooks/pre-commit b/Script/GitHooks/pre-commit index 76635da3e..5c6be0519 100755 --- a/Script/GitHooks/pre-commit +++ b/Script/GitHooks/pre-commit @@ -13,12 +13,10 @@ my @Targets = ( "Examples/minimum_user/src/src_user/Settings/TlmCmd/DataBase/TLM_DB/SAMPLE_MOBC_TLM_DB.xlsm", "Examples/minimum_user/src/src_user/Settings/sils_define.h", "Examples/minimum_user/src/src_user/Settings/build_settings.h", - "Examples/minimum_user/src/src_user/Library/git_revision.c", "Examples/2nd_obc_user/src/src_user/Settings/TlmCmd/DataBase/CMD_DB/SAMPLE_AOBC_CMD_DB.xlsm", "Examples/2nd_obc_user/src/src_user/Settings/TlmCmd/DataBase/TLM_DB/SAMPLE_AOBC_TLM_DB.xlsm", "Examples/2nd_obc_user/src/src_user/Settings/sils_define.h", "Examples/2nd_obc_user/src/src_user/Settings/build_settings.h", - "Examples/2nd_obc_user/src/src_user/Library/git_revision.c" ); print "[] pwd\n" if $DEBUG; diff --git a/c2a_core_main.c b/c2a_core_main.c index 3540a82b1..1f76a9d12 100644 --- a/c2a_core_main.c +++ b/c2a_core_main.c @@ -1,6 +1,7 @@ #pragma section REPRO #include "c2a_core_main.h" +#include "./Library/git_revision.h" #include "./Library/print.h" #include "./System/TaskManager/task_dispatcher.h" #include "./System/ApplicationManager/app_manager.h" @@ -15,6 +16,12 @@ #include +// git revisionをコードに埋め込む +const char GIT_REV_CORE[41] = GIT_REVISION_C2A_CORE; +const uint32_t GIT_REV_CORE_SHORT = GIT_REVISION_C2A_CORE_SHORT; +const char GIT_REV_USER[41] = GIT_REVISION_C2A_USER; +const uint32_t GIT_REV_USER_SHORT = GIT_REVISION_C2A_USER_SHORT; + void C2A_core_init(void) { CA_initialize(); // Cmd Analyze diff --git a/c2a_core_main.h b/c2a_core_main.h index e1d20d7ae..21809cb81 100644 --- a/c2a_core_main.h +++ b/c2a_core_main.h @@ -10,6 +10,6 @@ void C2A_core_main(void); #define C2A_CORE_VER_MAJOR (3) #define C2A_CORE_VER_MINOR (9) #define C2A_CORE_VER_PATCH (0) -#define C2A_CORE_VER_PRE ("beta.5") +#define C2A_CORE_VER_PRE ("beta.6") #endif