Skip to content

Commit

Permalink
fix(build): 修复git状态变化时没有重新生成img的BUG
Browse files Browse the repository at this point in the history
- make-image的依赖中添加check_git_status
- build.py 脚本中调用check_git_status.generate_timestamp,防止在ninja中执行两次才能正确依赖
  • Loading branch information
xiaoapeng committed Dec 14, 2024
1 parent 3d4d22a commit 4809a25
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
12 changes: 2 additions & 10 deletions cmake/git-status.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
include_guard(GLOBAL)

# 定义生成 git 状态时间戳文件的自定义命令
add_custom_command(
OUTPUT .gitstatus.timestamp .gitstatus_make
COMMAND ${Python3_EXECUTABLE} ${FLY_TOP_DIR}/tool/python/check_git_status.py --output-dir ${CMAKE_BINARY_DIR}/
COMMENT " "

)

# 添加自定义目标来生成 git 状态时间戳文件
add_custom_target(check_git_status ALL
DEPENDS .gitstatus_make
add_custom_target(check_git_status
COMMAND ${Python3_EXECUTABLE} ${FLY_TOP_DIR}/tool/python/check_git_status.py --output-dir ${CMAKE_BINARY_DIR}/
)

4 changes: 2 additions & 2 deletions cmake/jlink-make-image.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ function(add_jlink_image CMAKE_TARGET)
--speed ${CUSTOM_FUNC_SPEED} --symlink-name ${CMAKE_TARGET}_jlink_CURRENT --firmware-parts ${CUSTOM_FUNC_FIRMWARE_LIST}
COMMAND ${CMAKE_COMMAND} -E touch ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/.${CMAKE_TARGET}_make_img.timestamp
COMMAND ${CMAKE_COMMAND} -E create_symlink ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/${CMAKE_TARGET}_jlink_CURRENT ${FLY_TOP_DIR}/image/CURRENT
DEPENDS ${CUSTOM_FUNC_DEPENDS} ${CMAKE_BINARY_DIR}/.gitstatus.timestamp
DEPENDS ${CUSTOM_FUNC_DEPENDS} ${CMAKE_BINARY_DIR}/.gitstatus.timestamp
COMMENT "${CUSTOM_FUNC_IMAGE_NAME}:Make a jlink burn package"
)

# 添加自定义目标来生成 img 文件
add_custom_target(${CMAKE_TARGET}_make_img
DEPENDS ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/.${CMAKE_TARGET}_make_img.timestamp
DEPENDS check_git_status ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/.${CMAKE_TARGET}_make_img.timestamp
)

if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
Expand Down
4 changes: 2 additions & 2 deletions cmake/openocd-make-image.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ function(add_openocd_image CMAKE_TARGET)
--symlink-name ${CMAKE_TARGET}_openocd_CURRENT --firmware-parts ${CUSTOM_FUNC_FIRMWARE_LIST}
COMMAND ${CMAKE_COMMAND} -E touch ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/.${CMAKE_TARGET}_make_img.timestamp
COMMAND ${CMAKE_COMMAND} -E create_symlink ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/${CMAKE_TARGET}_openocd_CURRENT ${FLY_TOP_DIR}/image/CURRENT
DEPENDS ${CUSTOM_FUNC_DEPENDS} ${CMAKE_BINARY_DIR}/.gitstatus.timestamp
DEPENDS ${CUSTOM_FUNC_DEPENDS} ${CMAKE_BINARY_DIR}/.gitstatus.timestamp
COMMENT "${CUSTOM_FUNC_IMAGE_NAME}:Make a openocd burn package"
)

# 添加自定义目标来生成 img 文件
add_custom_target(${CMAKE_TARGET}_make_img
DEPENDS ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/.${CMAKE_TARGET}_make_img.timestamp
DEPENDS check_git_status ${FLY_TOP_DIR}/image/${CUSTOM_FUNC_IMAGE_NAME}/.${CMAKE_TARGET}_make_img.timestamp
)

if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
Expand Down
4 changes: 4 additions & 0 deletions tool/python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import menuconfig
import platform
import json
import check_git_status

K_CONFIG_FILR_PATH = 'Kconfig'
DOT_CONFIG_FILE_PATH = '.config'
Expand Down Expand Up @@ -210,6 +211,9 @@ def run_make_img(source_dir, flash_target='default'):
if not os.path.exists(f"{source_dir}/{CMAKE_BUILD_DIR_PATH}"):
print("build not exist!!")
exit(1)

# 生成时间戳文件,
check_git_status.generate_timestamp(f"{source_dir}/{CMAKE_BUILD_DIR_PATH}")
os.system(f"cmake --build {source_dir}/{CMAKE_BUILD_DIR_PATH} --target {flash_target}_make_img")

def run_rttlog(source_dir):
Expand Down
28 changes: 13 additions & 15 deletions tool/python/check_git_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,13 @@ def get_git_status():
raise Exception("Failed to run git status")
return result.stdout

def main():
parser = argparse.ArgumentParser(description='Generate git status information.')

parser.add_argument('--output-dir', required=True, help='Directory to output the generated information.')

args = parser.parse_args()
if not os.path.exists(args.output_dir):
raise Exception(f"Output directory '{args.output_dir}' does not exist.")


def generate_timestamp(output_dir, is_output_log = False):
status = get_git_status()
is_clean = len(status.strip()) == 0
status_str = "clean" if is_clean else "dirty"

status_file = os.path.join(args.output_dir, '.gitstatus')
timestamp_file = os.path.join(args.output_dir, '.gitstatus.timestamp')
status_file = os.path.join(output_dir, '.gitstatus')
timestamp_file = os.path.join(output_dir, '.gitstatus.timestamp')

# Check if the current status is different from the last status
previous_status = ""
Expand All @@ -40,9 +31,16 @@ def main():
# Update the timestamp file
with open(timestamp_file, 'w') as f:
f.write(str(time.time()))
print(f"Git status changed to '{status_str}'. Timestamp updated.")
if is_output_log:
print(f"Git status changed to '{status_str}'. Timestamp updated.")
else:
print("Git status has not changed.")
if is_output_log:
print("Git status has not changed.")

if __name__ == "__main__":
main()
parser = argparse.ArgumentParser(description='Generate git status information.')
parser.add_argument('--output-dir', required=True, help='Directory to output the generated information.')
args = parser.parse_args()
if not os.path.exists(args.output_dir):
raise Exception(f"Output directory '{args.output_dir}' does not exist.")
generate_timestamp(args.output_dir, True)

0 comments on commit 4809a25

Please sign in to comment.