Advertisement
3v1n0

folder-builder-and-sync.sh

Mar 9th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. export BUILD_FOLDER=$1
  4. export MYLOCALE="it"
  5. export INSTALL_TARGET="ubuntu-vmware.local"
  6. export PATH=$HOME/.local/bin:/opt/dev/bin:$PATH
  7.  
  8. export CPUs=$(grep -w -c processor /proc/cpuinfo)
  9. export CONCURRENCY_LEVEL=$((CPUs+CPUs/4))
  10. export MAKEFLAGS="-j$CONCURRENCY_LEVEL"
  11. # export LC_ALL="C.UTF-8"
  12.  
  13. builder=""
  14.  
  15. if [ -z "$BUILD_FOLDER" ]; then
  16.   echo "Impossible to build in this folder"
  17.   exit 1
  18. fi
  19.  
  20. schroot -c unstable -- jhbuild shell << "EOF"
  21. if [ -z "$JHBUILD_CHECKOUT_FOLDER" ]; then
  22.   echo "Add checkout folder definition to your environment, edit your .jhbuildrc:"
  23.   echo "  os.environ['JHBUILD_CHECKOUT_FOLDER'] = checkoutroot"
  24.   exit 1
  25. fi
  26.  
  27. if [ -z "$JHBUILD_BUILD_FOLDER" ]; then
  28.   echo "Add checkout folder definition to your environment, edit your .jhbuildrc:"
  29.   echo "  os.environ['JHBUILD_BUILD_FOLDER'] = buildroot"
  30.   exit 1
  31. fi
  32.  
  33. file_path=$(realpath --relative-to=$JHBUILD_CHECKOUT_FOLDER $BUILD_FOLDER)
  34.  
  35. if [ "$file_path" == "." ] || [[ "$file_path" == "../"* ]]; then
  36.   echo "File path is not buildable: '$file_path'"
  37.   exit 1
  38. fi
  39.  
  40. project_path=$(echo $file_path | cut -f1 -d/)
  41. if [ -z "$project_path" ]; then
  42.   echo "Impossible to get a good project path from $file_path"
  43.   exit 1
  44. fi
  45.  
  46. source_path="$JHBUILD_CHECKOUT_FOLDER/$project_path"
  47. builder_path="$JHBUILD_BUILD_FOLDER/$project_path"
  48.  
  49. builder="make"
  50.  
  51. if ! [ -f "$builder_path/Makefile" ]; then
  52.   builder_path="$JHBUILD_CHECKOUT_FOLDER/$project_path"
  53.  
  54.   if ! [ -f "$builder_path/Makefile" ]; then
  55.     builder=""
  56.   fi
  57. fi
  58.  
  59. if [ "$builder" == "make" ]; then
  60.   if [ ! -f "$builder_path/compile_commands.json" ] ||
  61.      [ ! -f "$builder_path/compile_commands_headers.stamp" ] ||
  62.      [ "$builder_path/config.status" -nt "$builder_path/compile_commands.json" ] ||
  63.      [ "$source_path/configure.ac" -nt "$builder_path/config.status" ]; then
  64.     echo "Using bear make to generate compile_commands.json"
  65.     builder="bear -a -o $builder_path/compile_commands.json make"
  66.   fi
  67. fi
  68.  
  69. if [ -z "$builder" ]; then
  70.   builder="ninja"
  71.   builder_path="$JHBUILD_BUILD_FOLDER/$project_path"
  72.  
  73.   if ! [ -f "$builder_path/build.ninja" ]; then
  74.     builder_path="$JHBUILD_CHECKOUT_FOLDER/$project_path"
  75.  
  76.     if ! [ -f "$builder_path/build.ninja" ]; then
  77.       builder=""
  78.     fi
  79.   fi
  80. fi
  81.  
  82. if [ -z "$builder" ]; then
  83.   echo "Impossible to find a valid build path for $project_path"
  84.   exit 1;
  85. fi
  86.  
  87. echo "builder is $builder"
  88. $builder install -C "$builder_path"
  89. builder_exit=$?
  90.  
  91. if [ -n "$MYLOCALE" ]; then
  92.   find $JHBUILD_PREFIX/share/locale -mindepth 1 -maxdepth 1 \
  93.        ! -name "$MYLOCALE" -type d -exec rm -fr {} \;
  94. fi
  95.  
  96. if [ $builder_exit -eq 0 ] && [ -n "$INSTALL_TARGET" ]; then
  97.   # if timeout 0.5 ping -q -c1 -W1 $INSTALL_TARGET &> /dev/null; then
  98.     rsync -a --delete $JHBUILD_PREFIX $INSTALL_TARGET:$(dirname $JHBUILD_PREFIX) --stats
  99.   # else
  100.     # echo "BUILD DONE; BUT NOT SYCED WITH '$INSTALL_TARGET'"
  101.   # fi
  102. fi
  103.  
  104. # if [ $builder_exit -eq 0 ] &&
  105. #    (([ -f "$builder_path/compile_commands.json" ] && [ ! -f "$builder_path/compile_commands_headers.stamp" ]) ||
  106. #      [ "$builder_path/compile_commands.json" -nt "$JHBUILD_CHECKOUT_FOLDER/compile_commands.json" ]); then
  107. #   $JHBUILD_CHECKOUT_FOLDER/generate-full-compile-commands.sh --update-root $project_path
  108. # fi
  109.  
  110. if [ $builder_exit -eq 0 ] &&
  111.    (([ -f "$builder_path/compile_commands.json" ] && [ ! -f "$builder_path/compile_commands_headers.stamp" ]) ||
  112.      [ "$builder_path/compile_commands.json" -nt "$builder_path/compile_commands_headers.stamp" ]); then
  113.   $JHBUILD_CHECKOUT_FOLDER/generate-full-compile-commands.sh $project_path
  114. fi
  115.  
  116. if [ $builder_path != $source_path ] && [ -e $builder_path/compile_commands.json ]; then
  117.   cp -uv $builder_path/compile_commands.json $source_path/compile_commands.json
  118. fi
  119.  
  120. exit $builder_exit
  121. EOF
  122.  
  123. jhbuild_ret=$?
  124.  
  125. # if [ $jhbuild_ret -eq 0 ] && timeout 0.5 ping -q -c1 -W1 ubuntu-vmware.local &> /dev/null; then
  126. #   echo rsync -a --delete $JHBUILD_PREFIX ubuntu-vmware.local:$(dirname $JHBUILD_PREFIX) --stats --info=progress2
  127. # fi
  128.  
  129. exit $jhbuild_ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement