powerd: add an option to disable turbo mode
[dragonfly.git] / test / fastbulk / dobuild
1 #!/bin/csh
2 #
3 # This is run from the chroot via fastbulk, which has CDd
4 # into a particular pkgsrc directory and wants us to build it.
5 # The script is run as /tmp/track/dobuild
6
7 set logname = "$argv[1]"
8
9 # We do not want to interfere with builds of other versions
10 # of the same package, use a temporary lock file to prevent a
11 # conflict.
12 #
13 if ( $#argv == 1 ) then
14         set pkgwild = "`bmake show-var VARNAME=PKGWILDCARD`.lck"
15         set pkgname = "`bmake show-var VARNAME=PKGNAME`"
16
17         if ( -f /usr/pkgsrc/packages/All/${pkgname}.tgz ) then
18                 if ( -f /tmp/logs/good/$logname ) then
19                     rm -f /tmp/logs/run/$logname
20                     echo "FASTBULK QUICK ${logname}: `date`" \
21                         >> /tmp/logs/good/$logname
22                     echo "FASTBULK: Package already exists, will not build" \
23                         >> /tmp/logs/good/$logname
24                 else
25                     echo "FASTBULK: Package already exists, will not build"
26                 endif
27                 exit 0
28         endif
29
30         mkdir -p /tmp/track/locks
31         echo "FASTBULK START ${argv[1]}: `date`"
32         lockf "/tmp/track/locks/$pkgwild" /tmp/track/dobuild ${argv[1]} "$pkgwild"
33         if ( $status == 0 ) then
34                 echo "FASTBULK SUCCESS ${argv[1]}: `date`"
35                 exit 0
36         else
37                 echo "FASTBULK FAILURE ${argv[1]}: `date`"
38                 find /var/db/pkg/$pkgname -name '*.core' -delete
39                 rmdir /var/db/pkg/$pkgname >& /dev/null
40                 exit 1
41         endif
42 endif
43
44 # Get the package name and clean up any garbage that might
45 # interfere with the build.
46 #
47 set pkgname = "`bmake show-var VARNAME=PKGNAME`"
48 set pkgwild = "$argv[2]"
49 unsetenv PKG_PATH
50
51 # Make sure /var/db/pkg/ does not have any .core files messing it up,
52 # remove the recorded installation if it becomes empty.
53 #
54 find /var/db/pkg/$pkgname -name '*.core' -delete
55 rmdir /var/db/pkg/$pkgname >& /dev/null
56
57 # Check if already installed, prevent overwrite of
58 # previous run's logfile if it exists, by deleting
59 # the current run file.  Else put in a simple logfile.
60 #
61 pkg_info -q -e $pkgname
62 if ( $status == 0 ) then
63     if ( -f /tmp/logs/good/$logname ) then
64         rm -f /tmp/logs/run/$logname
65     endif
66     echo "(already installed from previous run)"
67     exit 0
68 endif
69
70 # Delete potential conflicts
71 #
72 pkg_delete -r "$pkgwild"
73
74 # If we already have a binary package just install
75 # it.
76 #
77 if ( -f /usr/pkgsrc/packages/All/${pkgname}.tgz ) then
78     echo "(found in /usr/pkgsrc/packages)"
79     bmake deinstall DEINSTALLDEPENDS=ALL SKIP_LICENSE_CHECK=yes
80     setenv PKG_PATH /usr/pkgsrc/packages/All
81     echo "pkg_add -f ${pkgname}"
82     pkg_add -f ${pkgname}
83     exit $status
84 endif
85
86 # We need to build the package.
87 #
88 # Delete any conflicting installed packages or the one we want to build
89 # will refuse to build.  The binary package files are left intact.
90 #
91 foreach i ( `bmake show-var VARNAME=CONFLICTS` )
92     echo "DELETING CONFLICTING PACKAGE: $i"
93     pkg_delete -r "$i"
94 end
95
96 # If the dist file checksum fails and the dist file is over
97 # 4 hours old we re-download it.
98 #
99
100 set dollar = '$'
101 set distfiles = "`bmake -V '${dollar}{DISTFILES}'`"
102 bmake checksum SKIP_LICENSE_CHECK=yes
103 if ( $status != 0 ) then
104     echo "Deleting distfiles ( $distfiles ) if over 4h old"
105     foreach dfile ( $distfiles )
106         find /usr/pkgsrc/distfiles -name "$dfile" -mtime +4h -delete
107     end
108 endif
109
110 # To ensure a clean build deinstall anything that
111 # may cause our build repackage to fail.
112 #
113 # Clean after repackaging to keep the work topology footprint small.
114 #
115 # We create a binary package and then pkg_add it.
116 #
117 bmake deinstall DEINSTALLDEPENDS=ALL SKIP_LICENSE_CHECK=yes
118 bmake repackage SKIP_LICENSE_CHECK=yes
119 if ( $status == 0 ) then
120     bmake clean SKIP_LICENSE_CHECK=yes
121     setenv PKG_PATH /usr/pkgsrc/packages/All
122     echo "pkg_add -f ${pkgname}"
123     pkg_add -f ${pkgname}
124     if ( $status != 0 ) then
125         if ( -f ${PKG_PATH}/${pkgname}.tgz ) then
126             echo "FASTBULK WARNING: Cannot install due to probable conflicts"
127             echo "                  but the binary package DID build."
128             echo "                  Exiting w/code 0 to mark as successful."
129         else
130             exit 1
131         endif
132     endif
133     exit 0
134 endif
135
136 # comment this bmake out if you want to keep the work dir
137 # for failed builds.
138 #
139 bmake clean SKIP_LICENSE_CHECK=yes
140 exit 1