From ee3163ab2c56e0ea72c58ad25c6e3194ca2a1fd6 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Thu, 15 Jan 2026 23:18:03 +0900 Subject: [PATCH] coreutils: Remove limitation for prefix --- README.md | 2 -- docs/src/extensions.md | 6 ++++++ src/bin/coreutils.rs | 28 +++++++++++----------------- util/build-gnu.sh | 8 +++----- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e770bd543a2..59a2e2c6b3f 100644 --- a/README.md +++ b/README.md @@ -227,8 +227,6 @@ To install every program with a prefix (e.g. uu-echo uu-cat): make PROG_PREFIX=uu- install ``` -`PROG_PREFIX` requires separator `-`, `_`, or `=`. - To install the multicall binary: ```shell diff --git a/docs/src/extensions.md b/docs/src/extensions.md index 458b9c41e8c..fa92c54a099 100644 --- a/docs/src/extensions.md +++ b/docs/src/extensions.md @@ -25,6 +25,12 @@ $ ls -w=80 With GNU coreutils, `--help` usually prints the help message and `--version` prints the version. We also commonly provide short options: `-h` for help and `-V` for version. +## `coreutils` + +Our `coreutils` calls utility by `coreutils utility-name` and has `--list` to run against busybox test suite. +Our `coreutils` is called as `utility-name` if its binary name ends with `utility-name` to support prefixed names. +Longer name is prioritized e.g. `sum` with the prefix `ck` is called as `cksum`. + ## `env` GNU `env` allows the empty string to be used as an environment variable name. diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 6a9141936f3..55c885237f5 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -52,24 +52,18 @@ fn main() { process::exit(0); }); - // binary name equals util name? - if let Some(&(uumain, _)) = utils.get(binary_as_util) { - validation::setup_localization_or_exit(binary_as_util); - process::exit(uumain(vec![binary.into()].into_iter().chain(args))); - } + // binary name ends with util name? + let matched_util = utils + .keys() + .filter(|&&u| binary_as_util.ends_with(u) && !binary_as_util.ends_with("coreutils")) + .max_by_key(|u| u.len()); //Prefer stty more than tty. coreutils is not ls - // binary name equals prefixed util name? - // * prefix/stem may be any string ending in a non-alphanumeric character - // For example, if the binary is named `uu_test`, it will match `test` as a utility. - let util_name = - if let Some(util) = validation::find_prefixed_util(binary_as_util, utils.keys().copied()) { - // prefixed util => replace 0th (aka, executable name) argument - Some(OsString::from(util)) - } else { - // unmatched binary name => regard as multi-binary container and advance argument list - uucore::set_utility_is_second_arg(); - args.next() - }; + let util_name = if let Some(&util) = matched_util { + Some(OsString::from(util)) + } else { + uucore::set_utility_is_second_arg(); + args.next() + }; // 0th argument equals util name? if let Some(util_os) = util_name { diff --git a/util/build-gnu.sh b/util/build-gnu.sh index dfefa6d2641..48beaeee581 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -88,19 +88,17 @@ fi cd - export CARGOFLAGS # tell to make - "${MAKE}" UTILS=install -[ -e "${UU_BUILD_DIR}/ginstall" ] || ln -vf "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" # The GNU tests use renamed install to ginstall if [ "${SELINUX_ENABLED}" = 1 ];then # Build few utils for SELinux for faster build. MULTICALL=y fails... - "${MAKE}" UTILS="cat chcon chmod cp cut dd echo env groups id ln ls mkdir mkfifo mknod mktemp mv printf rm rmdir runcon seq stat test touch tr true uname wc whoami" + "${MAKE}" UTILS="cat chcon chmod cp cut dd echo env groups id install ln ls mkdir mkfifo mknod mktemp mv printf rm rmdir runcon seq stat test touch tr true uname wc whoami" else # Use MULTICALL=y for faster build - "${MAKE}" MULTICALL=y SKIP_UTILS="install more" + "${MAKE}" MULTICALL=y SKIP_UTILS=more for binary in $("${UU_BUILD_DIR}"/coreutils --list) do [ -e "${UU_BUILD_DIR}/${binary}" ] || ln -vf "${UU_BUILD_DIR}/coreutils" "${UU_BUILD_DIR}/${binary}" done fi - +[ -e "${UU_BUILD_DIR}/ginstall" ] || ln -vf "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" # The GNU tests use renamed install to ginstall ## cd "${path_GNU}" && echo "[ pwd:'${PWD}' ]"