OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
4.8 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-cleanup
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. #Description: Cleanup the build environment
  18. [ -n "$SDEROOT" ] ||
  19. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  20. . $SDEROOT/lib/libsde.in
  21. nocheck=0
  22. downclean=0
  23. buildclean=0
  24. cacheclean=0
  25. cleanup_usage() {
  26. cat <<EOT
  27. Usage: sde cleanup [ -build ] [ -cache ] [ -full ] [ -nocheck ] [ -download ]
  28. sde cleanup [ dir(s) ]
  29. EOT
  30. }
  31. while [ "$1" ] ; do
  32. case "$1" in
  33. -build)
  34. buildclean=1 ;;
  35. -cache)
  36. cacheclean=1 ;;
  37. -full)
  38. buildclean=1 ; cacheclean=1 ;;
  39. -nocheck)
  40. nocheck=1 ;;
  41. -download)
  42. downclean=1 ;;
  43. -*) cleanup_usage
  44. exit 1 ;;
  45. *)
  46. break ;;
  47. esac
  48. shift
  49. done
  50. # Cleanup download/* and quit
  51. #
  52. if [ $downclean -eq 1 ]; then
  53. echo "Searching for obsolete downloads (this may take some time) ..."
  54. $SDEROOT/bin/sde-download -list-unknown | cut -d ' ' -f 3 |
  55. while read fn; do
  56. [ "$fn" ] && rm -v "$fn"
  57. done
  58. exit
  59. fi
  60. # Remove src.*
  61. #
  62. for x in tmp src.* build/*/TOOLCHAIN/src.*; do
  63. if [ -d "$x" -o -L "$x" ] ; then
  64. if [ "$#" != 0 ] ; then
  65. delme=0
  66. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  67. [ "$delme" = 0 ] && continue
  68. fi
  69. delme=1
  70. for y in build.pid; do
  71. if [ $delme = 1 -a -f "$x/$y" ] ; then
  72. if [ "`fuser "$x/$y"`" ] ; then
  73. echo "Found active $y in $x: Not removing!"
  74. delme=0
  75. fi
  76. fi
  77. done
  78. if [ $delme = 1 ] ; then
  79. echo "removing $x .."
  80. rm -rf "$x"
  81. fi
  82. fi
  83. done
  84. # Remove build/*
  85. #
  86. fullhelp=0
  87. for x in build/* ; do
  88. if [ -d "$x" ] ; then
  89. if [ "$#" != 0 ] ; then
  90. delme=0
  91. for y ; do [ "${y%/}" = "$x" ] && delme=1 ; done
  92. [ "$delme" = 0 ] && continue
  93. fi
  94. # handle (c)cache pools first
  95. if [ ${x/build\/ccache/} != $x ]; then
  96. if [ $cacheclean = 1 ]; then
  97. echo "removing $x ..."
  98. rm -rf "$x"
  99. else
  100. echo "Not removing $x (cache)."
  101. fullhelp=1
  102. fi
  103. continue
  104. fi
  105. if [ $buildclean = 1 ] ; then
  106. for y in proc TOOLCHAIN/loop TOOLCHAIN/config TOOLCHAIN/download; do
  107. umount -d -f "$x/$y" > /dev/null 2>&1
  108. umount -d -f -l "$x/$y" > /dev/null 2>&1
  109. rmdir "$x/$y" > /dev/null 2>&1
  110. if [ -d "$x/$y" ] ; then
  111. echo "Found $y in $x: Not removing!"
  112. delme=0
  113. fi
  114. done
  115. if [ "$delme" != 0 ] ; then
  116. echo "removing $x ..."
  117. rm -rf "$x"
  118. fi
  119. else
  120. echo "Not removing $x (build)."
  121. fullhelp=1
  122. fi
  123. fi
  124. done
  125. [ $fullhelp -eq 1 ] &&
  126. echo -e "\nUse '$0 -build' to remove builds and '$0 -cache'
  127. to also flush the cache."
  128. [ "$nocheck" = 1 ] && exit 0
  129. echo -e "\nSearching for lingering temp/backup files (this may take some time) ..."
  130. sderootdirs="scripts/. bin/. etc/. lib/. misc/. doc/. src/. package/. architecture/. target/."
  131. # Remove temp/backup files
  132. #
  133. bash scripts/xfind.sh $sderootdirs -type f \( -name '*~' -o \
  134. -name 'a.out' -o -name 'core.*' -o -name 'core' \) | xargs rm -vf
  135. # Print warnings for 'lingering' files
  136. # (we have to distinguish between the targets and the rest)
  137. #
  138. sderootdirs=${sderootdirs% target/.}
  139. bash scripts/xfind.sh ${sderootdirs} \( \
  140. \( -name 'DEADJOE' -o -name '*-[xX]' -o -name '.[^.]*' \
  141. -o -name '*.orig' -o -name '*.rej' -o -name '*#*' \
  142. -o -name '*.mine' -o -name '*.r[1-9][0-9]*' \
  143. -o -name TRANS.TBL -o -name '*.cksum-err' -o -name x \
  144. -o -name '*[.-]old' -o -name a.out -o -name '*~' \
  145. -o -name '*.incomplete' -o -name '*.ckext-err' \) \
  146. -printf 'WARNING: Found %p\n' \
  147. \) -o \( \
  148. \( ! -type d ! -type f \) \
  149. -printf 'WARNING: Neither a dir nor a regular file: %p\n' \
  150. \)
  151. # for targets we tolerate .files
  152. bash scripts/xfind.sh target/. \
  153. \( \
  154. \( -name 'DEADJOE' -o -name '*-[xX]' \
  155. -o -name '*.orig' -o -name '*.rej' -o -name '*#*' \
  156. -o -name '*.mine' -o -name '*.r[1-9][0-9]*' \
  157. -o -name TRANS.TBL -o -name '*.cksum-err' -o -name x \
  158. -o -name '*[.-]old' -o -name a.out -o -name '*~' \
  159. -o -name '*.incomplete' -o -name '*.ckext-err' \) \
  160. -printf 'WARNING: Found %p\n' \
  161. \) -o \( \
  162. \( ! -type d ! -type f \) \
  163. -printf 'WARNING: Neither a dir nor a regular file: %p\n' \
  164. \)
  165. exit 0