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.

278 lines
8.3 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Build-Target
  6. # Copyright (C) 2006 - 2008 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. #
  18. # Run this command from the ROCK directory as ./scripts/Build-Target
  19. # after running the ./scripts/Config and ./scripts/Download commands.
  20. #
  21. # It compiles/builds all the packages and stores them tar balls suitable
  22. # for distribution.
  23. #
  24. # This script is the ROCK work-horse. It builds in a chroot environment
  25. # (stage 2..9) and goes through a number of build stages:
  26. #
  27. config=default
  28. build_only_this_job=
  29. daemon_mode=0
  30. autodownload=1
  31. options="$*"
  32. downloadopt="-q"
  33. while [ $# -gt 0 ] ; do
  34. case "$1" in
  35. -cfg) config=$2 ; shift ;;
  36. -job) build_only_this_job=$2 ; shift ;;
  37. -daemon) daemon_mode=1 ;;
  38. -nodaemon) daemon_mode=0 ;;
  39. -nodownload) autodownload=0 ;;
  40. *) echo "Usage: $0 [ -daemon ] [ -nodownload ] [ -cfg config ]" \
  41. "[ -job <stage>-<package> ]" ; exit 1 ;;
  42. esac
  43. shift
  44. done
  45. ./lib/sde-config/migrate.sh "$config" || exit 1
  46. if [ "$daemon_mode" = 1 ] ; then
  47. . config/$config/config
  48. echo "Running $0 in the background (messages go to logfile only).."
  49. echo "Logfile: build/$SDECFG_ID/TOOLCHAIN/logs/build_target.log"
  50. nohup $0 $options -nodaemon > /dev/null 2> /dev/null < /dev/null &
  51. exit 0
  52. fi
  53. . lib/functions.in
  54. . lib/parse-config
  55. build_root="$base/build/$SDECFG_ID"
  56. build_toolchain="$base/build/$SDECFG_ID/TOOLCHAIN"
  57. build_logs="$build_toolchain/logs" ; mkdir -p "${build_logs}"
  58. build_pkgs="$build_toolchain/pkgs" ; mkdir -p "${build_root}"
  59. if [ "$SDECFG_PARANOIA_CHECK" = 1 ] ; then
  60. ./bin/sde-check-system || exit 1
  61. fi
  62. # Package Build loop - executed by build-target
  63. #
  64. pkgloop() {
  65. local x= y=
  66. if [ "$SDECFG_NOBROKENDEPS" = 1 ]; then
  67. nobrokendeps="-nobrokendeps"
  68. else
  69. nobrokendeps=
  70. fi
  71. if [ -z "$build_only_this_job" ]; then
  72. if [ "`ls ${build_root}/var/adm/logs/*.err 2> /dev/null`" ] ; then
  73. echo_header "Removing old error logs ..."
  74. for y in 0 1 2 3 4 5 6 7 8 9; do
  75. if [ "$SDECFG_RETRY_BROKEN" -eq 1 -o $y -le "$SDECFG_ABORT_ON_ERROR_AFTER" ]; then
  76. for x in ${build_root}/var/adm/logs/$y-*.err ; do
  77. if [ -f $x ]; then
  78. echo_status "Removing ${x#$build_root/} ..."
  79. rm -f $x
  80. fi
  81. done
  82. fi
  83. done
  84. fi
  85. if [ "`ls ${build_root}/var/adm/logs/*.out 2> /dev/null`" ] ; then
  86. echo_header "Removing old output logs ..."
  87. for x in ${build_root}/var/adm/logs/*.out ; do
  88. echo_status "Removing ${x#$build_root/} ..."
  89. rm -f $x
  90. done
  91. fi
  92. while
  93. next="`./scripts/Create-PkgQueue \
  94. -cfg "$config" -single $nobrokendeps`"
  95. [ "$next" ]
  96. do
  97. pkgloop_package $next
  98. done
  99. else
  100. rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.log"
  101. rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.err"
  102. next="$( awk 'BEGIN { FS=" "; }
  103. $5 == "'${build_only_this_job#*-}'" && \
  104. $2 ~ /'${build_only_this_job%%-*}'/ \
  105. { $1="'${build_only_this_job%%-*}' 0";
  106. print; exit; }' < config/$config/packages )"
  107. [ "$next" ] && pkgloop_package $next
  108. exit 0
  109. fi
  110. local pkglst=`mktemp` errors=0; rm -f tmp/invalid-files.lst
  111. echo_header "Searching for old lingering files ..."
  112. sed '/^[^X]/d ; s,.*=,,' config/$config/packages | cut -d' ' -f5 |
  113. if [ $SDECFG_PKGFILE_VER = 1 ] ; then
  114. while read p; do
  115. v=$( grep '^Package Name and Version:' \
  116. build/$SDECFG_ID/var/adm/packages/$p \
  117. 2>/dev/null | cut -f6 -d' ' )
  118. echo "$p-$v"
  119. done
  120. else
  121. cat
  122. fi > $pkglst
  123. for file in $( ls build/$SDECFG_ID/TOOLCHAIN/pkgs/ 2> /dev/null ) ; do
  124. x="$file"
  125. case $SDECFG_PKGFILE_TYPE in
  126. tar.*) x=${x%.$SDECFG_PKGFILE_TYPE} ;;
  127. none) : ;;
  128. esac
  129. if ! grep -qx "$x" $pkglst && ! test "$x" = packages.db ; then
  130. file="build/$SDECFG_ID/TOOLCHAIN/pkgs/$file"
  131. echo_error "$file should not be present" \
  132. "(now in tmp/invalid-files.lst)!"
  133. mkdir -p tmp; echo "$file" >> tmp/invalid-files.lst
  134. errors=1
  135. fi
  136. done
  137. for dir in build/$SDECFG_ID/var/adm/{cache,cksums,dependencies,descs,flists,md5sums,packages} ; do
  138. for file in $( ls $dir 2> /dev/null ) ; do
  139. if [ $SDECFG_PKGFILE_VER = 1 ] ; then
  140. x="$file-"
  141. else
  142. x="$file"
  143. fi
  144. if ! grep -q "$x" $pkglst ; then
  145. echo_error "$dir/$file should not be present (now in tmp/invalid-files.lst)!"
  146. mkdir -p tmp; echo "$dir/$file" >> tmp/invalid-files.lst
  147. errors=1
  148. fi
  149. done
  150. done
  151. for file in $( ls build/$SDECFG_ID/var/adm/logs/ ) ; do
  152. x="`echo $file | sed -e 's/^.-//' -e 's/\.log//' -e 's/\.err//' -e s'/\.out//'`"
  153. if [ $SDECFG_PKGFILE_VER = 1 ] ; then
  154. x=$x-
  155. else
  156. x=$x
  157. fi
  158. if ! grep -q "$x" $pkglst ; then
  159. file="build/$SDECFG_ID/var/adm/logs/$file"
  160. echo_error "$file should not be present (now in tmp/invalid-files.lst)!"
  161. mkdir -p tmp; echo "$file" >> tmp/invalid-files.lst
  162. errors=1
  163. fi
  164. done
  165. [ $errors = 0 ] && echo_status "None found."
  166. rm $pkglst
  167. }
  168. # Process one line of output generated by Create-PkgQueue
  169. #
  170. pkgloop_package() {
  171. for x in stagelevel pkg_depnr pkg_stages pkg_pri pkg_tree \
  172. pkg_name pkg_ver pkg_prefix pkg_extra
  173. do eval "$x=\$1" ; shift ; done
  174. [ "$build_only_this_job" -a \
  175. "$stagelevel-$pkg_name" != "$build_only_this_job" ] && return
  176. [ $(expr "$pkg_stages" : ".*$stagelevel.*") -eq 0 ] && return
  177. pkg_laststage=$(echo "$pkg_stages" | sed "s,-,,g; s,.*\(.\),\1,")
  178. cmd_root="-root auto"
  179. [ $stagelevel -gt 1 ] && cmd_root="$cmd_root -chroot"
  180. if [ "$pkg_prefix" != "/" ] ; then
  181. cmd_prefix="-prefix $pkg_prefix"
  182. else cmd_prefix= ; fi
  183. if [ "$autodownload" = 1 ]; then
  184. ./bin/sde-download -cfg $config $downloadopt $pkg_name
  185. fi
  186. cmd_buildpkg="./scripts/Build-Pkg -$stagelevel -cfg $config"
  187. cmd_buildpkg="$cmd_buildpkg $cmd_root $cmd_prefix $pkg_name"
  188. # Execute action handler
  189. if ! pkgloop_action && \
  190. [ $stagelevel -le "$SDECFG_ABORT_ON_ERROR_AFTER" ] ; then
  191. exit 1
  192. fi
  193. if [ ! -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.log -a \
  194. ! -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err ]
  195. then
  196. echo_header "Package build ended abnormally!"
  197. echo_error "Usually a package build creates either a *.log"
  198. echo_error "or a *.err file. Neither the 1st nor the 2nd is"
  199. echo_error "there. So I'm going to create a *.err file now"
  200. echo_error "and abort the build process."
  201. touch ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err
  202. exit 1
  203. fi
  204. if [ $stagelevel -gt 0 -a $pkg_laststage -eq $stagelevel -a "$SDECFG_PKGFILE_TYPE" != none ]; then
  205. if [ -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err ]; then
  206. echo_error "Creation of binary package isn't possible, because the package was not"
  207. echo_error "built successfully in (at least) the current stage."
  208. else
  209. ./lib/sde-binary/package.sh --type "$SDECFG_PKGFILE_TYPE" \
  210. $( if [ "${SDECFG_PKGFILE_VER}" = 1 ]; then echo '--versioned'; fi ) \
  211. --root "${build_root}" --output "${build_pkgs}" ${pkg_name}
  212. fi
  213. fi
  214. }
  215. # Action executed by pkgloop(). This function may be redefined
  216. # before calling pkgloop().
  217. #
  218. pkgloop_action() {
  219. $cmd_buildpkg
  220. }
  221. # Try to umount any directories mounted by Build-Pkg -chroot
  222. # if we are the last process using them.
  223. #
  224. umount_chroot() {
  225. exec 201> /dev/null
  226. if ! ( cd ${build_logs}; fuser *.log > /dev/null 2>&1 ); then
  227. echo_status "Unmounting loop mounts ..."
  228. umount -d -f $build_toolchain/{loop,config,download} 2> /dev/null
  229. umount -d -f -l $build_toolchain/{loop,config,download} 2> /dev/null
  230. umount -d -f $build_root/proc 2> /dev/null
  231. umount -d -f -l $build_root/proc 2> /dev/null
  232. fi
  233. }
  234. # must trap outside the group command
  235. trap 'umount_chroot' EXIT
  236. {
  237. ln -sf build_target_$$.log ${build_logs}/build_target.log
  238. ./bin/sde-build-tools -1 -c $config
  239. _built=0
  240. for x in $( get_expanded ./target/%/build.sh $targetchain ); do
  241. if [ -f $x ]; then
  242. . $x
  243. _built=1
  244. break
  245. fi
  246. done
  247. [ $_built = 1 ] || echo_warning "No target/*/build.sh controlling the build!"
  248. } 2>&1 201>> "${build_logs}/build_target_$$.log" | \
  249. tee -a "${build_logs}/build_target_$$.log"