1 | #!/usr/bin/perl -w
|
---|
2 | # automatic buildskript
|
---|
3 | # reads configuration from option -b BUILDLIST
|
---|
4 | # $Id: dassbuild_all.pl 753 2009-06-12 14:39:03Z joergs $
|
---|
5 |
|
---|
6 |
|
---|
7 | use strict;
|
---|
8 | use Getopt::Std;
|
---|
9 | use File::stat;
|
---|
10 | use File::Basename;
|
---|
11 |
|
---|
12 | my $wert1;
|
---|
13 | my $wert2;
|
---|
14 | my $wert3;
|
---|
15 |
|
---|
16 | format TABELLE =
|
---|
17 | @<<<<<<<<<<<<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
---|
18 | $wert1, $wert2, $wert3
|
---|
19 | .
|
---|
20 |
|
---|
21 |
|
---|
22 | # Programmoptionen:
|
---|
23 | # -b buildlist
|
---|
24 | # -x (buildlog im seperaten xterm)
|
---|
25 | # -d Zielpfad um Install Source zu erzeugen
|
---|
26 |
|
---|
27 | my $workdir=`pwd`;
|
---|
28 | chomp $workdir;
|
---|
29 |
|
---|
30 | # Pfad, zu dem die Pfade in buildlist stehen
|
---|
31 | my $src_root="../../";
|
---|
32 |
|
---|
33 |
|
---|
34 | my $BUILD_DEST_DIR="/tmp/build.$ENV{'USER'}/";
|
---|
35 | my $INSTALL_SRC_SKEL_DIR="/net/dist/data/dist/sles/8/skeleton-i386/smartclient/";
|
---|
36 |
|
---|
37 | my $build = "dassbuild.sh";
|
---|
38 | our ( $opt_x, $opt_b, $opt_d );
|
---|
39 | my @ArrayofBuilds;
|
---|
40 | getopts('xb:d:');
|
---|
41 |
|
---|
42 | my $skipped_last = 0;
|
---|
43 |
|
---|
44 | if (!$opt_b && !$opt_d) {
|
---|
45 | print <<EOF
|
---|
46 | Usage:
|
---|
47 | -b BUILDLIST
|
---|
48 | compiles packages specified in BUILDLIST
|
---|
49 | -d INSTALL_SRC_DEST_DIR
|
---|
50 | creates a new install source in INSTALL_SRC_DEST_DIR
|
---|
51 | EOF
|
---|
52 | };
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 | #
|
---|
57 | # build packages from buildlist
|
---|
58 | #
|
---|
59 |
|
---|
60 | if( $opt_b ) {
|
---|
61 | (open(BUILDLIST,$opt_b)) || die "Die Buildlist $opt_b konnte nicht gefunden werden";
|
---|
62 |
|
---|
63 |
|
---|
64 | while (<BUILDLIST>) #Buildlist parsen
|
---|
65 | {
|
---|
66 | my $dir;
|
---|
67 | my $arch;
|
---|
68 | my $opt;
|
---|
69 | next if (/^\#.*$/);
|
---|
70 | # if (/([\w\/]+)\s*:([\/\w\-\+\.]+)\s+:((\s*\-\-\w*)*)$/)
|
---|
71 | if (/(\S+)\s*:(\S+)\s*:(\S+)\s*$/)
|
---|
72 | {
|
---|
73 | ($dir, $arch, $opt) = ($1, $2, $3);
|
---|
74 | chomp ($arch);
|
---|
75 | my @build=($dir, $arch, $opt);
|
---|
76 | push @ArrayofBuilds, [@build];
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 | print "What will be done:\n\n";
|
---|
83 | ($wert1,$wert2,$wert3)= ("BUILD_DIST","BUILD_MODE","Package");
|
---|
84 | $~="TABELLE";
|
---|
85 | write;
|
---|
86 | for my $i (0 .. $#ArrayofBuilds)
|
---|
87 | {
|
---|
88 | ($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][2],$ArrayofBuilds[$i][0]);
|
---|
89 | $~="TABELLE";
|
---|
90 | write;
|
---|
91 | }
|
---|
92 |
|
---|
93 | print 'Are all options OK? (y/n)';
|
---|
94 |
|
---|
95 | my $answer=<STDIN>;
|
---|
96 | chomp ($answer);
|
---|
97 | if ($answer ne "y") {die("canceled")};
|
---|
98 |
|
---|
99 | $ENV{'DEST_DIR'}=$BUILD_DEST_DIR;
|
---|
100 |
|
---|
101 | my $mypath;
|
---|
102 | for my $i (0 .. $#ArrayofBuilds)
|
---|
103 | {
|
---|
104 | print("$ArrayofBuilds[$i][0]\t\t$ArrayofBuilds[$i][1]\t\t$ArrayofBuilds[$i][2]\n");
|
---|
105 | $mypath = $src_root.$ArrayofBuilds[$i][0];
|
---|
106 |
|
---|
107 | if( $ArrayofBuilds[$i][2] && !$skipped_last )
|
---|
108 | {
|
---|
109 | $ENV{'BUILD_MODE'}=$ArrayofBuilds[$i][2];
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 | $ENV{'BUILD_MODE'}="--verify";
|
---|
114 | }
|
---|
115 | $ENV{'BUILD_DIST'}=$ArrayofBuilds[$i][1];
|
---|
116 |
|
---|
117 |
|
---|
118 | $_=$ArrayofBuilds[$i][0];
|
---|
119 | print "$_ \n";
|
---|
120 | tr/\//\_/;
|
---|
121 | `mkdir -p $BUILD_DEST_DIR`;
|
---|
122 | `mkdir -p $BUILD_DEST_DIR/log`;
|
---|
123 | my $logfilename = "$BUILD_DEST_DIR/log/$_$ArrayofBuilds[$i][1].log";
|
---|
124 |
|
---|
125 | my $build_cmd="cd $mypath && $build";
|
---|
126 |
|
---|
127 | # open a xterm to display build output
|
---|
128 | if ($opt_x)
|
---|
129 | {
|
---|
130 | system "xterm -T \"build log for PACKET: $mypath ARCH:$ArrayofBuilds[$i][1] \" -e less +F $logfilename &";
|
---|
131 | print "++++++++++++++++++++++++++++++++++++++++++\n";
|
---|
132 | }
|
---|
133 |
|
---|
134 | # if mypath is not a directory, so it is a .src.rpm (hopefully)
|
---|
135 | if( ! -d $mypath ) {
|
---|
136 | my $base = basename($mypath);
|
---|
137 | my $dir = dirname($mypath);
|
---|
138 | # TODO: find the src.rpm with the highest version/release number
|
---|
139 | $build_cmd = "cd $dir && $build $base-[0-9]*rpm";
|
---|
140 | }
|
---|
141 |
|
---|
142 | print "++++++++++++++++++++++++++++++++++++++++++\n";
|
---|
143 | print "BUILD_DIST: $ENV{'BUILD_DIST'}\n";
|
---|
144 | print "BUILD_MODE: $ENV{'BUILD_MODE'}\n";
|
---|
145 | print "executing build command:\n";
|
---|
146 | print "$build_cmd\n";
|
---|
147 |
|
---|
148 | my $do_log = open( LOG_FD, ">$logfilename" );
|
---|
149 | if( $do_log ) {
|
---|
150 | print "you can watch building with following command: \n";
|
---|
151 | print "less +F $logfilename\n\n";
|
---|
152 | } else {
|
---|
153 | print "could not open logfile $logfilename\n";
|
---|
154 | }
|
---|
155 | open( PIPE, "$build_cmd 2>&1 |" );
|
---|
156 | while( <PIPE> ) {
|
---|
157 | if( ! $opt_x ) {
|
---|
158 | print;
|
---|
159 | }
|
---|
160 | print LOG_FD if $do_log;
|
---|
161 | }
|
---|
162 | close PIPE; my $retval=$?>>8;
|
---|
163 | close LOG_FD if $do_log;
|
---|
164 |
|
---|
165 | if ( $retval == 0 ) {
|
---|
166 | $ArrayofBuilds[$i][3] = "OK";
|
---|
167 | print"****** ******\n";
|
---|
168 | print"****** building of $ArrayofBuilds[$i][0]: OK \n" ;
|
---|
169 | print"****** ******\n";
|
---|
170 | } elsif ( $retval == 1 ) {
|
---|
171 | $ArrayofBuilds[$i][3] = "skipped";
|
---|
172 | $skipped_last = 1;
|
---|
173 | } else {
|
---|
174 | $ArrayofBuilds[$i][3] = "*FAILED*";
|
---|
175 | print"****** ******\n";
|
---|
176 | print"\n\n\nERROR: building of $ArrayofBuilds[$i][0]: *FAILED*\n";
|
---|
177 | print"****** ******\n";
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | print "Building results:\n";
|
---|
182 |
|
---|
183 |
|
---|
184 |
|
---|
185 | ($wert1,$wert2,$wert3)= ("BUILD_DIST","Result","Package");
|
---|
186 | $~="TABELLE";
|
---|
187 | write;
|
---|
188 |
|
---|
189 | for my $i (0 .. $#ArrayofBuilds)
|
---|
190 | {
|
---|
191 | #($wert1,$wert2,$wert3)= ($ArrayofBuilds[$i][0],$ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3]);
|
---|
192 | ($wert1,$wert2,$wert3) = ($ArrayofBuilds[$i][1],$ArrayofBuilds[$i][3],$ArrayofBuilds[$i][0]);
|
---|
193 | $~="TABELLE";
|
---|
194 | write;
|
---|
195 | # print("$ArrayofBuilds[$i][0]:Result: $ArrayofBuilds[$i][3]");
|
---|
196 | }
|
---|
197 |
|
---|
198 | print "buildall.pl terminated\n";
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 | #
|
---|
204 | # generating install source
|
---|
205 | #
|
---|
206 |
|
---|
207 | if( $opt_d ) {
|
---|
208 |
|
---|
209 | my $INSTALL_SRC_DEST_DIR=$opt_d;
|
---|
210 | chomp $INSTALL_SRC_DEST_DIR;
|
---|
211 |
|
---|
212 | # create target directory
|
---|
213 | run_command( "mkdir -p $INSTALL_SRC_DEST_DIR" );
|
---|
214 | # copy skeletion to dest
|
---|
215 | run_command( "rsync -av $INSTALL_SRC_SKEL_DIR $INSTALL_SRC_DEST_DIR" );
|
---|
216 |
|
---|
217 | # copy build packages to dest
|
---|
218 | foreach my $i ( "i386", "i486", "i586", "i686", "noarch", "src" ) {
|
---|
219 | run_command( "mkdir -p $INSTALL_SRC_DEST_DIR/suse/$i" );
|
---|
220 | run_command( "rsync -av $BUILD_DEST_DIR/*/*.$i.rpm $INSTALL_SRC_DEST_DIR/suse/$i/" );
|
---|
221 | }
|
---|
222 |
|
---|
223 | # create_package_descr (do that has to run on target distribution?)
|
---|
224 | run_command( "cd $INSTALL_SRC_DEST_DIR/suse/; /usr/lib/YaST2/bin/create_package_descr -o $INSTALL_SRC_DEST_DIR/setup/descr" );
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | #
|
---|
229 | # functions
|
---|
230 | #
|
---|
231 |
|
---|
232 | # executes a command (single string).
|
---|
233 | # returns
|
---|
234 | # the returncode
|
---|
235 | # and (combined) stdout and stderr
|
---|
236 |
|
---|
237 | sub run_command
|
---|
238 | {
|
---|
239 | my $command = shift;
|
---|
240 |
|
---|
241 | print "executing command: " . $command . "\n";
|
---|
242 |
|
---|
243 | open(RESULT, $command . ' 2>&1 |' );
|
---|
244 | my @result = <RESULT>;
|
---|
245 | close(RESULT);
|
---|
246 | my $retcode = $?>>8;
|
---|
247 |
|
---|
248 | print @result;
|
---|
249 | if( $retcode ) { print "return code: " . $retcode . "\n"; }
|
---|
250 |
|
---|
251 | return($retcode, @result);
|
---|
252 | }
|
---|