summaryrefslogtreecommitdiffstats
path: root/lib/control.sh
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-09-05 02:30:26 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-09-05 02:30:26 (EDT)
commit23d87a924356c99a9c50ce7d6cdb6e222ced02a5 (patch)
tree4f7efd48d38cff87e58fdf799d2262bbfc448e7f /lib/control.sh
parent6a776ac1077ef1c4dd249a6032dee9e7ff259341 (diff)
Largely rewrite control library module.
Diffstat (limited to 'lib/control.sh')
-rw-r--r--lib/control.sh288
1 files changed, 97 insertions, 191 deletions
diff --git a/lib/control.sh b/lib/control.sh
index f8d826d..0132121 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -1,4 +1,4 @@
-# opkhelper
+# opkbuild
# lib/control
# Functions for parsing control files.
#
@@ -17,231 +17,137 @@
# 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_CONTROL_SH}" ] && return 0
-_OH_CONTROL_SH=true
+[ -n "${_OB_CONTROL_SM}" ] && return 0
+_OB_CONTROL_SM='true'
-. @@LIBDIR@@/messages
-. @@LIBDIR@@/locale
-. @@LIBDIR@@/util
+. '@@LIBOPKBUILD@@/messages.sm'
+. '@@LIBOPKBUILD@@/locale.sm'
+. '@@LIBOPKBUILD@@/util.sm'
-# Constant global parameters:
-OH_CONTROL_SOURCE_FIELDS_REQUIRED='Maintainer'
-OH_CONTROL_SOURCE_FIELDS_OPTIONAL='Build-Depends Homepage'
-OH_CONTROL_BINARY_FIELDS_REQUIRED='Architecture Platform Priority Description'
-OH_CONTROL_BINARY_FIELDS_OPTIONAL='Essential Depends Recommends Suggests '\
-'Pre-Depends Conflicts Provides Replaces'
-OH_CONTROL_SOURCE_FIELD_MAINTAINER=
-OH_CONTROL_SOURCE_FIELD_BUILD_DEPENDS=
-OH_CONTROL_SOURCE_FIELD_HOMEPAGE=
-OH_CONTROL_BINARY_FIELD_ARCHITECTURE=
-OH_CONTROL_BINARY_FIELD_PLATFORM=
-OH_CONTROL_BINARY_FIELD_PRIORITY=
-OH_CONTROL_BINARY_FIELD_DESCRIPTION=
-OH_CONTROL_BINARY_FIELD_ESSENTIAL=
-OH_CONTROL_BINARY_FIELD_DEPENDS=
-OH_CONTROL_BINARY_FIELD_RECOMMENDS=
-OH_CONTROL_BINARY_FIELD_SUGGESTS=
-OH_CONTROL_BINARY_FIELD_PRE_DEPENDS=
-OH_CONTROL_BINARY_FIELD_CONFLICTS=
-OH_CONTROL_BINARY_FIELD_PROVIDES=
-OH_CONTROL_BINARY_FIELD_REPLACES=
+OB_CONTROL_NAME=
+OB_CONTROL_VALUE=
-oh_control_parse_source()
+ob_parse_control()
{
- _control_parse "${OH_SOURCE_DIR}/control" 'SOURCE'
-}
-
-oh_control_parse_binary()
-{
- _control_parse "${OH_SOURCE_DIR}/${1}.pkg/control" 'BINARY'
-}
-
-oh_control_gen_source()
-{
- _old_package="${OH_CONTROL_BINARY_FIELD_PACKAGE}"
- _old_version="${OH_BINARY_VERSION}"
- _old_architecture="${OH_CONTROL_BINARY_FIELD_ARCHITECTURE}"
- _old_recommends="${OH_CONTROL_BINARY_FIELD_RECOMMENDS}"
- _old_description="${OH_CONTROL_BINARY_FIELD_DESCRIPTION}"
-
- OH_CONTROL_BINARY_FIELD_PACKAGE="src:${OH_SOURCE}"
- OH_BINARY_VERSION="${OH_SOURCE_VERSION}"
- OH_CONTROL_BINARY_FIELD_ARCHITECTURE='all'
- OH_CONTROL_BINARY_FIELD_RECOMMENDS="${OH_CONTROL_SOURCE_FIELD_BUILD_DEPENDS}"
- OH_CONTROL_BINARY_FIELD_DESCRIPTION="${OH_SOURCE} source package"
-
- _control_gen 'SOURCE' \
- "src:${OH_SOURCE}.control/control" "src:${OH_SOURCE}.data"
-
- OH_CONTROL_BINARY_FIELD_PACKAGE="${_old_package}"
- OH_BINARY_VERSION="${_old_version}"
- OH_CONTROL_BINARY_FIELD_ARCHITECTURE="${_old_architecture}"
- OH_CONTROL_BINARY_FIELD_RECOMMENDS="${_old_recommends}"
- OH_CONTROL_BINARY_FIELD_DESCRIPTION="${_old_description}"
-}
-
-oh_control_gen_binary()
-{
- _control_gen 'BINARY' \
- "${1}.control/control" "${1}.data"
-}
-
-_control_parse()
-{
- _control="${1}"
- _type="${2}"
- _req=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_REQUIRED\}) "
- _opt=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_OPTIONAL\}) "
- _all="${_req}${_opt}"
- _got=' '
+ _obpco_file=
+ _obpco_field_cb=
+ _obpco_req_fields=
+ _obpco_opt_fields=
+ _obpco_all_fields=
+ _obpco_got_fields=
+ _obpco_line_nr=
+ _obpco_line=
+ _obpco_name=
+ _obpco_value=
+
+ if [ ${#} -eq 4 ]; then
+ _obpco_file="${1}"
+ _obpco_field_cb="${2}"
+ _obpco_req_fields="${3}"
+ _obpco_opt_fields="${4}"
+ else
+ unset _obpco_file _obpco_field_cb _obpco_req_fields _obpco_opt_fields \
+ _obpco_all_fields _obpco_got_fields \
+ _obpco_line_nr _obpco_line _obpco_name _obpco_value
+ return 125
+ fi
- # Initialize fields.
- for _name in ${_all}; do
- _param="OH_CONTROL_${_type}_FIELD_$(echo "${_name}" | \
- LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')"
- eval "${_param}="
- done
- _param=
+ _obpco_all_fields=" ${_obpco_req_fields} ${_obpco_opt_fields} "
+ _obpco_got_fields=' '
- _line_nr=0
+ _obpco_line_nr=0
- while IFS= read -r _line; do
- _line_nr=$(($_line_nr + 1))
- if [ "${_line# }" = "${_line}" ]; then
+ while IFS= read -r _obpco_line; do
+ _obpco_line_nr=$(($_obpco_line_nr + 1))
+ if [ -z "$(echo ${_obpco_line})" ]; then
+ _ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
+ 'control_empty_line'
+ elif [ "${_obpco_line# }" = "${_obpco_line}" ]; then
# "Name: Value" line.
- _name="${_line%%:*}"
- _value="${_line#*: }"
- if [ -z "${_name}" -o "${_name}" = "${_line}" \
- -o -z "${_value}" ]; then
+ _obpco_name="${_line%%:*}"
+ _obpco_value="${_line#*: }"
+ if [ -z "${_obpco_name}" -o "${_obpco_name}" = "${_obpco_line}" \
+ -o -z "${_obpco_value}" ]; then
# Badly formatted control field.
- _control_parse_error "${_control}" "${_line_nr}" \
- "${oh_str_control_bad_nv}"
+ _ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
+ 'control_bad_nv'
continue
fi
- if [ "${_all% ${_name} *}" = "${_all}" ]; then
+ if [ "${_obpco_all_fields% ${_obpco_name} *}" = \
+ "${_obpco_all_fields}" ]; then
# Unknown field.
- _control_parse_error "${_control}" "${_line_nr}" \
- "${oh_str_control_unknown_field}" \
- "${_name}"
+ _ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
+ 'control_unknown_field' "${_obpco_name}"
else
# Remove field from list of required fields.
- _req="$(echo "${_req}" | sed "s/${_name}//")"
+ _obpco_req_fields="$(echo "${_obpco_req_fields}" | \
+ sed "s/${_obpco_name}//")"
fi
- if [ "${_got% ${_name} }" != "${_got}" ]; then
+ if [ "${_obpco_got_fields% ${_obpco_name} *}" != \
+ "${_obpco_got_fields}" ]; then
# Duplicate field.
- _control_parse_error "${_control}" "${_line_nr}" \
- "${oh_str_control_duplicate_field}" \
- "${_field}"
+ _ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
+ 'control_duplicate_field' "${_obpco_name}"
else
- _got="${_got}${_field} "
+ _obpco_got_fields="${_obpco_got_fields}${_obpco_name} "
+ fi
+ OB_CONTROL_NAME="${_obpco_name}"
+ OB_CONTROL_VALUE="${_obpco_value}"
+ "${_obpco_field_cb}"
+ if [ ${?} -ne 0 ]; then
+ unset _obpco_file _obpco_field_cb \
+ _obpco_req_fields _obpco_opt_fields \
+ _obpco_all_fields _obpco_got_fields \
+ _obpco_line_nr _obpco_line _obpco_name _obpco_value
+ return 0
fi
- _param="OH_CONTROL_${_type}_FIELD_$(echo "${_name}" | \
- LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')"
- # Escape the value.
- _value="$(echo "${_value}" | sed "s/'/'\\\\''/g")"
- eval "${_param}='${_value}'"
else
# Continuation line.
- if [ -z "${_param}" ]; then
+ if [ -z "${_name}" ]; then
# Expecting a "Name: Value" line.
- _control_parse_error "${_control}" "${_line_nr}" \
- "${oh_str_control_found_continuation}"
+ _ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
+ 'control_found_continuation'
continue
fi
- _value="${_line# }"
- _value="$(echo "${_value}" | sed "s/'/'\\\\''/g")"
- eval "${_param}='${_param}
-${_value}'"
+ _obpco_value="${_obpco_value}
+${_line# }"
fi
done <"${_control}"
- _req="${_req## }"
- _req="${_req%% }"
- if [ -n "${_req}" ]; then
+ _obpco_req_fields="${_obpco_req_fields## }"
+ _obpco_req_fields="${_obpco_req_fields%% }"
+ if [ -n "${_obpco_req_fields}" ]; then
# Missing required control fields.
- _control_parse_error "${_control}" 0 \
- "${oh_str_control_missing_fields}" \
- "$(echo "${_req}" | sed 's/ / /g' | \
- sed "s/ /${oh_str_list_item_separator}/g")"
+ _obpco_req_fields="$(echo "${_obpco_req_fields}" | sed 's/ / /g' | \
+ sed "s/ /$(ob_get_msg 'list_item_separator')/g")"
+ _ob_parse_control_error "${_obpco_file}" '0' \
+ 'control_missing_fields' \
+ "${_obpco_req_fields}"
fi
+
+ unset _obpco_file _obpco_field_cb _obpco_req_fields _obpco_opt_fields \
+ _obpco_all_fields _obpco_got_fields \
+ _obpco_line_nr _obpco_line _obpco_name _obpco_value
+ return 0
}
-_control_parse_error()
+_ob_parse_control_error()
{
- _file="${1}"
- _line_nr="${2}"
- _error="${3}"
+ _obpcoe_file="${1}"
+ _obpcoe_line_nr="${2}"
+ _obpcoe_msg_id="${3}"
+ _obpcoe_file_info=
shift 3
- if [ "${_line_nr}" -eq 0 ]; then
- _file_info=$(printf '%20s:' "${_file}")
+ if [ "${_obpcoe_line_nr}" -eq 0 ]; then
+ _obpcoe_file_info="$(printf '%20s:' "${_obpcoe_file}")"
else
- _file_info=$(printf '%20s(l%d):' "${_file}" "${_line_nr}")
+ _obpcoe_file_info="$(printf '%20s(l%d):' "${_obpcoe_file}" \
+ "${_obpcoe_line_nr}")"
fi
- oh_warn "${_file_info} ${_error}" "${@}"
-}
-
-_control_gen()
-{
- _type="${1}"
- _control="${2}"
- _data="${3}"
- # TODO: Handle platforms and architectures like "any" and "any-linux-any".
+ oh_warn "${_obpcoe_file_info} $(ob_get_msg "${_obpcoe_msg_id}")" "${@}"
- # Calculate installed size.
- # Don't use du, since that considers the allocated size of files, symbolic
- # links, and directories (i.e. actual file sizes plus the filesystem
- # overhead on the build system).
- # See the following for more information:
- # <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/du.html>
- # <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=630533>
- # <https://www.gnu.org/software/coreutils/manual/html_node/du-invocation.html>
- _sizes="$(find "${_data}" -type f -exec wc -c '{}' ';' | cut -d ' ' -f 1)"
- _inst_size=0
- for _size in ${_sizes}; do
- _inst_size=$(($_inst_size + $_size))
- done
- # Convert bytes to kibibytes and round up.
- # Note: There is an inconsistency between the Debian Policy Manual and opkg
- # in the units of this field. Debian Policy defines this field in units of
- # kibibytes:
- # The disk space is given as the integer value of the estimated installed
- # size in bytes, divided by 1024 and rounded up.
- # However, opkg apparently attempts to convert this value from bytes to
- # kibibytes in its determination of whether the package's data will fit on
- # the system:
- # pkg_size_kbs = (pkg->installed_size + 1023)/1024;
- # TODO: Further investigate opkg's disk space calculation and, if necessary,
- # patch opkg and submit a bug report.
- _inst_size=$((($_inst_size + 1023) / 1024))
-
- mkdir -p "${_control%/*}"
-
- cat >"${_control}" <<EOF
-Package: ${OH_CONTROL_BINARY_FIELD_PACKAGE}
-Source: ${OH_SOURCE}
-Version: ${OH_BINARY_VERSION}
-Architecture: ${_arch}
-EOF
-
- for _name in Essential Depends Recommends Suggests Pre-Depends Conflicts \
- Provides Replaces; do
- _param="OH_CONTROL_BINARY_FIELD_$(echo "${_name}" | \
- LC_CTYPE=C tr '[:lower:]-' '[:upper:]_')"
- _value="$(eval echo \$\{"${_param}"\})"
- if [ -n "${_value}" ]; then
- printf '%s: %s\n' "${_name}" "${_value}" >>"${_control}"
- fi
- done
-
- cat >>"${_control}" <<EOF
-Installed-Size: ${_inst_size}
-Description:$(echo "${OH_CONTROL_BINARY_FIELD_DESCRIPTION}" | sed 's/^/ /')
-EOF
-
- if [ -n "${OH_CONTROL_SOURCE_FIELD_HOMEPAGE}" ]; then
- printf '%s: %s\n' 'Homepage' "${OH_CONTROL_SOURCE_FIELD_HOMEPAGE}" \
- >>"${_control}"
- fi
+ unset _obpcoe_file _obpcoe_line_nr _obpcoe_msg_id _obpcoe_file_info
+ return 0
}