Skip to content

Commit 62b6a2e

Browse files
move logic in check_makefile.sh
1 parent b9b038f commit 62b6a2e

File tree

3 files changed

+59
-46
lines changed

3 files changed

+59
-46
lines changed

.github/workflows/_check_makefile.yml

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -97,49 +97,7 @@ jobs:
9797
echo "BOLOS_SDK=${BOLOS_SDK}" >> "${GITHUB_ENV}"
9898
echo "BOLOS_SDK will be set to: ${BOLOS_SDK}"
9999
100-
- name: Check for forbidden flags
101-
id: check-no-debug-flag
102-
shell: bash
103-
if: ${{ needs.call_get_app_metadata.outputs.is_rust == 'false' }}
104-
working-directory: app-repository
105-
run: |
106-
forbidden_flags=$(jq -r '.forbidden.c[]' ../ledger-app-workflows/config/forbidden-flags.json)
107-
108-
BUILD_DEVICE_NAME="${{ matrix.device }}"
109-
BUILD_DEVICE_NAME="${BUILD_DEVICE_NAME/sp/s2}"
110-
111-
entrypoint_filepath=$(grep -rP \
112-
--exclude-dir='deps' \
113-
--exclude-dir='tests' \
114-
--exclude-dir='vendor' \
115-
--include='*.c' \
116-
'\b(app_)?main\s*\([^)]*\)' . | cut -d':' -f1 | head -n1)
117-
118-
entrypoint_filepath=${entrypoint_filepath#./}
119-
entrypoint_filepath=${entrypoint_filepath%.c}.o
120-
121-
build_dir=$(ledger-manifest -ob ledger_app.toml)
122-
if [ -z "${build_dir}" ]; then
123-
echo "build directory not found in ledger_app.toml!" >&2
124-
exit 1
125-
fi
126-
127-
make ${{ needs.call_get_app_metadata.outputs.flags }} \
128-
${ADDITIONAL_ARGS} \
129-
BOLOS_SDK="${BOLOS_SDK}" \
130-
--dry-run build/${BUILD_DEVICE_NAME}/obj/app/${entrypoint_filepath} 2>&1 | tee -a build_dry_run_output.txt
131-
132-
for forbidden_flag in $forbidden_flags; do
133-
echo "[INFO] Checking for forbidden flag $forbidden_flag"
134-
if grep -q "$forbidden_flag" build_dry_run_output.txt; then
135-
echo "[ERROR] Detected forbidden flag $forbidden_flag in build output. Aborting."
136-
exit 1
137-
else
138-
echo "[INFO] Did not find forbidden flag $forbidden_flag in build output. Continuing."
139-
fi
140-
done
141-
142100
- name: Run script
143101
run: |
144102
./ledger-app-workflows/scripts/check_all.sh -c makefile -t "${{ matrix.device }}" \
145-
-a ./app-repository -m "${DOWNLOAD_MANIFEST_ARTIFACT_NAME}"
103+
-a ./app-repository -m "${DOWNLOAD_MANIFEST_ARTIFACT_NAME}" -w ../ledger-app-workflows

scripts/check_all.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ help() {
3333
echo
3434
echo " -c <check> : Requested check from (${ALL_CHECKS}). Default is all."
3535
echo " -d <dir> : Database directory"
36+
echo " -w <dir> : Workflows directory"
3637
echo " -a <dir> : Application directory"
3738
echo " -b <dir> : Application build directory"
3839
echo " -m <file> : Manifest (file or directory)"
@@ -50,14 +51,15 @@ help() {
5051
#
5152
#===============================================================================
5253

53-
while getopts ":a:b:c:d:m:t:rvh" opt; do
54+
while getopts ":a:b:c:d:m:t:w:rvh" opt; do
5455
case ${opt} in
5556
a) APP_DIR=${OPTARG} ;;
5657
b) BUILD_DIR=${OPTARG} ;;
5758
c) REQUESTED_CHECK=${OPTARG} ;;
5859
d) DATABASE_DIR=${OPTARG} ;;
5960
m) MANIFEST=${OPTARG} ;;
6061
t) TARGET=${OPTARG} ;;
62+
w) WORKFLOWS_DIR=${OPTARG} ;;
6163
r) IS_RUST=true ;;
6264
v) VERBOSE=true ;;
6365
h) help ;;
@@ -128,6 +130,16 @@ if [[ (-z ${REQUESTED_CHECK}) || ("${REQUESTED_CHECK}" == app_load_params) ]]; t
128130
fi
129131
fi
130132

133+
if [[ (-z ${REQUESTED_CHECK}) || ("${REQUESTED_CHECK}" == makefile) ]]; then
134+
if [[ -z "${WORKFLOWS_DIR}" ]]; then
135+
# Check if WORKFLOWS_DIR is already present
136+
WORKFLOWS_DIR="/tmp/ledger-app-workflows"
137+
if [[ ! -d "$WORKFLOWS_DIR" ]]; then
138+
git clone "${verbose_mode[@]}" https://github.com/LedgerHQ/ledger-app-database.git "${WORKFLOWS_DIR}"
139+
fi
140+
fi
141+
fi
142+
131143
#===============================================================================
132144
#
133145
# log functions
@@ -206,7 +218,7 @@ call_step() {
206218
COMMAND="python3 ${DATABASE_DIR}/scripts/app_load_params_check.py --database_path ${DATABASE_DIR}/app-load-params-db.json --app_manifests_path ${MANIFEST_DIR}"
207219
;;
208220
"makefile")
209-
COMMAND="${dirName}/check_makefile.sh ${APP_DIR} ${REPO_NAME} ${MANIFEST_DIR} ${TARGET}"
221+
COMMAND="${dirName}/check_makefile.sh ${APP_DIR} ${REPO_NAME} ${MANIFEST_DIR} ${WORKFLOWS_DIR} ${TARGET}"
210222
;;
211223
"readme")
212224
COMMAND="${dirName}/check_readme.sh ${APP_DIR} ${REPO_NAME}"

scripts/check_makefile.sh

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ main() (
1010
repo="$1"
1111
repo_name="$2"
1212
manifests_dir="$3"
13-
target="$4"
13+
workflows_dir="$4"
14+
target="$5"
1415

1516
declare -A variants_array
1617
declare -A appnames_array
@@ -92,6 +93,48 @@ main() (
9293
error=1
9394
fi
9495

96+
# check if there are no forbidden compilation flags (e.g. debug flags)
97+
forbidden_flags_file="${workflows_dir}/config/forbidden-flags.json"
98+
forbidden_flags=$(jq -r '.forbidden.c[]' "$forbidden_flags_file")
99+
100+
entrypoint_filepath=$(grep -rP \
101+
--exclude-dir='deps' \
102+
--exclude-dir='tests' \
103+
--exclude-dir='vendor' \
104+
--include='*.c' \
105+
'\b(app_)?main\s*\([^)]*\)' . | cut -d':' -f1 | head -n1)
106+
entrypoint_filepath=${entrypoint_filepath#./}
107+
entrypoint_filepath=${entrypoint_filepath%.c}.o
108+
109+
build_dir=$(ledger-manifest -ob ledger_app.toml)
110+
if [ -n "${build_dir}" ]; then
111+
for cur_manifest in $manifests_list; do
112+
for variant in "${!variants_array[@]}"; do
113+
build_target=$(jq -r ".VARIANTS.${variant}.TARGET" "${cur_manifest}")
114+
eval "BOLOS_SDK=\$$(echo "${build_target/s2/sp}" | tr '[:lower:]' '[:upper:]')_SDK"
115+
116+
log_info "Trying to make --dry-run for rule build/${build_target}/obj/app/${entrypoint_filepath}. Using $BOLOS_SDK"
117+
118+
make -C "${build_dir}" \
119+
BOLOS_SDK="${BOLOS_SDK}" \
120+
--dry-run build/"${build_target}"/obj/app/"${entrypoint_filepath}" 2>&1 | tee build_dry_run_output.txt
121+
122+
for forbidden_flag in $forbidden_flags; do
123+
log_info "Checking for forbidden flag $forbidden_flag"
124+
if grep -q "$forbidden_flag" build_dry_run_output.txt; then
125+
log_error_no_header "Detected forbidden flag $forbidden_flag in build output."
126+
error=1
127+
else
128+
log_info "Did not find forbidden flag $forbidden_flag in build output."
129+
fi
130+
done
131+
done
132+
done
133+
else
134+
log_error_no_header "build directory not found in ledger_app.toml!" >&2
135+
error=1
136+
fi
137+
95138
if [[ error -eq 0 ]]; then
96139
log_success "The Makefile is compliant"
97140
else

0 commit comments

Comments
 (0)