Skip to content

Commit 7af95e8

Browse files
committed
feat: allow specifying FW version instead of relying on git tag
1 parent 21c773e commit 7af95e8

3 files changed

Lines changed: 57 additions & 18 deletions

File tree

src/ic_project.cmake

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function(ic_project
6262
set(optional_keyword_args
6363
BOARD_REV
6464
BUILD_TYPE
65+
FW_VERSION
6566
)
6667
list(APPEND keyword_args
6768
${required_keyword_args}
@@ -95,6 +96,8 @@ function(ic_project
9596

9697
set_definition("${out_board_name}" "${_BOARD_NAME}" PARENT_SCOPE)
9798
if_set_definition("${out_board_rev}" "${_BOARD_REV}" PARENT_SCOPE)
99+
if_set_definition("${out_fw_version}" "${_FW_VERSION}" PARENT_SCOPE)
100+
if_set_definition("${out_build_type}" "${_BUILD_TYPE}" PARENT_SCOPE)
98101

99102
# Warn about git tag
100103
execute_process(
@@ -104,27 +107,40 @@ function(ic_project
104107
OUTPUT_QUIET
105108
)
106109
if(res AND NOT res EQUAL 0)
107-
message(
108-
WARNING
109-
"The ${out_fw_version} should be set by git tag but there is no tag"
110-
)
110+
if(NOT DEFINED ${out_fw_version})
111+
message(
112+
WARNING
113+
"The ${out_fw_version} should be set by git tag but there is no tag"
114+
)
115+
endif()
111116
set(has_git_tag 0)
112117
else()
113118
set(has_git_tag 1)
119+
execute_process(
120+
COMMAND git describe --tags --dirty=+ --always --abbrev=7
121+
OUTPUT_VARIABLE git_tag
122+
OUTPUT_STRIP_TRAILING_WHITESPACE
123+
)
114124
endif()
115125

116-
# Set firmware version
126+
# Set short git commit hash
117127
execute_process(
118-
COMMAND git describe --tags --dirty=+ --always --abbrev=7
119-
OUTPUT_VARIABLE git_tag
128+
COMMAND git describe --dirty=+ --always --abbrev=7 --exclude *
129+
OUTPUT_VARIABLE git_hash
120130
OUTPUT_STRIP_TRAILING_WHITESPACE
121131
)
122-
set_definition("${out_fw_version}" ${git_tag} PARENT_SCOPE)
132+
set_definition("${out_git_hash}" ${git_hash} PARENT_SCOPE)
123133

124-
if_set_definition("${out_build_type}" "${_BUILD_TYPE}" PARENT_SCOPE)
134+
if(NOT DEFINED ${out_fw_version})
135+
if(${has_git_tag})
136+
set_definition("${out_fw_version}" ${git_tag} PARENT_SCOPE)
137+
else()
138+
set_definition("${out_fw_version}" ${git_hash} PARENT_SCOPE)
139+
endif()
140+
endif()
125141

126142
# Set git dirty commit
127-
string(FIND ${git_tag} + res)
143+
string(FIND ${git_hash} + res)
128144
if(res EQUAL -1)
129145
set_definition("${out_git_dirty}" 0 PARENT_SCOPE)
130146
else()
@@ -150,14 +166,6 @@ function(ic_project
150166
set_definition("${out_git_tag_rev}" "" PARENT_SCOPE)
151167
endif()
152168

153-
# Set short git commit hash
154-
execute_process(
155-
COMMAND git describe --dirty=+ --always --abbrev=7 --exclude *
156-
OUTPUT_VARIABLE git_hash
157-
OUTPUT_STRIP_TRAILING_WHITESPACE
158-
)
159-
set_definition("${out_git_hash}" ${git_hash} PARENT_SCOPE)
160-
161169
string(TIMESTAMP build_date "%Y%m%d")
162170
set_definition("${out_build_date}" ${build_date} PARENT_SCOPE)
163171
string(TIMESTAMP timestamp)

src/ic_utils.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ macro(set_definition name value)
4444
endif()
4545

4646
set(${name} ${value} ${ARGN})
47+
set(${name} ${value})
4748
add_compile_definitions(${name}=${value})
4849
message(STATUS "${name} = ${value}")
4950
endmacro()

tests/test_ic_project.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ assert("Dipple Snurp 3" STREQUAL ${IC_PROJECT_NAME})
3535
assert(FF3 STREQUAL ${IC_BOARD_NAME})
3636
assert(${IC_FULL_NAME} MATCHES Flumbr_Dipple_Snurp_3_FF3_.+_[0-9]+)
3737

38+
foreach(ic_out_var ${ic_out})
39+
unset("${ic_out_var}")
40+
endforeach()
41+
3842
test_cmake_group_end()
3943

4044
test_cmake_group_begin("ic_project() with optional args")
@@ -68,4 +72,30 @@ assert(proto STREQUAL ${IC_BUILD_TYPE})
6872
assert(Flampr STREQUAL ${IC_CLIENT_NAME})
6973
assert(${IC_FULL_NAME} MATCHES Flampr_flying-vanilla-bean_toffee@NFF2_.+_[0-9]+_proto)
7074

75+
foreach(ic_out_var ${ic_out})
76+
unset("${ic_out_var}")
77+
endforeach()
78+
79+
test_cmake_group_end()
80+
81+
test_cmake_group_begin("ic_project() with FW_VERSION arg")
82+
83+
ic_project_out(ic_out)
84+
ic_project(
85+
# output variables
86+
${ic_out}
87+
88+
# keyword arguments
89+
CLIENT_NAME "Flumbr"
90+
PROJECT_NAME "Dipple Snurp 3"
91+
BOARD_NAME FF3
92+
FW_VERSION 1.0.0
93+
)
94+
95+
assert(1.0.0 STREQUAL ${IC_FW_VERSION})
96+
97+
foreach(ic_out_var ${ic_out})
98+
unset("${ic_out_var}")
99+
endforeach()
100+
71101
test_cmake_group_end()

0 commit comments

Comments
 (0)