You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

145 lines
2.5 KiB

  1. #!/bin/bash
  2. set -e
  3. build_directory="/build"
  4. output_directory="$build_directory/out"
  5. date="$(date '+%Y%m%d%H%M')"
  6. function initializeSourceTree() {
  7. manifest="$1"
  8. branch="$2"
  9. repo init -u "$manifest" -b "$branch"
  10. }
  11. function repoSync() {
  12. repo sync "$@"
  13. }
  14. function getPrebuilts() {
  15. cd "$build_directory"
  16. # TODO: Add persistence for the gpg keyring and avoid
  17. # pulling keys when unecessary
  18. gpg \
  19. --keyserver pool.sks-keyservers.net \
  20. --recv-key 7A029E54DD5DCE7A
  21. gpg \
  22. --keyserver pool.sks-keyservers.net \
  23. --recv-key A801183E69B37AA9
  24. bash ./vendor/replicant/get-prebuilts
  25. }
  26. function buildToolchain() {
  27. cd "$build_directory"
  28. ./vendor/replicant/build-toolchain
  29. }
  30. function loadBuildVars() {
  31. source "$build_directory"/build/envsetup.sh
  32. }
  33. function lunchDevice() {
  34. device="$1"
  35. mode="$2"
  36. lunch replicant_"$device"-"${mode:-userdebug}"
  37. }
  38. function buildPackage() {
  39. device="$1"
  40. mode="$2"
  41. loadBuildVars
  42. lunchDevice "$device" "$mode"
  43. getPrebuilts
  44. cd "$build_directory"
  45. make -j ${threads:-4} bacon
  46. }
  47. function partialBuildPackage() {
  48. device="$2"
  49. sub_project="$3"
  50. cd "$build_directory"/"$sub_project"
  51. mm -B
  52. make -j ${threads:-4} snod
  53. }
  54. function cleanBuild() {
  55. cd "$build_directory"
  56. loadBuildVars
  57. make clean
  58. }
  59. function createBuildBundle() {
  60. device="$1"
  61. device_output_directory="$output_directory/target/product/$device"
  62. cd "$device_output_directory"
  63. tar \
  64. -C "$device_output_directory" \
  65. -cvf "$output_directory/$device-replicant-$date.tar.xz" \
  66. "boot.img" \
  67. "system.img" \
  68. "userdata.img" \
  69. "recovery.img" \
  70. replicant_*.root.zip
  71. }
  72. cd "$build_directory"
  73. if [ $# -eq 0 ]; then
  74. echo -e "No parameter specified."
  75. exit 1
  76. else
  77. while [ $# -ne 0 ]; do
  78. case $1 in
  79. -j | --threads )
  80. threads="$2"
  81. shift
  82. ;;
  83. -i | --initialize )
  84. manifest="$2"
  85. branch="$3"
  86. initializeSourceTree "$manifest" "$branch"
  87. shift
  88. shift
  89. ;;
  90. -p | --pull )
  91. options="${@:2}"
  92. repoSync "$options"
  93. ;;
  94. -t | --build-toolchain )
  95. buildToolchain
  96. ;;
  97. -b | --build )
  98. device="$2"
  99. buildPackage "$device"
  100. shift
  101. ;;
  102. -B | --partial )
  103. device="$2"
  104. sub_project="$3"
  105. partialBuildPackage "$device" "$sub_project"
  106. shift
  107. ;;
  108. -c | --clean )
  109. cleanBuild
  110. ;;
  111. -P | --package )
  112. device="$2"
  113. createBuildBundle "$device"
  114. shift
  115. ;;
  116. esac
  117. shift
  118. done
  119. fi