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.

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