summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/control.sh6
-rw-r--r--lib/deps.sh2
-rw-r--r--lib/metadata.sh64
-rw-r--r--lib/metadata/proteanos.sh47
-rw-r--r--lib/output.sh6
-rw-r--r--lib/package.sh96
-rw-r--r--lib/package/2.sh15
-rw-r--r--lib/time.sh3
8 files changed, 159 insertions, 80 deletions
diff --git a/lib/control.sh b/lib/control.sh
index 35913aa..76ba516 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -245,8 +245,7 @@ ob_set_binary_substvar()
value="$(printf '%s' "${value}" | sed -n "${_OB_SUBSTVAR_TRIM_SED}")"
# Convert package name to clean form.
- package="$(printf '%s' "${package}" | tr 'A-Z' 'a-z' | \
- tr -C 'a-z0-9' '_')"
+ package="$(ob_clean_name "${package}")"
# TODO: Maybe disallow variable names beginning with hyphens, and/or
# otherwise make this safer.
@@ -326,8 +325,7 @@ ob_substvars()
# Perform the substitution.
name_tr="$(printf '%s' "${name}" | tr 'A-Z-' 'a-z_')"
- package="$(printf '%s' "${package}" | tr 'A-Z' 'a-z' | \
- tr -C 'a-z0-9' '_')"
+ package="$(ob_clean_name "${package}")"
if eval "[ x\"\${_ob_substvar_src_${name_tr}:+set}\" = x'set' ]"
then
name_tr="_ob_substvar_src_${name_tr}"
diff --git a/lib/deps.sh b/lib/deps.sh
index 32b05e8..2dd7c10 100644
--- a/lib/deps.sh
+++ b/lib/deps.sh
@@ -42,7 +42,7 @@
## the given platform.
## @operand dep req The dependency to parse.
## @return Returns 0.
-## @stdout If \fB-a\fP and \fB\p\fP aren't given, the entire dependency string
+## @stdout If \fB-a\fP and \fB-p\fP aren't given, the entire dependency string
## is printed, with normalized formatting. If \fB-a\fP and/or \fB-p\fP
## are given and the dependency applies to their arguments, the
## dependency string is printed, except for the architecture (if
diff --git a/lib/metadata.sh b/lib/metadata.sh
index da3ff60..bc7e717 100644
--- a/lib/metadata.sh
+++ b/lib/metadata.sh
@@ -1,6 +1,6 @@
# Functions for parsing and validating package metadata
#
-# Copyright (C) 2012, 2014, 2018, 2019 Patrick McDermott
+# Copyright (C) 2012, 2014, 2018-2020 Patrick McDermott
#
# This file is part of opkbuild.
#
@@ -61,6 +61,25 @@ ob_validate_binary_name()
return 0
}
+## @brief Convert a source or binary package name to a "clean" identifier name
+## @details \fBob_clean_name\fP() encodes characters in a source or binary
+## package name that would be invalid in a shell variable or function
+## name. This conversion is performed by the metadata plugin selected
+## at libopkbuild's build time.
+## @operand name req The source or binary package name to convert.
+## @return Returns 0 on success.
+## @stdout Prints the converted name.
+## @pure yes This function has no side effects.
+ob_clean_name()
+{
+ local name="${1}"
+ shift 1 || _ob_abort
+
+ _ob_metadata_do 'clean_name' "${name}" || return ${?}
+
+ return 0
+}
+
## @brief Parse a source package version
## @details \fBob_parse_version\fP() validates and parses a source package
## version identifier using the metadata plugin selected at
@@ -334,3 +353,46 @@ ob_get_system_path()
return 0
}
+
+## @brief Validate a section name
+## @details \fBob_validate_section\fP() validates a package archive section name
+## against the list in the metadata plugin selected at libopkbuild's
+## build time.
+## @operand section req The section name to validate.
+## @return Returns 0 if valid or 1 if invalid.
+## @pure yes This function has no side effects.
+ob_validate_section()
+{
+ local section="${1}"
+ shift 1 || _ob_abort
+
+ _ob_metadata_do 'validate_section' "${section}" || return ${?}
+
+ return 0
+}
+
+## @brief Get a possibly architecture-qualified package name
+## @details \fBob_qualify_package_name\fP() qualifies the name of a binary
+## package with the host architecture if the package is in a section
+## whose packages are coinstallable.
+## @operand name req The name of the binary package.
+## @operand host_arch req The host architecture.
+## @return Returns 0.
+## @stdout Prints \fIname\fP, possibly followed by a colon and \fIhost_arch\fP.
+## @pure yes This function has no side effects.
+ob_qualify_package_name()
+{
+ local name="${1}"
+ local host_arch="${2}"
+ shift 2 || _ob_abort
+ local sect=
+
+ sect="$(ob_get_binary_parameter "${name}" 'Section')"
+ if _ob_metadata_do 'section_is_coinstallable' "${sect}"; then
+ printf '%s:%s' "${name}" "${host_arch}"
+ else
+ printf '%s' "${name}"
+ fi
+
+ return 0
+}
diff --git a/lib/metadata/proteanos.sh b/lib/metadata/proteanos.sh
index 40d5d32..6d68ccb 100644
--- a/lib/metadata/proteanos.sh
+++ b/lib/metadata/proteanos.sh
@@ -1,6 +1,6 @@
# Functions for parsing, validating, and retrieving metadata for ProteanOS
#
-# Copyright (C) 2012, 2019 Patrick McDermott
+# Copyright (C) 2012, 2019-2020 Patrick McDermott
#
# This file is part of opkbuild.
#
@@ -19,10 +19,13 @@
_OB_NAME_RE_PROTEANOS='^[a-z0-9][a-z0-9+.-]+$'
_OB_VERSION_RE_PROTEANOS='^'
+_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'([1-9][0-9]*:)?'
_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'[0-9a-z.~+]+'
_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'(\+sip[1-9][0-9]*)?'
-_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'(-[1-9][0-9]*)?'
+_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'(-[0-9]+)?'
_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'(\+[a-z0-9]+~[1-9][0-9]*)?'
+_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'(~bpu[1-9][0-9]*'
+_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'\+[1-9][0-9]*)?'
_OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'$'
_ob_validate_source_name()
@@ -67,6 +70,16 @@ _ob_validate_binary_name()
return 0
}
+_ob_clean_name()
+{
+ local name="${1}"
+ shift 1 || _ob_abort
+
+ printf '%s' "${name}" | sed 's/-/_h_/g; s/+/_p_/g; s/[.]/_d_/g;'
+
+ return 0
+}
+
_ob_validate_version()
{
local version="${1}"
@@ -162,3 +175,33 @@ _ob_get_system_path()
return 0
}
+
+_ob_validate_section()
+{
+ local section="${1}"
+ shift 1 || _ob_abort
+
+ case "${section}" in
+ boot | dbg | dev | doc | lib | libdev | locale | share | util)
+ return 0
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}
+
+_ob_section_is_coinstallable()
+{
+ local sect="${1}"
+ shift 1 || _ob_abort
+
+ case "${sect}" in
+ 'lib')
+ return 0
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}
diff --git a/lib/output.sh b/lib/output.sh
index 056c929..defadee 100644
--- a/lib/output.sh
+++ b/lib/output.sh
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with opkbuild. If not, see <http://www.gnu.org/licenses/>.
-## @brief Print an error message and exit
+## @brief Print an error message
## @details \fBob_error\fP() prints \fIarguments\fP according to \fIformat\fP.
## @operand format req The format string. See \fBprintf\fP(1) for the syntax
## of \fIformat\fP.
@@ -25,7 +25,7 @@
## \fIformat\fP.
## @return Returns 0.
## @stderr Prints the formatted message, preceded by the program name and
-## "Error:".
+## "Error:" (or a translation thereof).
## @pure yes This function has no side effects.
ob_error()
{
@@ -46,7 +46,7 @@ ob_error()
## \fIformat\fP.
## @return Returns 0.
## @stderr Prints the formatted message, preceded by the program name and
-## "Warning:".
+## "Warning:" (or a translation thereof).
## @pure yes This function has no side effects.
ob_warn()
{
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-]* | '')
diff --git a/lib/package/2.sh b/lib/package/2.sh
index ce96e5f..6a2b2f9 100644
--- a/lib/package/2.sh
+++ b/lib/package/2.sh
@@ -20,7 +20,7 @@
_OB_SOURCE_FIELDS_REQUIRED_2='Maintainer'
_OB_SOURCE_FIELDS_OPTIONAL_2='Build-Depends Homepage'
_OB_BINARY_FIELDS_REQUIRED_2='Architecture Platform Description'
-_OB_BINARY_FIELDS_OPTIONAL_2='Essential Depends Recommends Suggests '\
+_OB_BINARY_FIELDS_OPTIONAL_2='Section Essential Depends Recommends Suggests '\
'Pre-Depends Conflicts Provides Replaces'
_ob_source_substvars_set_2=false
@@ -28,6 +28,7 @@ _ob_source_substvars_set_2=false
_ob_parse_package_metadata_2()
{
local pkg=
+ local sect=
ob_parse_control "${_ob_package_dir}/control" _ob_srcfield_2 '' \
"${_OB_SOURCE_FIELDS_REQUIRED_2}" \
@@ -39,6 +40,11 @@ _ob_parse_package_metadata_2()
_ob_binfield_2 "${pkg}" \
"${_OB_BINARY_FIELDS_REQUIRED_2}" \
"${_OB_BINARY_FIELDS_OPTIONAL_2}"
+ sect="$(ob_get_binary_parameter "${pkg}" 'Section')"
+ if [ -n "${sect}" ] && ! ob_validate_section "${sect}"; then
+ _ob_warn_msg 'bad_section' "${pkg}" "${sect}"
+ continue
+ fi
done
return 0
@@ -46,7 +52,6 @@ _ob_parse_package_metadata_2()
_ob_get_binary_packages_2()
{
- local pkgs=
local pkg_control=
for pkg_control in "${_ob_package_dir}/"*'.pkg/control'; do
@@ -58,14 +63,10 @@ _ob_get_binary_packages_2()
pkg_control="${pkg_control%.pkg/control}"
pkg_control="${pkg_control##*/}"
- ob_validate_binary_name "${pkg_control}"
-
- pkgs="${pkgs} ${pkg_control}"
+ printf '%s ' "${pkg_control}"
done
- _ob_set_binary_packages "${pkgs}"
-
return 0
}
diff --git a/lib/time.sh b/lib/time.sh
index aa4990b..910d825 100644
--- a/lib/time.sh
+++ b/lib/time.sh
@@ -52,6 +52,7 @@ _ob_month_to_days()
1) d=0;; 2) d=31;; 3) d=59;; 4) d=90;;
5) d=120;; 6) d=151;; 7) d=181;; 8) d=212;;
9) d=243;; 10) d=273;; 11) d=304;; 12) d=334;;
+ 13)d=365;;
esac
[ ${month} -ge 2 ] && _ob_is_leap_year ${year} && : $((++d))
printf '%d' ${d}
@@ -157,7 +158,7 @@ _ob_gmtime()
while :; do
_ob_is_leap_year ${year} && days_in_year=366 || days_in_year=365
- [ ${timep} -le ${days_in_year} ] && break
+ [ ${timep} -lt ${days_in_year} ] && break
: $((timep -= ${days_in_year}))
: $((year += 1))
done