From ef9da61736858fc1ffb3b6deab8b6057daefc6d8 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 25 Sep 2023 09:59:14 -0400 Subject: metadata, package: Encode binary package names Remove restriction on duplicate "clean" names. --- (limited to 'lib') 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-]* | '') -- cgit v0.9.1