Skip to content

Commit

Permalink
添加更多构建时的版本信息
Browse files Browse the repository at this point in the history
- 获取详细的(--long) git describe 输出
- 显示本地构建或者远程CI构建
  • Loading branch information
SourLemonJuice committed Jun 15, 2024
1 parent 6a998a9 commit 2ef5eb4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/GitHub_CI_Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ on:
pull_request:
branches: [ "main" ]

env:
CI_HOST_INFO: GitHub Build CI

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build with make
run: make --directory=./source/
run: make --directory="./source/" build_host_description=$(CI_HOST_INFO)
- name: Upload executable file
uses: actions/upload-artifact@v4
with:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Maybe I'll put them to *main.c* at later.

[Google Style Guide C++](https://google.github.io/styleguide/cppguide.html)(or just want to be)

## GitHub CI

![Build CI Badge](https://github.com/SourLemonJuice/i18nglish.c/actions/workflows/GitHub_CI_Build.yml/badge.svg)

## License

Published Under MIT License.
9 changes: 7 additions & 2 deletions source/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ source_files = main.c i7h_processor.c
executable_name = i18nglish.out

# About git repo info
git_commit_info = $(shell git describe --abbrev=40 --dirty --always)
git_commit_info = "$(shell git describe --abbrev=40 --dirty --always --long)"
# Add more build info(remote CI or just a local PC)
build_host_description = "Local build"

# ' and " in shell is so... Ugly!!

ALL: i18nglish.out

i18nglish.out: $(source_files)
/usr/bin/clang $(source_files) \
--output $(executable_name) \
-DAPP_GIT_COMMIT_INFO=\"$(git_commit_info)\"
-DAPP_GIT_COMMIT_INFO=\"$(git_commit_info)\" \
-DAPP_BUILD_HOST_DESCRIPTION=\"$(build_host_description)\"

clean:
rm -i ./$(executable_name)
1 change: 1 addition & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ int main(int argc, char *argv[])
printf("Build Date:\t%s, Time: %s\n", __DATE__, __TIME__);
printf("Git commit:\t%s\n", APP_GIT_COMMIT_INFO);
printf("Compiler ver:\t%s\n", __VERSION__); // __VERSION__ is not a std macro.
printf("Build host:\t%s\n", APP_BUILD_HOST_DESCRIPTION);
printf("==== Author info ====\n");
printf("Developed by 酸柠檬猹/SourLemonJuice 2024\n");
printf("Published under MIT license\n");
Expand Down
11 changes: 9 additions & 2 deletions source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@

#include <stdlib.h>

/* For compiler defin flag(gcc -D) */
/*
For compiler defin flag(gcc -D)
Those macros should be defined by compiler
*/
#ifndef APP_GIT_COMMIT_INFO
#define APP_GIT_COMMIT_INFO "ERROR: APP_GIT_COMMIT_INFO should be defined by compiler"
#define APP_GIT_COMMIT_INFO "[Build ERROR] APP_GIT_COMMIT_INFO not defined"
#endif

#ifndef APP_BUILD_HOST_DESCRIPTION
#define APP_BUILD_HOST_DESCRIPTION "[Build ERROR] APP_BUILD_HOST_DESCRIPTION not defined"
#endif

/* Self define */
Expand Down

0 comments on commit 2ef5eb4

Please sign in to comment.