blob: 3beb024a86d837a54adb87508d013f82acd003ee [file] [log] [blame]
Elliott Hughes23f25132019-09-04 21:11:05 -07001/*
Elliott Hughes23f25132019-09-04 21:11:05 -07002 --- To sync with upstream:
Jiyong Park24dafcf2017-10-13 20:02:57 +09003
Elliott Hughes23f25132019-09-04 21:11:05 -07004 # Update source and regenerate generated files.
5 git remote add toybox https://github.com/landley/toybox.git
6 git fetch toybox && git merge toybox/master && ./regenerate.sh
Jiyong Park24dafcf2017-10-13 20:02:57 +09007
Elliott Hughes23f25132019-09-04 21:11:05 -07008 # Make any necessary Android.bp changes and rebuild.
9 mm -j32
Jiyong Park24dafcf2017-10-13 20:02:57 +090010
Elliott Hughes23f25132019-09-04 21:11:05 -070011 # Run all the tests.
12 ./run-tests-on-android.sh
13 # Run a single test.
14 ./run-tests-on-android.sh wc
Jiyong Park24dafcf2017-10-13 20:02:57 +090015
Elliott Hughes23f25132019-09-04 21:11:05 -070016 # Upload changes.
17 git commit -a --amend
18 git push aosp HEAD:refs/for/master # Push to gerrit for review.
19 git push aosp HEAD:master # Push directly, avoiding gerrit.
Jiyong Park24dafcf2017-10-13 20:02:57 +090020
Jiyong Park24dafcf2017-10-13 20:02:57 +090021
Elliott Hughes23f25132019-09-04 21:11:05 -070022 --- To add a toy:
Elliott Hughesa3cc9bc2019-08-15 16:10:41 -070023
Elliott Hughes23f25132019-09-04 21:11:05 -070024 # Edit the three .config-* files to enable the toy you want for the targets
25 # you want it on, and regenerate the generated files:
26 ./regenerate.sh
Elliott Hughesa3cc9bc2019-08-15 16:10:41 -070027
Elliott Hughes23f25132019-09-04 21:11:05 -070028 # Edit the relevant `srcs` below, depending on where the toy should be
29 # available.
30
31 # If you just want to use the toy via "toybox x" rather than "x", you can
32 # stop now. If you want this toy to have a symbolic link in /system/bin,
33 # add the toy to symlinks.
34
35*/
Jiyong Park24dafcf2017-10-13 20:02:57 +090036
Bob Badour5d35ee22021-02-11 12:57:17 -080037package {
38 default_applicable_licenses: ["external_toybox_license"],
39}
40
41license {
42 name: "external_toybox_license",
43 visibility: [":__subpackages__"],
44 license_kinds: [
45 "SPDX-license-identifier-0BSD",
46 "SPDX-license-identifier-CC0-1.0",
47 "SPDX-license-identifier-Unlicense",
48 "legacy_unencumbered",
49 ],
50 license_text: [
51 "LICENSE",
52 ],
53}
54
Elliott Hughes75f90862020-05-13 16:37:07 -070055all_srcs = [
56 "lib/args.c",
57 "lib/commas.c",
58 "lib/dirtree.c",
59 "lib/env.c",
60 "lib/help.c",
61 "lib/lib.c",
62 "lib/linestack.c",
63 "lib/llist.c",
64 "lib/net.c",
65 "lib/portability.c",
66 "lib/tty.c",
67 "lib/xwrap.c",
68 "main.c",
69 "toys/lsb/gzip.c",
70 "toys/lsb/hostname.c",
71 "toys/lsb/md5sum.c",
72 "toys/lsb/mktemp.c",
73 "toys/lsb/seq.c",
74 "toys/net/microcom.c",
75 "toys/other/dos2unix.c",
76 "toys/other/readlink.c",
77 "toys/other/setsid.c",
78 "toys/other/stat.c",
79 "toys/other/timeout.c",
80 "toys/other/truncate.c",
81 "toys/other/which.c",
82 "toys/other/xxd.c",
83 "toys/other/yes.c",
84 "toys/pending/dd.c",
85 "toys/pending/diff.c",
86 "toys/pending/expr.c",
87 "toys/pending/getopt.c",
88 "toys/pending/tr.c",
89 "toys/posix/basename.c",
90 "toys/posix/cat.c",
91 "toys/posix/chmod.c",
92 "toys/posix/cmp.c",
93 "toys/posix/comm.c",
94 "toys/posix/cp.c",
95 "toys/posix/cpio.c",
96 "toys/posix/cut.c",
97 "toys/posix/date.c",
98 "toys/posix/dirname.c",
99 "toys/posix/du.c",
100 "toys/posix/echo.c",
101 "toys/posix/env.c",
102 "toys/posix/find.c",
103 "toys/posix/getconf.c",
104 "toys/posix/grep.c",
105 "toys/posix/head.c",
106 "toys/posix/id.c",
107 "toys/posix/ln.c",
108 "toys/posix/ls.c",
109 "toys/posix/mkdir.c",
Elliott Hughesf7d74aa2020-11-12 16:15:49 -0800110 "toys/posix/nl.c",
Elliott Hughes75f90862020-05-13 16:37:07 -0700111 "toys/posix/od.c",
112 "toys/posix/paste.c",
113 "toys/posix/patch.c",
Elliott Hughes838baaf2020-06-04 16:30:19 -0700114 "toys/posix/printf.c",
Elliott Hughes75f90862020-05-13 16:37:07 -0700115 "toys/posix/pwd.c",
116 "toys/posix/rm.c",
117 "toys/posix/rmdir.c",
118 "toys/posix/sed.c",
119 "toys/posix/sleep.c",
120 "toys/posix/sort.c",
121 "toys/posix/tail.c",
122 "toys/posix/tar.c",
123 "toys/posix/tee.c",
124 "toys/posix/test.c",
125 "toys/posix/touch.c",
126 "toys/posix/true.c",
127 "toys/posix/uname.c",
128 "toys/posix/uniq.c",
129 "toys/posix/wc.c",
130 "toys/posix/xargs.c",
131]
132
133linux_srcs = [
134 "toys/posix/ps.c",
135 "toys/other/taskset.c",
136]
137
138device_srcs = [
139 "toys/android/getenforce.c",
140 "toys/android/load_policy.c",
141 "toys/android/log.c",
142 "toys/android/restorecon.c",
143 "toys/android/runcon.c",
144 "toys/android/sendevent.c",
145 "toys/android/setenforce.c",
146 "toys/lsb/dmesg.c",
147 "toys/lsb/killall.c",
148 "toys/lsb/mknod.c",
149 "toys/lsb/mount.c",
150 "toys/lsb/pidof.c",
151 "toys/lsb/sync.c",
152 "toys/lsb/umount.c",
153 "toys/net/ifconfig.c",
154 "toys/net/netcat.c",
155 "toys/net/netstat.c",
156 "toys/net/ping.c",
157 "toys/net/rfkill.c",
158 "toys/net/tunctl.c",
159 "toys/other/acpi.c",
160 "toys/other/base64.c",
161 "toys/other/blkdiscard.c",
162 "toys/other/blkid.c",
163 "toys/other/blockdev.c",
164 "toys/other/chcon.c",
165 "toys/other/chroot.c",
166 "toys/other/chrt.c",
167 "toys/other/clear.c",
168 "toys/other/devmem.c",
169 "toys/other/fallocate.c",
170 "toys/other/flock.c",
171 "toys/other/fmt.c",
172 "toys/other/free.c",
173 "toys/other/freeramdisk.c",
174 "toys/other/fsfreeze.c",
175 "toys/other/fsync.c",
176 "toys/other/help.c",
177 "toys/other/hwclock.c",
178 "toys/other/i2ctools.c",
179 "toys/other/inotifyd.c",
180 "toys/other/insmod.c",
181 "toys/other/ionice.c",
182 "toys/other/losetup.c",
183 "toys/other/lsattr.c",
184 "toys/other/lsmod.c",
185 "toys/other/lspci.c",
186 "toys/other/lsusb.c",
187 "toys/other/makedevs.c",
188 "toys/other/mkswap.c",
189 "toys/other/modinfo.c",
190 "toys/other/mountpoint.c",
191 "toys/other/nbd_client.c",
192 "toys/other/nsenter.c",
193 "toys/other/partprobe.c",
194 "toys/other/pivot_root.c",
195 "toys/other/pmap.c",
196 "toys/other/printenv.c",
197 "toys/other/pwdx.c",
198 "toys/other/rev.c",
199 "toys/other/rmmod.c",
200 "toys/other/rtcwake.c",
201 "toys/other/setfattr.c",
202 "toys/other/swapoff.c",
203 "toys/other/swapon.c",
204 "toys/other/sysctl.c",
205 "toys/other/tac.c",
206 "toys/other/uptime.c",
207 "toys/other/usleep.c",
208 "toys/other/uuidgen.c",
209 "toys/other/vconfig.c",
210 "toys/other/vmstat.c",
211 "toys/other/watch.c",
212 "toys/pending/getfattr.c",
213 "toys/pending/lsof.c",
214 "toys/pending/modprobe.c",
215 "toys/pending/more.c",
216 "toys/pending/readelf.c",
217 "toys/pending/stty.c",
218 "toys/pending/traceroute.c",
219 "toys/pending/vi.c",
220 "toys/posix/cal.c",
221 "toys/posix/chgrp.c",
222 "toys/posix/cksum.c",
223 "toys/posix/df.c",
224 "toys/posix/expand.c",
225 "toys/posix/false.c",
226 "toys/posix/file.c",
227 "toys/posix/iconv.c",
228 "toys/posix/kill.c",
229 "toys/posix/mkfifo.c",
230 "toys/posix/nice.c",
Elliott Hughes75f90862020-05-13 16:37:07 -0700231 "toys/posix/nohup.c",
Elliott Hughes75f90862020-05-13 16:37:07 -0700232 "toys/posix/renice.c",
233 "toys/posix/split.c",
234 "toys/posix/strings.c",
235 "toys/posix/time.c",
236 "toys/posix/tty.c",
237 "toys/posix/ulimit.c",
238 "toys/posix/unlink.c",
239 "toys/posix/uudecode.c",
240 "toys/posix/uuencode.c",
241]
242
243toybox_symlinks = [
Elliott Hughesf4f0f692021-02-03 10:34:13 -0800244 "[",
Elliott Hughes75f90862020-05-13 16:37:07 -0700245 "acpi",
246 "base64",
247 "basename",
248 "blockdev",
249 "cal",
250 "cat",
251 "chattr",
252 "chcon",
253 "chgrp",
254 "chmod",
255 "chown",
256 "chroot",
257 "chrt",
258 "cksum",
259 "clear",
260 "comm",
261 "cmp",
262 "cp",
263 "cpio",
264 "cut",
265 "date",
266 "dd",
267 "devmem",
268 "df",
269 "diff",
270 "dirname",
271 "dmesg",
272 "dos2unix",
273 "du",
274 "echo",
275 "egrep",
276 "env",
277 "expand",
278 "expr",
279 "fallocate",
280 "false",
281 "fgrep",
282 "file",
283 "find",
284 "flock",
285 "fmt",
286 "free",
287 "fsync",
288 "getconf",
289 "getenforce",
290 "grep",
291 "groups",
292 "gunzip",
293 "gzip",
294 "head",
295 "hostname",
296 "hwclock",
297 "i2cdetect",
298 "i2cdump",
299 "i2cget",
300 "i2cset",
301 "iconv",
302 "id",
303 "ifconfig",
304 "inotifyd",
305 "insmod",
306 "install",
307 "ionice",
308 "iorenice",
309 "kill",
310 "killall",
311 "load_policy",
312 "ln",
313 "log",
314 "logname",
315 "losetup",
316 "ls",
317 "lsattr",
318 "lsmod",
319 "lsof",
320 "lspci",
321 "lsusb",
322 "md5sum",
323 "mkdir",
324 "mkfifo",
325 "mknod",
326 "mkswap",
327 "mktemp",
328 "microcom",
329 "modinfo",
330 "more",
331 "mount",
332 "mountpoint",
333 "mv",
334 "nc",
335 "netcat",
336 "netstat",
337 "nice",
338 "nl",
339 "nohup",
340 "nproc",
341 "nsenter",
342 "od",
343 "paste",
344 "patch",
345 "pgrep",
346 "pidof",
347 "pkill",
348 "pmap",
349 "printenv",
350 "printf",
351 "ps",
352 "pwd",
353 "readelf",
354 "readlink",
355 "realpath",
356 "renice",
357 "restorecon",
358 "rm",
359 "rmdir",
360 "rmmod",
361 "rtcwake",
362 "runcon",
363 "sed",
364 "sendevent",
365 "seq",
366 "setenforce",
367 "setsid",
368 "sha1sum",
369 "sha224sum",
370 "sha256sum",
371 "sha384sum",
372 "sha512sum",
373 "sleep",
374 "sort",
375 "split",
376 "stat",
377 "strings",
378 "stty",
379 "swapoff",
380 "swapon",
381 "sync",
382 "sysctl",
383 "tac",
384 "tail",
385 "tar",
386 "taskset",
387 "tee",
388 "test",
389 "time",
390 "timeout",
391 "top",
392 "touch",
393 "tr",
394 "true",
395 "truncate",
396 "tty",
397 "ulimit",
398 "umount",
399 "uname",
400 "uniq",
401 "unix2dos",
402 "unlink",
403 "unshare",
404 "uptime",
405 "usleep",
406 "uudecode",
407 "uuencode",
408 "uuidgen",
409 "vmstat",
410 "watch",
411 "wc",
412 "which",
413 "whoami",
414 "xargs",
415 "xxd",
416 "yes",
417 "zcat",
418]
419
Jiyong Park24dafcf2017-10-13 20:02:57 +0900420cc_defaults {
421 name: "toybox-defaults",
Elliott Hughes75f90862020-05-13 16:37:07 -0700422 srcs: all_srcs,
Jiyong Park24dafcf2017-10-13 20:02:57 +0900423
424 cflags: [
Jiyong Park24dafcf2017-10-13 20:02:57 +0900425 "-Os",
426 "-Wall",
427 "-Werror",
428 "-Wno-char-subscripts",
Elliott Hughesced4a432018-12-03 13:02:28 -0800429 "-Wno-deprecated-declarations",
Jiyong Park24dafcf2017-10-13 20:02:57 +0900430 "-Wno-missing-field-initializers",
Elliott Hughes5a850042019-01-07 11:58:11 -0800431 "-Wno-pointer-arith",
Jiyong Park24dafcf2017-10-13 20:02:57 +0900432 "-Wno-sign-compare",
433 "-Wno-string-plus-int",
434 "-Wno-unused-parameter",
Elliott Hughes00969f62019-08-22 10:54:26 -0700435 "-Wno-unused-variable",
Jiyong Park24dafcf2017-10-13 20:02:57 +0900436 "-funsigned-char",
437 "-ffunction-sections",
438 "-fdata-sections",
439 "-fno-asynchronous-unwind-tables",
440 "-DTOYBOX_VENDOR=\"-android\"",
441 ],
442
Elliott Hughes36e1c152018-10-05 16:41:37 -0700443 target: {
Elliott Hughes00969f62019-08-22 10:54:26 -0700444 linux_glibc: {
445 local_include_dirs: ["android/linux"],
Elliott Hughesa3cc9bc2019-08-15 16:10:41 -0700446 },
447
Yi-Yo Chiang2d03a5e2021-04-23 16:04:29 +0800448 linux_bionic: {
449 local_include_dirs: ["android/linux"],
450 },
451
Elliott Hughesa3cc9bc2019-08-15 16:10:41 -0700452 darwin: {
Elliott Hughes00969f62019-08-22 10:54:26 -0700453 local_include_dirs: ["android/mac"],
Elliott Hughesa3cc9bc2019-08-15 16:10:41 -0700454 cflags: [
455 // You can't have toybox cp(1) on macOS before 10.13.
456 "-mmacosx-version-min=10.13",
457 "-UMACOSX_DEPLOYMENT_TARGET",
458 "-DMACOSX_DEPLOYMENT_TARGET=10.13",
459 // macOS' getgroups(3) signature differs.
460 "-Wno-pointer-sign",
461 // diff.c defines MIN and MAX which (only on macOS) we're
462 // also getting from <sys/param.h>.
463 "-Wno-macro-redefined",
464 ],
465 },
466
Elliott Hughes00969f62019-08-22 10:54:26 -0700467 linux: {
Elliott Hughes75f90862020-05-13 16:37:07 -0700468 srcs: linux_srcs,
Elliott Hughes00969f62019-08-22 10:54:26 -0700469 },
470
Elliott Hughes36e1c152018-10-05 16:41:37 -0700471 android: {
Elliott Hughesa3cc9bc2019-08-15 16:10:41 -0700472 local_include_dirs: ["android/device"],
Elliott Hughes75f90862020-05-13 16:37:07 -0700473 srcs: device_srcs,
Elliott Hughes36e1c152018-10-05 16:41:37 -0700474 },
475 },
Jiyong Park24dafcf2017-10-13 20:02:57 +0900476}
477
Jiyong Park24dafcf2017-10-13 20:02:57 +0900478//###########################################
479// toybox for /system, /vendor, and /recovery
480//###########################################
481
Elliott Hughes75f90862020-05-13 16:37:07 -0700482cc_defaults {
483 name: "toybox-shared-defaults",
484 defaults: ["toybox-defaults"],
485
486 // This doesn't actually prevent us from dragging in libc++ at runtime
487 // on the device because libnetd_client.so is C++, but it improves host
488 // startup time.
489 stl: "none",
490
491 shared_libs: [
492 "libcrypto",
493 "libz",
494 ],
495
496 target: {
497 android: {
498 shared_libs: [
499 "liblog",
500 "libprocessgroup",
501 "libselinux",
502 ],
503 symlinks: toybox_symlinks,
504 },
505 },
506}
507
Jiyong Park24dafcf2017-10-13 20:02:57 +0900508cc_binary {
509 name: "toybox",
Elliott Hughes75f90862020-05-13 16:37:07 -0700510 defaults: ["toybox-shared-defaults"],
Elliott Hughes36e1c152018-10-05 16:41:37 -0700511 host_supported: true,
Jiyong Park37923492018-06-01 12:21:14 +0900512 recovery_available: true,
Yifan Hongd0123d62020-10-21 18:44:25 -0700513 vendor_ramdisk_available: true,
Jiyong Park24dafcf2017-10-13 20:02:57 +0900514}
515
516cc_binary {
517 name: "toybox_vendor",
Elliott Hughes75f90862020-05-13 16:37:07 -0700518 defaults: ["toybox-shared-defaults"],
Jiyong Park24dafcf2017-10-13 20:02:57 +0900519 vendor: true,
520}
Julien Desprezba11fb92019-06-21 08:52:39 -0700521
522//###########################################
Elliott Hughes75f90862020-05-13 16:37:07 -0700523// Static toybox binaries for legacy devices
524//###########################################
525
526cc_binary {
527 name: "toybox-static",
528 defaults: ["toybox-defaults"],
529 static_executable: true,
530 compile_multilib: "both",
531 multilib: {
532 lib32: { suffix: "32", },
533 lib64: { suffix: "64", },
534 },
535 stl: "libc++_static",
536 static_libs: [
537 "libc",
538 "libm",
539 "libz",
540 "libbase",
541 "libcgrouprc",
542 "libcgrouprc_format",
543 "libcrypto_static",
544 "liblog",
545 "libprocessgroup",
546 "libselinux",
547 ],
Elliott Hughes805e1ca2020-08-21 16:32:38 -0700548 dist: {
549 targets: [
Elliott Hughes3c9b6c52020-08-25 17:04:03 -0700550 "sdk",
Elliott Hughes805e1ca2020-08-21 16:32:38 -0700551 ],
552 },
Elliott Hughes75f90862020-05-13 16:37:07 -0700553}
554
555//###########################################
Julien Desprezba11fb92019-06-21 08:52:39 -0700556// Running the toybox tests
557//###########################################
558
559sh_test {
560 name: "toybox-tests",
561 src: "run-tests-on-android.sh",
562 filename: "run-tests-on-android.sh",
563 test_suites: ["general-tests"],
Julien Desprezf749c212019-06-28 11:38:30 -0700564 host_supported: true,
565 device_supported: false,
frankfengef80c622020-07-22 11:06:21 -0700566 require_root:true,
Julien Desprezba11fb92019-06-21 08:52:39 -0700567 data: [
568 "tests/**/*",
569 "scripts/runtest.sh",
570 ],
571}