From 21d3167febf5d79d1bdd26e75a9303f00834a12b Mon Sep 17 00:00:00 2001 From: Levon Gevorgyan Date: Fri, 22 Aug 2025 11:51:41 -0500 Subject: [PATCH] fix add_project_versioning_to_ffmpeg --- lib/build.sh | 39 ++++++++++++++++++++++----------------- lib/common.sh | 13 ------------- lib/compile_opts.sh | 2 +- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/lib/build.sh b/lib/build.sh index bb110f5..711b686 100644 --- a/lib/build.sh +++ b/lib/build.sh @@ -570,35 +570,40 @@ build_libc() ( ) add_project_versioning_to_ffmpeg() { local optFile - optFile="$(command ls ./**/ffmpeg_opt.c)" + local fname='ffmpeg_opt.c' + optFile="$(command ls ./**/"${fname}")" if [[ ! $? -eq 0 || ${optFile} == '' || ! -f ${optFile} ]]; then - echo_fail "could not find ffmpeg_opt.c to add project versioning" + echo_fail "could not find ${fname} to add project versioning" fi - local lineNum=0 local searchFor='Universal media converter\n' local foundUsageStart=0 + local newOptFile="${TMP_DIR}/${fname}" + test -f "${newOptFile}" && rm "${newOptFile}" while read -r line; do - lineNum=$((lineNum + 1)) - if line_contains "${line}" "${searchFor}"; then - foundUsageStart=1 - continue - fi + # if we found the line previously, add the versioning if [[ ${foundUsageStart} -eq 1 ]]; then if line_starts_with "${line}" '}'; then - break + echo_info "found ${line} on ${lineNum}" + for info in "${FFMPEG_BUILDER_INFO[@]}"; do + local newline="av_log(NULL, AV_LOG_INFO, \"${info}\n\");" + echo "${newline}" >>"${newOptFile}" + lineNum=$((lineNum + 1)) + done + newline="av_log(NULL, AV_LOG_INFO, \"\n\");" + echo "${newline}" >>"${newOptFile}" + foundUsageStart=0 fi fi + # find the line we are searching for + if line_contains "${line}" "${searchFor}"; then + foundUsageStart=1 + fi + # start building the new file + echo "${line}" >>"${newOptFile}" done <"${optFile}" - echo_info "found ${line} on ${lineNum}" - for info in "${FFMPEG_BUILDER_INFO[@]}"; do - local newline=" av_log(NULL, AV_LOG_INFO, \"${info}\n\");" - insert_line "${newline}" "${lineNum}" "${optFile}" || return 1 - lineNum=$((lineNum + 1)) - done - newline=" av_log(NULL, AV_LOG_INFO, \"\n\");" - insert_line "${newline}" "${lineNum}" "${optFile}" || return 1 + cp "${newOptFile}" "${optFile}" || return 1 return 0 } diff --git a/lib/common.sh b/lib/common.sh index e72b58b..4a0426c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -162,16 +162,3 @@ line_starts_with() { is_darwin() { line_contains "$(print_os)" darwin } - -insert_line() { - local line="$1" - local lineNum="$2" - local file="$3" - ed -s "${file}" <