Discussion:
[PATCH] basename: -s SUFFIX.
Add Reply
enh
2018-11-13 04:57:28 UTC
Reply
Permalink
AOSP doesn't need -a specifically, but since it's needed for -s we may
as well accept it too.
---
tests/basename.test | 5 +++++
toys/posix/basename.c | 33 ++++++++++++++++++++++++++-------
2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/tests/basename.test b/tests/basename.test
index 25e5493..9fd570f 100755
--- a/tests/basename.test
+++ b/tests/basename.test
@@ -24,3 +24,8 @@ testcmd "invalid suffix" "isthisasuffix? suffix"
"isthisasuffix?\n" "" ""

# Zero-length suffix
testcmd "zero-length suffix" "a/b/c ''" "c\n" "" ""
+
+# -s.
+testcmd "-s" "-s .txt /a/b/c.txt" "c\n" "" ""
+testcmd "-s implies -a" "-s .txt /a/b/c.txt /a/b/d.txt" "c\nd\n" "" ""
+testcmd "-a" "-a /a/b/f1 /c/d/f2" "f1\nf2\n" "" ""
diff --git a/toys/posix/basename.c b/toys/posix/basename.c
index 0436bfe..11b9622 100644
--- a/toys/posix/basename.c
+++ b/toys/posix/basename.c
@@ -5,25 +5,44 @@
* See http://opengroup.org/onlinepubs/9699919799/utilities/basename.html


-USE_BASENAME(NEWTOY(basename, "<1>2", TOYFLAG_USR|TOYFLAG_BIN))
+USE_BASENAME(NEWTOY(basename, "<1as:", TOYFLAG_USR|TOYFLAG_BIN))

config BASENAME
bool "basename"
default y
help
- usage: basename string [suffix]
+ usage: basename [-a] [-s SUFFIX] NAME... | NAME [SUFFIX]

- Return non-directory portion of a pathname removing suffix
+ Return non-directory portion of a pathname removing suffix.
+
+ -a All arguments are names.
+ -s SUFFIX Remove suffix (implies -a).
*/

+#define FOR_basename
#include "toys.h"

+GLOBALS(
+ char *s;
+)
+
void basename_main(void)
{
- char *base = basename(*toys.optargs), *suffix = toys.optargs[1];
+ char **arg;
+
+ if (toys.optflags&FLAG_s) toys.optflags |= FLAG_a;
+
+ if (!(toys.optflags&FLAG_a)) {
+ if (toys.optc > 2) error_exit("too many args");
+ TT.s = toys.optargs[1];
+ toys.optargs[1] = NULL;
+ }

- // chop off the suffix if provided
- if (suffix && *suffix && (suffix = strend(base, suffix))) *suffix = 0;
+ for (arg = toys.optargs; *arg; ++arg) {
+ char *base = basename(*arg), *p;

- puts(base);
+ // Chop off the suffix if provided.
+ if (TT.s && *TT.s && (p = strend(base, TT.s))) *p = 0;
+ puts(base);
+ }
}
--
2.19.1.930.g4563a0d9d0-goog
Rob Landley
2018-11-13 22:58:08 UTC
Reply
Permalink
Post by enh
AOSP doesn't need -a specifically, but since it's needed for -s we may
as well accept it too.
I would like to read along with the group: what git repo does the hermetic build
stuff go into, and is there a starting commit I should look at?

(The top level Android.mk in platform/system/core is "include $(call
first-makefiles-under,$(LOCAL_PATH))" and given the lack of ordering of that if
you _are_ doing a hermetic build it has to be set up before then, but I dunno
how to go backwards from there...)

Rob
enh
2018-11-13 23:16:21 UTC
Reply
Permalink
any switch requires:

1. a symlink to toybox in prebuilts/build-tools/toybox/linux-x86/:
https://android-review.googlesource.com/c/platform/prebuilts/build-tools/+/822999

2. that soong be told that the tool now comes from toybox:
https://android-review.googlesource.com/c/platform/build/soong/+/822624
Post by Rob Landley
Post by enh
AOSP doesn't need -a specifically, but since it's needed for -s we may
as well accept it too.
I would like to read along with the group: what git repo does the hermetic build
stuff go into, and is there a starting commit I should look at?
(The top level Android.mk in platform/system/core is "include $(call
first-makefiles-under,$(LOCAL_PATH))" and given the lack of ordering of that if
you _are_ doing a hermetic build it has to be set up before then, but I dunno
how to go backwards from there...)
Rob
_______________________________________________
Toybox mailing list
http://lists.landley.net/listinfo.cgi/toybox-landley.net
Rob Landley
2018-11-19 18:45:10 UTC
Reply
Permalink
Post by enh
Post by Rob Landley
Post by enh
AOSP doesn't need -a specifically, but since it's needed for -s we may
as well accept it too.
I would like to read along with the group: what git repo does the hermetic
build stuff go into, and is there a starting commit I should look at?
(The top level Android.mk in platform/system/core is "include $(call
first-makefiles-under,$(LOCAL_PATH))" and given the lack of ordering of that
if you _are_ doing a hermetic build it has to be set up before then, but I
dunno how to go backwards from there...)
https://android-review.googlesource.com/c/platform/prebuilts/build-tools/+/822999
https://android-review.googlesource.com/c/platform/build/soong/+/822624
I looked a bit more, and it mostly seems to be changes to this file:

https://android.googlesource.com/platform/build/soong/+/master/ui/build/paths/config.go

And this directory:

https://android.googlesource.com/platform/prebuilts/build-tools/+/master/toybox/linux-x86

Except... the directory is x86-only? You currently only support building on an
x86 host, not on arm?

Rob
Rob Landley
2018-11-28 23:21:27 UTC
Reply
Permalink
Post by Rob Landley
Except... the directory is x86-only? You currently only support building on an
x86 host, not on arm?
correct. i'll worry about supporting arm hosts when i have one that's
Did you ever read through my old https://landley.net/aboriginal/about.html page?

Making distro builds host-agnostic was sort of my thing for a longish time. :)
speaking of too slow to be useful... given that there's already some
__APPLE__ in the tree, i'm looking to see how hard it would be to at
least build those parts of toybox that are used in an AOSP build for
macOS.
I've seen. (And the list header rewrite thing worked! Your emails did not wind
up in the spam folder this time, although the "list copy came through first" vs
"cc: copy came through first" thing is still splitting them across two folders
because gmail can't _not_ kill duplicates.)

At one point, I'm told that worked. At least for a subset of the commands. Stuff
like "ps" is extremely linux-specific because there _is_ no portable way to do
that. Although I'm told BSD's Linux emulation layer works? But my own attempts
at testing that...

https://landley.net/notes-2013.html#15-09-2013
https://landley.net/notes-2014.html#01-04-2014
https://landley.net/notes-2014.html#18-06-2014
https://landley.net/notes-2014.html#11-09-2014

Have not gone well.

Rob

Loading...