summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-10-23 23:46:58 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-10-23 23:46:58 (EDT)
commit399adfd4e44a84b7ca664703240be40d4bc23528 (patch)
treea21b276d7096f03c8586a91af2b7fd1b077e0e75
parentcd8d946a86d0730244badfc79c18c6f3e914ee62 (diff)
parentac831a4fb9a65678fb80d3c22b9db72c7140a3d7 (diff)
Merge branch 'feature/substvars'.
-rw-r--r--lib/control.sh142
-rw-r--r--lib/package.sh17
-rw-r--r--lib/package/2.sh27
-rw-r--r--locale/en_MID/libopkbuild_1.sh1
-rw-r--r--locale/en_US/libopkbuild_1.sh1
-rw-r--r--src/ob-gencontrol.sh7
6 files changed, 171 insertions, 24 deletions
diff --git a/lib/control.sh b/lib/control.sh
index 0e9a1f6..abbb2f2 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -23,6 +23,8 @@ _OB_CONTROL_SM='true'
ob_use messages
ob_use locale
+_OB_SUBSTVARS_MAX_DEPTH=50
+
OB_CONTROL_NAME=
OB_CONTROL_VALUE=
@@ -32,17 +34,22 @@ ob_parse_control()
_obpco_all_fields _obpco_got_fields \
_obpco_line_nr _obpco_line _obpco_name _obpco_value
- if [ ${#} -eq 4 ]; then
+ if [ ${#} -eq 2 ]; then
+ _obpco_file="${1}"
+ _obpco_field_cb="${2}"
+ _obpco_check_fields='false'
+ elif [ ${#} -eq 4 ]; then
_obpco_file="${1}"
_obpco_field_cb="${2}"
_obpco_req_fields="${3}"
_obpco_opt_fields="${4}"
+ _obpco_check_fields='true'
+ _obpco_all_fields=" ${_obpco_req_fields} ${_obpco_opt_fields} "
else
_ob_return 125
return ${?}
fi
- _obpco_all_fields=" ${_obpco_req_fields} ${_obpco_opt_fields} "
_obpco_got_fields=' '
_obpco_line_nr=0
@@ -64,23 +71,27 @@ ob_parse_control()
fi
fi
_obpco_name="${_obpco_line%%:*}"
- _obpco_value="${_obpco_line#*: }"
- if [ -z "${_obpco_name}" -o "${_obpco_name}" = "${_obpco_line}" \
- -o -z "${_obpco_value}" ]; then
+ _obpco_value="${_obpco_line#*:}"
+ _obpco_value="${_obpco_value# }"
+ if [ -z "${_obpco_name}" \
+ -o "${_obpco_name}" = "${_obpco_line}" ]; then
# Badly formatted control field.
_ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
'control_bad_nv'
continue
fi
- if [ "${_obpco_all_fields% ${_obpco_name} *}" = \
- "${_obpco_all_fields}" ]; then
- # Unknown field.
- _ob_parse_control_error "${_obpco_file}" "${_obpco_line_nr}" \
- 'control_unknown_field' "${_obpco_name}"
- else
- # Remove field from list of required fields.
- _obpco_req_fields="$(echo "${_obpco_req_fields}" | \
- sed "s/${_obpco_name}//")"
+ if ${_obpco_check_fields}; then
+ if [ "${_obpco_all_fields% ${_obpco_name} *}" = \
+ "${_obpco_all_fields}" ]; then
+ # Unknown field.
+ _ob_parse_control_error \
+ "${_obpco_file}" "${_obpco_line_nr}" \
+ 'control_unknown_field' "${_obpco_name}"
+ else
+ # Remove field from list of required fields.
+ _obpco_req_fields="$(echo "${_obpco_req_fields}" | \
+ sed "s/${_obpco_name}//")"
+ fi
fi
if [ "${_obpco_got_fields% ${_obpco_name} *}" != \
"${_obpco_got_fields}" ]; then
@@ -113,21 +124,106 @@ ${_obpco_line# }"
fi
fi
- _obpco_req_fields="${_obpco_req_fields## }"
- _obpco_req_fields="${_obpco_req_fields%% }"
- if [ -n "${_obpco_req_fields}" ]; then
- # Missing required control fields.
- _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}"
+ if ${_obpco_check_fields}; then
+ _obpco_req_fields="${_obpco_req_fields## }"
+ _obpco_req_fields="${_obpco_req_fields%% }"
+ if [ -n "${_obpco_req_fields}" ]; then
+ # Missing required control fields.
+ _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
fi
_ob_return 0
return ${?}
}
+ob_set_substvar()
+{
+ _ob_local _obssv_name _obssv_value
+
+ if [ ${#} -eq 2 ]; then
+ _obssv_name="${1}"
+ _obssv_value="${2}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ # Trim leading and trailing whitespace from value.
+ _obssv_value="$(echo "${_obssv_value}" | sed -n '
+ H; # Store each input line in the hold space.
+ ${ # At the last line of input, …
+ g; # … restore the hold space into the pattern space, …
+ s/^[ \t\n]*//; # … remove leading whitespace, …
+ s/[ \t\n]*$//; # … remove trailing whitespace, and …
+ p; # … print the results.
+ };
+ ')"
+
+ _obssv_name="$(echo "${_obssv_name}" | tr 'a-z-' 'A-Z_')"
+ eval "_OB_SUBSTVAR_${_obssv_name}='${_obssv_value}'"
+
+ _ob_return 125
+ return ${?}
+}
+
+ob_substvars()
+{
+ _ob_local _obsv_string _obsv_depth \
+ _obsv_lhs _obsv_name _obsv_rhs _obsv_old_rhs _obsv_value
+
+ if [ ${#} -eq 1 ]; then
+ _obsv_string="${1}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ # Logic inspired by that of dpkg's Dpkg::Substvars::substvars() subroutine.
+
+ _obsv_depth=0
+
+ while true; do
+ _obsv_lhs="${_obsv_string%%\$\{*}"
+ if [ ${#_obsv_lhs} -eq ${#_obsv_string} ]; then
+ # No "${" was found.
+ break
+ fi
+ _obsv_string="${_obsv_string#*\$\{}"
+ _obsv_name="${_obsv_string%%\}*}"
+ _obsv_rhs="${_obsv_string#*\}}"
+
+ if [ ${#_obsv_rhs} -lt ${#_obsv_old_rhs} ]; then
+ # Reset the nesting counter if we've advanced the right side of the
+ # matched space.
+ _obsv_depth=0
+ fi
+ if [ ${_obsv_depth} -ge ${_OB_SUBSTVARS_MAX_DEPTH} ]; then
+ # Warn of possible recursion.
+ ob_warn "$(ob_get_msg 'substvar_deep_nesting')"
+ _ob_return 1
+ return ${?}
+ fi
+ _obsv_old_rhs="${_obsv_rhs}"
+
+ # Perform the substitution.
+ _obsv_name="$(echo "${_obsv_name}" | tr 'a-z-' 'A-Z_')"
+ _obsv_value="$(eval echo \"\$\{"_OB_SUBSTVAR_${_obsv_name}"\}\")"
+ _obsv_string="${_obsv_lhs}${_obsv_value}${_obsv_rhs}"
+ _obsv_depth=$(($_obsv_depth + 1))
+ done
+
+ printf '%s\n' "${_obsv_string}"
+
+ _ob_return 0
+ return ${?}
+}
+
_ob_parse_control_error()
{
_ob_local _obpcoe_file _obpcoe_line_nr _obpcoe_msg_id \
diff --git a/lib/package.sh b/lib/package.sh
index 6a77ca0..63d599a 100644
--- a/lib/package.sh
+++ b/lib/package.sh
@@ -334,6 +334,23 @@ ob_summarize_package_plat()
return ${?}
}
+ob_set_package_substvars()
+{
+ _ob_local _obspsv_pkg
+
+ if [ ${#} -eq 1 ]; then
+ _obspsv_pkg="${1}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ _ob_package_do 'set_package_substvars' "${_obspsv_pkg}"
+
+ _ob_return ${?}
+ return ${?}
+}
+
_ob_package_do()
{
_ob_local _obpd_func
diff --git a/lib/package/2.sh b/lib/package/2.sh
index 745369f..d9f049a 100644
--- a/lib/package/2.sh
+++ b/lib/package/2.sh
@@ -153,3 +153,30 @@ EOF
_ob_return 0
return ${?}
}
+
+_ob_set_package_substvars_2()
+{
+ _ob_local _obspsv2_pkg
+
+ if [ ${#} -eq 1 ]; then
+ _obspsv2_pkg="${1}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ ob_parse_control "${_OB_PACKAGE_DIR}/substvars" _ob_substvar_2
+
+ ob_set_substvar 'Source-Version' "$(ob_get_source_parameter 'Version')"
+ ob_set_substvar 'Binary-Version' "$(ob_get_source_parameter 'Version')"
+}
+
+_ob_substvar_2()
+{
+ _ob_local
+
+ ob_set_substvar "${OB_CONTROL_NAME}" "${OB_CONTROL_VALUE}"
+
+ _ob_return 0
+ return ${?}
+}
diff --git a/locale/en_MID/libopkbuild_1.sh b/locale/en_MID/libopkbuild_1.sh
index d6588c8..13647f0 100644
--- a/locale/en_MID/libopkbuild_1.sh
+++ b/locale/en_MID/libopkbuild_1.sh
@@ -30,6 +30,7 @@ msg_libopkbuild_1_control_duplicate_field='«control_duplicate_field»'
msg_libopkbuild_1_control_found_contination='«control_found_continuation»'
msg_libopkbuild_1_list_item_separator='«list_item_separator»'
msg_libopkbuild_1_control_missing_fields='«control_missing_fields»'
+msg_libopkbuild_1_substvar_deep_nesting='«substvar_deep_nesting»'
# changelog.sm
msg_libopkbuild_1_changelog_found_blank_line='«changelog_found_blank_line»'
diff --git a/locale/en_US/libopkbuild_1.sh b/locale/en_US/libopkbuild_1.sh
index fb02288..e20ab95 100644
--- a/locale/en_US/libopkbuild_1.sh
+++ b/locale/en_US/libopkbuild_1.sh
@@ -30,6 +30,7 @@ msg_libopkbuild_1_control_duplicate_field='duplicate field "%s"'
msg_libopkbuild_1_control_found_contination='found continuation line where expected start of field'
msg_libopkbuild_1_list_item_separator=', '
msg_libopkbuild_1_control_missing_fields='missing fields: %s'
+msg_libopkbuild_1_substvar_deep_nesting='Possible recursion in substitutions'
# changelog.sm
msg_libopkbuild_1_changelog_found_blank_line='found blank line where expected %s'
diff --git a/src/ob-gencontrol.sh b/src/ob-gencontrol.sh
index ee5741c..0526573 100644
--- a/src/ob-gencontrol.sh
+++ b/src/ob-gencontrol.sh
@@ -38,12 +38,15 @@ main()
gen_md5sums "src-${OPK_SOURCE}"
else
for pkg in ${OPK_PACKAGES}; do
+ ob_set_package_substvars "${pkg}"
arch="$(ob_get_binary_parameter "${pkg}" 'Architecture')"
[ "${arch}" != 'all' ] && arch="${OPK_HOST_ARCH}"
plat="$(ob_get_binary_parameter "${pkg}" 'Platform')"
[ "${plat}" != 'all' ] && plat="${OPK_HOST_PLAT}"
+ desc="$(ob_get_binary_parameter "${pkg}" 'Description')"
+ desc="$(ob_substvars "${desc}")"
gen_control "${pkg}" "${OPK_BINARY_VERSION}" "${arch}" "${plat}" \
- "$(ob_get_binary_parameter "${pkg}" 'Description')" 'true'
+ "${desc}" 'true'
install_maintainer_scripts "${pkg}"
gen_conffiles "${pkg}"
gen_md5sums "${pkg}"
@@ -110,10 +113,12 @@ EOF
'Depends'|'Recommends'|'Suggests'|'Pre-Depends')
value="$(ob_reduce_deps -a "${OPK_HOST_ARCH}" \
"${value}")"
+ value="$(ob_substvars "${value}")"
;;
'Conflicts'|'Provides'|'Replaces')
value="$(ob_reduce_deps -a "${OPK_HOST_ARCH}" -u \
"${value}")"
+ value="$(ob_substvars "${value}")"
;;
esac
printf '%s: %s\n' "${name}" "${value}" \