Write .kati_stamp file atomically

It is possible to get a mismatch between the .kati_stamp file and the
build.ninja file by exiting due to error or interrupt after the ninja
file is written but before the stamp file is written.  If the change
that caused the previous stamp file verification to fail are then
reverted, for example an environment variable set back to what it was in
the stamp file, the next run of kati could see the old stamp file and
not rewrite the non-matching ninja file.

To avoid stamp and ninja file mismatches, delete the old stamp file just
before starting to write any new files.  To avoid a partially written
stamp file write the stamp file to .kati_stamp.tmp, and then atomically
rename it to .kati_stamp.

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