From 96ae2fd553a92b78adb6e1d3520bfa3ab91e042a Mon Sep 17 00:00:00 2001 From: Levon Gevorgyan Date: Sat, 9 Aug 2025 16:04:36 -0500 Subject: [PATCH] add project versioning --- lib/build.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/common.sh | 10 ++++++++++ lib/docker.sh | 20 ++++++++++---------- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/lib/build.sh b/lib/build.sh index 6c05887..5d85847 100644 --- a/lib/build.sh +++ b/lib/build.sh @@ -281,6 +281,10 @@ do_build() { local build="${1:-''}" download_release "${build}" || return 1 get_build_conf "${build}" || return 1 + + # add build configuration to FFMPEG_BUILDER_INFO + FFMPEG_BUILDER_INFO+=("${build}=${ver}") + set_compile_opts || return 1 for dep in "${deps[@]}"; do do_build "${dep}" || return 1 @@ -315,6 +319,9 @@ build() { fi test -f "${testfile}" && ${SUDO_MODIFY} rm "${testfile}" + # embed this project's enables/versions + # into ffmpeg with this variable + FFMPEG_BUILDER_INFO=("ffmpeg-builder=$(cd "${REPO_DIR}" && git rev-parse HEAD)") for build in "${FFMPEG_ENABLES[@]}"; do do_build "${build}" || return 1 done @@ -464,11 +471,47 @@ build_libopus() { ${SUDO_MODIFY} make -j"${JOBS}" install || return 1 return 0 } +add_project_versioning_to_ffmpeg() { + local optFile + optFile="$(command ls ./**/ffmpeg_opt.c)" + if [[ ! $? -eq 0 || ${optFile} == '' || ! -f ${optFile} ]]; then + echo_fail "could not find ffmpeg_opt.c to add project versioning" + fi + + local lineNum=0 + local searchFor='Universal media converter\n' + local foundUsageStart=0 + while read -r line; do + lineNum=$((lineNum + 1)) + if line_contains "${line}" "${searchFor}"; then + foundUsageStart=1 + continue + fi + if [[ ${foundUsageStart} -eq 1 ]]; then + if line_starts_with "${line}" '}'; then + break + fi + fi + 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\");" + sed -i "${lineNum}i ${newline}" "${optFile}" || return 1 + lineNum=$((lineNum + 1)) + done + local newline="\ av_log(NULL, AV_LOG_INFO, \"\\\n\");" + sed -i "${lineNum}i ${newline}" "${optFile}" || return 1 + + return 0 +} build_ffmpeg() { for enable in "${FFMPEG_ENABLES[@]}"; do test "${enable}" == 'libsvtav1_psy' && enable='libsvtav1' CONFIGURE_FLAGS+=("--enable-${enable}") done + add_project_versioning_to_ffmpeg || return 1 + ./configure \ "${CONFIGURE_FLAGS[@]}" \ "${FFMPEG_EXTRA_FLAGS[@]}" \ diff --git a/lib/common.sh b/lib/common.sh index 708fa83..f6331ce 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -148,3 +148,13 @@ line_contains() { return 1 fi } + +line_starts_with() { + local line="$1" + local substr="$2" + if [[ $line == "${substr}"* ]]; then + return 0 + else + return 1 + fi +} diff --git a/lib/docker.sh b/lib/docker.sh index d7fabbf..38f9e90 100644 --- a/lib/docker.sh +++ b/lib/docker.sh @@ -198,16 +198,6 @@ docker_run_image() { for distro in "${DISTROS[@]}"; do image_tag="$(set_distro_image_tag "${distro}")" - # if a docker registry is defined, pull from it - if [[ ${DOCKER_REGISTRY} != '' ]]; then - docker_login || return 1 - docker pull \ - "${DOCKER_REGISTRY}/${image_tag}" - docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}" - fi - - echo_info "running ffmpeg build for ${image_tag}" - # TODO REMOVE if is_root_owned "${IGN_DIR}"; then docker run \ @@ -229,6 +219,16 @@ docker_run_image() { rm -rf "${DOCKER_WORKDIR}"/gitignore fi + # if a docker registry is defined, pull from it + if [[ ${DOCKER_REGISTRY} != '' ]]; then + docker_login || return 1 + docker pull \ + "${DOCKER_REGISTRY}/${image_tag}" + docker tag "${DOCKER_REGISTRY}/${image_tag}" "${image_tag}" + fi + + echo_info "running ffmpeg build for ${image_tag}" + docker run \ "${DOCKER_RUN_FLAGS[@]}" \ -u "$(id -u):$(id -g)" \