Advertisement
bryceman

update_file_list.sh

Mar 16th, 2012
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. # Check for existence of project file
  5. if [ -e $1.files ]
  6. then
  7.     printf "Updating '%s' project...\n" $1
  8.     project=$1
  9.     shift
  10. else
  11.     printf "Error: Project file '%s' not found!\n" $1.files
  12.     exit 1
  13. fi
  14.  
  15. # Save copy of old one before updating
  16. cp -f $project.files $project.files.old
  17.  
  18. # Grab the files that are listed before the first empty line, leaving them untouched
  19. sed $project.files -r -e '/^\s*$/q' > $project.files.new
  20.  
  21. # Re-insert the empty line between non-auto files and the rest
  22. echo >> $project.files.new
  23.  
  24. #
  25. # Grab all files listed in all dependency files in all specified sub-directories
  26. #
  27. until [ -z "$1" ]  # Until all parameters used up . . .
  28. do
  29.  
  30.     # Check for existence of dependencies dir
  31.     if [ -d $1/dep ]
  32.     then
  33.         depdir=$1/dep
  34.     else
  35.         depdir=$1
  36.     fi
  37.     printf "Scanning for dependencies in '%s'...\n" $depdir
  38.     ls $depdir/*.d > /dev/null 2> /dev/null
  39.     result=$?
  40.     if [ $result -ne 0 ]
  41.     then
  42.         printf "Error (%d): No dependency files found in '%s'!\n" $result $depdir
  43.         exit 1
  44.     fi
  45.  
  46.     # Grab all files listed in all dependency files in all possibly-matching sub-directories
  47.     sed -nr -f $0.sed $depdir/*.d | \
  48.         # Sort and filter for uniques before dumping them
  49.         sort | uniq >> $project.files.new
  50.  
  51.     shift
  52.  
  53. done
  54.  
  55. # Check whether file lists differ
  56. if ! diff -q $project.files $project.files.new
  57. then
  58.     # Copy new file list over old and warn user that they need to re-open the project
  59.     echo "Warning: Qt Creator file list has been updated. Project should be re-opened."
  60.     mv -f $project.files.new $project.files
  61. else
  62.     # Just get rid of the temp file
  63.     rm -f $project.files.new
  64. fi
  65.  
  66. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement