1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Base subroutines for the Project-Builder project
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 |
|
---|
8 | package ProjectBuilder::Base;
|
---|
9 |
|
---|
10 | use strict;
|
---|
11 | use lib qw (lib);
|
---|
12 | use File::Basename;
|
---|
13 | use File::Path;
|
---|
14 | use File::Copy;
|
---|
15 | use File::Temp qw(tempdir);
|
---|
16 | use Data::Dumper;
|
---|
17 | use POSIX qw(strftime);
|
---|
18 | use Time::localtime qw(localtime);
|
---|
19 |
|
---|
20 | use ProjectBuilder::Changelog qw (pb_changelog);
|
---|
21 |
|
---|
22 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
23 |
|
---|
24 | use Exporter;
|
---|
25 |
|
---|
26 | # Export, by default, all the functions into the namespace of
|
---|
27 | # any code which uses this module.
|
---|
28 |
|
---|
29 | our $debug = 0;
|
---|
30 | our $LOG = \*STDOUT;
|
---|
31 |
|
---|
32 | our @ISA = qw(Exporter);
|
---|
33 | our @EXPORT = qw(pb_env_init pb_conf_read pb_conf_get pb_conf_get_if pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init pb_get_pkg $debug $LOG);
|
---|
34 |
|
---|
35 | $ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
|
---|
36 |
|
---|
37 | sub pb_env_init {
|
---|
38 |
|
---|
39 | my $proj=shift || undef;
|
---|
40 | my $pbinit=shift || undef;
|
---|
41 | my $ver;
|
---|
42 | my $tag;
|
---|
43 |
|
---|
44 | #
|
---|
45 | # Check project name
|
---|
46 | # Could be with env var PBPROJ
|
---|
47 | # or option -p
|
---|
48 | # if not define take the first in conf file
|
---|
49 | #
|
---|
50 | if ((defined $ENV{'PBPROJ'}) &&
|
---|
51 | (not (defined $proj))) {
|
---|
52 | $proj = $ENV{'PBPROJ'};
|
---|
53 | }
|
---|
54 |
|
---|
55 | #
|
---|
56 | # We get the pbconf file for that project
|
---|
57 | # and use its content
|
---|
58 | #
|
---|
59 | my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconf");
|
---|
60 | pb_log(2,"DEBUG pbconf: ".Dumper($pbconf)."\n");
|
---|
61 |
|
---|
62 | my %pbconf = %$pbconf;
|
---|
63 | if (not defined $proj) {
|
---|
64 | # Take the first as the default project
|
---|
65 | $proj = (keys %pbconf)[0];
|
---|
66 | if (defined $proj) {
|
---|
67 | pb_log(0,"WARNING: using $proj as default project as none has been specified\n");
|
---|
68 | pb_log(0," Please either create a pbconf reference for project $proj in $ENV{'PBETC'}\n");
|
---|
69 | pb_log(0," or call pb with the -p project option or use the env var PBPROJ\n");
|
---|
70 | pb_log(0," if you want to use another project\n");
|
---|
71 | }
|
---|
72 | }
|
---|
73 | die "No project defined - use env var PBPROJ or -p proj or a pbconf entry in $ENV{'PBETC'}" if (not (defined $proj));
|
---|
74 |
|
---|
75 | # That's always the environment variable that will be used
|
---|
76 | $ENV{'PBPROJ'} = $proj;
|
---|
77 | pb_log(2,"PBPROJ: $ENV{'PBPROJ'}\n");
|
---|
78 |
|
---|
79 | if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
|
---|
80 | die "Please create a pbconf reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
|
---|
81 | }
|
---|
82 |
|
---|
83 | #
|
---|
84 | # Detect the root dir for hosting all the content generated with pb
|
---|
85 | #
|
---|
86 | # Tree will look like this:
|
---|
87 | #
|
---|
88 | # maint pbdir PBDIR dev dir (optional) PBDEVDIR
|
---|
89 | # | |
|
---|
90 | # ------------------------ --------------------
|
---|
91 | # | | | |
|
---|
92 | # pbproj1 pbproj2 PBPROJ pbproj1 pbproj2 PBDEVPROJ
|
---|
93 | # | |
|
---|
94 | # --------------------------------------------- ----------
|
---|
95 | # * * | | | | * *
|
---|
96 | # 1.0 dev pbconf ... build delivery PBCONF dev tag PBDEVROOT
|
---|
97 | # | | PBDESTDIR |
|
---|
98 | # ------ pbrc PBBUILDDIR -------
|
---|
99 | # | | | |
|
---|
100 | # dev tag PBROOT 1.0 1.1
|
---|
101 | # |
|
---|
102 | # -------
|
---|
103 | # | |
|
---|
104 | # 1.0 1.1
|
---|
105 | # |
|
---|
106 | # ----------------------------------
|
---|
107 | # | | | |
|
---|
108 | # pkg1 pbproj1.pb pbfilter pbcl
|
---|
109 | # |
|
---|
110 | # -----------------
|
---|
111 | # | | |
|
---|
112 | # rpm deb pbfilter
|
---|
113 | #
|
---|
114 | #
|
---|
115 | # (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdir (when appropriate)
|
---|
116 | # Names under a pbproj and the corresponding pbconf should be similar
|
---|
117 | #
|
---|
118 |
|
---|
119 | my ($pbdir) = pb_conf_get_if("pbdir");
|
---|
120 | my %pbdir = %$pbdir;
|
---|
121 |
|
---|
122 | if (not defined $ENV{'PBDIR'}) {
|
---|
123 | if ((not defined $pbdir) || (not defined $pbdir{$ENV{'PBPROJ'}})) {
|
---|
124 | pb_log(0,"WARNING: no pbdir defined, using /var/cache\n");
|
---|
125 | pb_log(0," Please create a pbdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
|
---|
126 | pb_log(0," if you want to use another directory\n");
|
---|
127 | $ENV{'PBDIR'} = "/var/cache";
|
---|
128 | } else {
|
---|
129 | # That's always the environment variable that will be used
|
---|
130 | $ENV{'PBDIR'} = $pbdir{$ENV{'PBPROJ'}};
|
---|
131 | }
|
---|
132 | }
|
---|
133 | # Expand potential env variable in it
|
---|
134 | eval { $ENV{'PBDIR'} =~ s/(\$ENV.+\})/$1/eeg };
|
---|
135 |
|
---|
136 | pb_log(2,"PBDIR: $ENV{'PBDIR'}\n");
|
---|
137 | #
|
---|
138 | # Set delivery directory
|
---|
139 | #
|
---|
140 | $ENV{'PBDESTDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/delivery";
|
---|
141 |
|
---|
142 | pb_log(2,"PBDESTDIR: $ENV{'PBDESTDIR'}\n");
|
---|
143 | #
|
---|
144 | # Removes all directory existing below the delivery dir
|
---|
145 | # as they are temp dir only
|
---|
146 | # Files stay and have to be cleaned up manually if needed
|
---|
147 | # those files serves as communication channels between pb phases
|
---|
148 | # Removing them prevents a following phase to detect what has been done before
|
---|
149 | #
|
---|
150 | if (-d $ENV{'PBDESTDIR'}) {
|
---|
151 | opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
|
---|
152 | foreach my $d (readdir(DIR)) {
|
---|
153 | next if ($d =~ /^\./);
|
---|
154 | next if (-f "$ENV{'PBDESTDIR'}/$d");
|
---|
155 | pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
|
---|
156 | }
|
---|
157 | closedir(DIR);
|
---|
158 | }
|
---|
159 | if (! -d "$ENV{'PBDESTDIR'}") {
|
---|
160 | pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
|
---|
161 | }
|
---|
162 |
|
---|
163 | #
|
---|
164 | # Set build directory
|
---|
165 | #
|
---|
166 | $ENV{'PBBUILDDIR'}="$ENV{'PBDIR'}/$ENV{'PBPROJ'}/build";
|
---|
167 | if (! -d "$ENV{'PBBUILDDIR'}") {
|
---|
168 | pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
|
---|
169 | }
|
---|
170 |
|
---|
171 | pb_log(2,"PBBUILDDIR: $ENV{'PBBUILDDIR'}\n");
|
---|
172 | #
|
---|
173 | # Set temp directory
|
---|
174 | #
|
---|
175 | if (not defined $ENV{'TMPDIR'}) {
|
---|
176 | $ENV{'TMPDIR'}="/tmp";
|
---|
177 | }
|
---|
178 | $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
|
---|
179 | pb_log(2,"PBTMP: $ENV{'PBTMP'}\n");
|
---|
180 |
|
---|
181 | #
|
---|
182 | # Check pbconf compliance
|
---|
183 | #
|
---|
184 | $ENV{'PBCONF'} = "$ENV{'PBDIR'}/$ENV{'PBPROJ'}/pbconf";
|
---|
185 | pb_log(2,"PBCONF: $ENV{'PBCONF'}\n");
|
---|
186 |
|
---|
187 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
|
---|
188 |
|
---|
189 | if ((! -d "$ENV{'PBCONF'}") || (defined $pbinit)) {
|
---|
190 | pb_log(1,"Checking out pbconf\n");
|
---|
191 | pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
|
---|
192 | } else {
|
---|
193 | pb_log(1,"pbconf found, checking content\n");
|
---|
194 | my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBCONF'},"URL:");
|
---|
195 | my ($scheme2, $account2, $host2, $port2, $path2) = pb_get_uri($cmsurl);
|
---|
196 | if ($scheme2 ne $scheme) {
|
---|
197 | pb_log(1,"WARNING: Content of $ENV{'PBCONF'} irrelevant, cleaning up and checking it out\n");
|
---|
198 | pb_rm_rf("$ENV{'PBCONF'}");
|
---|
199 | pb_cms_checkout($scheme,$pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONF'});
|
---|
200 | } elsif ($cmsurl ne $pbconf{$ENV{'PBPROJ'}}) {
|
---|
201 | # The local content doesn't correpond to the repository
|
---|
202 | pb_log(0,"ERROR: Inconsistency detected:\n");
|
---|
203 | pb_log(0," * $ENV{'PBCONF'} refers to $cmsurl but\n");
|
---|
204 | pb_log(0," * $ENV{'PBETC'} refers to $pbconf{$ENV{'PBPROJ'}}\n");
|
---|
205 | die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
|
---|
206 | } else {
|
---|
207 | pb_log(1,"Content correct - doing nothing - you may want to update your repository however\n");
|
---|
208 | # they match - do nothing - there may be local changes
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | # Check where is our PBROOT (release tag name can't be guessed the first time)
|
---|
213 | if (not defined $ENV{'PBROOT'}) {
|
---|
214 | if (! -f ("$ENV{'PBDESTDIR'}/pbrc")) {
|
---|
215 | opendir(DIR,$ENV{'PBCONF'}) || die "Unable to open directory $ENV{'PBCONF'}: $!";
|
---|
216 | my $maxmtime = 0;
|
---|
217 | foreach my $d (readdir(DIR)) {
|
---|
218 | next if ($d =~ /^\./);
|
---|
219 | next if (! -d $d);
|
---|
220 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
|
---|
221 | = stat($d);
|
---|
222 | # Keep the most recent
|
---|
223 | pb_log(2,"Looking at $d: $mtime\n");
|
---|
224 | if ($mtime > $maxmtime) {
|
---|
225 | $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$d";
|
---|
226 | $maxmtime = $mtime;
|
---|
227 | }
|
---|
228 | }
|
---|
229 | closedir(DIR);
|
---|
230 | die "No directory found under $ENV{'PBCONF'}" if (not defined $ENV{'PBROOT'});
|
---|
231 | pb_log(0,"WARNING: no pbroot defined, using $ENV{'PBROOT'}\n");
|
---|
232 | pb_log(0," Please use -r release if you want to use another release\n");
|
---|
233 | } else {
|
---|
234 | my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
|
---|
235 | # That's always the environment variable that will be used
|
---|
236 | die "Please remove inconsistent $ENV{'PBDESTDIR'}/pbrc" if ((not defined $pbroot) || (not defined $pbroot->{$ENV{'PBPROJ'}}));
|
---|
237 | $ENV{'PBROOT'} = $pbroot->{$ENV{'PBPROJ'}};
|
---|
238 | }
|
---|
239 | } else {
|
---|
240 | # transform in full path if relative
|
---|
241 | $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$ENV{'PBROOT'}" if ($ENV{'PBROOT'} !~ /^\//);
|
---|
242 | die "$ENV{'PBROOT'} is not a directory" if (not -d $ENV{'PBROOT'});
|
---|
243 | }
|
---|
244 |
|
---|
245 | my %version = ();
|
---|
246 | my %defpkgdir = ();
|
---|
247 | my %extpkgdir = ();
|
---|
248 | my %filteredfiles = ();
|
---|
249 | my %supfiles = ();
|
---|
250 |
|
---|
251 | if ((-f "$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
|
---|
252 | # List of pkg to build by default (mandatory)
|
---|
253 | my ($defpkgdir) = pb_conf_get("defpkgdir");
|
---|
254 | # List of additional pkg to build when all is called (optional)
|
---|
255 | # Valid version names (optional)
|
---|
256 | # List of files to filter (optional)
|
---|
257 | # Project version and tag (optional)
|
---|
258 | my ($extpkgdir, $version, $filteredfiles, $supfiles, $pkgv, $pkgt) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles","projver","projtag");
|
---|
259 | pb_log(2,"DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n");
|
---|
260 | pb_log(2,"DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n");
|
---|
261 | pb_log(2,"DEBUG: version: ".Dumper($version)."\n");
|
---|
262 | pb_log(2,"DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n");
|
---|
263 | pb_log(2,"DEBUG: supfiles: ".Dumper($supfiles)."\n");
|
---|
264 | # Global
|
---|
265 | %defpkgdir = %$defpkgdir;
|
---|
266 | %extpkgdir = %$extpkgdir if (defined $extpkgdir);
|
---|
267 | %version = %$version if (defined $version);
|
---|
268 | %filteredfiles = %$filteredfiles if (defined $filteredfiles);
|
---|
269 | %supfiles = %$supfiles if (defined $supfiles);
|
---|
270 | #
|
---|
271 | # Get global Version/Tag
|
---|
272 | #
|
---|
273 | if (not defined $ENV{'PBVER'}) {
|
---|
274 | if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
|
---|
275 | $ENV{'PBVER'}=$pkgv->{$ENV{'PBPROJ'}};
|
---|
276 | } else {
|
---|
277 | die "No projver found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
278 | }
|
---|
279 | }
|
---|
280 | die "Invalid version name $ENV{'PBVER'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBVER'} =~ /$version{$ENV{'PBPROJ'}}/));
|
---|
281 |
|
---|
282 | if (not defined $ENV{'PBTAG'}) {
|
---|
283 | if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
|
---|
284 | $ENV{'PBTAG'}=$pkgt->{$ENV{'PBPROJ'}};
|
---|
285 | } else {
|
---|
286 | die "No projtag found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
287 | }
|
---|
288 | }
|
---|
289 | die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
|
---|
290 | } else {
|
---|
291 | if (defined $pbinit) {
|
---|
292 | my $ptr = pb_get_pkg();
|
---|
293 | my @pkgs = @$ptr;
|
---|
294 | @pkgs = ("pkg1") if (not @pkgs);
|
---|
295 |
|
---|
296 | open(CONF,"> $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
297 | print CONF << "EOF";
|
---|
298 | #
|
---|
299 | # Project Builder configuration file
|
---|
300 | # For project $ENV{'PBPROJ'}
|
---|
301 | #
|
---|
302 | # \$Id\$
|
---|
303 | #
|
---|
304 |
|
---|
305 | #
|
---|
306 | # What is the project URL
|
---|
307 | #
|
---|
308 | #pbproj $ENV{'PBPROJ'} = svn://svn.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
|
---|
309 | #pbproj $ENV{'PBPROJ'} = svn://svn+ssh.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
|
---|
310 | #pbproj $ENV{'PBPROJ'} = cvs://cvs.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
|
---|
311 | #pbproj $ENV{'PBPROJ'} = http://www.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
|
---|
312 | #pbproj $ENV{'PBPROJ'} = ftp://ftp.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
|
---|
313 | #pbproj $ENV{'PBPROJ'} = file:///src/$ENV{'PBPROJ'}-devel.tar.gz
|
---|
314 | #pbproj $ENV{'PBPROJ'} = dir:///src/$ENV{'PBPROJ'}-devel
|
---|
315 |
|
---|
316 | #
|
---|
317 | # Packager label
|
---|
318 | #
|
---|
319 | #packager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
|
---|
320 | #
|
---|
321 |
|
---|
322 | # For delivery to a machine by SSH (potentially the FTP server)
|
---|
323 | # Needs hostname, account and directory
|
---|
324 | #
|
---|
325 | #sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
|
---|
326 | #sshlogin $ENV{'PBPROJ'} = bill
|
---|
327 | #sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
|
---|
328 | #sshport $ENV{'PBPROJ'} = 22
|
---|
329 |
|
---|
330 | #
|
---|
331 | # For Virtual machines management
|
---|
332 | # Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
|
---|
333 | # followed by '_' and by release number
|
---|
334 | # a .vmtype extension will be added to the resulting string
|
---|
335 | # a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
|
---|
336 | #
|
---|
337 | #vmlist $ENV{'PBPROJ'} = mandrake_10.1,mandrake_10.2,mandriva_2006.0,mandriva_2007.0,mandriva_2007.1,mandriva_2008.0,redhat_7.3,redhat_9,fedora_4,fedora_5,fedora_6,fedora_7,rhel_3,rhel_4,rhel_5,suse_10.0,suse_10.1,suse_10.2,suse_10.3,sles_9,sles_10,gentoo_nover,debian_3.1,debian_4.0,ubuntu_6.06,ubuntu_7.04,ubuntu_7.10
|
---|
338 |
|
---|
339 | #
|
---|
340 | # Valid values for vmtype are
|
---|
341 | # qemu, (vmware, xen, ... TBD)
|
---|
342 | #vmtype $ENV{'PBPROJ'} = qemu
|
---|
343 |
|
---|
344 | # Hash for VM stuff on vmtype
|
---|
345 | #vmntp default = pool.ntp.org
|
---|
346 |
|
---|
347 | # We suppose we can commmunicate with the VM through SSH
|
---|
348 | #vmhost $ENV{'PBPROJ'} = localhost
|
---|
349 | #vmlogin $ENV{'PBPROJ'} = pb
|
---|
350 | #vmport $ENV{'PBPROJ'} = 2222
|
---|
351 |
|
---|
352 | # Timeout to wait when VM is launched/stopped
|
---|
353 | #vmtmout default = 120
|
---|
354 |
|
---|
355 | # per VMs needed paramaters
|
---|
356 | #vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
|
---|
357 | #vmpath $ENV{'PBPROJ'} = /home/qemu
|
---|
358 | #vmsize $ENV{'PBPROJ'} = 5G
|
---|
359 |
|
---|
360 | #
|
---|
361 | # Global version/tag for the project
|
---|
362 | #
|
---|
363 | #projver $ENV{'PBPROJ'} = devel
|
---|
364 | #projtag $ENV{'PBPROJ'} = 1
|
---|
365 |
|
---|
366 | # Hash of valid version names
|
---|
367 | #version $ENV{'PBPROJ'} = devel,stable
|
---|
368 |
|
---|
369 | # Adapt to your needs:
|
---|
370 | # Optional if you need to overwrite the global values above
|
---|
371 | #
|
---|
372 | EOF
|
---|
373 |
|
---|
374 | foreach my $pp (@pkgs) {
|
---|
375 | print CONF << "EOF";
|
---|
376 | #pkgver $pp = stable
|
---|
377 | #pkgtag $pp = 3
|
---|
378 | EOF
|
---|
379 | }
|
---|
380 | foreach my $pp (@pkgs) {
|
---|
381 | print CONF << "EOF";
|
---|
382 | # Hash of default package/package directory
|
---|
383 | #defpkgdir $pp = dir-$pp
|
---|
384 | EOF
|
---|
385 | }
|
---|
386 |
|
---|
387 | print CONF << "EOF";
|
---|
388 | # Hash of additional package/package directory
|
---|
389 | #extpkgdir minor-pkg = dir-minor-pkg
|
---|
390 |
|
---|
391 | # List of files per pkg on which to apply filters
|
---|
392 | # Files are mentioned relatively to pbroot/defpkgdir
|
---|
393 | EOF
|
---|
394 | foreach my $pp (@pkgs) {
|
---|
395 | print CONF << "EOF";
|
---|
396 | #filteredfiles $pp = Makefile.PL,configure.in,install.sh,$pp.8
|
---|
397 | #supfiles $pp = $pp.init
|
---|
398 | EOF
|
---|
399 | }
|
---|
400 | close(CONF);
|
---|
401 | pb_mkdir_p("$ENV{'PBROOT'}/pbfilter") || die "Unable to create $ENV{'PBROOT'}/pbfilter";
|
---|
402 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/all.pbf";
|
---|
403 | print CONF << "EOF";
|
---|
404 | #
|
---|
405 | # \$Id\$
|
---|
406 | #
|
---|
407 | # Filter for all files
|
---|
408 | #
|
---|
409 | # PBSRC is replaced by the source package format
|
---|
410 | #filter PBSRC = ftp://ftp.$ENV{'PBPROJ'}.org/src/%{name}-%{version}.tar.gz
|
---|
411 |
|
---|
412 | # PBVER is replaced by the version (\$pbver in code)
|
---|
413 | #filter PBVER = \$pbver
|
---|
414 |
|
---|
415 | # PBDATE is replaced by the date (\$pbdate in code)
|
---|
416 | #filter PBDATE = \$pbdate
|
---|
417 |
|
---|
418 | # PBLOG is replaced by the changelog if value is yes
|
---|
419 | #filter PBLOG = yes
|
---|
420 |
|
---|
421 | # PBTAG is replaced by the tag (\$pbtag in code)
|
---|
422 | #filter PBTAG = \$pbtag
|
---|
423 |
|
---|
424 | # PBREV is replaced by the revision (\$pbrev in code)
|
---|
425 | #filter PBREV = \$pbrev
|
---|
426 |
|
---|
427 | # PBPKG is replaced by the package name (\$pbpkg in code)
|
---|
428 | #filter PBPKG = \$pbpkg
|
---|
429 |
|
---|
430 | # PBPACKAGER is replaced by the packager name (\$pbpackager in code)
|
---|
431 | #filter PBPACKAGER = \$pbpackager
|
---|
432 |
|
---|
433 | # PBDESC contains the description of the package
|
---|
434 | #filter PBDESC = "Bla-Bla"
|
---|
435 |
|
---|
436 | # PBURL contains the URL of the Web site of the project
|
---|
437 | #filter PBURL = http://www.$ENV{'PBPROJ'}.org
|
---|
438 | EOF
|
---|
439 | close(CONF);
|
---|
440 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/rpm.pbf";
|
---|
441 | print CONF << "EOF";
|
---|
442 | #
|
---|
443 | # \$Id\$
|
---|
444 | #
|
---|
445 | # Filter for rpm build
|
---|
446 | #
|
---|
447 |
|
---|
448 | # PBGRP is replaced by the RPM group of apps
|
---|
449 | # Cf: http://fedoraproject.org/wiki/RPMGroups
|
---|
450 | #filter PBGRP = Applications/Archiving
|
---|
451 |
|
---|
452 | # PBLIC is replaced by the license of the application
|
---|
453 | # Cf: http://fedoraproject.org/wiki/Licensing
|
---|
454 | #filter PBLIC = GPL
|
---|
455 |
|
---|
456 | # PBDEP is replaced by the list of dependencies
|
---|
457 | #filter PBDEP =
|
---|
458 |
|
---|
459 | # PBSUF is replaced by the package name (\$pbpkg in code)
|
---|
460 | #filter PBSUF = \$pbsuf
|
---|
461 |
|
---|
462 | # PBOBS is replaced by the Obsolete line
|
---|
463 | #filter PBOBS =
|
---|
464 |
|
---|
465 | EOF
|
---|
466 | close(CONF);
|
---|
467 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/deb.pbf";
|
---|
468 | print CONF << "EOF";
|
---|
469 | #
|
---|
470 | # \$Id\$
|
---|
471 | #
|
---|
472 | # Filter for debian build
|
---|
473 | #
|
---|
474 | # PBGRP is replaced by the group of apps
|
---|
475 | #filter PBGRP = utils
|
---|
476 |
|
---|
477 | # PBLIC is replaced by the license of the application
|
---|
478 | # Cf:
|
---|
479 | #filter PBLIC = GPL
|
---|
480 |
|
---|
481 | # PBVER is replaced by the version (\$pbver in code)
|
---|
482 | #filter PBVER = \$pbver
|
---|
483 |
|
---|
484 | # PBDEP is replaced by the list of dependencies
|
---|
485 | #filter PBDEP =
|
---|
486 |
|
---|
487 | # PBSUG is replaced by the list of suggestions
|
---|
488 | #filter PBSUG =
|
---|
489 |
|
---|
490 | # PBREC is replaced by the list of recommandations
|
---|
491 | #filter PBREC =
|
---|
492 |
|
---|
493 | # PBLOG is replaced by the changelog if value is yes
|
---|
494 | #filter PBLOG = yes
|
---|
495 |
|
---|
496 | # PBPKG is replaced by the package name (\$pbpkg in code)
|
---|
497 | #filter PBPKG = \$pbpkg
|
---|
498 |
|
---|
499 | # PBPACKAGER is replaced by the packager name (\$pbpackager in code)
|
---|
500 | #filter PBPACKAGER = \$pbpackager
|
---|
501 |
|
---|
502 | EOF
|
---|
503 | close(CONF);
|
---|
504 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/md.pbf";
|
---|
505 | print CONF << "EOF";
|
---|
506 | # Specific group for Mandriva for $ENV{'PBPROJ'}
|
---|
507 | # Cf: http://wiki.mandriva.com/en/Development/Packaging/Groups
|
---|
508 | filter PBGRP = Archiving/Backup
|
---|
509 |
|
---|
510 | # PBLIC is replaced by the license of the application
|
---|
511 | # Cf: http://wiki.mandriva.com/en/Development/Packaging/Licenses
|
---|
512 | #filter PBLIC = GPL
|
---|
513 |
|
---|
514 | EOF
|
---|
515 | close(CONF);
|
---|
516 | open(CONF,"> $ENV{'PBROOT'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOT'}/pbfilter/novell.pbf";
|
---|
517 | print CONF << "EOF";
|
---|
518 | # Specific group for SuSE for $ENV{'PBPROJ'}
|
---|
519 | # Cf: http://en.opensuse.org/SUSE_Package_Conventions/RPM_Groups
|
---|
520 | filter PBGRP = Productivity/Archiving/Backup
|
---|
521 |
|
---|
522 | # PBLIC is replaced by the license of the application
|
---|
523 | # Cf: http://en.opensuse.org/Packaging/SUSE_Package_Conventions/RPM_Style#1.6._License_Tag
|
---|
524 | #filter PBLIC = GPL
|
---|
525 |
|
---|
526 | EOF
|
---|
527 | close(CONF);
|
---|
528 | foreach my $pp (@pkgs) {
|
---|
529 | pb_mkdir_p("$ENV{'PBROOT'}/$pp/deb") || die "Unable to create $ENV{'PBROOT'}/$pp/deb";
|
---|
530 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/control") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/control";
|
---|
531 | print CONF << "EOF";
|
---|
532 | Source: PBPKG
|
---|
533 | Section: PBGRP
|
---|
534 | Priority: optional
|
---|
535 | Maintainer: PBPACKAGER
|
---|
536 | Build-Depends: debhelper (>= 4.2.20), PBDEP
|
---|
537 | Standards-Version: 3.6.1
|
---|
538 |
|
---|
539 | Package: PBPKG
|
---|
540 | Architecture: amd64 i386 ia64
|
---|
541 | Section: PBGRP
|
---|
542 | Priority: optional
|
---|
543 | Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
|
---|
544 | Recommends: PBREC
|
---|
545 | Suggests: PBSUG
|
---|
546 | Description:
|
---|
547 | PBDESC
|
---|
548 | .
|
---|
549 | Homepage: PBURL
|
---|
550 |
|
---|
551 | EOF
|
---|
552 | close(CONF);
|
---|
553 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/copyright") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/copyright";
|
---|
554 | print CONF << "EOF";
|
---|
555 | This package is debianized by PBPACKAGER
|
---|
556 | `date`
|
---|
557 |
|
---|
558 | The current upstream source was downloaded from
|
---|
559 | ftp://ftp.$ENV{'PBPROJ'}.org/src/.
|
---|
560 |
|
---|
561 | Upstream Authors: Put their name here
|
---|
562 |
|
---|
563 | Copyright:
|
---|
564 |
|
---|
565 | This package is free software; you can redistribute it and/or modify
|
---|
566 | it under the terms of the GNU General Public License as published by
|
---|
567 | the Free Software Foundation; version 2 dated June, 1991.
|
---|
568 |
|
---|
569 | This package is distributed in the hope that it will be useful,
|
---|
570 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
571 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
572 | GNU General Public License for more details.
|
---|
573 |
|
---|
574 | You should have received a copy of the GNU General Public License
|
---|
575 | along with this package; if not, write to the Free Software
|
---|
576 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
|
---|
577 | MA 02110-1301, USA.
|
---|
578 |
|
---|
579 | On Debian systems, the complete text of the GNU General
|
---|
580 | Public License can be found in /usr/share/common-licenses/GPL.
|
---|
581 |
|
---|
582 | EOF
|
---|
583 | close(CONF);
|
---|
584 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/changelog") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/changelog";
|
---|
585 | print CONF << "EOF";
|
---|
586 | PBLOG
|
---|
587 | EOF
|
---|
588 | close(CONF);
|
---|
589 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/compat") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/compat";
|
---|
590 | print CONF << "EOF";
|
---|
591 | 4
|
---|
592 | EOF
|
---|
593 | close(CONF);
|
---|
594 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/pkg1.dirs") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/$pp.dirs";
|
---|
595 | print CONF << "EOF";
|
---|
596 | EOF
|
---|
597 | close(CONF);
|
---|
598 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/$pp.docs") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/$pp.docs";
|
---|
599 | print CONF << "EOF";
|
---|
600 | INSTALL
|
---|
601 | COPYING
|
---|
602 | AUTHORS
|
---|
603 | NEWS
|
---|
604 | README
|
---|
605 | EOF
|
---|
606 | close(CONF);
|
---|
607 | open(CONF,"> $ENV{'PBROOT'}/$pp/deb/rules") || die "Unable to create $ENV{'PBROOT'}/$pp/deb/rules";
|
---|
608 | print CONF << 'EOF';
|
---|
609 | #!/usr/bin/make -f
|
---|
610 | # -*- makefile -*-
|
---|
611 | # Sample debian/rules that uses debhelper.
|
---|
612 | # GNU copyright 1997 to 1999 by Joey Hess.
|
---|
613 | #
|
---|
614 | # $Id$
|
---|
615 | #
|
---|
616 |
|
---|
617 | # Uncomment this to turn on verbose mode.
|
---|
618 | #export DH_VERBOSE=1
|
---|
619 |
|
---|
620 | # Define package name variable for a one-stop change.
|
---|
621 | PACKAGE_NAME = PBPKG
|
---|
622 |
|
---|
623 | # These are used for cross-compiling and for saving the configure script
|
---|
624 | # from having to guess our platform (since we know it already)
|
---|
625 | DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
|
---|
626 | DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
|
---|
627 |
|
---|
628 | CFLAGS = -Wall -g
|
---|
629 |
|
---|
630 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
|
---|
631 | CFLAGS += -O0
|
---|
632 | else
|
---|
633 | CFLAGS += -O2
|
---|
634 | endif
|
---|
635 | ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
|
---|
636 | INSTALL_PROGRAM += -s
|
---|
637 | endif
|
---|
638 | config.status: configure
|
---|
639 | dh_testdir
|
---|
640 |
|
---|
641 | # Configure the package.
|
---|
642 | CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
|
---|
643 | --mandir=\$${prefix}/share/man
|
---|
644 |
|
---|
645 | # Build both architecture dependent and independent
|
---|
646 | build: build-arch build-indep
|
---|
647 |
|
---|
648 | # Build architecture dependent
|
---|
649 | build-arch: build-arch-stamp
|
---|
650 |
|
---|
651 | build-arch-stamp: config.status
|
---|
652 | dh_testdir
|
---|
653 |
|
---|
654 | # Compile the package.
|
---|
655 | $(MAKE)
|
---|
656 |
|
---|
657 | touch build-stamp
|
---|
658 |
|
---|
659 | # Build architecture independent
|
---|
660 | build-indep: build-indep-stamp
|
---|
661 |
|
---|
662 | build-indep-stamp: config.status
|
---|
663 | # Nothing to do, the only indep item is the manual which is available as html in original source
|
---|
664 | touch build-indep-stamp
|
---|
665 |
|
---|
666 | # Clean up
|
---|
667 | clean:
|
---|
668 | dh_testdir
|
---|
669 | dh_testroot
|
---|
670 | rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
|
---|
671 | # Clean temporary document directory
|
---|
672 | rm -rf debian/doc-temp
|
---|
673 | # Clean up.
|
---|
674 | -$(MAKE) distclean
|
---|
675 | rm -f config.log
|
---|
676 | ifneq "$(wildcard /usr/share/misc/config.sub)" ""
|
---|
677 | cp -f /usr/share/misc/config.sub config.sub
|
---|
678 | endif
|
---|
679 | ifneq "$(wildcard /usr/share/misc/config.guess)" ""
|
---|
680 | cp -f /usr/share/misc/config.guess config.guess
|
---|
681 | endif
|
---|
682 |
|
---|
683 | dh_clean
|
---|
684 |
|
---|
685 | # Install architecture dependent and independent
|
---|
686 | install: install-arch install-indep
|
---|
687 |
|
---|
688 | # Install architecture dependent
|
---|
689 | install-arch: build-arch
|
---|
690 | dh_testdir
|
---|
691 | dh_testroot
|
---|
692 | dh_clean -k -s
|
---|
693 | dh_installdirs -s
|
---|
694 |
|
---|
695 | # Install the package files into build directory:
|
---|
696 | # - start with upstream make install
|
---|
697 | $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/us
|
---|
698 | r/share/man
|
---|
699 | # - copy html manual to temporary location for renaming
|
---|
700 | mkdir -p debian/doc-temp
|
---|
701 | dh_install -s
|
---|
702 |
|
---|
703 | # Install architecture independent
|
---|
704 | install-indep: build-indep
|
---|
705 | dh_testdir
|
---|
706 | dh_testroot
|
---|
707 | dh_clean -k -i
|
---|
708 | dh_installdirs -i
|
---|
709 | dh_install -i
|
---|
710 |
|
---|
711 | # Must not depend on anything. This is to be called by
|
---|
712 | # binary-arch/binary-indep
|
---|
713 | # in another 'make' thread.
|
---|
714 | binary-common:
|
---|
715 | dh_testdir
|
---|
716 | dh_testroot
|
---|
717 | dh_installchangelogs ChangeLog
|
---|
718 | dh_installdocs
|
---|
719 | dh_installman
|
---|
720 | dh_link
|
---|
721 | dh_strip
|
---|
722 | dh_compress
|
---|
723 | dh_fixperms
|
---|
724 | dh_installdeb
|
---|
725 | dh_shlibdeps
|
---|
726 | dh_gencontrol
|
---|
727 | dh_md5sums
|
---|
728 | dh_builddeb
|
---|
729 |
|
---|
730 | # Build architecture independant packages using the common target.
|
---|
731 | binary-indep: build-indep install-indep
|
---|
732 | $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
|
---|
733 |
|
---|
734 | # Build architecture dependant packages using the common target.
|
---|
735 | binary-arch: build-arch install-arch
|
---|
736 | $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
|
---|
737 |
|
---|
738 | # Build architecture depdendent and independent packages
|
---|
739 | binary: binary-arch binary-indep
|
---|
740 | .PHONY: clean binary
|
---|
741 |
|
---|
742 | EOF
|
---|
743 | close(CONF);
|
---|
744 | pb_mkdir_p("$ENV{'PBROOT'}/$pp/rpm") || die "Unable to create $ENV{'PBROOT'}/$pp/rpm";
|
---|
745 | open(CONF,"> $ENV{'PBROOT'}/$pp/rpm/$pp.spec") || die "Unable to create $ENV{'PBROOT'}/$pp/rpm/$pp.spec";
|
---|
746 | print CONF << 'EOF';
|
---|
747 | #
|
---|
748 | # $Id$
|
---|
749 | #
|
---|
750 |
|
---|
751 | Summary: bla-bla
|
---|
752 | Summary(fr): french bla-bla
|
---|
753 |
|
---|
754 | Name: PBPKG
|
---|
755 | Version: PBVER
|
---|
756 | Release: PBTAGPBSUF
|
---|
757 | License: PBLIC
|
---|
758 | Group: PBGRP
|
---|
759 | Url: PBURL
|
---|
760 | Source: PBSRC
|
---|
761 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
|
---|
762 | Requires: PBDEP
|
---|
763 |
|
---|
764 | %description
|
---|
765 | PBDESC
|
---|
766 |
|
---|
767 | %description -l fr
|
---|
768 | french desc
|
---|
769 |
|
---|
770 | %prep
|
---|
771 | %setup -q
|
---|
772 |
|
---|
773 | %build
|
---|
774 | %configure
|
---|
775 | make %{?_smp_mflags}
|
---|
776 |
|
---|
777 | %install
|
---|
778 | %{__rm} -rf $RPM_BUILD_ROOT
|
---|
779 | make DESTDIR=$RPM_BUILD_ROOT install
|
---|
780 |
|
---|
781 | %clean
|
---|
782 | %{__rm} -rf $RPM_BUILD_ROOT
|
---|
783 |
|
---|
784 | %files
|
---|
785 | %defattr(-,root,root)
|
---|
786 | %doc ChangeLog
|
---|
787 | %doc INSTALL COPYING README AUTHORS NEWS
|
---|
788 |
|
---|
789 | %changelog
|
---|
790 | PBLOG
|
---|
791 |
|
---|
792 | EOF
|
---|
793 | close(CONF);
|
---|
794 | pb_mkdir_p("$ENV{'PBROOT'}/$pp/pbfilter") || die "Unable to create $ENV{'PBROOT'}/$pp/pbfilter";
|
---|
795 |
|
---|
796 | pb_log(0,"\nDo not to forget to commit the pbconf directory in your CMS if needed\n");
|
---|
797 | }
|
---|
798 | } else {
|
---|
799 | die "Unable to open $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
|
---|
800 | }
|
---|
801 | }
|
---|
802 | umask 0022;
|
---|
803 | return(\%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
|
---|
804 | }
|
---|
805 |
|
---|
806 | # Internal mkdir -p function
|
---|
807 | sub pb_mkdir_p {
|
---|
808 | my @dir = @_;
|
---|
809 | my $ret = mkpath(@dir, 0, 0755);
|
---|
810 | return($ret);
|
---|
811 | }
|
---|
812 |
|
---|
813 | # Internal rm -rf function
|
---|
814 | sub pb_rm_rf {
|
---|
815 | my @dir = @_;
|
---|
816 | my $ret = rmtree(@dir, 0, 0);
|
---|
817 | return($ret);
|
---|
818 | }
|
---|
819 |
|
---|
820 | # Internal system function
|
---|
821 | sub pb_system {
|
---|
822 |
|
---|
823 | my $cmd=shift;
|
---|
824 | my $cmt=shift || $cmd;
|
---|
825 |
|
---|
826 | pb_log(0,"$cmt... ");
|
---|
827 | #system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
|
---|
828 | system($cmd);
|
---|
829 | if ($? == -1) {
|
---|
830 | pb_log(0,"failed to execute ($cmd) : $!\n");
|
---|
831 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
832 | } elsif ($? & 127) {
|
---|
833 | pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
|
---|
834 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
835 | } elsif ($? == 0) {
|
---|
836 | pb_log(0,"OK\n");
|
---|
837 | } else {
|
---|
838 | pb_log(0, "child ($cmd) exited with value ".($? >> 8)."\n");
|
---|
839 | pb_display_file("$ENV{'PBTMP'}/system.log");
|
---|
840 | }
|
---|
841 | }
|
---|
842 |
|
---|
843 | sub pb_display_file {
|
---|
844 |
|
---|
845 | my $file=shift;
|
---|
846 |
|
---|
847 | return if (not -f $file);
|
---|
848 | open(FILE,"$file");
|
---|
849 | while (<FILE>) {
|
---|
850 | print $_;
|
---|
851 | }
|
---|
852 | close(FILE);
|
---|
853 | }
|
---|
854 |
|
---|
855 | # Function which returns a pointer on a table
|
---|
856 | # corresponding to a set of values queried in the conf file
|
---|
857 | # and test the returned vaue as they need to exist in that case
|
---|
858 | sub pb_conf_get {
|
---|
859 |
|
---|
860 | my @param = @_;
|
---|
861 | my @return = pb_conf_get_if(@param);
|
---|
862 |
|
---|
863 | die "No params found for $ENV{'PBPROJ'}" if (not @return);
|
---|
864 |
|
---|
865 | foreach my $i (0..$#param) {
|
---|
866 | die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $return[$i]);
|
---|
867 | }
|
---|
868 | return(@return);
|
---|
869 | }
|
---|
870 |
|
---|
871 | # Function which returns a pointer on a table
|
---|
872 | # corresponding to a set of values queried in the conf file
|
---|
873 | # Those value may be undef if they do not exist
|
---|
874 | sub pb_conf_get_if {
|
---|
875 |
|
---|
876 | my @param = @_;
|
---|
877 |
|
---|
878 | # Everything is returned via ptr1
|
---|
879 | my @ptr1 = ();
|
---|
880 | my @ptr2 = ();
|
---|
881 | @ptr1 = pb_conf_read_if("$ENV{'PBETC'}", @param) if (defined $ENV{'PBETC'});
|
---|
882 | @ptr2 = pb_conf_read_if("$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb", @param) if ((defined $ENV{'PBROOT'}) and (defined $ENV{'PBPROJ'}));
|
---|
883 |
|
---|
884 | my $p1;
|
---|
885 | my $p2;
|
---|
886 |
|
---|
887 | pb_log(2,"DEBUG: param1: ".Dumper(@ptr1)."\n");
|
---|
888 | pb_log(2,"DEBUG: param2: ".Dumper(@ptr2)."\n");
|
---|
889 |
|
---|
890 | foreach my $i (0..$#param) {
|
---|
891 | $p1 = $ptr1[$i];
|
---|
892 | $p2 = $ptr2[$i];
|
---|
893 | # Always try to take the param from the home dir conf file in priority
|
---|
894 | # in order to mask what could be defined under the CMS to allow for overloading
|
---|
895 | if (not defined $p2) {
|
---|
896 | # No ref in CMS project conf file so use the home dir one.
|
---|
897 | $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (not defined $p1->{$ENV{'PBPROJ'}});
|
---|
898 | } else {
|
---|
899 | # Ref found in CMS project conf file
|
---|
900 | if (not defined $p1) {
|
---|
901 | # No ref in home dir project conf file so use the CMS one.
|
---|
902 | $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if (not defined $p2->{$ENV{'PBPROJ'}});
|
---|
903 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
904 | } else {
|
---|
905 | # Both are defined - handling the overloading
|
---|
906 | if (not defined $p1->{'default'}) {
|
---|
907 | if (defined $p2->{'default'}) {
|
---|
908 | $p1->{'default'} = $p2->{'default'};
|
---|
909 | }
|
---|
910 | }
|
---|
911 |
|
---|
912 | if (not defined $p1->{$ENV{'PBPROJ'}}) {
|
---|
913 | if (defined $p2->{$ENV{'PBPROJ'}}) {
|
---|
914 | $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
|
---|
915 | } else {
|
---|
916 | $p1->{$ENV{'PBPROJ'}} = $p1->{'default'};
|
---|
917 | }
|
---|
918 | }
|
---|
919 | }
|
---|
920 | }
|
---|
921 | $ptr1[$i] = $p1;
|
---|
922 | pb_log(2,"DEBUG: param ptr1: ".Dumper(@ptr1)."\n");
|
---|
923 | }
|
---|
924 | return(@ptr1);
|
---|
925 | }
|
---|
926 |
|
---|
927 | # Function which returns a pointer on a hash
|
---|
928 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
929 | # if that conf file doesn't exist returns undef
|
---|
930 | sub pb_conf_read_if {
|
---|
931 |
|
---|
932 | my $conffile = shift;
|
---|
933 | my @param = @_;
|
---|
934 |
|
---|
935 | open(CONF,$conffile) || return((undef));
|
---|
936 | close(CONF);
|
---|
937 | return(pb_conf_read($conffile,@param));
|
---|
938 | }
|
---|
939 |
|
---|
940 | # Function which returns a pointer on a hash
|
---|
941 | # corresponding to a declaration (arg2) in a conf file (arg1)
|
---|
942 | sub pb_conf_read {
|
---|
943 |
|
---|
944 | my $conffile = shift;
|
---|
945 | my @param = @_;
|
---|
946 | my $trace;
|
---|
947 | my @ptr;
|
---|
948 | my %h;
|
---|
949 |
|
---|
950 | open(CONF,$conffile) || die "Unable to open $conffile";
|
---|
951 | while(<CONF>) {
|
---|
952 | if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
|
---|
953 | pb_log(2,"DEBUG: 1:$1 2:$2 3:$3\n");
|
---|
954 | $h{$1}{$2}=$3;
|
---|
955 | }
|
---|
956 | }
|
---|
957 | close(CONF);
|
---|
958 |
|
---|
959 | for my $param (@param) {
|
---|
960 | push @ptr,$h{$param};
|
---|
961 | }
|
---|
962 | pb_log(2,"DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n");
|
---|
963 | return(@ptr);
|
---|
964 | }
|
---|
965 |
|
---|
966 | # Analyze a url passed and return protocol, account, password, server, port, path
|
---|
967 | sub pb_get_uri {
|
---|
968 |
|
---|
969 | my $uri = shift || undef;
|
---|
970 |
|
---|
971 | pb_log(2,"DEBUG: uri:$uri\n");
|
---|
972 | # A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
|
---|
973 | # Cf man URI
|
---|
974 | my ($scheme, $authority, $path, $query, $fragment) =
|
---|
975 | $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?| if (defined $uri);
|
---|
976 | my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?| if (defined $authority);
|
---|
977 |
|
---|
978 | $scheme = "" if (not defined $scheme);
|
---|
979 | $authority = "" if (not defined $authority);
|
---|
980 | $path = "" if (not defined $path);
|
---|
981 | $account = "" if (not defined $account);
|
---|
982 | $host = "" if (not defined $host);
|
---|
983 | $port = "" if (not defined $port);
|
---|
984 |
|
---|
985 | pb_log(2,"DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n");
|
---|
986 | return($scheme, $account, $host, $port, $path);
|
---|
987 | }
|
---|
988 |
|
---|
989 |
|
---|
990 | # Setup environment for CMS system for URL passed
|
---|
991 | sub pb_cms_init {
|
---|
992 |
|
---|
993 | my $proj = shift || undef;
|
---|
994 |
|
---|
995 | # Use the project URI
|
---|
996 | my ($uri) = pb_conf_get("pburl");
|
---|
997 |
|
---|
998 | # Extract values from that URI
|
---|
999 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri->{$ENV{'PBPROJ'}});
|
---|
1000 |
|
---|
1001 | if ($scheme =~ /^svn/) {
|
---|
1002 | $ENV{'PBREVISION'}= pb_cms_getinfo($scheme,$uri->{$ENV{'PBPROJ'}},"Revision:");
|
---|
1003 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBDEVDIR'}" ; svnversion .)`;
|
---|
1004 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
1005 | } elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
1006 | $ENV{'PBREVISION'}="flat";
|
---|
1007 | $ENV{'PBCMSLOGFILE'}="flat.log";
|
---|
1008 | } elsif ($scheme eq "cvs") {
|
---|
1009 | # Way too slow
|
---|
1010 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
1011 | #chomp($ENV{'PBREVISION'});
|
---|
1012 | $ENV{'PBREVISION'}="CVS";
|
---|
1013 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
1014 | #
|
---|
1015 | # Export content if needed
|
---|
1016 | #
|
---|
1017 | my ($cvsrsh) = pb_conf_get_if("cvsrsh");
|
---|
1018 | $ENV{'CVS_RSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
|
---|
1019 | } else {
|
---|
1020 | die "cms $scheme unknown";
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | #
|
---|
1024 | #if (not defined $scheme) {
|
---|
1025 | # We're an upstream guy
|
---|
1026 | # Try to make it easy for us
|
---|
1027 | #pb_log(2,"WARNING: Assuming a local project under $ENV{'PBDIR'}/$ENV{'PBPROJ'}:\n");
|
---|
1028 | #pb_log(2," If not, pleaase setup a pbproj entry in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb\n");
|
---|
1029 | #return("");
|
---|
1030 | #}
|
---|
1031 |
|
---|
1032 | return($scheme,$uri->{$ENV{'PBPROJ'}});
|
---|
1033 | }
|
---|
1034 |
|
---|
1035 | sub pb_get_date {
|
---|
1036 |
|
---|
1037 | return(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | sub pb_cms_export {
|
---|
1041 |
|
---|
1042 | my $uri = shift;
|
---|
1043 | my $source = shift;
|
---|
1044 | my $destdir = shift;
|
---|
1045 | my $tmp;
|
---|
1046 | my $tmp1;
|
---|
1047 |
|
---|
1048 | my @date = pb_get_date();
|
---|
1049 | # If it's not flat, then we have a real uri as source
|
---|
1050 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
1051 |
|
---|
1052 | if ($scheme eq "svn") {
|
---|
1053 | if (-d $source) {
|
---|
1054 | $tmp = $destdir;
|
---|
1055 | } else {
|
---|
1056 | $tmp = $destdir."/".basename($source);
|
---|
1057 | }
|
---|
1058 | pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
|
---|
1059 | } elsif ($scheme eq "dir") {
|
---|
1060 | if (-d $source) {
|
---|
1061 | $tmp = $destdir;
|
---|
1062 | } else {
|
---|
1063 | $tmp = $destdir."/".basename($source);
|
---|
1064 | }
|
---|
1065 | pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
|
---|
1066 | } elsif (($scheme eq "http") || ($scheme eq "ftp")) {
|
---|
1067 | my $f = basename($path);
|
---|
1068 | unlink "$ENV{'PBTMP'}/$f";
|
---|
1069 | if (-x "/usr/bin/wget") {
|
---|
1070 | pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri","Downloading $uri with wget to $ENV{'PBTMP'}/$f\n");
|
---|
1071 | } elsif (-x "/usr/bin/curl") {
|
---|
1072 | pb_system("/usr/bin/curl $uri -o $ENV{'PBTMP'}/$f","Downloading $uri with curl to $ENV{'PBTMP'}/$f\n");
|
---|
1073 | } else {
|
---|
1074 | die "Unable to download $uri.\nNo wget/curl available, please install one of those";
|
---|
1075 | }
|
---|
1076 | pb_cms_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
|
---|
1077 | } elsif ($scheme eq "file") {
|
---|
1078 | use File::MimeInfo;
|
---|
1079 | my $mm = mimetype($path);
|
---|
1080 | pb_log(2,"mimetype: $mm\n");
|
---|
1081 |
|
---|
1082 | if ($mm =~ /\/x-bzip-compressed-tar$/) {
|
---|
1083 | # tar+bzip2
|
---|
1084 | } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
|
---|
1085 | # tar+lzma
|
---|
1086 | } elsif ($mm =~ /\/x-compressed-tar$/) {
|
---|
1087 | # tar+gzip
|
---|
1088 | } elsif ($mm =~ /\/x-tar$/) {
|
---|
1089 | # tar
|
---|
1090 | } elsif ($mm =~ /\/zip$/) {
|
---|
1091 | # zip
|
---|
1092 | }
|
---|
1093 | pb_log(0,"scheme file not implemented yet\n");
|
---|
1094 | } elsif ($scheme eq "cvs") {
|
---|
1095 | my $dir=dirname($destdir);
|
---|
1096 | my $base=basename($destdir);
|
---|
1097 | if (-d $source) {
|
---|
1098 | $tmp1 = $source;
|
---|
1099 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
1100 | } else {
|
---|
1101 | $tmp1 = dirname($source);
|
---|
1102 | $tmp1 =~ s|$ENV{'PBROOT'}/||;
|
---|
1103 | $tmp1 = $tmp1."/".basename($source);
|
---|
1104 | }
|
---|
1105 | # CVS needs a relative path !
|
---|
1106 | my ($cvsroot) = pb_conf_get("cvsroot");
|
---|
1107 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
1108 | pb_system("cd $dir ; cvs -d $cvsroot->{$ENV{'PBPROJ'}} export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
|
---|
1109 | } else {
|
---|
1110 | die "cms $scheme unknown";
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 |
|
---|
1115 | sub pb_create_authors {
|
---|
1116 |
|
---|
1117 | my $authors=shift;
|
---|
1118 | my $dest=shift;
|
---|
1119 | my $scheme=shift;
|
---|
1120 |
|
---|
1121 | return if ($authors eq "/dev/null");
|
---|
1122 | open(SAUTH,$authors) || die "Unable to open $authors";
|
---|
1123 | open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
|
---|
1124 | print DAUTH "Authors of the project are:\n";
|
---|
1125 | print DAUTH "===========================\n";
|
---|
1126 | while (<SAUTH>) {
|
---|
1127 | my ($nick,$gcos) = split(/:/);
|
---|
1128 | chomp($gcos);
|
---|
1129 | print DAUTH "$gcos";
|
---|
1130 | if (defined $scheme) {
|
---|
1131 | print DAUTH " ($nick under $scheme)\n";
|
---|
1132 | } else {
|
---|
1133 | print DAUTH "\n";
|
---|
1134 | }
|
---|
1135 | }
|
---|
1136 | close(DAUTH);
|
---|
1137 | close(SAUTH);
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | sub pb_cms_log {
|
---|
1141 | my $scheme = shift;
|
---|
1142 | my $pkgdir = shift;
|
---|
1143 | my $dest = shift;
|
---|
1144 | my $chglog = shift;
|
---|
1145 | my $authors = shift;
|
---|
1146 |
|
---|
1147 | pb_create_authors($authors,$dest,$scheme);
|
---|
1148 |
|
---|
1149 | if ($scheme eq "svn") {
|
---|
1150 | if (! -f "$dest/ChangeLog") {
|
---|
1151 | if (-x "/usr/bin/svn2cl") {
|
---|
1152 | pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
|
---|
1153 | } else {
|
---|
1154 | # To be written from pbcl
|
---|
1155 | pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
|
---|
1156 | }
|
---|
1157 | }
|
---|
1158 | } elsif ($scheme eq "flat") {
|
---|
1159 | if (! -f "$dest/ChangeLog") {
|
---|
1160 | pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
|
---|
1161 | }
|
---|
1162 | } elsif ($scheme eq "cvs") {
|
---|
1163 | my $tmp=basename($pkgdir);
|
---|
1164 | # CVS needs a relative path !
|
---|
1165 | if (! -f "$dest/ChangeLog") {
|
---|
1166 | if (-x "/usr/bin/cvs2cl") {
|
---|
1167 | pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
|
---|
1168 | } else {
|
---|
1169 | # To be written from pbcl
|
---|
1170 | pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
|
---|
1171 | }
|
---|
1172 | }
|
---|
1173 | } else {
|
---|
1174 | die "cms $scheme unknown";
|
---|
1175 | }
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | sub pb_cms_getinfo {
|
---|
1179 |
|
---|
1180 | my $scheme = shift;
|
---|
1181 | my $dir = shift;
|
---|
1182 | my $info = shift || "URL:";
|
---|
1183 |
|
---|
1184 | my $res = "";
|
---|
1185 | my $void = "";
|
---|
1186 |
|
---|
1187 | if ($scheme =~ /^svn/) {
|
---|
1188 | open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
|
---|
1189 | while (<PIPE>) {
|
---|
1190 | ($void,$res) = split(/^$info/) if (/^$info/);
|
---|
1191 | }
|
---|
1192 | $res =~ s/^\s*//;
|
---|
1193 | close(PIPE);
|
---|
1194 | chomp($res);
|
---|
1195 | } elsif ($scheme eq "flat") {
|
---|
1196 | } elsif ($scheme eq "cvs") {
|
---|
1197 | } else {
|
---|
1198 | die "cms $scheme unknown";
|
---|
1199 | }
|
---|
1200 | pb_log(2,"Found CMS info: $res\n");
|
---|
1201 | return($res);
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 | sub pb_cms_copy {
|
---|
1205 | my $scheme = shift;
|
---|
1206 | my $oldurl = shift;
|
---|
1207 | my $newurl = shift;
|
---|
1208 |
|
---|
1209 | if ($scheme eq "svn") {
|
---|
1210 | pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
|
---|
1211 | } elsif ($scheme eq "flat") {
|
---|
1212 | } elsif ($scheme eq "cvs") {
|
---|
1213 | } else {
|
---|
1214 | die "cms $scheme unknown";
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | sub pb_cms_checkout {
|
---|
1219 | my $scheme = shift;
|
---|
1220 | my $url = shift;
|
---|
1221 | my $destination = shift;
|
---|
1222 |
|
---|
1223 | if ($scheme =~ /^svn/) {
|
---|
1224 | pb_system("svn co $url $destination","Checking $url to $destination ");
|
---|
1225 | } elsif ($scheme eq "flat") {
|
---|
1226 | } elsif ($scheme eq "cvs") {
|
---|
1227 | } else {
|
---|
1228 | die "cms $scheme unknown";
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 |
|
---|
1232 | sub pb_cms_checkin {
|
---|
1233 | my $scheme = shift;
|
---|
1234 | my $dir = shift;
|
---|
1235 |
|
---|
1236 | my $ver = basename($dir);
|
---|
1237 | if ($scheme eq "svn") {
|
---|
1238 | pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
|
---|
1239 | pb_system("svn up $dir","Updating $dir");
|
---|
1240 | } elsif ($scheme eq "flat") {
|
---|
1241 | } elsif ($scheme eq "cvs") {
|
---|
1242 | } else {
|
---|
1243 | die "cms $scheme unknown";
|
---|
1244 | }
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | sub pb_cms_isdiff {
|
---|
1248 | my $scheme = shift;
|
---|
1249 |
|
---|
1250 | if ($scheme eq "svn") {
|
---|
1251 | open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
|
---|
1252 | my $l = 0;
|
---|
1253 | while (<PIPE>) {
|
---|
1254 | $l++;
|
---|
1255 | }
|
---|
1256 | return($l);
|
---|
1257 | } elsif ($scheme eq "flat") {
|
---|
1258 | } elsif ($scheme eq "cvs") {
|
---|
1259 | } else {
|
---|
1260 | die "cms $scheme unknown";
|
---|
1261 | }
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | # Get all filters to apply
|
---|
1265 | # They're cumulative from less specific to most specific
|
---|
1266 | # suffix is .pbf
|
---|
1267 |
|
---|
1268 | sub pb_get_filters {
|
---|
1269 |
|
---|
1270 | my @ffiles;
|
---|
1271 | my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
|
---|
1272 | my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
|
---|
1273 | my $pbpkg = shift || die "No package specified";
|
---|
1274 | my $dtype = shift || "";
|
---|
1275 | my $dfam = shift || "";
|
---|
1276 | my $ddir = shift || "";
|
---|
1277 | my $dver = shift || "";
|
---|
1278 | my $ptr; # returned value pointer on the hash of filters
|
---|
1279 | my %ptr;
|
---|
1280 | my %h;
|
---|
1281 |
|
---|
1282 | # Global filter files first, then package specificities
|
---|
1283 | if (-d "$ENV{'PBROOT'}/pbfilter") {
|
---|
1284 | $mfile00 = "$ENV{'PBROOT'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/all.pbf");
|
---|
1285 | $mfile0 = "$ENV{'PBROOT'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dtype.pbf");
|
---|
1286 | $mfile1 = "$ENV{'PBROOT'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$dfam.pbf");
|
---|
1287 | $mfile2 = "$ENV{'PBROOT'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir.pbf");
|
---|
1288 | $mfile3 = "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/pbfilter/$ddir-$dver.pbf");
|
---|
1289 |
|
---|
1290 | push @ffiles,$mfile00 if (defined $mfile00);
|
---|
1291 | push @ffiles,$mfile0 if (defined $mfile0);
|
---|
1292 | push @ffiles,$mfile1 if (defined $mfile1);
|
---|
1293 | push @ffiles,$mfile2 if (defined $mfile2);
|
---|
1294 | push @ffiles,$mfile3 if (defined $mfile3);
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | if (-d "$ENV{'PBROOT'}/$pbpkg/pbfilter") {
|
---|
1298 | $ffile00 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/all.pbf");
|
---|
1299 | $ffile0 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dtype.pbf");
|
---|
1300 | $ffile1 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$dfam.pbf");
|
---|
1301 | $ffile2 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir.pbf");
|
---|
1302 | $ffile3 = "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOT'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
|
---|
1303 |
|
---|
1304 | push @ffiles,$ffile00 if (defined $ffile00);
|
---|
1305 | push @ffiles,$ffile0 if (defined $ffile0);
|
---|
1306 | push @ffiles,$ffile1 if (defined $ffile1);
|
---|
1307 | push @ffiles,$ffile2 if (defined $ffile2);
|
---|
1308 | push @ffiles,$ffile3 if (defined $ffile3);
|
---|
1309 | }
|
---|
1310 | if (@ffiles) {
|
---|
1311 | pb_log(2,"DEBUG ffiles: ".Dumper(\@ffiles)."\n");
|
---|
1312 |
|
---|
1313 | foreach my $f (@ffiles) {
|
---|
1314 | open(CONF,$f) || next;
|
---|
1315 | while(<CONF>) {
|
---|
1316 | if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
|
---|
1317 | $h{$1}{$2}=$3;
|
---|
1318 | }
|
---|
1319 | }
|
---|
1320 | close(CONF);
|
---|
1321 |
|
---|
1322 | $ptr = $h{"filter"};
|
---|
1323 | pb_log(2,"DEBUG f:".Dumper($ptr)."\n");
|
---|
1324 | }
|
---|
1325 | } else {
|
---|
1326 | $ptr = { };
|
---|
1327 | }
|
---|
1328 | %ptr = %$ptr;
|
---|
1329 | return(\%ptr);
|
---|
1330 | }
|
---|
1331 |
|
---|
1332 | # Function which applies filter on pb build files
|
---|
1333 | sub pb_filter_file_pb {
|
---|
1334 |
|
---|
1335 | my $f=shift;
|
---|
1336 | my $ptr=shift;
|
---|
1337 | my %filter=%$ptr;
|
---|
1338 | my $destfile=shift;
|
---|
1339 | my $dtype=shift;
|
---|
1340 | my $pbsuf=shift;
|
---|
1341 | my $pbproj=shift;
|
---|
1342 | my $pbpkg=shift;
|
---|
1343 | my $pbver=shift;
|
---|
1344 | my $pbtag=shift;
|
---|
1345 | my $pbrev=shift;
|
---|
1346 | my $pbdate=shift;
|
---|
1347 | my $defpkgdir = shift;
|
---|
1348 | my $extpkgdir = shift;
|
---|
1349 | my $pbpackager = shift;
|
---|
1350 | my $chglog = shift || undef;
|
---|
1351 |
|
---|
1352 | pb_log(2,"DEBUG: From $f to $destfile\n");
|
---|
1353 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
1354 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
1355 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
1356 | while (<FILE>) {
|
---|
1357 | my $line = $_;
|
---|
1358 | foreach my $s (keys %filter) {
|
---|
1359 | # Process single variables
|
---|
1360 | pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
|
---|
1361 | my $tmp = $filter{$s};
|
---|
1362 | next if (not defined $tmp);
|
---|
1363 | # Expand variables if any single one found
|
---|
1364 | pb_log(2,"DEBUG tmp: $tmp\n");
|
---|
1365 | if ($tmp =~ /\$/) {
|
---|
1366 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
1367 | # special case for ChangeLog only for pb
|
---|
1368 | } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
|
---|
1369 | my $p = $defpkgdir->{$pbpkg};
|
---|
1370 | $p = $extpkgdir->{$pbpkg} if (not defined $p);
|
---|
1371 | pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
|
---|
1372 | $tmp = "";
|
---|
1373 | }
|
---|
1374 | $line =~ s|$s|$tmp|;
|
---|
1375 | }
|
---|
1376 | print DEST $line;
|
---|
1377 | }
|
---|
1378 | close(FILE);
|
---|
1379 | close(DEST);
|
---|
1380 | }
|
---|
1381 |
|
---|
1382 | # Function which applies filter on files (external call)
|
---|
1383 | sub pb_filter_file_inplace {
|
---|
1384 |
|
---|
1385 | my $ptr=shift;
|
---|
1386 | my %filter=%$ptr;
|
---|
1387 | my $destfile=shift;
|
---|
1388 | my $pbproj=shift;
|
---|
1389 | my $pbpkg=shift;
|
---|
1390 | my $pbver=shift;
|
---|
1391 | my $pbtag=shift;
|
---|
1392 | my $pbrev=shift;
|
---|
1393 | my $pbdate=shift;
|
---|
1394 | my $pbpackager=shift;
|
---|
1395 |
|
---|
1396 | my $cp = "$ENV{'PBTMP'}/".basename($destfile);
|
---|
1397 | copy($destfile,$cp) || die "Unable to create $cp";
|
---|
1398 |
|
---|
1399 | pb_filter_file($cp,$ptr,$destfile,$pbproj,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
|
---|
1400 | unlink $cp;
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | # Function which applies filter on files (external call)
|
---|
1404 | sub pb_filter_file {
|
---|
1405 |
|
---|
1406 | my $f=shift;
|
---|
1407 | my $ptr=shift;
|
---|
1408 | my %filter=%$ptr;
|
---|
1409 | my $destfile=shift;
|
---|
1410 | my $pbproj=shift;
|
---|
1411 | my $pbpkg=shift;
|
---|
1412 | my $pbver=shift;
|
---|
1413 | my $pbtag=shift;
|
---|
1414 | my $pbrev=shift;
|
---|
1415 | my $pbdate=shift;
|
---|
1416 | my $pbpackager=shift;
|
---|
1417 |
|
---|
1418 | pb_log(2,"DEBUG: From $f to $destfile\n");
|
---|
1419 | pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
|
---|
1420 | open(DEST,"> $destfile") || die "Unable to create $destfile";
|
---|
1421 | open(FILE,"$f") || die "Unable to open $f: $!";
|
---|
1422 | while (<FILE>) {
|
---|
1423 | my $line = $_;
|
---|
1424 | foreach my $s (keys %filter) {
|
---|
1425 | # Process single variables
|
---|
1426 | pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
|
---|
1427 | my $tmp = $filter{$s};
|
---|
1428 | next if (not defined $tmp);
|
---|
1429 | # Expand variables if any single one found
|
---|
1430 | if ($tmp =~ /\$/) {
|
---|
1431 | eval { $tmp =~ s/(\$\w+)/$1/eeg };
|
---|
1432 | }
|
---|
1433 | $line =~ s|$s|$tmp|;
|
---|
1434 | }
|
---|
1435 | print DEST $line;
|
---|
1436 | }
|
---|
1437 | close(FILE);
|
---|
1438 | close(DEST);
|
---|
1439 | }
|
---|
1440 |
|
---|
1441 | sub pb_log_init {
|
---|
1442 |
|
---|
1443 | $debug = shift || 0;
|
---|
1444 | $LOG = shift || \*STDOUT;
|
---|
1445 |
|
---|
1446 | }
|
---|
1447 |
|
---|
1448 | sub pb_log {
|
---|
1449 |
|
---|
1450 | my $dlevel = shift;
|
---|
1451 | my $msg = shift;
|
---|
1452 |
|
---|
1453 | print $LOG "$msg" if ($dlevel <= $debug);
|
---|
1454 | }
|
---|
1455 |
|
---|
1456 | #
|
---|
1457 | # Return the list of packages we are working on
|
---|
1458 | #
|
---|
1459 | sub pb_get_pkg {
|
---|
1460 |
|
---|
1461 | my @pkgs = ();
|
---|
1462 | my $defpkgdir = shift || undef;
|
---|
1463 | my $extpkgdir = shift || undef;
|
---|
1464 |
|
---|
1465 | # Get packages list
|
---|
1466 | if (not defined $ARGV[0]) {
|
---|
1467 | @pkgs = keys %$defpkgdir if (defined $defpkgdir);
|
---|
1468 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
1469 | @pkgs = keys %$defpkgdir if (defined $defpkgdir);
|
---|
1470 | push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
|
---|
1471 | } else {
|
---|
1472 | @pkgs = @ARGV;
|
---|
1473 | }
|
---|
1474 | pb_log(0,"Packages: ".join(',',@pkgs)."\n");
|
---|
1475 | return(\@pkgs);
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | 1;
|
---|