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

Pre Release (v3.9.0-beta.6): git_revision.cをどうにかする #82

Merged
merged 25 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
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
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
14 changes: 0 additions & 14 deletions Examples/minimum_user/src/src_user/Library/git_revision.c

This file was deleted.

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

This file was deleted.

31 changes: 31 additions & 0 deletions Examples/minimum_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: ���̃q�A�h�L�������g���ǂ��̏�������wine��cmd.exe(Windows 6.1.7601)���Ɠ����Ȃ��H
(
echo.#ifndef C2A_USER_GIT_REVISION_H_
echo.#define C2A_USER_GIT_REVISION_H_
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
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 // C2A_USER_GIT_REVISION_H_
) > Settings\git_revision_config.h

REM current directory�Ɉړ�(src_user/Script/Git)
cd /d %~dp0
25 changes: 25 additions & 0 deletions Examples/minimum_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 C2A_USER_GIT_REVISION_H_
#define C2A_USER_GIT_REVISION_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 // C2A_USER_GIT_REVISION_H_
EOS
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 0 additions & 29 deletions Examples/minimum_user/src/src_user/Script/git_revision.bat

This file was deleted.

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

This file was deleted.

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

This file was deleted.

44 changes: 44 additions & 0 deletions Examples/minimum_user/src/src_user/Settings/git_revision_config.h
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shift-JIS 時代から生き残ってた PR だからか表示が壊れてるけど,UTF-8

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を流し込む場合の設定
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
* この場合,以下の定数をコマンドラインオプション(-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 このファイルを自動生成する場合
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
* 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 "fa8a1ecd5872b1c5972e22cad1bbb449cade6fe8"
#define GIT_REVISION_C2A_CORE_SHORT 0xfa8a1ec
#define GIT_REVISION_C2A_USER "fa8a1ecd5872b1c5972e22cad1bbb449cade6fe8"
#define GIT_REVISION_C2A_USER_SHORT 0xfa8a1ec
#endif // generated version

#if 0
/*! @brief commit hashを埋め込まない場合の設定
meltingrabbit marked this conversation as resolved.
Show resolved Hide resolved
* 実際には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 @@ -15,7 +16,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 "../Drivers/Aocs/aobc_telemetry_buffer.h"
#include "../Drivers/Com/gs_validate.h"
#include "../Settings/build_settings.h"
Expand Down
5 changes: 5 additions & 0 deletions Examples/minimum_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,9 +60,13 @@ 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 での時間計測のためにここで初期化

Printf("C2A_init: TMGR_init done.\n");
timer_setting_(); // Timer 割り込み開始
Printf("C2A_init: timer_setting_ done.\n");
Expand Down
63 changes: 63 additions & 0 deletions Library/git_revision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @file git_revision.h
* @brief git revisionをコードに埋め込むための準備をする
*/
#ifndef GIT_REVISION_H_
#define GIT_REVISION_H_

#include <stdint.h>

#include <src_user/Settings/git_revision_config.h> //!< 設定ないしcommit hashを読み込む

/*! @brief コンパイルオプションないしuserの設定で定義されたcommit hashを読み込んで埋め込みます
sksat marked this conversation as resolved.
Show resolved Hide resolved
* 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_
11 changes: 11 additions & 0 deletions Script/Git/revision.bat
Original file line number Diff line number Diff line change
@@ -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%"
Loading