Optimize RunCommand by removing /bin/sh wrapper when possible

For every $(shell echo "test: $PATH") command, when SHELL is /bin/bash,
we essentially run: (each arg wrapped in [])

  [/bin/sh] [-c] [/bin/bash -c "echo \"test: \$PATH\""]

This is redundant, since we can just use SHELL, and then we don't need
to do an extra level of shell escaping either. This change makes us run
this instead:

  [/bin/bash] [-c] [echo "test: $PATH"]

If SHELL is more complicated than an absolute path to a binary, then
we'll fall back to /bin/sh.

Using the benchmark introduced in the last change, this reduces a
minimal RunCommand execution with a simple SHELL from 3.7ms to 1.3ms.

For a more complex benchmark (though less normalized), for an AOSP
Android build, this change shrinks the average time spent in $(shell)
functions from 4.5ms to 3ms.

Change-Id: I622116e33565e58bb123ee9e9bdd302616a6609c
8 files changed
tree: a2fe0615ee60651cc5014a1d689db797965b88f1
  1. cmd/
  2. make-c/
  3. testcase/
  4. .gitignore
  5. .travis.yml
  6. affinity.cc
  7. affinity.h
  8. Android.bp
  9. ast.go
  10. AUTHORS
  11. bootstrap.go
  12. buf.go
  13. buf_test.go
  14. command.cc
  15. command.h
  16. CONTRIBUTING.md
  17. CONTRIBUTORS
  18. dep.cc
  19. dep.go
  20. dep.h
  21. depgraph.go
  22. doc.go
  23. eval.cc
  24. eval.go
  25. eval.h
  26. evalcmd.go
  27. exec.cc
  28. exec.go
  29. exec.h
  30. expr.cc
  31. expr.go
  32. expr.h
  33. expr_test.go
  34. file.cc
  35. file.h
  36. file_cache.cc
  37. file_cache.h
  38. fileutil.cc
  39. fileutil.go
  40. fileutil.h
  41. fileutil_bench.cc
  42. find.cc
  43. find.h
  44. find_test.cc
  45. flags.cc
  46. flags.go
  47. flags.h
  48. func.cc
  49. func.go
  50. func.h
  51. func_test.go
  52. INTERNALS.md
  53. io.cc
  54. io.h
  55. LICENSE
  56. loc.h
  57. log.cc
  58. log.go
  59. log.h
  60. m2n
  61. main.cc
  62. make-c.sh
  63. Makefile
  64. Makefile.ckati
  65. Makefile.kati
  66. ninja.cc
  67. ninja.go
  68. ninja.h
  69. ninja_test.cc
  70. ninja_test.go
  71. pack.sh
  72. parser.cc
  73. parser.go
  74. parser.h
  75. pathutil.go
  76. pathutil_test.go
  77. query.go
  78. README.md
  79. regen.cc
  80. regen.h
  81. rule.cc
  82. rule.h
  83. rule_parser.go
  84. rule_parser_test.go
  85. runtest.rb
  86. serialize.go
  87. shellutil.go
  88. shellutil_test.go
  89. stats.cc
  90. stats.go
  91. stats.h
  92. stmt.cc
  93. stmt.h
  94. string_piece.cc
  95. string_piece.h
  96. string_piece_test.cc
  97. stringprintf.cc
  98. stringprintf.h
  99. strutil.cc
  100. strutil.go
  101. strutil.h
  102. strutil_bench.cc
  103. strutil_test.cc
  104. strutil_test.go
  105. symtab.cc
  106. symtab.go
  107. symtab.h
  108. testutil.h
  109. thread_local.h
  110. thread_pool.cc
  111. thread_pool.h
  112. timeutil.cc
  113. timeutil.h
  114. var.cc
  115. var.go
  116. var.h
  117. version.go
  118. version.h
  119. version_unknown.cc
  120. worker.go
README.md

kati

Build Status

kati is an experimental GNU make clone. The main goal of this tool is to speed-up incremental build of Android.

Currently, kati does not offer a faster build by itself. It instead converts your Makefile to a ninja file.

How to use for Android

Now AOSP has kati and ninja, so all you have to do is

% export USE_NINJA=true

All Android's build commands (m, mmm, mmma, etc.) should just work.

How to use for Android (deprecated way)

Set up kati:

% cd ~/src
% git clone https://github.com/google/kati
% cd kati
% make

Build Android:

% cd <android-directory>
% source build/envsetup.sh
% lunch <your-choice>
% ~/src/kati/m2n --kati_stats  # Use --goma if you are a Googler.
% ./ninja.sh

You need ninja in your $PATH.

More usage examples (deprecated way)

“make clean”

% ./ninja.sh -t clean

Note ./ninja.sh passes all parameters to ninja.

Build a specific target

For example, the following is equivalent to “make cts”:

% ./ninja.sh cts

Or, if you know the path you want, you can do:

% ./ninja.sh out/host/linux-x86/bin/adb