diff --git a/README.md b/README.md index f05bf77ea39..450dae31722 100644 --- a/README.md +++ b/README.md @@ -228,8 +228,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 13b055ae0a9..febabc984c2 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -89,19 +89,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 ginstall ## cd "${path_GNU}" && echo "[ pwd:'${PWD}' ]"