1/* 2 --- To sync with upstream: 3 4 # 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 7 8 # Make any necessary Android.bp changes and rebuild. 9 mm -j32 10 11 # Run all the tests. 12 ./run-tests-on-android.sh 13 # Run a single test. 14 ./run-tests-on-android.sh wc 15 16 # 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. 20 21 22 --- To add a toy: 23 24 # 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 ./post_update.sh . 27 28 # 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` below. 34 35*/ 36 37package { 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 55all_srcs = [ 56 "lib/args.c", 57 "lib/commas.c", 58 "lib/dirtree.c", 59 "lib/elf.c", 60 "lib/env.c", 61 "lib/hash.c", 62 "lib/lib.c", 63 "lib/llist.c", 64 "lib/net.c", 65 "lib/portability.c", 66 "lib/tty.c", 67 "lib/utf8.c", 68 "lib/xwrap.c", 69 "main.c", 70 "toys/lsb/gzip.c", 71 "toys/lsb/hostname.c", 72 "toys/lsb/md5sum.c", 73 "toys/lsb/mktemp.c", 74 "toys/lsb/seq.c", 75 "toys/net/microcom.c", 76 "toys/other/dos2unix.c", 77 "toys/other/getopt.c", 78 "toys/other/readlink.c", 79 "toys/other/setsid.c", 80 "toys/other/stat.c", 81 "toys/other/timeout.c", 82 "toys/other/truncate.c", 83 "toys/other/which.c", 84 "toys/other/xxd.c", 85 "toys/other/yes.c", 86 "toys/pending/diff.c", 87 "toys/pending/expr.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/dd.c", 99 "toys/posix/dirname.c", 100 "toys/posix/du.c", 101 "toys/posix/echo.c", 102 "toys/posix/env.c", 103 "toys/posix/file.c", 104 "toys/posix/find.c", 105 "toys/posix/getconf.c", 106 "toys/posix/grep.c", 107 "toys/posix/head.c", 108 "toys/posix/id.c", 109 "toys/posix/ln.c", 110 "toys/posix/ls.c", 111 "toys/posix/mkdir.c", 112 "toys/posix/nl.c", 113 "toys/posix/od.c", 114 "toys/posix/paste.c", 115 "toys/posix/patch.c", 116 "toys/posix/printf.c", 117 "toys/posix/pwd.c", 118 "toys/posix/rm.c", 119 "toys/posix/rmdir.c", 120 "toys/posix/sed.c", 121 "toys/posix/sleep.c", 122 "toys/posix/sort.c", 123 "toys/posix/tail.c", 124 "toys/posix/tar.c", 125 "toys/posix/tee.c", 126 "toys/posix/test.c", 127 "toys/posix/touch.c", 128 "toys/posix/true.c", 129 "toys/posix/uname.c", 130 "toys/posix/uniq.c", 131 "toys/posix/wc.c", 132 "toys/posix/xargs.c", 133] 134 135linux_srcs = [ 136 "toys/lsb/mount.c", 137 "toys/lsb/umount.c", 138 "toys/posix/ps.c", 139 "toys/other/flock.c", 140 "toys/other/nsenter.c", 141 "toys/other/taskset.c", 142] 143 144device_srcs = [ 145 "toys/android/getenforce.c", 146 "toys/android/load_policy.c", 147 "toys/android/log.c", 148 "toys/android/restorecon.c", 149 "toys/android/runcon.c", 150 "toys/android/sendevent.c", 151 "toys/android/setenforce.c", 152 "toys/lsb/dmesg.c", 153 "toys/lsb/killall.c", 154 "toys/lsb/mknod.c", 155 "toys/lsb/pidof.c", 156 "toys/lsb/sync.c", 157 "toys/net/ifconfig.c", 158 "toys/net/netcat.c", 159 "toys/net/netstat.c", 160 "toys/net/ping.c", 161 "toys/net/rfkill.c", 162 "toys/net/tunctl.c", 163 "toys/other/acpi.c", 164 "toys/other/base64.c", 165 "toys/other/blkdiscard.c", 166 "toys/other/blkid.c", 167 "toys/other/blockdev.c", 168 "toys/other/chcon.c", 169 "toys/other/chroot.c", 170 "toys/other/chrt.c", 171 "toys/other/clear.c", 172 "toys/other/devmem.c", 173 "toys/other/fallocate.c", 174 "toys/other/fmt.c", 175 "toys/other/free.c", 176 "toys/other/freeramdisk.c", 177 "toys/other/fsfreeze.c", 178 "toys/other/fsync.c", 179 "toys/other/gpiod.c", 180 "toys/other/help.c", 181 "toys/other/hwclock.c", 182 "toys/other/i2ctools.c", 183 "toys/other/inotifyd.c", 184 "toys/other/insmod.c", 185 "toys/other/ionice.c", 186 "toys/other/losetup.c", 187 "toys/other/lsattr.c", 188 "toys/other/lsmod.c", 189 "toys/other/lsusb.c", 190 "toys/other/makedevs.c", 191 "toys/other/memeater.c", 192 "toys/other/mkswap.c", 193 "toys/other/modinfo.c", 194 "toys/other/mountpoint.c", 195 "toys/other/nbd_client.c", 196 "toys/other/partprobe.c", 197 "toys/other/pivot_root.c", 198 "toys/other/pmap.c", 199 "toys/other/printenv.c", 200 "toys/other/pwdx.c", 201 "toys/other/readelf.c", 202 "toys/other/rev.c", 203 "toys/other/rmmod.c", 204 "toys/other/rtcwake.c", 205 "toys/other/setfattr.c", 206 "toys/other/swapoff.c", 207 "toys/other/swapon.c", 208 "toys/other/sysctl.c", 209 "toys/other/tac.c", 210 "toys/other/uclampset.c", 211 "toys/other/uptime.c", 212 "toys/other/usleep.c", 213 "toys/other/uuidgen.c", 214 "toys/other/vconfig.c", 215 "toys/other/vmstat.c", 216 "toys/other/watch.c", 217 "toys/pending/brctl.c", 218 "toys/pending/getfattr.c", 219 "toys/pending/lsof.c", 220 "toys/pending/modprobe.c", 221 "toys/pending/more.c", 222 "toys/pending/stty.c", 223 "toys/pending/traceroute.c", 224 "toys/pending/vi.c", 225 "toys/posix/cal.c", 226 "toys/posix/chgrp.c", 227 "toys/posix/cksum.c", 228 "toys/posix/df.c", 229 "toys/posix/expand.c", 230 "toys/posix/false.c", 231 "toys/posix/iconv.c", 232 "toys/posix/kill.c", 233 "toys/posix/logger.c", 234 "toys/posix/mkfifo.c", 235 "toys/posix/nice.c", 236 "toys/posix/nohup.c", 237 "toys/posix/renice.c", 238 "toys/posix/split.c", 239 "toys/posix/strings.c", 240 "toys/posix/time.c", 241 "toys/posix/tty.c", 242 "toys/posix/ulimit.c", 243 "toys/posix/unlink.c", 244 "toys/posix/uudecode.c", 245 "toys/posix/uuencode.c", 246] 247 248toybox_symlinks = [ 249 "[", 250 "acpi", 251 "base64", 252 "basename", 253 "blockdev", 254 "brctl", 255 "cal", 256 "cat", 257 "chattr", 258 "chcon", 259 "chgrp", 260 "chmod", 261 "chown", 262 "chroot", 263 "chrt", 264 "cksum", 265 "clear", 266 "comm", 267 "cmp", 268 "cp", 269 "cpio", 270 "cut", 271 "date", 272 "dd", 273 "devmem", 274 "df", 275 "diff", 276 "dirname", 277 "dmesg", 278 "dos2unix", 279 "du", 280 "echo", 281 "egrep", 282 "env", 283 "expand", 284 "expr", 285 "fallocate", 286 "false", 287 "fgrep", 288 "file", 289 "find", 290 "flock", 291 "fmt", 292 "free", 293 "fsync", 294 "getconf", 295 "getenforce", 296 "getfattr", 297 "getopt", 298 "gpiodetect", 299 "gpiofind", 300 "gpioget", 301 "gpioinfo", 302 "gpioset", 303 "grep", 304 "groups", 305 "gunzip", 306 "gzip", 307 "head", 308 "hostname", 309 "hwclock", 310 "i2cdetect", 311 "i2cdump", 312 "i2cget", 313 "i2cset", 314 "i2ctransfer", 315 "iconv", 316 "id", 317 "ifconfig", 318 "inotifyd", 319 "insmod", 320 "install", 321 "ionice", 322 "iorenice", 323 "kill", 324 "killall", 325 "load_policy", 326 "ln", 327 "log", 328 "logger", 329 "logname", 330 "losetup", 331 "ls", 332 "lsattr", 333 "lsmod", 334 "lsof", 335 "lspci", 336 "lsusb", 337 "md5sum", 338 "memeater", 339 "mkdir", 340 "mkfifo", 341 "mknod", 342 "mkswap", 343 "mktemp", 344 "microcom", 345 "modinfo", 346 "more", 347 "mount", 348 "mountpoint", 349 "mv", 350 "nc", 351 "netcat", 352 "netstat", 353 "nice", 354 "nl", 355 "nohup", 356 "nproc", 357 "nsenter", 358 "od", 359 "paste", 360 "patch", 361 "pgrep", 362 "pidof", 363 "pkill", 364 "pmap", 365 "printenv", 366 "printf", 367 "ps", 368 "pwd", 369 "readelf", 370 "readlink", 371 "realpath", 372 "renice", 373 "restorecon", 374 "rm", 375 "rmdir", 376 "rmmod", 377 "rtcwake", 378 "runcon", 379 "sed", 380 "sendevent", 381 "seq", 382 "setenforce", 383 "setfattr", 384 "setsid", 385 "sha1sum", 386 "sha224sum", 387 "sha256sum", 388 "sha384sum", 389 "sha512sum", 390 "sleep", 391 "sort", 392 "split", 393 "stat", 394 "strings", 395 "stty", 396 "swapoff", 397 "swapon", 398 "sync", 399 "sysctl", 400 "tac", 401 "tail", 402 "tar", 403 "taskset", 404 "tee", 405 "test", 406 "time", 407 "timeout", 408 "top", 409 "touch", 410 "tr", 411 "true", 412 "truncate", 413 "tty", 414 "uclampset", 415 "ulimit", 416 "umount", 417 "uname", 418 "uniq", 419 "unix2dos", 420 "unlink", 421 "unshare", 422 "uptime", 423 "usleep", 424 "uudecode", 425 "uuencode", 426 "uuidgen", 427 "vi", 428 "vmstat", 429 "watch", 430 "wc", 431 "which", 432 "whoami", 433 "xargs", 434 "xxd", 435 "yes", 436 "zcat", 437] 438 439cc_defaults { 440 name: "toybox-defaults", 441 srcs: all_srcs, 442 443 cflags: [ 444 "-Os", 445 "-Wall", 446 "-Werror", 447 "-Wno-char-subscripts", 448 "-Wno-deprecated-declarations", 449 "-Wno-invalid-source-encoding", 450 "-Wno-missing-field-initializers", 451 "-Wno-pointer-arith", 452 "-Wno-sign-compare", 453 "-Wno-string-plus-int", 454 "-Wno-unused-parameter", 455 "-Wno-unused-variable", 456 "-funsigned-char", 457 "-ffunction-sections", 458 "-fdata-sections", 459 "-fno-asynchronous-unwind-tables", 460 "-DTOYBOX_VENDOR=\"-android\"", 461 ], 462 463 target: { 464 host_linux: { 465 local_include_dirs: ["android/linux"], 466 }, 467 468 darwin: { 469 local_include_dirs: ["android/mac"], 470 cflags: [ 471 // macOS' getgroups(3) signature differs. 472 "-Wno-pointer-sign", 473 // diff.c defines MIN and MAX which (only on macOS) we're 474 // also getting from <sys/param.h>. 475 "-Wno-macro-redefined", 476 ], 477 ldflags: [ 478 "-Wl,-dead_strip", 479 ], 480 }, 481 482 linux: { 483 srcs: linux_srcs, 484 }, 485 486 android: { 487 local_include_dirs: ["android/device"], 488 srcs: device_srcs, 489 }, 490 }, 491} 492 493//########################################### 494// toybox for /system, /vendor, and /recovery 495//########################################### 496 497cc_defaults { 498 name: "toybox-shared-defaults", 499 defaults: ["toybox-defaults"], 500 501 // This doesn't actually prevent us from dragging in libc++ at runtime 502 // on the device because libnetd_client.so is C++, but it improves host 503 // startup time. 504 stl: "none", 505 506 target: { 507 android: { 508 shared_libs: [ 509 "libcrypto", 510 "liblog", 511 "libprocessgroup", 512 "libselinux", 513 "libz", 514 ], 515 symlinks: toybox_symlinks, 516 }, 517 host: { 518 static_libs: [ 519 "libcrypto", 520 "libz", 521 ], 522 }, 523 }, 524} 525 526cc_binary { 527 name: "toybox", 528 defaults: ["toybox-shared-defaults"], 529 host_supported: true, 530 recovery_available: true, 531 vendor_ramdisk_available: true, 532} 533 534cc_binary { 535 name: "toybox_vendor", 536 defaults: ["toybox-shared-defaults"], 537 vendor: true, 538} 539 540//########################################### 541// Static toybox binaries for legacy devices 542//########################################### 543 544cc_binary { 545 name: "toybox-static", 546 defaults: ["toybox-defaults"], 547 static_executable: true, 548 compile_multilib: "both", 549 multilib: { 550 lib32: { 551 suffix: "32", 552 }, 553 lib64: { 554 suffix: "64", 555 }, 556 }, 557 stl: "libc++_static", 558 static_libs: [ 559 "libc", 560 "libm", 561 "libz", 562 "libbase", 563 "libcgrouprc", 564 "libcgrouprc_format", 565 "libcrypto_static", 566 "liblog", 567 "libprocessgroup", 568 "libselinux", 569 ], 570 dist: { 571 targets: [ 572 "sdk", 573 ], 574 }, 575} 576 577//########################################### 578// Running the toybox tests 579//########################################### 580 581sh_test { 582 name: "toybox-tests", 583 src: "run-tests-on-android.sh", 584 filename: "run-tests-on-android.sh", 585 test_suites: ["general-tests"], 586 host_supported: true, 587 device_supported: false, 588 require_root: true, 589 data: [ 590 "tests/**/*", 591 "scripts/runtest.sh", 592 ], 593} 594 595cc_test { 596 name: "toybox-gtests", 597 compile_multilib: "first", 598 srcs: [ 599 "toybox-gtests.cpp", 600 ], 601 static_libs: [ 602 "libbase", 603 "liblog", 604 ], 605 test_suites: ["device-tests"], 606 require_root: true, 607 data: [ 608 "tests/**/*", 609 "scripts/runtest.sh", 610 ], 611} 612