xref: /aosp_15_r20/external/libpng/ci/ci_verify_version.sh (revision a67afe4df73cf47866eedc69947994b8ff839aba)
1*a67afe4dSAndroid Build Coastguard Worker#!/usr/bin/env bash
2*a67afe4dSAndroid Build Coastguard Workerset -o errexit -o pipefail -o posix
3*a67afe4dSAndroid Build Coastguard Worker
4*a67afe4dSAndroid Build Coastguard Worker# Copyright (c) 2019-2024 Cosmin Truta.
5*a67afe4dSAndroid Build Coastguard Worker#
6*a67afe4dSAndroid Build Coastguard Worker# Use, modification and distribution are subject to the MIT License.
7*a67afe4dSAndroid Build Coastguard Worker# Please see the accompanying file LICENSE_MIT.txt
8*a67afe4dSAndroid Build Coastguard Worker#
9*a67afe4dSAndroid Build Coastguard Worker# SPDX-License-Identifier: MIT
10*a67afe4dSAndroid Build Coastguard Worker
11*a67afe4dSAndroid Build Coastguard Worker# shellcheck source=ci/lib/ci.lib.sh
12*a67afe4dSAndroid Build Coastguard Workersource "$(dirname "$0")/lib/ci.lib.sh"
13*a67afe4dSAndroid Build Coastguard Workercd "$CI_TOPLEVEL_DIR"
14*a67afe4dSAndroid Build Coastguard Worker
15*a67afe4dSAndroid Build Coastguard Workerfunction ci_init_shellify {
16*a67afe4dSAndroid Build Coastguard Worker    [[ -f $CI_SCRIPT_DIR/ci_shellify.sh ]] || {
17*a67afe4dSAndroid Build Coastguard Worker        ci_err_internal "missing script: '$CI_SCRIPT_DIR/ci_shellify.sh'"
18*a67afe4dSAndroid Build Coastguard Worker    }
19*a67afe4dSAndroid Build Coastguard Worker}
20*a67afe4dSAndroid Build Coastguard Worker
21*a67afe4dSAndroid Build Coastguard Workerfunction ci_run_shellify {
22*a67afe4dSAndroid Build Coastguard Worker    ci_info "shellifying:" "$@"
23*a67afe4dSAndroid Build Coastguard Worker    local my_result
24*a67afe4dSAndroid Build Coastguard Worker    "$BASH" "$CI_SCRIPT_DIR/ci_shellify.sh" "$@"
25*a67afe4dSAndroid Build Coastguard Worker    echo "$my_result" | "$BASH" --posix || ci_err "bad shellify output"
26*a67afe4dSAndroid Build Coastguard Worker    echo "$my_result"
27*a67afe4dSAndroid Build Coastguard Worker}
28*a67afe4dSAndroid Build Coastguard Worker
29*a67afe4dSAndroid Build Coastguard Workerfunction ci_verify_version {
30*a67afe4dSAndroid Build Coastguard Worker    ci_info "## START OF VERIFICATION ##"
31*a67afe4dSAndroid Build Coastguard Worker    local my_env_libpng_ver my_env_autoconf_ver my_env_cmake_ver my_expect
32*a67afe4dSAndroid Build Coastguard Worker    ci_init_shellify
33*a67afe4dSAndroid Build Coastguard Worker    my_env_libpng_ver="$(ci_run_shellify png.h)"
34*a67afe4dSAndroid Build Coastguard Worker    echo "$my_env_libpng_ver"
35*a67afe4dSAndroid Build Coastguard Worker    my_env_autoconf_ver="$(ci_run_shellify configure.ac)"
36*a67afe4dSAndroid Build Coastguard Worker    echo "$my_env_autoconf_ver"
37*a67afe4dSAndroid Build Coastguard Worker    my_env_cmake_ver="$(ci_run_shellify CMakeLists.txt)"
38*a67afe4dSAndroid Build Coastguard Worker    echo "$my_env_cmake_ver"
39*a67afe4dSAndroid Build Coastguard Worker    ci_info "## VERIFYING: png.h version definitions ##"
40*a67afe4dSAndroid Build Coastguard Worker    eval "$my_env_libpng_ver"
41*a67afe4dSAndroid Build Coastguard Worker    local my_expect="${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}"
42*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER_STRING" == "$my_expect"* ]]
43*a67afe4dSAndroid Build Coastguard Worker    then
44*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNG_LIBPNG_VER_STRING == $my_expect*"
45*a67afe4dSAndroid Build Coastguard Worker    else
46*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNG_LIBPNG_VER_STRING != $my_expect*"
47*a67afe4dSAndroid Build Coastguard Worker    fi
48*a67afe4dSAndroid Build Coastguard Worker    my_expect=$((PNG_LIBPNG_VER_MAJOR*10000 + PNG_LIBPNG_VER_MINOR*100 + PNG_LIBPNG_VER_RELEASE))
49*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER" == "$my_expect" ]]
50*a67afe4dSAndroid Build Coastguard Worker    then
51*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNG_LIBPNG_VER == $my_expect"
52*a67afe4dSAndroid Build Coastguard Worker    else
53*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNG_LIBPNG_VER != $my_expect"
54*a67afe4dSAndroid Build Coastguard Worker    fi
55*a67afe4dSAndroid Build Coastguard Worker    my_expect=$((PNG_LIBPNG_VER_MAJOR*10 + PNG_LIBPNG_VER_MINOR))
56*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER_SHAREDLIB" == "$my_expect" ]]
57*a67afe4dSAndroid Build Coastguard Worker    then
58*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNG_LIBPNG_VER_SHAREDLIB == $my_expect"
59*a67afe4dSAndroid Build Coastguard Worker    else
60*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNG_LIBPNG_VER_SHAREDLIB != $my_expect"
61*a67afe4dSAndroid Build Coastguard Worker    fi
62*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER_SONUM" == "$my_expect" ]]
63*a67afe4dSAndroid Build Coastguard Worker    then
64*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNG_LIBPNG_VER_SONUM == $my_expect"
65*a67afe4dSAndroid Build Coastguard Worker    else
66*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNG_LIBPNG_VER_SONUM != $my_expect"
67*a67afe4dSAndroid Build Coastguard Worker    fi
68*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER_DLLNUM" == "$my_expect" ]]
69*a67afe4dSAndroid Build Coastguard Worker    then
70*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNG_LIBPNG_VER_DLLNUM == $my_expect"
71*a67afe4dSAndroid Build Coastguard Worker    else
72*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNG_LIBPNG_VER_DLLNUM != $my_expect"
73*a67afe4dSAndroid Build Coastguard Worker    fi
74*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER_BUILD" == [01] ]]
75*a67afe4dSAndroid Build Coastguard Worker    then
76*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNG_LIBPNG_VER_BUILD == [01]"
77*a67afe4dSAndroid Build Coastguard Worker    else
78*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNG_LIBPNG_VER_BUILD != [01]"
79*a67afe4dSAndroid Build Coastguard Worker    fi
80*a67afe4dSAndroid Build Coastguard Worker    ci_info "## VERIFYING: png.h build definitions ##"
81*a67afe4dSAndroid Build Coastguard Worker    my_expect="${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}"
82*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNG_LIBPNG_VER_STRING" == "$my_expect" ]]
83*a67afe4dSAndroid Build Coastguard Worker    then
84*a67afe4dSAndroid Build Coastguard Worker        if [[ $PNG_LIBPNG_VER_BUILD -eq 0 ]]
85*a67afe4dSAndroid Build Coastguard Worker        then
86*a67afe4dSAndroid Build Coastguard Worker            ci_info "matched: \$PNG_LIBPNG_VER_BUILD -eq 0"
87*a67afe4dSAndroid Build Coastguard Worker        else
88*a67afe4dSAndroid Build Coastguard Worker            ci_err "mismatched: \$PNG_LIBPNG_VER_BUILD -ne 0"
89*a67afe4dSAndroid Build Coastguard Worker        fi
90*a67afe4dSAndroid Build Coastguard Worker        if [[ $PNG_LIBPNG_BUILD_BASE_TYPE -eq $PNG_LIBPNG_BUILD_STABLE ]]
91*a67afe4dSAndroid Build Coastguard Worker        then
92*a67afe4dSAndroid Build Coastguard Worker            ci_info "matched: \$PNG_LIBPNG_BUILD_BASE_TYPE -eq \$PNG_LIBPNG_BUILD_BETA"
93*a67afe4dSAndroid Build Coastguard Worker        else
94*a67afe4dSAndroid Build Coastguard Worker            ci_err "mismatched: \$PNG_LIBPNG_BUILD_BASE_TYPE -ne \$PNG_LIBPNG_BUILD_BETA"
95*a67afe4dSAndroid Build Coastguard Worker        fi
96*a67afe4dSAndroid Build Coastguard Worker    elif [[ "$PNG_LIBPNG_VER_STRING" == "$my_expect".git ]]
97*a67afe4dSAndroid Build Coastguard Worker    then
98*a67afe4dSAndroid Build Coastguard Worker        if [[ $PNG_LIBPNG_VER_BUILD -ne 0 ]]
99*a67afe4dSAndroid Build Coastguard Worker        then
100*a67afe4dSAndroid Build Coastguard Worker            ci_info "matched: \$PNG_LIBPNG_VER_BUILD -ne 0"
101*a67afe4dSAndroid Build Coastguard Worker        else
102*a67afe4dSAndroid Build Coastguard Worker            ci_err "mismatched: \$PNG_LIBPNG_VER_BUILD -eq 0"
103*a67afe4dSAndroid Build Coastguard Worker        fi
104*a67afe4dSAndroid Build Coastguard Worker        if [[ $PNG_LIBPNG_BUILD_BASE_TYPE -eq $PNG_LIBPNG_BUILD_BETA ]]
105*a67afe4dSAndroid Build Coastguard Worker        then
106*a67afe4dSAndroid Build Coastguard Worker            ci_info "matched: \$PNG_LIBPNG_BUILD_BASE_TYPE -eq \$PNG_LIBPNG_BUILD_BETA"
107*a67afe4dSAndroid Build Coastguard Worker        else
108*a67afe4dSAndroid Build Coastguard Worker            ci_err "mismatched: \$PNG_LIBPNG_BUILD_BASE_TYPE -ne \$PNG_LIBPNG_BUILD_BETA"
109*a67afe4dSAndroid Build Coastguard Worker        fi
110*a67afe4dSAndroid Build Coastguard Worker    else
111*a67afe4dSAndroid Build Coastguard Worker        ci_err "unexpected: \$PNG_LIBPNG_VER_STRING == '$PNG_LIBPNG_VER_STRING'"
112*a67afe4dSAndroid Build Coastguard Worker    fi
113*a67afe4dSAndroid Build Coastguard Worker    ci_info "## VERIFYING: png.h type definitions ##"
114*a67afe4dSAndroid Build Coastguard Worker    my_expect="$(echo "png_libpng_version_${PNG_LIBPNG_VER_STRING}" | tr . _)"
115*a67afe4dSAndroid Build Coastguard Worker    ci_spawn grep -w -e "$my_expect" png.h
116*a67afe4dSAndroid Build Coastguard Worker    ci_info "## VERIFYING: configure.ac version definitions ##"
117*a67afe4dSAndroid Build Coastguard Worker    eval "$my_env_autoconf_ver"
118*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNGLIB_VERSION" == "$PNG_LIBPNG_VER_STRING" ]]
119*a67afe4dSAndroid Build Coastguard Worker    then
120*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNGLIB_VERSION == \$PNG_LIBPNG_VER_STRING"
121*a67afe4dSAndroid Build Coastguard Worker    else
122*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNGLIB_VERSION != \$PNG_LIBPNG_VER_STRING"
123*a67afe4dSAndroid Build Coastguard Worker    fi
124*a67afe4dSAndroid Build Coastguard Worker    ci_info "## VERIFYING: CMakeLists.txt version definitions ##"
125*a67afe4dSAndroid Build Coastguard Worker    eval "$my_env_cmake_ver"
126*a67afe4dSAndroid Build Coastguard Worker    if [[ "$PNGLIB_VERSION" == "$PNG_LIBPNG_VER_STRING" && "$PNGLIB_SUBREVISION" == 0 ]]
127*a67afe4dSAndroid Build Coastguard Worker    then
128*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNGLIB_VERSION == \$PNG_LIBPNG_VER_STRING"
129*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNGLIB_SUBREVISION == 0"
130*a67afe4dSAndroid Build Coastguard Worker    elif [[ "$PNGLIB_VERSION.$PNGLIB_SUBREVISION" == "$PNG_LIBPNG_VER_STRING" ]]
131*a67afe4dSAndroid Build Coastguard Worker    then
132*a67afe4dSAndroid Build Coastguard Worker        ci_info "matched: \$PNGLIB_VERSION.\$PNGLIB_SUBREVISION == \$PNG_LIBPNG_VER_STRING"
133*a67afe4dSAndroid Build Coastguard Worker    else
134*a67afe4dSAndroid Build Coastguard Worker        ci_err "mismatched: \$PNGLIB_VERSION != \$PNG_LIBPNG_VER_STRING"
135*a67afe4dSAndroid Build Coastguard Worker    fi
136*a67afe4dSAndroid Build Coastguard Worker    ci_info "## END OF VERIFICATION ##"
137*a67afe4dSAndroid Build Coastguard Worker    ci_info "success!"
138*a67afe4dSAndroid Build Coastguard Worker}
139*a67afe4dSAndroid Build Coastguard Worker
140*a67afe4dSAndroid Build Coastguard Workerfunction usage {
141*a67afe4dSAndroid Build Coastguard Worker    echo "usage: $CI_SCRIPT_NAME [<options>]"
142*a67afe4dSAndroid Build Coastguard Worker    echo "options: -?|-h|--help"
143*a67afe4dSAndroid Build Coastguard Worker    exit "${@:-0}"
144*a67afe4dSAndroid Build Coastguard Worker}
145*a67afe4dSAndroid Build Coastguard Worker
146*a67afe4dSAndroid Build Coastguard Workerfunction main {
147*a67afe4dSAndroid Build Coastguard Worker    local opt
148*a67afe4dSAndroid Build Coastguard Worker    while getopts ":" opt
149*a67afe4dSAndroid Build Coastguard Worker    do
150*a67afe4dSAndroid Build Coastguard Worker        # This ain't a while-loop. It only pretends to be.
151*a67afe4dSAndroid Build Coastguard Worker        [[ $1 == -[?h]* || $1 == --help || $1 == --help=* ]] && usage 0
152*a67afe4dSAndroid Build Coastguard Worker        ci_err "unknown option: '$1'"
153*a67afe4dSAndroid Build Coastguard Worker    done
154*a67afe4dSAndroid Build Coastguard Worker    shift $((OPTIND - 1))
155*a67afe4dSAndroid Build Coastguard Worker    [[ $# -eq 0 ]] || {
156*a67afe4dSAndroid Build Coastguard Worker        echo >&2 "error: unexpected argument: '$1'"
157*a67afe4dSAndroid Build Coastguard Worker        usage 2
158*a67afe4dSAndroid Build Coastguard Worker    }
159*a67afe4dSAndroid Build Coastguard Worker    # And... go!
160*a67afe4dSAndroid Build Coastguard Worker    ci_verify_version
161*a67afe4dSAndroid Build Coastguard Worker}
162*a67afe4dSAndroid Build Coastguard Worker
163*a67afe4dSAndroid Build Coastguard Workermain "$@"
164