-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_utils.c
67 lines (57 loc) · 1.19 KB
/
git_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* Copyright (C) 2020 Université Grenoble Alpes
*/
/**
* Git information
* Thanks to https://nullpointer.io/post/easily-embed-version-information-in-software-releases/
*/
#include <stdio.h>
#define UNKNOWN "UNKNOWN"
static const char* get_software_git_version(void) {
#ifdef GIT_VERSION
return GIT_VERSION;
#else
return UNKNOWN;
#endif
}
static const char* get_software_git_commit(void) {
#ifdef GIT_COMMIT
return GIT_COMMIT;
#else
return UNKNOWN;
#endif
}
static const char* get_software_git_date(void) {
#ifdef GIT_DATE
return GIT_DATE;
#else
return UNKNOWN;
#endif
}
static const char* get_software_build_date(void) {
#ifdef BUILD_DATE
return BUILD_DATE;
#else
return UNKNOWN;
#endif
}
/*
* @brief git command
*
* @param argc
* @param argv
*/
int git_cmd(int argc, char *argv[]) {
(void) (argc);
(void) (argv);
#if defined(BANNER)
printf("%s\n", BANNER);
#elif defined(RIOT_APPLICATION)
printf("Application: %s\n", RIOT_APPLICATION);
#endif
printf("Version: %s\n", get_software_git_version());
printf("Commit SHA1: %s\n", get_software_git_commit());
printf("Commit date: %s\n", get_software_git_date());
printf("Build date: %s\n", get_software_build_date());
return 0;
}