diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/changelog.sh | 297 |
1 files changed, 174 insertions, 123 deletions
diff --git a/lib/changelog.sh b/lib/changelog.sh index 01e4644..7127282 100644 --- a/lib/changelog.sh +++ b/lib/changelog.sh @@ -1,4 +1,4 @@ -# opkhelper +# opkbuild # lib/changelog # Functions for parsing changelogs. # @@ -17,154 +17,205 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -[ -n "${_OH_CHANGELOG_SH}" ] && return 0 -_OH_CHANGELOG_SH=true +[ -n "${_OB_CHANGELOG_SM}" ] && return 0 +_OB_CHANGELOG_SM='true' -. @@LIBDIR@@/messages -. @@LIBDIR@@/locale -. @@LIBDIR@@/util +. '@@LIBOPKBUILD@@/messages.sm' +. '@@LIBOPKBUILD@@/locale.sm' +. '@@LIBOPKBUILD@@/util.sm' # Constant global parameters: -OH_SOURCE_RE='^[a-z0-9][a-z0-9+.-]+$' -OH_SOURCE_VERSION_ID_RE='^' -OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'[0-9a-z.~]+' -OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'(\+sip[1-9][0-9]*)?' -OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'(-[1-9][0-9]*)?' -OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'(\+[a-z0-9]+-[1-9][0-9]*)?' -OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'$' - -_changelog_parse_error() -{ - _line_nr="${1}" - _error="${2}" - shift 2 +# FIXME: Remove. +OB_SOURCE_RE='^[a-z0-9][a-z0-9+.-]+$' +OB_SOURCE_VERSION_ID_RE='^' +OB_SOURCE_VERSION_ID_RE="${OB_SOURCE_VERSION_ID_RE}"'[0-9a-z.~]+' +OB_SOURCE_VERSION_ID_RE="${OB_SOURCE_VERSION_ID_RE}"'(\+sip[1-9][0-9]*)?' +OB_SOURCE_VERSION_ID_RE="${OB_SOURCE_VERSION_ID_RE}"'(-[1-9][0-9]*)?' +OB_SOURCE_VERSION_ID_RE="${OB_SOURCE_VERSION_ID_RE}"'(\+[a-z0-9]+-[1-9][0-9]*)?' +OB_SOURCE_VERSION_ID_RE="${OB_SOURCE_VERSION_ID_RE}"'$' - _file_info=$(printf '%20s(l%d):' "${OH_SOURCE_DIR}/changelog" "${_line_nr}") - oh_warn "${_file_info} ${_error}" "${@}" -} +OB_CHANGELOG_SOURCE= +OB_CHANGELOG_VERSION= +OB_CHANGELOG_DISTRIBUTION= +OB_CHANGELOG_CHANGES= +OB_CHANGELOG_MAINTAINER= +OB_CHANGELOG_DATE= -_changelog_get_expect_str() +oh_parse_changelog() { - eval echo \$\{oh_str_changelog_expect_"${1}"\} -} + _obpch_file= + _obpch_entry_cb= + _obpch_line_nr= + _obpch_line= + _obpch_line_= + _obpch_expect= + _obpch_blank_lines= + _obpch_entries= + _obpch_source= + _obpch_distribution= + _obpch_version= + _obpch_maintainer= + _obpch_date= -oh_changelog_parse() -{ - # Parsing logic based on that of dpkg. + if [ ${#} -eq 2 ]; then + _obpch_file="${1}" + _obpch_entry_cb="${2}" + else + unset _obpch_file _obpch_entry_cb \ + _obpch_line_nr _obpch_line _obpch_line_ \ + _obpch_expect _obpch_blank_lines _obpch_entries \ + _obpch_source _obpch_distribution _obpch_version \ + _obpch_maintainer _obpch_date + return 125 + fi - _cb="${1}" + # Parsing logic based on that of dpkg. - _expect=first_heading - _line_nr=0 - _entries=0 + _obpch_line_nr=0 + _obpch_expect=first_heading + _obpch_entries=0 - while IFS= read _line; do - _line_nr=$(($_line_nr + 1)) - if [ -z "${_line}" ]; then - if [ "${_expect}" = start_changes ]; then - OH_CHANGELOG_CHANGES="${OH_CHANGELOG_CHANGES} -${_line}" - elif [ "${_expect}" = next_or_eof ]; then + while IFS= read _obpch_line; do + _obpch_line_nr=$(($_obpch_line_nr + 1)) + if [ -z "${_obpch_line}" ]; then + if [ "${_obpch_expect}" = start_changes ]; then + OB_CHANGELOG_CHANGES="${OB_CHANGELOG_CHANGES} +${_obpch_line}" + elif [ "${_obpch_expect}" = next_or_eof ]; then : - elif [ "${_expect}" != changes_or_trailer ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_found_blank_line}" \ - "$(_changelog_get_expect_str "${_expect}")" + elif [ "${_obpch_expect}" != changes_or_trailer ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_found_blank_line' \ + "$(_ob_get_changelog_expect_str "${_obpch_expect}")" else - _blank_lines="${_blank_lines} -${_line}" + _obpch_blank_lines="${_obpch_blank_lines} +${_obpch_line}" fi - elif [ "${_line# }" = "${_line}" ]; then - if [ "${_expect}" != first_heading -a \ - "${_expect}" != next_or_eof ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_found_heading}" \ - "$(_changelog_get_expect_str "${_expect}")" + elif [ "${_obpch_line# }" = "${_obpch_line}" ]; then + if [ "${_obpch_expect}" != first_heading -a \ + "${_obpch_expect}" != next_or_eof ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_found_heading' \ + "$(_ob_get_changelog_expect_str "${_obpch_expect}")" fi - _source="${_line%% (*}" - _line_="${_line#* (}" - _distribution="${_line_##*) }" - _line_="${_line_%) *}" - _version="${_line_}" - if [ -z "${_source}" -o -z "${_distribution}" -o \ - -z "${_version}" -o \ - "${_version% *}" != "${_version}" ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_bad_heading}" - OH_CHANGELOG_SOURCE= - OH_CHANGELOG_VERSION= - OH_CHANGELOG_DISTRIBUTION= - OH_CHANGELOG_CHANGES= + _obpch_source="${_obpch_line%% (*}" + _obpch_line_="${_obpch_line#* (}" + _obpch_distribution="${_obpch_line_##*) }" + _obpch_line_="${_obpch_line_%) *}" + _obpch_version="${_obpch_line_}" + if [ -z "${_obpch_source}" -o -z "${_obpch_distribution}" -o \ + -z "${_obpch_version}" -o \ + "${_obpch_version% *}" != "${_obpch_version}" ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_bad_heading' + OB_CHANGELOG_SOURCE= + OB_CHANGELOG_VERSION= + OB_CHANGELOG_DISTRIBUTION= + OB_CHANGELOG_CHANGES= else - echo "${_source}" | \ - grep -E "${OH_SOURCE_RE}" >/dev/null 2>&1 + echo "${_obpch_source}" | \ + grep -E "${OB_SOURCE_RE}" >/dev/null 2>&1 if [ "${?}" -ne 0 ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_bad_source}" "${source}" + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_bad_source' "${source}" fi - echo "${_version}" | \ - grep -E "${OH_SOURCE_VERSION_ID_RE}" >/dev/null 2>&1 + echo "${_obpch_version}" | \ + grep -E "${OB_SOURCE_VERSION_ID_RE}" >/dev/null 2>&1 if [ "${?}" -ne 0 ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_bad_source_version}" "${_version}" + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_bad_source_version' "${_obpch_version}" fi - OH_CHANGELOG_SOURCE="${_source}" - OH_CHANGELOG_VERSION="${_version}" - OH_CHANGELOG_DISTRIBUTION="${_distribution}" - OH_CHANGELOG_CHANGES="${_line}" + OB_CHANGELOG_SOURCE="${_obpch_source}" + OB_CHANGELOG_VERSION="${_obpch_version}" + OB_CHANGELOG_DISTRIBUTION="${_obpch_distribution}" + OB_CHANGELOG_CHANGES="${_obpch_line}" fi - _expect=start_changes - _blank_lines= - elif [ "${_line# -- }" != "${_line}" ]; then - if [ "${_expect}" != changes_or_trailer ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_found_trailer}" \ - "$(_changelog_get_expect_str "${_expect}")" + _obpch_expect=start_changes + _obpch_blank_lines= + elif [ "${_obpch_line# -- }" != "${_obpch_line}" ]; then + if [ "${_obpch_expect}" != changes_or_trailer ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_found_trailer' \ + "$(_ob_get_changelog_expect_str "${_obpch_expect}")" fi - _line="${_line# -- }" - _maintainer="${_line%% *}" - _date="${_line#* }" - if [ -z "${_maintainer}" -o -z "${_date}" -o \ - "${_maintainer}" = "${_date}" ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_bad_trailer}" - OH_CHANGELOG_MAINTAINER= - OH_CHANGELOG_DATE= - elif [ -n "${OH_CHANGELOG_SOURCE}" ]; then - OH_CHANGELOG_MAINTAINER="${_maintainer}" - OH_CHANGELOG_DATE="${_date}" - _entries=$(($_entries + 1)) - "${_cb}" - [ ${?} -ne 0 ] && return ${_entries} + _obpch_line="${_obpch_line# -- }" + _obpch_maintainer="${_obpch_line%% *}" + _obpch_date="${_obpch_line#* }" + if [ -z "${_obpch_maintainer}" -o -z "${_obpch_date}" -o \ + "${_obpch_maintainer}" = "${_obpch_date}" ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_bad_trailer' + OB_CHANGELOG_MAINTAINER= + OB_CHANGELOG_DATE= + elif [ -n "${OB_CHANGELOG_SOURCE}" ]; then + OB_CHANGELOG_MAINTAINER="${_obpch_maintainer}" + OB_CHANGELOG_DATE="${_obpch_date}" + _obpch_entries=$(($_obpch_entries + 1)) + "${_obpch_entry_cb}" + if [ ${?} -ne 0 ]; then + unset _obpch_file _obpch_entry_cb \ + _obpch_line_nr _obpch_line _obpch_line_ \ + _obpch_expect _obpch_blank_lines _obpch_entries \ + _obpch_source _obpch_distribution _obpch_version \ + _obpch_maintainer _obpch_date + return ${_obpch_entries} + fi fi - _expect=next_or_eof - _blank_lines= - elif [ "${_line# --}" != "${_line}" ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_bad_trailer}" - elif [ "${_line## }" != "${_line}" ]; then - if [ "${_expect}" != start_changes -a \ - "${_expect}" != changes_or_trailer ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_found_change}" \ - "$(_changelog_get_expect_str "${_expect}")" + _obpch_expect=next_or_eof + _obpch_blank_lines= + elif [ "${_obpch_line# --}" != "${_obpch_line}" ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_bad_trailer' + elif [ "${_obpch_line## }" != "${_obpch_line}" ]; then + if [ "${_obpch_expect}" != start_changes -a \ + "${_obpch_expect}" != changes_or_trailer ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_found_change' \ + "$(_ob_get_changelog_expect_str "${_obpch_expect}")" fi - OH_CHANGELOG_CHANGES="${OH_CHANGELOG_CHANGES} -${_blank_lines}${_line}" - _expect=changes_or_trailer - _blank_lines= + OB_CHANGELOG_CHANGES="${OB_CHANGELOG_CHANGES} +${_obpch_blank_lines}${_obpch_line}" + _obpch_expect=changes_or_trailer + _obpch_blank_lines= else - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_bad_line}" - _blank_lines= + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_bad_line' + _obpch_blank_lines= fi - done <"${OH_SOURCE_DIR}/changelog" + done <"${_obpch_file}" - if [ "${_expect}" != next_or_eof ]; then - _changelog_parse_error "${_line_nr}" \ - "${oh_str_changelog_found_eof}" \ - "$(_changelog_get_expect_str "${_expect}")" + if [ "${_obpch_expect}" != next_or_eof ]; then + _ob_parse_changelog_error "${_obpch_line_nr}" \ + 'changelog_found_eof' \ + "$(_ob_get_changelog_expect_str "${_obpch_expect}")" fi - return ${_entries} + unset _obpch_file _obpch_entry_cb \ + _obpch_line_nr _obpch_line _obpch_line_ \ + _obpch_expect _obpch_blank_lines _obpch_entries \ + _obpch_source _obpch_distribution _obpch_version \ + _obpch_maintainer _obpch_date + return ${_obpch_entries} +} + +_ob_parse_changelog_error() +{ + _obpche_file="${1}" + _obpche_line_nr="${2}" + _obpche_msg_id="${3}" + _obpche_file_info= + shift 3 + + _obpche_file_info=$(printf '%20s(l%d):' "${_obpche_file}" \ + "${_obpche_line_nr}") + + oh_warn "${_obpche_file_info} $(ob_get_msg "${_obpche_msg_id}")" "${@}" + + unset _obpche_file _obpche_line_nr _obpche_msg_id _obpche_file_info + return 0 +} + +_ob_get_changelog_expect_str() +{ + echo "$(ob_get_msg "changelog_expect_${1}")" } |