Skip to content

Commit d72d6f7

Browse files
authored
Merge pull request #10261 from oech3/core-freepfx
coreutils: Remove limitation for prefix
2 parents 6de9c9f + 084ab30 commit d72d6f7

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ To install every program with a prefix (e.g. uu-echo uu-cat):
228228
make PROG_PREFIX=uu- install
229229
```
230230

231-
`PROG_PREFIX` requires separator `-`, `_`, or `=`.
232-
233231
To install the multicall binary:
234232

235233
```shell

docs/src/extensions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ $ ls -w=80
2525
With GNU coreutils, `--help` usually prints the help message and `--version` prints the version.
2626
We also commonly provide short options: `-h` for help and `-V` for version.
2727

28+
## `coreutils`
29+
30+
Our `coreutils` calls utility by `coreutils utility-name` and has `--list` to run against busybox test suite.
31+
Our `coreutils` is called as `utility-name` if its binary name ends with `utility-name` to support prefixed names.
32+
Longer name is prioritized e.g. `sum` with the prefix `ck` is called as `cksum`.
33+
2834
## `env`
2935

3036
GNU `env` allows the empty string to be used as an environment variable name.

src/bin/coreutils.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,18 @@ fn main() {
5252
process::exit(0);
5353
});
5454

55-
// binary name equals util name?
56-
if let Some(&(uumain, _)) = utils.get(binary_as_util) {
57-
validation::setup_localization_or_exit(binary_as_util);
58-
process::exit(uumain(vec![binary.into()].into_iter().chain(args)));
59-
}
55+
// binary name ends with util name?
56+
let matched_util = utils
57+
.keys()
58+
.filter(|&&u| binary_as_util.ends_with(u) && !binary_as_util.ends_with("coreutils"))
59+
.max_by_key(|u| u.len()); //Prefer stty more than tty. coreutils is not ls
6060

61-
// binary name equals prefixed util name?
62-
// * prefix/stem may be any string ending in a non-alphanumeric character
63-
// For example, if the binary is named `uu_test`, it will match `test` as a utility.
64-
let util_name =
65-
if let Some(util) = validation::find_prefixed_util(binary_as_util, utils.keys().copied()) {
66-
// prefixed util => replace 0th (aka, executable name) argument
67-
Some(OsString::from(util))
68-
} else {
69-
// unmatched binary name => regard as multi-binary container and advance argument list
70-
uucore::set_utility_is_second_arg();
71-
args.next()
72-
};
61+
let util_name = if let Some(&util) = matched_util {
62+
Some(OsString::from(util))
63+
} else {
64+
uucore::set_utility_is_second_arg();
65+
args.next()
66+
};
7367

7468
// 0th argument equals util name?
7569
if let Some(util_os) = util_name {

util/build-gnu.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,17 @@ fi
8989
cd -
9090

9191
export CARGOFLAGS # tell to make
92-
make UTILS=install
93-
[ -e "${UU_BUILD_DIR}/ginstall" ] || ln -vf "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" # The GNU tests use renamed install to ginstall
9492
if [ "${SELINUX_ENABLED}" = 1 ];then
9593
# Build few utils for SELinux for faster build. MULTICALL=y fails...
96-
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"
94+
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"
9795
else
9896
# Use MULTICALL=y for faster build
99-
make MULTICALL=y SKIP_UTILS="install more"
97+
make MULTICALL=y SKIP_UTILS=more
10098
for binary in $("${UU_BUILD_DIR}"/coreutils --list)
10199
do [ -e "${UU_BUILD_DIR}/${binary}" ] || ln -vf "${UU_BUILD_DIR}/coreutils" "${UU_BUILD_DIR}/${binary}"
102100
done
103101
fi
104-
102+
[ -e "${UU_BUILD_DIR}/ginstall" ] || ln -vf "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" # The GNU tests use ginstall
105103
##
106104

107105
cd "${path_GNU}" && echo "[ pwd:'${PWD}' ]"

0 commit comments

Comments
 (0)