Last active
December 23, 2015 07:49
-
-
Save jtsagata/6603217 to your computer and use it in GitHub Desktop.
Continous compile a project using ccach, cmake, inotify-tools and ninja
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # sudo apt-get install inotify-tools ninja-build cmake | |
| CURPATH=`pwd` | |
| #Sounds to play. | |
| OKSOUND='/usr/share/sounds/pop.wav' | |
| ERRSOUND='/usr/share/sounds/KDE-K3B-Finish-Error.ogg' | |
| inotifywait -mqr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f %e' \ | |
| -e close_write,modify,moved_to,create . | while read date time dir file event; do | |
| ext="${file##*.}" | |
| # | |
| # Ninja Compile | |
| # | |
| if [[ "$ext" = "cpp" || "$ext" = "h" ]]; | |
| then | |
| FILECHANGE=${dir}${file} | |
| # convert absolute path to relative | |
| FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'` | |
| PROCESS_NUM=`ps -ef | grep "ninja" | grep -v "grep" | wc -l` | |
| if [[ $PROCESS_NUM -eq 1 ]]; | |
| then | |
| echo -e "At ${time} on ${date}, file $FILECHANGE was changed, but prev build is not finished" | |
| else | |
| echo -e "At ${time} on ${date}, file \e[00;31m$FILECHANGE\e[00m was changed. Rebuilding." | |
| ninja -C build | |
| if [[ $? -ne 0 ]]; | |
| then | |
| echo -e "\E[47;31mBuild Failed\033[0m\n" | |
| paplay $ERRSOUND | |
| else | |
| echo -e "\e[00;32mDone\e[00m\n" | |
| paplay $OKSOUND | |
| #git status | |
| fi | |
| fi | |
| fi | |
| # | |
| # CMake build | |
| # | |
| if [[ "$ext" = "cmake" || "$file" = "CMakeLists.txt" ]]; | |
| then | |
| PROCESS_NUM=`ps -ef | grep "cmake" | grep -v "grep" | wc -l` | |
| if [[ $PROCESS_NUM -eq 1 ]]; | |
| then | |
| echo "At ${time} on ${date}, file $FILECHANGE was changed, but cmake is still configuring" | |
| else | |
| echo "At ${time} on ${date}, file $FILECHANGE was changed. Rebuilding the project" | |
| (mkdir -p $CURPATH/build && cd $CURPATH/build && cmake .. -G Ninja) | |
| ninja -C build | |
| echo -e "\e[00;32mDone\e[00m\n" | |
| paplay $OKSOUND | |
| #git status | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment