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.

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