build-src.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. # Recommended command-line:
  3. #
  4. # commit-db.rb list-valid nightly|GIT_DIR=/your/rust/dir/.git ./build-src.sh
  5. prompt_changes() {
  6. local MAIN_GIT_DIR="$GIT_DIR"
  7. local GIT_DIR=./.git CORE_IO_COMMIT=$IO_COMMIT
  8. git init > /dev/null
  9. git add .
  10. git commit -m "rust src import" > /dev/null
  11. export CORE_IO_COMMIT
  12. bold_arrow; echo 'No patch found for' $IO_COMMIT
  13. bold_arrow; echo 'Nearby commit(s) with patches:'
  14. echo
  15. GIT_DIR="$MAIN_GIT_DIR" git_commits_ordered '%H %cd' $(get_patch_commits) $IO_COMMIT | \
  16. grep --color=always -1 $IO_COMMIT | sed /$IO_COMMIT/'s/$/ <=== your commit/'
  17. echo
  18. bold_arrow; echo -e "Try applying one of those using: \e[1;36mtry_patch COMMIT\e[0m"
  19. bold_arrow; echo -e "Remember to test your changes with: \e[1;36mcargo build\e[0m"
  20. bold_arrow; echo -e "Make your changes now (\e[1;36mctrl-D\e[0m when finished)"
  21. bash_diff_loop "No changes were made"
  22. bold_arrow; echo "Saving changes as $IO_COMMIT.patch"
  23. git clean -f -x
  24. git diff > ../../patches/$IO_COMMIT.patch
  25. rm -rf .git
  26. }
  27. if [ ! -t 1 ] || [ ! -t 2 ]; then
  28. echo "==> /dev/stdout or /dev/stderr is not attached to a terminal!"
  29. echo "==> This script must be run interactively."
  30. exit 1
  31. fi
  32. cd "$(dirname "$0")"
  33. . ./functions.sh
  34. PATCH_DIR="$PWD/patches"
  35. COMPILER_COMMITS=$(cat)
  36. IO_COMMITS=$(get_io_commits|sort -u)
  37. PATCH_COMMITS=$(get_patch_commits|sort -u)
  38. NEW_COMMITS=$(comm -2 -3 <(echo_lines $IO_COMMITS) <(echo_lines $PATCH_COMMITS))
  39. OLD_COMMITS=$(comm -1 -2 <(echo_lines $IO_COMMITS) <(echo_lines $PATCH_COMMITS))
  40. set -e
  41. set -o pipefail
  42. find src -mindepth 1 -type d -prune -exec rm -rf {} \;
  43. for IO_COMMIT in $OLD_COMMITS $(git_commits_ordered %H $NEW_COMMITS|tac); do
  44. if ! [ -d src/$IO_COMMIT ]; then
  45. prepare_version
  46. if [ -f patches/$IO_COMMIT.patch ]; then
  47. bold_arrow; echo "Patching $IO_COMMIT"
  48. patch -s -p1 -d src/$IO_COMMIT < patches/$IO_COMMIT.patch
  49. else
  50. cd src/$IO_COMMIT
  51. prompt_changes
  52. cd ../..
  53. fi
  54. fi
  55. done
  56. OLD_GIT_PERM=$(stat --printf=%a .git)
  57. trap "chmod $OLD_GIT_PERM .git; exit 1" SIGINT
  58. chmod 000 .git
  59. cargo ${1:-package}
  60. chmod $OLD_GIT_PERM .git