diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/control.sh | 6 | ||||
-rw-r--r-- | lib/deps.sh | 2 | ||||
-rw-r--r-- | lib/metadata.sh | 21 | ||||
-rw-r--r-- | lib/metadata/proteanos.sh | 13 | ||||
-rw-r--r-- | lib/output.sh | 6 | ||||
-rw-r--r-- | lib/package.sh | 26 | ||||
-rw-r--r-- | lib/time.sh | 3 |
7 files changed, 45 insertions, 32 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 dac8105..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 diff --git a/lib/metadata/proteanos.sh b/lib/metadata/proteanos.sh index a891e6e..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,6 +19,7 @@ _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}'(-[0-9]+)?' @@ -69,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}" 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 138609c..dbf6b67 100644 --- a/lib/package.sh +++ b/lib/package.sh @@ -36,11 +36,8 @@ _ob_package_do() _ob_find_binary_packages() { - local pkgs_clean= local pkg= - local pkg_clean= - pkgs_clean=' ' _ob_binary_packages='' for pkg in $(_ob_package_do 'get_binary_packages'); do @@ -50,16 +47,6 @@ _ob_find_binary_packages() 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} ${pkg}" done @@ -111,8 +98,7 @@ 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. +## @stderr Prints warning messages on invalid binary package names. ## @pure yes This function has no side effects. ob_get_binary_packages() { @@ -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-]* | '') @@ -308,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/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 |