build-src.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. # Recommended command-line:
  3. #
  4. # commit-db.rb list-valid nightly|GIT_DIR=/your/rust/dir/.git sync.sh
  5. git_file_exists() {
  6. [ "$(git ls-tree --name-only $IO_COMMIT -- $1)" = "$1" ]
  7. }
  8. git_extract() {
  9. slashes=${1//[^\/]/}
  10. git archive $IO_COMMIT $1|tar xf - -C src/$IO_COMMIT --strip-components=${#slashes}
  11. }
  12. git_commits_ordered() {
  13. format=$1
  14. shift
  15. if [ $# -ge 1 ]; then
  16. git log --topo-order --no-walk=sorted --date=iso-local --pretty=format:$format "$@"
  17. fi
  18. }
  19. echo_lines() {
  20. for i in "$@"; do
  21. echo $i
  22. done
  23. }
  24. get_io_commits() {
  25. for COMPILER_COMMIT in $COMPILER_COMMITS; do
  26. IO_COMMIT=$(git log -n1 --pretty=format:%H $COMPILER_COMMIT -- src/libstd/io)
  27. if ! grep -q $COMPILER_COMMIT mapping.rs; then
  28. echo "-Mapping(\"$COMPILER_COMMIT\",\"$IO_COMMIT\")" >> mapping.rs
  29. fi
  30. echo $IO_COMMIT
  31. done
  32. }
  33. get_patch_commits() {
  34. find $PATCH_DIR -type f -printf %f\\n|cut -d. -f1
  35. }
  36. prepare_version() {
  37. mkdir src/$IO_COMMIT
  38. git_extract src/libstd/io/
  39. if git_file_exists src/libstd/sys/common/memchr.rs; then
  40. git_extract src/libstd/sys/common/memchr.rs
  41. else
  42. git_extract src/libstd/memchr.rs
  43. fi
  44. rm -f src/$IO_COMMIT/stdio.rs src/$IO_COMMIT/lazy.rs
  45. }
  46. bold_arrow() {
  47. echo -ne '\e[1;36m==> \e[0m'
  48. }
  49. prompt_changes() {
  50. local MAIN_GIT_DIR="$GIT_DIR"
  51. local GIT_DIR=./.git CORE_IO_COMMIT=$IO_COMMIT
  52. git init > /dev/null
  53. git add .
  54. git commit -a -m "rust src import" > /dev/null
  55. export CORE_IO_COMMIT
  56. bold_arrow; echo 'No patch found for' $IO_COMMIT
  57. bold_arrow; echo 'Nearby commit(s) with patches:'
  58. echo
  59. GIT_DIR="$MAIN_GIT_DIR" git_commits_ordered '%H %cd' $(get_patch_commits) $IO_COMMIT | \
  60. grep --color=always -1 $IO_COMMIT | sed /$IO_COMMIT/'s/$/ <=== your commit/'
  61. echo
  62. bold_arrow; echo -e "Try applying one of those using: \e[1;36mpatch -p1 < ../../patches/COMMIT.patch\e[0m"
  63. bold_arrow; echo -e "Remember to test your changes with: \e[1;36mcargo build\e[0m"
  64. bold_arrow; echo -e "Make your changes now (\e[1;36mctrl-D\e[0m when finished)"
  65. bash <> /dev/stderr
  66. while git diff --exit-code > /dev/null; do
  67. bold_arrow; echo "No changes were made"
  68. while true; do
  69. bold_arrow; echo -n "(T)ry again or (A)bort? "
  70. read answer <> /dev/stderr
  71. case "$answer" in
  72. [tT])
  73. break
  74. ;;
  75. [aA])
  76. bold_arrow; echo "Aborting..."
  77. exit 1
  78. ;;
  79. esac
  80. done
  81. bash <> /dev/stderr
  82. done
  83. bold_arrow; echo "Saving changes as $IO_COMMIT.patch"
  84. git clean -f -x
  85. git diff > ../../patches/$IO_COMMIT.patch
  86. rm -rf .git
  87. }
  88. if [ ! -t 1 ] || [ ! -t 2 ]; then
  89. echo "==> /dev/stdout or /dev/stderr is not attached to a terminal!"
  90. echo "==> This script must be run interactively."
  91. exit 1
  92. fi
  93. cd "$(dirname "$0")"
  94. PATCH_DIR="$PWD/patches"
  95. COMPILER_COMMITS=$(cat)
  96. IO_COMMITS=$(get_io_commits|sort -u)
  97. PATCH_COMMITS=$(get_patch_commits|sort -u)
  98. NEW_COMMITS=$(comm -2 -3 <(echo_lines $IO_COMMITS) <(echo_lines $PATCH_COMMITS))
  99. OLD_COMMITS=$(comm -1 -2 <(echo_lines $IO_COMMITS) <(echo_lines $PATCH_COMMITS))
  100. find src -mindepth 1 -type d -prune -exec rm -rf {} \;
  101. for IO_COMMIT in $OLD_COMMITS $(git_commits_ordered %H $NEW_COMMITS|tac); do
  102. if ! [ -d src/$IO_COMMIT ]; then
  103. prepare_version
  104. if [ -f patches/$IO_COMMIT.patch ]; then
  105. patch -s -p1 -d src/$IO_COMMIT < patches/$IO_COMMIT.patch
  106. else
  107. cd src/$IO_COMMIT
  108. prompt_changes
  109. cd ../..
  110. fi
  111. fi
  112. done
  113. chmod 000 .git
  114. cargo package
  115. chmod 755 .git