Skip to content

Commit ed3335c

Browse files
authored
Improved postbuild tools (#80)
- tagged binary Target and file are given to the caller - testapp and ctestapp uses the postbuild tools - Fixed INSTALL_SFD that was always used
1 parent e787329 commit ed3335c

File tree

8 files changed

+96
-47
lines changed

8 files changed

+96
-47
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ RUN apt-get update && apt-get install -y \
88
cmake \
99
git \
1010
wget \
11+
python3 \
12+
python3-pip \
1113
&& rm -rf /var/lib/apt/lists/*
1214

15+
RUN python3 -m pip install scrutinydebugger
16+
1317
FROM base as static-analysis
1418
ARG CPPCHECK_VERSION="2.10.3"
1519
ARG CPPCHECK_URL="https://github.com/danmar/cppcheck/archive/refs/tags/${CPPCHECK_VERSION}.tar.gz"
1620
ARG CPPCHECK_FOLDER="cppcheck-${CPPCHECK_VERSION}"
1721
RUN apt-get update \
1822
&& apt-get install -y \
1923
build-essential \
20-
python3 \
2124
libpcre3-dev \
2225
&& wget $CPPCHECK_URL -O /tmp/cppcheck.tar.gz \
2326
&& tar -xvzf /tmp/cppcheck.tar.gz -C /tmp/ \

Jenkinsfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,4 +380,15 @@ pipeline {
380380
}
381381
}
382382
}
383+
post {
384+
// Clean after build
385+
always {
386+
cleanWs(cleanWhenNotBuilt: false,
387+
deleteDirs: true,
388+
disableDeferredWipeout: true,
389+
notFailBuild: true,
390+
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
391+
[pattern: '.propsfile', type: 'EXCLUDE']])
392+
}
393+
}
383394
}

lib/cmake/scrutiny.cmake

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ function (scrutiny_postbuild TARGET)
2121
SCRUTINY_CMD # OPTIONAL: Path to the scrutiny binary
2222
SFD_FILENAME # OPTIONAL: Name to give to the .sfd file
2323

24-
TAGGED_EXECUTABLE_TARGET_VAR # OPTIONAL: The output variable that will store the CMake target name of the tagged binary
2524
TAGGED_EXECUTABLE_NAME # OPTIONAL: Filename of the tagged binary
25+
TAGGED_EXECUTABLE_TARGET_VAR # OPTIONAL: The output variable that will store the CMake target name of the tagged binary
26+
TAGGED_EXECUTABLE_PATH_VAR # OPTIONAL: The output variable that will store the absolute path to the tagged binary
2627
SFD_TARGET_VAR # OPTIONAL: The output variable that will store the CMake target name of the SFD file
28+
SFD_PATH_VAR # OPTIONAL: The output variable that will store the absolute path to the SFD file
2729

2830
METADATA_PROJECT_NAME # OPTIONAL: The name of the project, embedded in the .sfd file
2931
METADATA_AUTHOR # OPTIONAL: The name of the project author, embedded in the .sfd file
@@ -66,19 +68,6 @@ function (scrutiny_postbuild TARGET)
6668
endif()
6769
endif()
6870

69-
# Validate SFD filename
70-
if (NOT arg_SFD_FILENAME)
71-
set(arg_SFD_FILENAME ${TARGET}.sfd) # Default value
72-
endif()
73-
if (NOT IS_ABSOLUTE ${arg_SFD_FILENAME})
74-
# Try to put next to the .elf
75-
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
76-
set(arg_SFD_FILENAME ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${arg_SFD_FILENAME})
77-
else()
78-
set(arg_SFD_FILENAME ${CMAKE_BINARY_DIR}/${arg_SFD_FILENAME})
79-
endif()
80-
endif()
81-
8271
# Catch potential abd argument and report them
8372
get_target_property(TARGET_TYPE ${TARGET} TYPE)
8473
if (NOT TARGET_TYPE STREQUAL "EXECUTABLE")
@@ -87,33 +76,49 @@ function (scrutiny_postbuild TARGET)
8776

8877
# Give the target we created to the caller
8978
get_target_property(TARGET_SUFFIX ${TARGET} SUFFIX)
90-
set(TAGGED_EXECUTABLE_TARGET ${TARGET}_tagged)
91-
if (arg_TAGGED_EXECUTABLE_TARGET_VAR)
92-
set(${arg_TAGGED_EXECUTABLE_TARGET_VAR} ${TAGGED_EXECUTABLE_TARGET} PARENT_SCOPE)
93-
endif()
9479

9580
# Tagged executable validation
9681
if (NOT arg_TAGGED_EXECUTABLE_NAME)
97-
set(arg_TAGGED_EXECUTABLE_NAME ${TARGET}-tagged) # Default value
82+
set(arg_TAGGED_EXECUTABLE_NAME ${TARGET}_tagged) # Default value
9883
if (TARGET_SUFFIX) # Apply the same suffix as the source
9984
set(arg_TAGGED_EXECUTABLE_NAME ${arg_TAGGED_EXECUTABLE_NAME}${TARGET_SUFFIX})
10085
endif()
10186
endif()
10287

10388
# If relative path, try to place next to the binary
104-
if (NOT IS_ABSOLUTE ${arg_TAGGED_EXECUTABLE_NAME})
89+
if (IS_ABSOLUTE ${arg_TAGGED_EXECUTABLE_NAME})
90+
set(TAGGED_EXECUTABLE_ABSPATH ${arg_TAGGED_EXECUTABLE_NAME})
91+
else()
10592
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
106-
set(arg_TAGGED_EXECUTABLE_NAME ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${arg_TAGGED_EXECUTABLE_NAME})
93+
set(TAGGED_EXECUTABLE_ABSPATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${arg_TAGGED_EXECUTABLE_NAME})
10794
else()
108-
set(arg_TAGGED_EXECUTABLE_NAME ${CMAKE_BINARY_DIR}/${arg_TAGGED_EXECUTABLE_NAME})
95+
set(TAGGED_EXECUTABLE_ABSPATH ${CMAKE_CURRENT_BINARY_DIR}/${arg_TAGGED_EXECUTABLE_NAME})
10996
endif()
11097
endif()
98+
if (arg_TAGGED_EXECUTABLE_PATH_VAR)
99+
set(${arg_TAGGED_EXECUTABLE_PATH_VAR} ${TAGGED_EXECUTABLE_ABSPATH} PARENT_SCOPE)
100+
endif()
101+
102+
103+
# Validate SFD filename
104+
if (NOT arg_SFD_FILENAME)
105+
set(arg_SFD_FILENAME ${TARGET}.sfd) # Default value
106+
endif()
107+
108+
if (IS_ABSOLUTE ${arg_SFD_FILENAME})
109+
set(SFD_ABSPATH ${arg_SFD_FILENAME})
110+
else()
111+
# Try to put next to the .elf
112+
if (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
113+
set(SFD_ABSPATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${arg_SFD_FILENAME})
114+
else()
115+
set(SFD_ABSPATH ${CMAKE_CURRENT_BINARY_DIR}/${arg_SFD_FILENAME})
116+
endif()
117+
endif()
118+
if (arg_SFD_PATH_VAR)
119+
set(${arg_SFD_PATH_VAR} ${SFD_ABSPATH} PARENT_SCOPE)
120+
endif()
111121

112-
# SFD
113-
set(SFD_TARGET ${TARGET}_sfd)
114-
if (arg_SFD_TARGET_VAR)
115-
set(${arg_SFD_TARGET_VAR} ${SFD_TARGET} PARENT_SCOPE)
116-
endif()
117122

118123
# Metadata
119124
set(METADATA_ARGS "")
@@ -138,11 +143,10 @@ function (scrutiny_postbuild TARGET)
138143

139144
list(LENGTH ALIAS_LIST_ABS ALIAS_COUNT) # Count the alias file to skip that step if 0
140145

141-
# --- Make the SFD ---
142146

143-
add_custom_command(OUTPUT ${arg_SFD_FILENAME}
147+
add_custom_command(OUTPUT ${SFD_ABSPATH}
144148
DEPENDS ${TARGET} ${ALIAS_LIST_ABS}
145-
COMMAND ${CMAKE_COMMAND} -E echo "Generating Scrutiny Firmware Description"
149+
COMMAND ${CMAKE_COMMAND} -E echo "Generating Scrutiny Firmware Description for ${TARGET}"
146150
COMMAND ${CMAKE_COMMAND} -E rm -rf ${arg_WORKDIR}
147151
COMMAND ${CMAKE_COMMAND} -E make_directory ${arg_WORKDIR}
148152
COMMAND ${arg_SCRUTINY_CMD}
@@ -155,19 +159,30 @@ function (scrutiny_postbuild TARGET)
155159
COMMAND ${arg_SCRUTINY_CMD} get-firmware-id $<TARGET_FILE:${TARGET}> --output ${arg_WORKDIR}
156160
COMMAND ${arg_SCRUTINY_CMD} make-metadata --output ${arg_WORKDIR} ${METADATA_ARGS}
157161
COMMAND ${arg_SCRUTINY_CMD} $<IF:$<NOT:$<EQUAL:${ALIAS_COUNT},0>>,add-alias,noop> ${arg_WORKDIR} --file ${ALIAS_LIST_ABS}
158-
COMMAND ${arg_SCRUTINY_CMD} make-sfd ${arg_WORKDIR} ${arg_SFD_FILENAME}
159-
COMMAND ${arg_SCRUTINY_CMD} $<IF:$<BOOL:arg_INSTALL_SFD>,install-sfd,noop> ${arg_SFD_FILENAME}
162+
COMMAND ${arg_SCRUTINY_CMD} make-sfd ${arg_WORKDIR} ${SFD_ABSPATH} $<$<BOOL:${arg_INSTALL_SFD}>:--install>
160163
)
161-
add_custom_target(${SFD_TARGET} ALL DEPENDS ${arg_SFD_FILENAME})
162-
set_target_properties(${SFD_TARGET} PROPERTIES TARGET_FILE ${arg_SFD_FILENAME})
163-
164164

165+
set(TAGGED_EXECUTABLE_TARGET ${TARGET}_tagged_target)
166+
set(SFD_TARGET ${TARGET}_sfd_target)
167+
168+
if (arg_SFD_TARGET_VAR)
169+
set(${arg_SFD_TARGET_VAR} ${SFD_TARGET} PARENT_SCOPE)
170+
endif()
171+
172+
if (arg_TAGGED_EXECUTABLE_TARGET_VAR)
173+
set(${arg_TAGGED_EXECUTABLE_TARGET_VAR} ${TAGGED_EXECUTABLE_TARGET} PARENT_SCOPE)
174+
endif()
175+
176+
# --- SFD
177+
add_custom_target(${SFD_TARGET} ALL DEPENDS ${SFD_ABSPATH})
178+
set_target_properties(${SFD_TARGET} PROPERTIES TARGET_FILE ${SFD_ABSPATH})
179+
165180
# --- Make the tagged binary ---
166-
add_custom_command(OUTPUT ${arg_TAGGED_EXECUTABLE_NAME}
181+
add_custom_command(OUTPUT ${TAGGED_EXECUTABLE_ABSPATH}
167182
DEPENDS ${TARGET}
168-
COMMAND ${arg_SCRUTINY_CMD} tag-firmware-id $<TARGET_FILE:${PROJECT_NAME}> ${arg_TAGGED_EXECUTABLE_NAME}
183+
COMMAND ${arg_SCRUTINY_CMD} tag-firmware-id $<TARGET_FILE:${PROJECT_NAME}> ${TAGGED_EXECUTABLE_ABSPATH}
169184
)
170-
add_custom_target(${TAGGED_EXECUTABLE_TARGET} ALL DEPENDS ${arg_TAGGED_EXECUTABLE_NAME})
171-
set_target_properties(${TAGGED_EXECUTABLE_TARGET} PROPERTIES TARGET_FILE ${arg_TAGGED_EXECUTABLE_NAME})
172-
185+
add_custom_target(${TAGGED_EXECUTABLE_TARGET} ALL DEPENDS ${TAGGED_EXECUTABLE_ABSPATH})
186+
set_target_properties(${TAGGED_EXECUTABLE_TARGET} PROPERTIES TARGET_FILE ${TAGGED_EXECUTABLE_ABSPATH})
187+
173188
endfunction()

projects/c_testapp/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ else()
7575
-gdwarf-4
7676
)
7777

78-
endif()
78+
scrutiny_postbuild(${PROJECT_NAME}
79+
INSTALL_SFD
7980

81+
METADATA_PROJECT_NAME "Scrutiny CTestAPP"
82+
METADATA_AUTHOR ""
83+
METADATA_VERSION "1.0.0"
8084

85+
ALIAS_FILES
86+
assets/aliases.json
87+
)
8188

89+
endif()

projects/c_testapp/assets/aliases.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"target" : "/rpv/x5001"
77
},
88
"/alias/enable_var" : {
9-
"target" : "/static/main.cpp/process_interactive_data()/enable"
9+
"target" : "/static/main.c/process_interactive_data/enable"
1010
},
1111
"/alias/counter_var" : {
12-
"target" : "/static/main.cpp/process_interactive_data()/counter"
12+
"target" : "/static/main.c/process_interactive_data/counter"
1313
},
1414
"/alias/counter_var_x2+1000" : {
15-
"target" : "/static/main.cpp/process_interactive_data()/counter",
15+
"target" : "/static/main.c/process_interactive_data/counter",
1616
"gain" : 2,
1717
"offset" : 1000
1818
}

projects/testapp/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,17 @@ else()
8282
-gdwarf-4
8383
)
8484

85-
endif()
85+
scrutiny_postbuild(${PROJECT_NAME}
86+
INSTALL_SFD
87+
88+
METADATA_PROJECT_NAME "Scrutiny TestAPP"
89+
METADATA_AUTHOR ""
90+
METADATA_VERSION "1.0.0"
8691

92+
ALIAS_FILES
93+
assets/aliases.json
94+
)
95+
96+
endif()
8797

8898

projects/testapp/scripts/make-sfd.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
# Can be called manually without invoking cmake.
4+
35
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
46

57
set -u

scripts/ci/shell.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -euo pipefail
33

44
APP_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../.. >/dev/null 2>&1 && pwd )"
55

6-
TARGET="${TARGET:-native}"
6+
TARGET="${TARGET:-native-gcc}"
77

88
DOCKER_TAG="scrutiny/embedded:$TARGET"
99

0 commit comments

Comments
 (0)