Skip to content

Commit

Permalink
Merge pull request #82 from ut-issl/feature/refactor-git-revision
Browse files Browse the repository at this point in the history
Pre Release (v3.9.0-beta.6): git_revision.cをどうにかする
  • Loading branch information
sksat authored May 17, 2023
2 parents 756280a + ebbf430 commit 784307c
Show file tree
Hide file tree
Showing 35 changed files with 352 additions and 214 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
27 changes: 15 additions & 12 deletions Examples/2nd_obc_user/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stddef.h> // for NULL
#include <stdint.h>

#include <src_core/Library/git_revision.h>
#include <src_core/Library/print.h>
#include <src_core/System/TimeManager/time_manager.h>
#include <src_core/System/ModeManager/mode_manager.h>
Expand All @@ -19,7 +20,6 @@
#include <src_core/Applications/timeline_command_dispatcher.h>
#include "../../Applications/DriverInstances/di_mobc.h"
// #include <src_core/TlmCmd/telemetry_generator.h>
#include "../../Library/git_revision.h"
#include "../../Library/vt100.h"

void APP_DBG_flush_screen_(void);
Expand Down
1 change: 0 additions & 1 deletion Examples/2nd_obc_user/src/src_user/Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.13)
project(C2A_USER_LIB)

set(C2A_SRCS
git_revision.c
print.c
vt100.c
)
Expand Down
14 changes: 0 additions & 14 deletions Examples/2nd_obc_user/src/src_user/Library/git_revision.c

This file was deleted.

15 changes: 0 additions & 15 deletions Examples/2nd_obc_user/src/src_user/Library/git_revision.h

This file was deleted.

31 changes: 31 additions & 0 deletions Examples/2nd_obc_user/src/src_user/Script/Git/revision.bat
Original file line number Diff line number Diff line change
@@ -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: このヒアドキュメントもどきの書き方はwineのcmd.exe(Windows 6.1.7601)だと動かない?
(
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
25 changes: 25 additions & 0 deletions Examples/2nd_obc_user/src/src_user/Script/Git/revision.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions Examples/2nd_obc_user/src/src_user/Script/git_revision.bat

This file was deleted.

18 changes: 0 additions & 18 deletions Examples/2nd_obc_user/src/src_user/Script/git_revision.sh

This file was deleted.

14 changes: 0 additions & 14 deletions Examples/2nd_obc_user/src/src_user/Script/git_revision.tmp

This file was deleted.

44 changes: 44 additions & 0 deletions Examples/2nd_obc_user/src/src_user/Settings/git_revision_config.h
Original file line number Diff line number Diff line change
@@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define TELEMETRY_SOURCE_H_

#include "string.h" // for memcpy
#include <src_core/Library/git_revision.h>
#include <src_core/System/ApplicationManager/app_manager.h>
#include <src_core/System/TaskManager/task_dispatcher.h>
#include <src_core/System/ModeManager/mode_manager.h>
Expand All @@ -16,7 +17,6 @@
#include <src_core/TlmCmd/command_analyze.h>
#include <src_core/TlmCmd/block_command_executor.h>
#include "../Applications/app_headers.h"
#include "../Library/git_revision.h"
#include "../Settings/build_settings.h"

#endif
3 changes: 3 additions & 0 deletions Examples/2nd_obc_user/src/src_user/c2a_main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <src_core/Library/git_revision.h>
#include <src_core/Library/print.h>
#include <src_core/c2a_core_main.h>
#include <src_core/System/TimeManager/time_manager.h>
Expand Down Expand Up @@ -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 での時間計測のためにここで初期化
Expand Down
1 change: 1 addition & 0 deletions Examples/2nd_obc_user/sync_with_minimum_user.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 15 additions & 12 deletions Examples/minimum_user/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stddef.h> // for NULL
#include <stdint.h>

#include <src_core/Library/git_revision.h>
#include <src_core/Library/print.h>
#include <src_core/System/TimeManager/time_manager.h>
#include <src_core/System/ModeManager/mode_manager.h>
Expand All @@ -19,7 +20,6 @@
#include <src_core/Applications/timeline_command_dispatcher.h>
#include "../../Applications/DriverInstances/di_gs.h"
// #include <src_core/TlmCmd/telemetry_generator.h>
#include "../../Library/git_revision.h"
#include "../../Library/vt100.h"

void APP_DBG_flush_screen_(void);
Expand Down
1 change: 0 additions & 1 deletion Examples/minimum_user/src/src_user/Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.13)
project(C2A_USER_LIB)

set(C2A_SRCS
git_revision.c
print.c
vt100.c
)
Expand Down
Loading

0 comments on commit 784307c

Please sign in to comment.