mirror of the now-defunct rocklinux.org
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.

350 lines
10 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Build-Target
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. #
  25. # Run this command from the ROCK directory as ./scripts/Build-Target
  26. # after running the ./scripts/Config and ./scripts/Download commands.
  27. #
  28. # It compiles/builds all the packages and stores them tar balls suitable
  29. # for distribution.
  30. #
  31. # This script is the ROCK work-horse. It builds in a chroot environment
  32. # (stage 2..9) and goes through a number of build stages:
  33. #
  34. config=default
  35. build_only_this_job=
  36. daemon_mode=0
  37. options="$*"
  38. while [ "$1" ] ; do
  39. case "$1" in
  40. -cfg) config=$2 ; shift ; shift ;;
  41. -job) build_only_this_job=$2 ; shift ; shift ;;
  42. -daemon) daemon_mode=1 ; shift ;;
  43. -nodaemon) daemon_mode=0 ; shift ;;
  44. *) echo "Usage: $0 [ -daemon ] [ -cfg config ]" \
  45. "[ -job <stage>-<package> ]" ; exit 1 ;;
  46. esac
  47. done
  48. if [ "$daemon_mode" = 1 ] ; then
  49. echo "Running $0 in the background (messages go to logfile only).."
  50. nohup $0 $options -nodaemon > /dev/null 2> /dev/null < /dev/null &
  51. exit 0
  52. fi
  53. . scripts/parse-config
  54. . scripts/functions
  55. build_dir="$base/build/$ROCKCFG_ID"
  56. build_logs="$build_dir/logs" ; mkdir -p "${build_logs}"
  57. build_root="$build_dir/root" ; mkdir -p "${build_root}"
  58. build_pkgs="$build_dir/pkgs"
  59. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 ] ; then
  60. ./scripts/Check-System || exit 1
  61. fi
  62. # Package Build loop - executed by build-target
  63. #
  64. pkgloop() {
  65. if [ "$ROCKCFG_NOBROKENDEPS" = 1 ]; then
  66. nobrokendeps="-nobrokendeps"
  67. else
  68. nobrokendeps=""
  69. fi
  70. if [ "$ROCKCFG_RETRY_BROKEN" -eq 1 -a \
  71. "`ls ${build_root}/var/adm/logs/*.err 2> /dev/null`" ] ; then
  72. echo_header "Removing old error logs ..."
  73. for x in ${build_root}/var/adm/logs/*.err ; do
  74. echo_status "Removing ${x#$build_root/} ..."
  75. rm -f $x
  76. done
  77. fi
  78. rm -f "${build_root}"/var/adm/logs/*.out
  79. if [ "$ROCKCFG_PARALLEL" = 1 -a -z "$build_only_this_job" ]
  80. then
  81. qdir="$base/build/$ROCKCFG_ID/queue"
  82. mkdir -p $qdir
  83. if [ -z "$ROCKCFG_PARALLEL_ADDJOB" ] ; then
  84. echo "
  85. Job Queue for parallel (cluster) build created.
  86. You have not configuread a command for adding jobs. So you need to use the
  87. ROCK Linux built-in job queue. To do so, you need to login to your build
  88. nodes and execute the command:
  89. ./scripts/Build-Job -cfg $config -daemon
  90. "
  91. touch $qdir/use_build_job_daemon
  92. else
  93. echo "
  94. Job Queue for parallel (cluster) build created.
  95. You have configuread a command for adding jobs. So if everything is configured
  96. in the right way, the nodes will automatically start building the jobs.
  97. "
  98. rm -f $qdir/use_build_job_daemon
  99. fi
  100. newqueue=1 ; printstatus=1 ; printstatus_counter=30
  101. finished=0 ; trap 'rm -f $qdir/queue.txt ; exit 130' SIGINT
  102. while
  103. if [ -f $qdir/print_status ] ; then
  104. rm -f $qdir/print_status
  105. printstatus=1 ; printstatus_counter=0
  106. fi
  107. if [ "$printstatus" = 1 ] ; then
  108. if [ $printstatus_counter -le 0 ] ; then
  109. ./scripts/Create-ParaStatus -cfg "$config"
  110. printstatus=0 ; printstatus_counter=300
  111. else
  112. printstatus_counter=$(($printstatus_counter - 1))
  113. fi
  114. fi
  115. for x in $qdir/*.msg ; do
  116. if [ -f "$x" ] ; then
  117. expand -t20 < $x ; rm -f $x
  118. printstatus=1 ; newqueue=1
  119. fi
  120. done
  121. if [ "$newqueue" = 1 ] ; then
  122. ./scripts/Create-PkgQueue -cfg $config \
  123. $nobrokendeps | sort -r -n -k2 | \
  124. if [ $ROCKCFG_PARALLEL_MAX -gt 0 ]
  125. then head -$ROCKCFG_PARALLEL_MAX
  126. else cat ; fi > $qdir/queue.new
  127. mv $qdir/queue.new $qdir/queue.txt
  128. newqueue=0
  129. while read next ; do
  130. set $next ; qid="$1-$6"
  131. if [ ! -f $qdir/$qid.job ] ; then
  132. date "+%H:%M %Y-%m-%d: creating new job '$qid'" | expand -t20
  133. echo "Job $qid waiting in the job queue (priority $2)" > $qdir/$qid.todo
  134. printstatus=1
  135. # we need to remove some variables that should be uniqe per node
  136. dump_env | grep -v HOSTNAME= > $qdir/$qid.new
  137. mv $qdir/$qid.new $qdir/$qid.job
  138. if [ "$ROCKCFG_PARALLEL_ADDJOB" ] ; then
  139. x="${ROCKCFG_PARALLEL_ADDJOB//\{\}/.\/scripts\/Build-Job -cfg $config $qid}" ; sh -c "$x"
  140. fi
  141. fi
  142. done < $qdir/queue.txt
  143. fi
  144. if [ -s $qdir/queue.txt ] || \
  145. [ "`ls $qdir/*.job 2>/dev/null`" ]
  146. then
  147. finished=0
  148. else
  149. finished=$(( $finished + 1 ))
  150. newqueue=1
  151. fi
  152. [ $finished -le 3 ]
  153. do
  154. sleep 1
  155. done
  156. echo "All packages build."
  157. sleep 2 ; rm -rf $qdir ; trap - SIGINT
  158. else
  159. if [ "$build_only_this_job" ] ; then
  160. rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.log"
  161. rm -f "${build_root}"/var/adm/logs/${build_only_this_job}.err"
  162. next="$( awk 'BEGIN { FS=" "; }
  163. $5 == "'${build_only_this_job#*-}'" && \
  164. $2 ~ /'${build_only_this_job%%-*}'/ \
  165. { $1="'${build_only_this_job%%-*}' 0";
  166. print; exit; }' < config/$config/packages )"
  167. [ "$next" ] && pkgloop_package $next
  168. exit 0
  169. else
  170. while
  171. next="`./scripts/Create-PkgQueue \
  172. -cfg "$config" -single $nobrokendeps`"
  173. [ "$next" ]
  174. do
  175. pkgloop_package $next
  176. done
  177. fi
  178. fi
  179. local pkglst=`mktemp` errors=0; rm -f src/invalid-files.lst
  180. echo_header "Searching for old liggering files ..."
  181. grep "^X" config/$config/packages |
  182. if [ $ROCKCFG_PKGFILE_VER = 1 ] ; then
  183. cut -d' ' -f5-6 | sed "s/ /-/"
  184. else
  185. cut -d' ' -f5
  186. fi > $pkglst
  187. for file in $( ls build/$ROCKCFG_ID/pkgs/ ) ; do
  188. x="$file"
  189. [ $ROCKCFG_CREATE_GEM = 0 ] || x=${x%.gem}
  190. [ $ROCKCFG_CREATE_TARBZ2 = 0 ] || x=${x%.tar.bz2}
  191. if ! grep -qx "$x" $pkglst ; then
  192. file="build/$ROCKCFG_ID/pkgs/$file"
  193. echo_error "$file should not be present" \
  194. "(now in src/invalid-files.lst)!"
  195. mkdir -p src; echo "$file" >> src/invalid-files.lst
  196. errors=1
  197. fi
  198. done
  199. for dir in build/$ROCKCFG_ID/root/var/adm/{cache,cksums,dependencies,descs,flists,md5sums,packages} ; do
  200. for file in $( ls $dir ) ; do
  201. if [ $ROCKCFG_PKGFILE_VER = 1 ] ; then
  202. x="$file-"
  203. else
  204. x="$file"
  205. fi
  206. if ! grep -q "$x" $pkglst ; then
  207. echo_error "$dir/$file should not be present (now in src/invalid-files.lst)!"
  208. mkdir -p src; echo "$dir/$file" >> src/invalid-files.lst
  209. errors=1
  210. fi
  211. done
  212. done
  213. for file in $( ls build/$ROCKCFG_ID/root/var/adm/logs/ ) ; do
  214. x="`echo $file | sed -e 's/^.-//' -e 's/\.log//' -e 's/\.err//' -e s'/\.out//'`"
  215. if [ $ROCKCFG_PKGFILE_VER = 1 ] ; then
  216. x=$x-
  217. else
  218. x=$x
  219. fi
  220. if ! grep -q "$x" $pkglst ; then
  221. file="build/$ROCKCFG_ID/root/var/adm/logs/$file"
  222. echo_error "$file should not be present (now in src/invalid-files.lst)!"
  223. mkdir -p src; echo "$file" >> src/invalid-files.lst
  224. errors=1
  225. fi
  226. done
  227. [ $errors = 0 ] && echo_status "No errors found."
  228. rm $pkglst
  229. }
  230. # Process one line of output generated by Create-PkgQueue
  231. #
  232. pkgloop_package() {
  233. for x in stagelevel pkg_depnr pkg_stages pkg_pri pkg_tree \
  234. pkg_name pkg_ver pkg_prefix pkg_extra
  235. do eval "$x=\$1" ; shift ; done
  236. [ "$build_only_this_job" -a \
  237. "$stagelevel-$pkg_name" != "$build_only_this_job" ] && return
  238. [ $(expr "$pkg_stages" : ".*$stagelevel.*") -eq 0 ] && return
  239. pkg_laststage=$(echo "$pkg_stages" | sed "s,-,,g; s,.*\(.\),\1,")
  240. cmd_root="-root auto"
  241. [ $stagelevel -gt 1 ] && cmd_root="$cmd_root -chroot"
  242. if [ "$pkg_prefix" != "/" ] ; then
  243. cmd_prefix="-prefix $pkg_prefix"
  244. else cmd_prefix="" ; fi
  245. cmd_buildpkg="./scripts/Build-Pkg -$stagelevel -cfg $config"
  246. cmd_buildpkg="$cmd_buildpkg $cmd_root $cmd_prefix $pkg_name"
  247. # Execute action handler
  248. pkgloop_action || [ "$ROCKCFG_ABORT_ON_ERROR" != 1 ] || exit 1
  249. if [ ! -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.log -a \
  250. ! -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err ]
  251. then
  252. echo_header "Package build ended abnormally!"
  253. echo_error "Usually a package build creates eighter a *.log"
  254. echo_error "or a *.err file. Neither the 1st nor the 2nd is"
  255. echo_error "there. So I'm going to create a *.err file now"
  256. echo_error "and abort the build process."
  257. touch ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err
  258. exit 1
  259. fi
  260. if [ $pkg_laststage -eq $stagelevel ] && \
  261. [ "$ROCKCFG_CREATE_TARBZ2" = 1 -o "$ROCKCFG_CREATE_GEM" = 1 ]
  262. then
  263. if [ -f ${build_root}/var/adm/logs/$stagelevel-$pkg_name.err ]
  264. then echo_error "Creation of binary package isn't possible,"
  265. echo_error "because the package was not successfully"
  266. echo_error "built in (at least) the current stage."
  267. else
  268. echo_header "Creating binary package file for ${pkg_name}."
  269. mkdir -p "${build_pkgs}"
  270. if [ "$ROCKCFG_PKGFILE_VER" = 1 ]
  271. then v="-${pkg_ver}"; else v=""; fi
  272. echo_status "Building build/.../pkgs/`
  273. `${pkg_name}${v}.tar.bz2"
  274. ( cd "$build_root/"
  275. cut -f2- -d' ' var/adm/flists/$pkg_name | \
  276. tar -cf- --no-recursion --files-from=- | bzip2
  277. ) > "${build_pkgs}/${pkg_name}${v}.tar.bz2.tmp"
  278. if [ "$ROCKCFG_CREATE_GEM" = 1 ] ; then
  279. echo_status "Building build/.../pkgs/`
  280. `${pkg_name}${v}.gem"
  281. mine -C "$build_root/var/adm" \
  282. "${build_pkgs}/${pkg_name}${v}.tar.bz2.tmp" \
  283. $pkg_name "$build_pkgs/${pkg_name}${v}.gem.tmp"
  284. fi
  285. if [ "$ROCKCFG_CREATE_TARBZ2" = 1 ] ; then
  286. mv "$build_pkgs/${pkg_name}${v}.tar.bz2.tmp" \
  287. "$build_pkgs/${pkg_name}${v}.tar.bz2"
  288. if [ "$ROCKCFG_CREATE_GEM" = 1 ] ; then
  289. mv "$build_pkgs/${pkg_name}${v}.gem.tmp" \
  290. "$build_pkgs/${pkg_name}${v}.gem"
  291. fi
  292. else
  293. echo_status "Removing temporary tar.bz2."
  294. rm -f "$build_pkgs/${pkg_name}${v}.tar.bz2.tmp"
  295. mv "$build_pkgs/${pkg_name}${v}.gem.tmp" \
  296. "$build_pkgs/${pkg_name}${v}.gem"
  297. fi
  298. fi
  299. fi
  300. }
  301. # Action executed by pkgloop(). This function may be redefined
  302. # before calling pkgloop().
  303. #
  304. pkgloop_action() {
  305. $cmd_buildpkg
  306. }
  307. {
  308. ln -sf build_target_$$.log ${build_logs}/build_target.log
  309. ./scripts/Build-Tools -1 -cfg $config
  310. . ./target/$ROCKCFG_TARGET/build.sh
  311. } 2>&1 | tee -a "${build_logs}/build_target_$$.log"