diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-09-25 09:59:14 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-09-25 11:37:56 (EDT) |
commit | ef9da61736858fc1ffb3b6deab8b6057daefc6d8 (patch) | |
tree | c5fb739e632533f33b4f1aa0804d9ec5e987dd17 | |
parent | dfc2e98ae678073977cd66a41592aee25454d757 (diff) |
metadata, package: Encode binary package names
Remove restriction on duplicate "clean" names.
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | lib/control.sh | 6 | ||||
-rw-r--r-- | lib/metadata.sh | 19 | ||||
-rw-r--r-- | lib/metadata/proteanos.sh | 10 | ||||
-rw-r--r-- | lib/package.sh | 26 | ||||
-rw-r--r-- | locale/C/libopkbuild_2.sh | 1 |
6 files changed, 41 insertions, 26 deletions
@@ -7,6 +7,11 @@ libopkbuild: * ProteanOS source package versions may now contain epochs. This complies with the latest draft of SPF 2.0. + * A new ob_clean_name() function has been added. + ob_get_binary_packages() no longer complains about duplicate "clean" + binary package names such as "libc-1" and "libc++.1". This will + allow SPF 2.0 to remove the restriction on "binary package clean + names". Build system: 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/metadata.sh b/lib/metadata.sh index da0c893..bc7e717 100644 --- a/lib/metadata.sh +++ b/lib/metadata.sh @@ -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 59f2c14..6d68ccb 100644 --- a/lib/metadata/proteanos.sh +++ b/lib/metadata/proteanos.sh @@ -70,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/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/locale/C/libopkbuild_2.sh b/locale/C/libopkbuild_2.sh index 3cd4b25..0dd836c 100644 --- a/locale/C/libopkbuild_2.sh +++ b/locale/C/libopkbuild_2.sh @@ -25,7 +25,6 @@ msg_libopkbuild_2_output_info_format='%s: %s' # lib/package.sh msg_libopkbuild_2_unable_to_detect_package_format='Unable to detect package format' msg_libopkbuild_2_bad_binary_name='Bad binary package name: "%s"' -msg_libopkbuild_2_duplicate_clean_binary_name='Duplicate clean binary package name: "%s"' # lib/package/*.sh msg_libopkbuild_2_bad_section='Binary package "%s" has invalid section name "%s"' |