summaryrefslogtreecommitdiffstats
path: root/lib/package.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/package.sh')
-rw-r--r--lib/package.sh96
1 files changed, 35 insertions, 61 deletions
diff --git a/lib/package.sh b/lib/package.sh
index 27ea8cb..dbf6b67 100644
--- a/lib/package.sh
+++ b/lib/package.sh
@@ -18,9 +18,9 @@
# along with opkbuild. If not, see <http://www.gnu.org/licenses/>.
_ob_package_dir=
+_ob_package_format_full=
_ob_package_format=
_ob_binary_packages=
-_ob_got_binary_packages=false
_ob_source_parameters=
_ob_binary_parameters=
@@ -34,6 +34,25 @@ _ob_package_do()
return 0
}
+_ob_find_binary_packages()
+{
+ local pkg=
+
+ _ob_binary_packages=''
+
+ for pkg in $(_ob_package_do 'get_binary_packages'); do
+ # Validate the name.
+ if ! ob_validate_binary_name "${pkg}"; then
+ _ob_warn_msg 'bad_binary_name' "${pkg}"
+ continue
+ fi
+
+ _ob_binary_packages="${_ob_binary_packages} ${pkg}"
+ done
+
+ return 0
+}
+
## @brief Initialize libopkbuild for a source package
## @details \fBob_init_package\fP() detects the version of and parses all
## metadata of a source package. This function must be called before
@@ -48,10 +67,11 @@ ob_init_package()
local dir="${1}"
shift 1 || _ob_abort
- _ob_package_dir="$(cd -- "${dir}" && pwd)"
+ _ob_package_dir="$(unset CDPATH; cd -- "${dir}" && pwd)"
+ _ob_package_format_full="$(cat -- "${_ob_package_dir}/format")"
if [ -r "${_ob_package_dir}/format" ]; then
- case "$(cat -- "${_ob_package_dir}/format")" in
+ case "${_ob_package_format_full}" in
2.0)
_ob_package_format='2'
;;
@@ -63,7 +83,7 @@ ob_init_package()
return 1
fi
- _ob_binary_packages=
+ _ob_find_binary_packages
_ob_package_do 'parse_package_metadata' || return ${?}
@@ -78,21 +98,15 @@ ob_init_package()
## @option -a host_plat The platform by which to filter binary packages.
## @return Returns 0 on success.
## @stdout Prints the resulting list of binary packages.
-## @stderr Prints warning messages on invalid binary package names and duplicate
-## "clean" binary package names.
-## @pure maybe This function caches a list of all binary packages to an internal
-## global variable to save time and avoid repeating warning messages
-## on subsequent invocations. It should therefore first be called
-## outside a subshell, though this is not required.
+## @stderr Prints warning messages on invalid binary package names.
+## @pure yes This function has no side effects.
ob_get_binary_packages()
{
local opt=
local host_arch=
local host_plat=
- local pkg=
- local pkgs_clean=
- local pkg_clean=
local pkgs=
+ local pkg=
OPTIND=1
while getopts 'a:p:' opt; do
@@ -110,38 +124,6 @@ ob_get_binary_packages()
done
shift $((${OPTIND} - 1))
- if ! ${_ob_got_binary_packages}; then
-
- _ob_package_do 'get_binary_packages'
-
- pkgs_clean=' '
-
- for pkg in ${_ob_binary_packages}; do
-
- # Validate the name.
- if ! ob_validate_binary_name "${pkg}"; then
- _ob_warn_msg 'bad_binary_name' "${pkg}"
- continue
- fi
-
- # Make sure the "clean" name is unique.
- pkg_clean="$(printf '%s' "${pkg}" | tr 'a-z' 'A-Z' | \
- tr -C 'A-Z0-9' '_')"
- case "${pkgs_clean}" in *" ${pkg_clean} "*)
- _ob_warn_msg 'duplicate_clean_binary_name' \
- "${pkg_clean}"
- continue
- esac
- pkgs_clean="${pkgs_clean}${pkg_clean} "
-
- _ob_binary_packages="${_ob_binary_packages} ${pkgs}"
-
- done
-
- _ob_got_binary_packages=true
-
- fi
-
pkgs=''
for pkg in ${_ob_binary_packages}; do
@@ -184,6 +166,10 @@ ob_get_source_parameter()
EOF
)"
+ case "${name}" in 'FORMAT')
+ printf '%s' "${_ob_package_format_full}"
+ esac
+
# TODO: Return error on no such field?
eval "printf '%s' \"\${_OB_SRCFIELD_${name}-}\""
@@ -208,9 +194,8 @@ ob_get_binary_parameter()
return 1
fi
- # Convert package name to its uppercase "clean" form.
- package="$(printf '%s' "${package}" | tr 'a-z' 'A-Z' | \
- tr -C 'A-Z0-9' '_')"
+ # Convert package name to clean form.
+ package="$(ob_clean_name "${package}")"
# Convert field name to uppercase and validate.
case "${name}" in *[!A-Za-z0-9-]* | '')
@@ -275,16 +260,6 @@ ob_set_package_substvars()
return 0
}
-_ob_set_binary_packages()
-{
- local packages="${1}"
- shift 1 || _ob_abort
-
- _ob_binary_packages="${packages}"
-
- return 0
-}
-
_ob_set_source_parameter()
{
local name="${1}"
@@ -318,9 +293,8 @@ _ob_set_binary_parameter()
return 1
fi
- # Convert package name to its uppercase "clean" form.
- package="$(printf '%s' "${package}" | tr 'a-z' 'A-Z' | \
- tr -C 'A-Z0-9' '_')"
+ # Convert package name to clean form.
+ package="$(ob_clean_name "${package}")"
# Convert field name to uppercase and validate.
case "${name}" in *[!A-Za-z0-9-]* | '')