source: ProjectBuilder/devel/pb/lib/ProjectBuilder/Base.pm@ 287

Last change on this file since 287 was 287, checked in by Bruno Cornec, 16 years ago
  • Fix build process for new pb functions on changelogs
  • Fix bugs in newproj where project wasn't always used (some fixed pb were remaining)
File size: 31.2 KB
Line 
1#!/usr/bin/perl -w
2#
3# Base subroutines for the Project-Builder project
4#
5# $Id$
6#
7
8use strict;
9use lib qw (lib);
10use File::Basename;
11use File::Path;
12use File::Temp qw /tempdir/;
13use AppConfig qw(ARGCOUNT_HASH);
14use Data::Dumper;
15
16use ProjectBuilder::Changelog qw (pb_changelog);
17
18$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
19
20sub pb_env_init {
21
22my $proj=shift || undef;
23my $pbinit=shift || undef;
24my $ver;
25my $tag;
26
27# For the moment not dynamic
28my $debug = 0; # Debug level
29my $LOG = *STDOUT; # Where to log
30
31#
32# Check project name
33# Could be with env var PBPROJ
34# or option -p
35# if not define take the first in conf file
36#
37if ((defined $ENV{'PBPROJ'}) &&
38 (not (defined $proj))) {
39 $proj = $ENV{'PBPROJ'};
40}
41
42#
43# We get the pbrc file for that project
44# and use its content
45#
46my ($pbrc) = pb_conf_read("$ENV{'PBETC'}","pbrc");
47print "DEBUG pbrc: ".Dumper($pbrc)."\n" if ($debug >= 1);
48
49my %pbrc = %$pbrc;
50if (not defined $proj) {
51 # Take the first as the default project
52 $proj = (keys %pbrc)[0];
53 print $LOG "Using $proj as default project as none has been specified\n" if (($debug >= 0) and (defined $proj));
54}
55die "No project defined - use env var PBPROJ or -p proj" if (not (defined $proj));
56
57#
58# Set delivery directory
59#
60if (not defined ($pbrc{$proj})) {
61 die "Please create a pbrc reference for project $proj in $ENV{'PBETC'}\n";
62}
63
64my $topdir=dirname($pbrc{$proj});
65# Expand potential env variable in it
66eval { $topdir =~ s/(\$ENV.+\})/$1/eeg };
67chdir $topdir || die "Unable to change directory to $topdir";
68$pbrc{$proj} = $topdir."/pbrc";
69$ENV{'PBDESTDIR'}=$topdir."/delivery";
70
71#
72# Use project configuration file if needed
73#
74if (not defined $ENV{'PBROOT'}) {
75 if (-f $pbrc{$proj}) {
76 my ($pbroot) = pb_conf_read($pbrc{$proj},"pbroot");
77 my %pbroot = %$pbroot;
78 # All lines should point to the same pbroot so take the first
79 $ENV{'PBROOT'} = (values %$pbroot)[0] if (defined $pbroot);
80 print $LOG "Using $ENV{'PBROOT'} as default pbroot from $pbrc{$proj}\n" if (($debug >= 0) and (defined $ENV{'PBROOT'}));
81 }
82 die "No pbroot defined - use env var PBROOT or -r pbroot " if (not defined $ENV{'PBROOT'});
83}
84
85#
86# Check pb conf compliance
87#
88$ENV{'PBCONF'} = "$ENV{'PBROOT'}/pbconf";
89if (defined $pbinit) {
90 print $LOG "Creating $ENV{'PBCONF'} directory\n";
91 pb_mkdir_p("$ENV{'PBCONF'}");
92 }
93die "Project $proj not Project-Builder compliant. Please populate $ENV{'PBCONF'}" if ( not -d "$ENV{'PBCONF'}");
94
95my %version = ();
96my %defpkgdir = ();
97my %extpkgdir = ();
98my %filteredfiles = ();
99
100if ((-f "$ENV{'PBCONF'}/$proj.pb") and (not defined $pbinit)) {
101 # List of pkg to build by default (mandatory)
102 # List of additional pkg to build when all is called (optional)
103 # Valid version names (optional)
104 # List of files to filter (optional)
105 my ($defpkgdir, $extpkgdir, $version, $filteredfiles, $pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$proj.pb","defpkgdir","extpkgdir","version","filteredfiles","projver","projtag");
106 print "DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n" if ($debug >= 1);
107 print "DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n" if ($debug >= 1);
108 print "DEBUG: version: ".Dumper($version)."\n" if ($debug >= 1);
109 print "DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n" if ($debug >= 1);
110 die "Unable to find defpkgdir in $ENV{'PBCONF'}/$proj.pb" if (not defined $defpkgdir);
111 # Global
112 %defpkgdir = %$defpkgdir;
113 # Global
114 %extpkgdir = %$extpkgdir if (defined $extpkgdir);
115 %version = %$version if (defined $version);
116 # Global
117 %filteredfiles = %$filteredfiles if (defined $filteredfiles);
118 #
119 # Get global Version/Tag
120 #
121
122 if (not defined $ENV{'PBVER'}) {
123 if ((defined $pkgv) && (defined $pkgv->{$proj})) {
124 $ENV{'PBVER'}=$pkgv->{$proj};
125 } else {
126 die "No projver found in $ENV{'PBCONF'}/$proj.pb";
127 }
128 }
129 die "Invalid version name $ENV{'PBVER'} in $ENV{'PBCONF'}/$proj.pb" if (($ENV{'PBVER'} !~ /[0-9.]+/) && (not exists $version{$ENV{'PBVER'}}));
130
131 if (not defined $ENV{'PBTAG'}) {
132 if ((defined $pkgt) && (defined $pkgt->{$proj})) {
133 $ENV{'PBTAG'}=$pkgt->{$proj};
134 } else {
135 die "No projtag found in $ENV{'PBCONF'}/$proj.pb";
136 }
137 }
138 die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBCONF'}/$proj.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
139} else {
140 if (defined $pbinit) {
141 open(CONF,"> $ENV{'PBCONF'}/$proj.pb") || die "Unable to create $ENV{'PBCONF'}/$proj.pb";
142 print CONF << "EOF";
143#
144# Project Builder configuration file
145# For project $proj
146#
147# \$Id\$
148#
149
150#
151# Which CMS system is used (Subversion, CVS or tar file content extracted)
152#
153#cms $proj = svn
154#cms $proj = cvs
155#cms $proj = flat
156
157#
158# Packager label
159#
160#packager $proj = "William Porte <bill\@$proj.org>"
161#
162
163# For delivery to a machine by SSH (potentially the FTP server)
164# Needs hostname, account and directory
165#
166#sshhost $proj = www.$proj.org
167#sshlogin $proj = bill
168#sshdir $proj = /$proj/ftp
169#sshport $proj = 22
170
171#
172# For Virtual machines management
173# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
174# followed by '_' and by release number
175# a .vmtype extension will be added to the resulting string
176# a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
177#
178#vmlist $proj = 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
179
180#
181# Valid values for vmtype are
182# qemu, (vmware, xen, ... TBD)
183#vmtype $proj = qemu
184
185# Hash for VM stuff on vmtype
186#vmntp default = pool.ntp.org
187
188# We suppose we can commmunicate with the VM through SSH
189#vmhost $proj = localhost
190#vmlogin $proj = pb
191#vmport $proj = 2222
192
193# Timeout to wait when VM is launched/stopped
194#vmtmout default = 120
195
196# per VMs needed paramaters
197#vmopt $proj = -m 384 -daemonize
198#vmpath $proj = /home/qemu
199#vmsize $proj = 5G
200
201#
202# Global version/tag for the project
203#
204#projver $proj = devel
205#projtag $proj = 1
206
207# Adapt to your needs:
208# Optional if you need to overwrite the global values above
209#
210#pkgver pkg1 = stable
211#pkgtag pkg1 = 3
212#pkgver nil
213#pkgtag nil
214
215# Hash of default package/package directory
216#defpkgdir pkg1 = pkg1dir
217
218# Hash of additional package/package directory
219#extpkgdir pkg1-doc = pkg1-docdir
220
221# Hash of valid version names
222#version devel
223#version stable
224
225# List of files per pkg on which to apply filters
226# Files are mentioned relatively to pbroot/defpkgdir
227#filteredfiles pkg1 = Makefile.PL
228#filteredfiles pkg1-doc = configure.in
229EOF
230 close(CONF);
231 pb_mkdir_p("$ENV{'PBCONF'}/pbfilter") || die "Unable to create $ENV{'PBCONF'}/pbfilter";
232 open(CONF,"> $ENV{'PBCONF'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/all.pbf";
233 print CONF << "EOF";
234#
235# \$Id\$
236#
237# Filter for all files
238#
239# PBSRC is replaced by the source package format
240#filter PBSRC = ftp://ftp.$proj.org/src/%{name}-%{version}.tar.gz
241
242# PBVER is replaced by the version (\$pbver in code)
243#filter PBVER = \$pbver
244
245# PBDATE is replaced by the date (\$pbdate in code)
246#filter PBDATE = \$pbdate
247
248# PBLOG is replaced by the changelog if value is yes
249#filter PBLOG = yes
250
251# PBTAG is replaced by the tag (\$pbtag in code)
252#filter PBTAG = \$pbtag
253
254# PBREV is replaced by the revision (\$pbrev in code)
255#filter PBREV = \$pbrev
256
257# PBPKG is replaced by the package name (\$pbpkg in code)
258#filter PBPKG = \$pbpkg
259
260# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
261#filter PBPACKAGER = \$pbpackager
262
263# PBDESC contains the description of the package
264#filter PBDESC = "Bla-Bla"
265
266# PBURL contains the URL of the Web site of the project
267#filter PBURL = http://www.$proj.org
268EOF
269 close(CONF);
270 open(CONF,"> $ENV{'PBCONF'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/rpm.pbf";
271 print CONF << "EOF";
272#
273# \$Id\$
274#
275# Filter for rpm build
276#
277
278# PBGRP is replaced by the RPM group of apps
279#filter PBGRP = Applications/Archiving
280
281# PBDEP is replaced by the list of dependencies
282#filter PBDEP =
283
284# PBSUF is replaced by the package name (\$pbpkg in code)
285#filter PBSUF = \$pbsuf
286
287# PBOBS is replaced by the Obsolete line
288#filter PBOBS =
289
290EOF
291 close(CONF);
292 open(CONF,"> $ENV{'PBCONF'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/deb.pbf";
293 print CONF << "EOF";
294#
295# \$Id\$
296#
297# Filter for debian build
298#
299# PBGRP is replaced by the group of apps
300#filter PBGRP = utils
301
302# PBVER is replaced by the version (\$pbver in code)
303#filter PBVER = \$pbver
304
305# PBDEP is replaced by the list of dependencies
306#filter PBDEP =
307
308# PBSUG is replaced by the list of suggestions
309#filter PBSUG =
310
311# PBREC is replaced by the list of recommandations
312#filter PBREC =
313
314# PBLOG is replaced by the changelog if value is yes
315#filter PBLOG = yes
316
317# PBPKG is replaced by the package name (\$pbpkg in code)
318#filter PBPKG = \$pbpkg
319
320# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
321#filter PBPACKAGER = \$pbpackager
322
323EOF
324 close(CONF);
325 open(CONF,"> $ENV{'PBCONF'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/md.pbf";
326 print CONF << "EOF";
327# Specific group for Mandriva for $proj
328filter PBGRP = Archiving/Backup
329EOF
330 close(CONF);
331 open(CONF,"> $ENV{'PBCONF'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBCONF'}/pbfilter/novell.pbf";
332 print CONF << "EOF";
333# Specific group for SuSE for $proj
334filter PBGRP = Productivity/Archiving/Backup
335EOF
336 close(CONF);
337 pb_mkdir_p("$ENV{'PBCONF'}/pkg1/deb") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb";
338 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/control") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/control";
339 print CONF << "EOF";
340Source: PBPKG
341Section: PBGRP
342Priority: optional
343Maintainer: PBPACKAGER
344Build-Depends: debhelper (>= 4.2.20), PBDEP
345Standards-Version: 3.6.1
346
347Package: PBPKG
348Architecture: amd64 i386 ia64
349Section: PBGRP
350Priority: optional
351Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
352Recommends: PBREC
353Suggests: PBSUG
354Description:
355 PBDESC
356 .
357 Homepage: PBURL
358
359EOF
360 close(CONF);
361 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/copyright") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/copyright";
362 print CONF << "EOF";
363This package is debianized by PBPACKAGER
364`date`
365
366The current upstream source was downloaded from
367ftp://ftp.$proj.org/src/.
368
369Upstream Authors: Put their name here
370
371Copyright:
372
373 This package is free software; you can redistribute it and/or modify
374 it under the terms of the GNU General Public License as published by
375 the Free Software Foundation; version 2 dated June, 1991.
376
377 This package is distributed in the hope that it will be useful,
378 but WITHOUT ANY WARRANTY; without even the implied warranty of
379 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
380 GNU General Public License for more details.
381
382 You should have received a copy of the GNU General Public License
383 along with this package; if not, write to the Free Software
384 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
385 MA 02110-1301, USA.
386
387On Debian systems, the complete text of the GNU General
388Public License can be found in /usr/share/common-licenses/GPL.
389
390EOF
391 close(CONF);
392 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/changelog") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/changelog";
393 print CONF << "EOF";
394PBLOG
395EOF
396 close(CONF);
397 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/compat") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/compat";
398 print CONF << "EOF";
3994
400EOF
401 close(CONF);
402 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/pkg1.dirs") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/pkg1.dirs";
403 print CONF << "EOF";
404EOF
405 close(CONF);
406 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/pkg1.docs") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/pkg1.docs";
407 print CONF << "EOF";
408INSTALL
409COPYING
410AUTHORS
411NEWS
412README
413EOF
414 close(CONF);
415 open(CONF,"> $ENV{'PBCONF'}/pkg1/deb/rules") || die "Unable to create $ENV{'PBCONF'}/pkg1/deb/rules";
416 print CONF << 'EOF';
417#!/usr/bin/make -f
418# -*- makefile -*-
419# Sample debian/rules that uses debhelper.
420# GNU copyright 1997 to 1999 by Joey Hess.
421#
422# $Id$
423#
424
425# Uncomment this to turn on verbose mode.
426#export DH_VERBOSE=1
427
428# Define package name variable for a one-stop change.
429PACKAGE_NAME = PBPKG
430
431# These are used for cross-compiling and for saving the configure script
432# from having to guess our platform (since we know it already)
433DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
434DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
435
436CFLAGS = -Wall -g
437
438ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
439 CFLAGS += -O0
440else
441 CFLAGS += -O2
442endif
443ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
444 INSTALL_PROGRAM += -s
445endif
446config.status: configure
447 dh_testdir
448
449 # Configure the package.
450 CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
451 --mandir=\$${prefix}/share/man
452
453# Build both architecture dependent and independent
454build: build-arch build-indep
455
456# Build architecture dependent
457build-arch: build-arch-stamp
458
459build-arch-stamp: config.status
460 dh_testdir
461
462 # Compile the package.
463 $(MAKE)
464
465 touch build-stamp
466
467# Build architecture independent
468build-indep: build-indep-stamp
469
470build-indep-stamp: config.status
471 # Nothing to do, the only indep item is the manual which is available as html in original source
472 touch build-indep-stamp
473
474# Clean up
475clean:
476 dh_testdir
477 dh_testroot
478 rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
479 # Clean temporary document directory
480 rm -rf debian/doc-temp
481 # Clean up.
482 -$(MAKE) distclean
483 rm -f config.log
484ifneq "$(wildcard /usr/share/misc/config.sub)" ""
485 cp -f /usr/share/misc/config.sub config.sub
486endif
487ifneq "$(wildcard /usr/share/misc/config.guess)" ""
488 cp -f /usr/share/misc/config.guess config.guess
489endif
490
491 dh_clean
492
493# Install architecture dependent and independent
494install: install-arch install-indep
495
496# Install architecture dependent
497install-arch: build-arch
498 dh_testdir
499 dh_testroot
500 dh_clean -k -s
501 dh_installdirs -s
502
503 # Install the package files into build directory:
504 # - start with upstream make install
505 $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/us
506r/share/man
507 # - copy html manual to temporary location for renaming
508 mkdir -p debian/doc-temp
509 dh_install -s
510
511# Install architecture independent
512install-indep: build-indep
513 dh_testdir
514 dh_testroot
515 dh_clean -k -i
516 dh_installdirs -i
517 dh_install -i
518
519# Must not depend on anything. This is to be called by
520# binary-arch/binary-indep
521# in another 'make' thread.
522binary-common:
523 dh_testdir
524 dh_testroot
525 dh_installchangelogs ChangeLog
526 dh_installdocs
527 dh_installman
528 dh_link
529 dh_strip
530 dh_compress
531 dh_fixperms
532 dh_installdeb
533 dh_shlibdeps
534 dh_gencontrol
535 dh_md5sums
536 dh_builddeb
537
538# Build architecture independant packages using the common target.
539binary-indep: build-indep install-indep
540 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
541
542# Build architecture dependant packages using the common target.
543binary-arch: build-arch install-arch
544 $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
545
546# Build architecture depdendent and independent packages
547binary: binary-arch binary-indep
548.PHONY: clean binary
549
550EOF
551 close(CONF);
552 pb_mkdir_p("$ENV{'PBCONF'}/pkg1/rpm") || die "Unable to create $ENV{'PBCONF'}/pkg1/rpm";
553 open(CONF,"> $ENV{'PBCONF'}/pkg1/rpm/pkg1.spec") || die "Unable to create $ENV{'PBCONF'}/pkg1/rpm/pkg1.spec";
554 print CONF << 'EOF';
555#
556# $Id$
557#
558
559Summary: bla-bla
560Summary(fr): french bla-bla
561
562Name: PBPKG
563Version: PBVER
564Release: PBTAGPBSUF
565License: GPL
566Group: PBGRP
567Url: PBURL
568Source: PBSRC
569BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
570Requires: PBDEP
571
572%description
573PBDESC
574
575%description -l fr
576french desc
577
578%prep
579%setup -q
580
581%build
582%configure
583make %{?_smp_mflags} VERSION=%{version}
584
585%install
586%{__rm} -rf $RPM_BUILD_ROOT
587make DESTDIR=$RPM_BUILD_ROOT install
588
589%clean
590%{__rm} -rf $RPM_BUILD_ROOT
591
592%files
593%defattr(-,root,root)
594%doc ChangeLog
595%doc INSTALL COPYING README AUTHORS NEWS
596
597%changelog
598PBLOG
599
600EOF
601 close(CONF);
602 pb_mkdir_p("$ENV{'PBCONF'}/pkg1/pbfilter") || die "Unable to create $ENV{'PBCONF'}/pkg1/pbfilter";
603
604 print "\nDo not to forget to commit the pbconf directory in your CMS if needed\n";
605 print "After having renamed the pkg1 directory to your package's name \n\n";
606 } else {
607 die "Unable to open $ENV{'PBCONF'}/$proj.pb";
608 }
609}
610
611#
612# Set temp directory
613#
614if (not defined $ENV{'TMPDIR'}) {
615 $ENV{'TMPDIR'}="/tmp";
616}
617$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
618
619#
620# Removes all directory existing below the delivery dir
621# as they are temp dir only
622# Files stay and have to be cleaned up manually
623#
624if (-d $ENV{'PBDESTDIR'}) {
625 opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
626 foreach my $d (readdir(DIR)) {
627 next if ($d =~ /^\./);
628 next if (-f "$ENV{'PBDESTDIR'}/$d");
629 pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
630 }
631 closedir(DIR);
632}
633if (! -d "$ENV{'PBDESTDIR'}") {
634 pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
635}
636
637#
638# Set build directory
639#
640$ENV{'PBBUILDDIR'}=$topdir."/build";
641if (! -d "$ENV{'PBBUILDDIR'}") {
642 pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
643}
644
645umask 0022;
646return($proj,$debug,$LOG,\%pbrc, \%filteredfiles, \%defpkgdir, \%extpkgdir);
647}
648
649# Internal mkdir -p function
650sub pb_mkdir_p {
651my @dir = @_;
652my $ret = mkpath(@dir, 0, 0755);
653return($ret);
654}
655
656# Internal rm -rf function
657sub pb_rm_rf {
658my @dir = @_;
659my $ret = rmtree(@dir, 0, 0);
660return($ret);
661}
662
663# Internal system function
664sub pb_system {
665
666my $cmd=shift;
667my $cmt=shift || $cmd;
668
669print "$cmt... ";
670#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
671system("$cmd");
672if ($? == -1) {
673 print "failed to execute ($cmd) : $!\n";
674 pb_display_file("$ENV{'PBTMP'}/system.log");
675} elsif ($? & 127) {
676 printf "child ($cmd) died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
677 pb_display_file("$ENV{'PBTMP'}/system.log");
678} elsif ($? == 0) {
679 print "OK\n";
680} else {
681 printf "child ($cmd) exited with value %d\n", $? >> 8;
682 pb_display_file("$ENV{'PBTMP'}/system.log");
683}
684}
685
686sub pb_display_file {
687
688my $file=shift;
689
690return if (not -f $file);
691open(FILE,"$file");
692while (<FILE>) {
693 print $_;
694}
695close(FILE);
696}
697
698# Function which returns a pointer on a table
699# corresponding to a set of values queried in the conf file
700# and test the returned vaue as they need to exist in that case
701sub pb_conf_get {
702
703my @param = @_;
704
705# Everything is returned via ptr1
706my @ptr1 = pb_conf_read("$ENV{'PBETC'}", @param);
707my @ptr2 = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb", @param);
708
709my $p1;
710my $p2;
711
712#print "DEBUG: param1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
713#print "DEBUG: param2: ".Dumper(@ptr2)."\n"; # if ($debug >= 1);
714
715foreach my $i (0..$#param) {
716 $p1 = $ptr1[$i];
717 $p2 = $ptr2[$i];
718 die "No $param[$i] defined for $ENV{'PBPROJ'}" if ((not @ptr1) && (not @ptr2));
719 die "No $param[$i] defined for $ENV{'PBPROJ'}" if ((not defined $p1) && (not defined $p2));
720 # Always try to take the param from the home dir conf file in priority
721 # in order to mask what could be defined under the CMS to allow for overloading
722 if (not defined $p2) {
723 # No ref in CMS project conf file so use the home dir one.
724 $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (not defined $p1->{$ENV{'PBPROJ'}});
725 } else {
726 # Ref found in CMS project conf file
727 if (not defined $p1) {
728 # No ref in home dir project conf file so use the CMS one.
729 $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if (not defined $p2->{$ENV{'PBPROJ'}});
730 $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
731 } else {
732 # Both are defined - handling the overloading
733 if (not defined $p1->{'default'}) {
734 if (defined $p2->{'default'}) {
735 $p1->{'default'} = $p2->{'default'};
736 }
737 }
738
739 if (not defined $p1->{$ENV{'PBPROJ'}}) {
740 if (defined $p2->{$ENV{'PBPROJ'}}) {
741 $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}};
742 } else {
743 $p1->{$ENV{'PBPROJ'}} = $p1->{'default'};
744 }
745 }
746 }
747 }
748 die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $p1->{$ENV{'PBPROJ'}});
749 $ptr1[$i] = $p1;
750 #print "DEBUG: param ptr1: ".Dumper(@ptr1)."\n"; # if ($debug >= 1);
751}
752return(@ptr1);
753}
754
755sub pb_no_err {
756}
757
758# Function which returns a pointer on a hash
759# corresponding to a declaration (arg2) in a conf file (arg1)
760sub pb_conf_read {
761
762my $conffile = shift;
763my @param = @_;
764my $trace;
765my @ptr;
766
767my $debug = 0;
768
769if ($debug > 0) {
770 $trace = 1;
771} else {
772 $trace = 0;
773}
774
775
776my $config = AppConfig->new({
777 # Auto Create variables mentioned in Conf file
778 CREATE => 1,
779 DEBUG => $trace,
780 ERROR => \&pb_no_err,
781 GLOBAL => {
782 # Each conf item is a hash
783 ARGCOUNT => ARGCOUNT_HASH,
784 },
785 });
786$config->file($conffile);
787for my $param (@param) {
788 push @ptr,$config->get($param);
789}
790print "DEBUG: params: ".Dumper(@param)." ".Dumper(@ptr)."\n" if ($debug >= 1);
791return(@ptr);
792}
793
794# Setup environment for CMS system
795sub pb_cms_init {
796
797my $proj = shift || undef;
798my $ret;
799
800my ($cms) = pb_conf_get("cms");
801
802if ($cms->{$proj} eq "svn") {
803 $ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; svnversion .)`;
804 chomp($ENV{'PBREVISION'});
805 $ENV{'PBCMSLOGFILE'}="svn.log";
806} elsif ($cms->{$proj} eq "flat") {
807 $ENV{'PBREVISION'}="flat";
808 $ENV{'PBCMSLOGFILE'}="flat.log";
809} elsif ($cms->{$proj} eq "cvs") {
810 # Way too slow
811 #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOT'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
812 #chomp($ENV{'PBREVISION'});
813 $ENV{'PBREVISION'}="CVS";
814 $ENV{'PBCMSLOGFILE'}="cvs.log";
815 #
816 # Export content if needed
817 #
818 my ($cvsroot,$cvsrsh) = pb_conf_get("cvsroot","cvsrsh");
819 $ENV{'CVSROOT'} = $cvsroot->{$proj} if (defined $cvsroot->{$proj});
820 $ENV{'CVSRSH'} = $cvsrsh->{$proj} if (defined $cvsrsh->{$proj});
821} else {
822 die "cms $cms->{$proj} unknown";
823}
824return($cms);
825}
826
827sub pb_cms_export {
828my $cms = shift;
829my $pbdate = shift || undef;
830my $source = shift;
831my $destdir = shift;
832my $tmp;
833my $tmp1;
834
835if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
836 if (-d $source) {
837 $tmp = $destdir;
838 } else {
839 $tmp = $destdir."/".basename($source);
840 }
841 pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
842} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
843 if (-d $source) {
844 $tmp = $destdir;
845 } else {
846 $tmp = $destdir."/".basename($source);
847 }
848 pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
849} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
850 my $dir=dirname($destdir);
851 my $base=basename($destdir);
852 if (-d $source) {
853 $tmp1 = $source;
854 $tmp1 =~ s|$ENV{'PBROOT'}/||;
855 } else {
856 $tmp1 = dirname($source);
857 $tmp1 =~ s|$ENV{'PBROOT'}/||;
858 $tmp1 = $tmp1."/".basename($source);
859 }
860 # CVS needs a relative path !
861 pb_system("cd $dir ; cvs export -D \"$pbdate\" -d $base $tmp1","Exporting $source from CVS to $destdir");
862} else {
863 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
864}
865}
866
867
868sub pb_create_authors {
869
870my $authors=shift;
871my $dest=shift;
872my $cms=shift;
873
874return if ($authors eq "/dev/null");
875open(SAUTH,$authors) || die "Unable to open $authors";
876open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
877print DAUTH "Authors of the project are:\n";
878print DAUTH "===========================\n";
879while (<SAUTH>) {
880 my ($nick,$gcos) = split(/:/);
881 chomp($gcos);
882 print DAUTH "$gcos";
883 if (defined $cms) {
884 print DAUTH " ($nick under $cms)\n";
885 } else {
886 print DAUTH "\n";
887 }
888}
889close(DAUTH);
890close(SAUTH);
891}
892
893sub pb_cms_log {
894my $cms = shift;
895my $pkgdir = shift;
896my $dest = shift;
897my $chglog = shift;
898my $authors = shift;
899
900pb_create_authors($authors,$dest,$cms->{$ENV{'PBPROJ'}});
901
902if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
903 if (! -f "$dest/ChangeLog") {
904 if (-x "/usr/bin/svn2cl") {
905 pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN");
906 } else {
907 # To be written from pbcl
908 pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
909 }
910 }
911} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
912 # Nothing to do
913} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
914 my $tmp=basename($pkgdir);
915 # CVS needs a relative path !
916 if (! -f "$dest/ChangeLog") {
917 if (-x "/usr/bin/cvs2cl") {
918 pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN");
919 } else {
920 # To be written from pbcl
921 pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
922 }
923 }
924} else {
925 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
926}
927}
928
929sub pb_cms_getinfo {
930my $cms = shift;
931my $url = "";
932my $void = "";
933
934if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
935 open(PIPE,"LANGUAGE=C svn info $ENV{'PBROOT'} |") || die "Unable to get svn info from $ENV{'PBROOT'}";
936 while (<PIPE>) {
937 ($void,$url) = split(/^URL:/) if (/^URL:/);
938 }
939 close(PIPE);
940 chomp($url);
941} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
942} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
943} else {
944 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
945}
946return($url);
947}
948
949sub pb_cms_copy {
950my $cms = shift;
951my $oldurl = shift;
952my $newurl = shift;
953
954if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
955 pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
956} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
957} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
958} else {
959 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
960}
961}
962
963sub pb_cms_checkout {
964my $cms = shift;
965my $url = shift;
966my $destination = shift;
967
968if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
969 pb_system("svn co $url $destination","Checking $url to $destination ");
970} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
971} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
972} else {
973 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
974}
975}
976
977sub pb_cms_checkin {
978my $cms = shift;
979my $dir = shift;
980
981my $ver = basename($dir);
982if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
983 pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
984 pb_system("svn up $dir","Updating $dir");
985} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
986} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
987} else {
988 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
989}
990}
991
992sub pb_cms_isdiff {
993my $cms = shift;
994
995if ($cms->{$ENV{'PBPROJ'}} eq "svn") {
996 open(PIPE,"svn diff $ENV{'PBROOT'} |") || die "Unable to get svn diff from $ENV{'PBROOT'}";
997 my $l = 0;
998 while (<PIPE>) {
999 $l++;
1000 }
1001 return($l);
1002} elsif ($cms->{$ENV{'PBPROJ'}} eq "flat") {
1003} elsif ($cms->{$ENV{'PBPROJ'}} eq "cvs") {
1004} else {
1005 die "cms $cms->{$ENV{'PBPROJ'}} unknown";
1006}
1007}
1008
1009# Get all filters to apply
1010# They're cumulative from less specific to most specific
1011# suffix is .pbf
1012
1013sub pb_get_filters {
1014
1015# For the moment not dynamic
1016my $debug = 0; # Debug level
1017my $LOG = *STDOUT; # Where to log
1018
1019my @ffiles;
1020my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
1021my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
1022my $pbpkg = shift || die "No package specified";
1023my $dtype = shift || "";
1024my $dfam = shift || "";
1025my $ddir = shift || "";
1026my $dver = shift || "";
1027my $ptr; # returned value pointer on the hash of filters
1028my %ptr;
1029
1030# Global filter files first, then package specificities
1031if (-d "$ENV{'PBCONF'}/pbfilter") {
1032 $mfile00 = "$ENV{'PBCONF'}/pbfilter/all.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/all.pbf");
1033 $mfile0 = "$ENV{'PBCONF'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$dtype.pbf");
1034 $mfile1 = "$ENV{'PBCONF'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$dfam.pbf");
1035 $mfile2 = "$ENV{'PBCONF'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$ddir.pbf");
1036 $mfile3 = "$ENV{'PBCONF'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/pbfilter/$ddir-$dver.pbf");
1037
1038 push @ffiles,$mfile00 if (defined $mfile00);
1039 push @ffiles,$mfile0 if (defined $mfile0);
1040 push @ffiles,$mfile1 if (defined $mfile1);
1041 push @ffiles,$mfile2 if (defined $mfile2);
1042 push @ffiles,$mfile3 if (defined $mfile3);
1043}
1044
1045if (-d "$ENV{'PBCONF'}/$pbpkg/pbfilter") {
1046 $ffile00 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/all.pbf");
1047 $ffile0 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dtype.pbf");
1048 $ffile1 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$dfam.pbf");
1049 $ffile2 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir.pbf");
1050 $ffile3 = "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBCONF'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
1051
1052 push @ffiles,$ffile00 if (defined $ffile00);
1053 push @ffiles,$ffile0 if (defined $ffile0);
1054 push @ffiles,$ffile1 if (defined $ffile1);
1055 push @ffiles,$ffile2 if (defined $ffile2);
1056 push @ffiles,$ffile3 if (defined $ffile3);
1057}
1058if (@ffiles) {
1059 print $LOG "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
1060
1061 my $config = AppConfig->new({
1062 # Auto Create variables mentioned in Conf file
1063 CREATE => 1,
1064 DEBUG => 0,
1065 GLOBAL => {
1066 # Each conf item is a hash
1067 ARGCOUNT => AppConfig::ARGCOUNT_HASH
1068 }
1069 });
1070
1071 $config->file(@ffiles);
1072 $ptr = $config->get("filter");
1073 print $LOG "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
1074} else {
1075 $ptr = { };
1076}
1077%ptr = %$ptr;
1078return(\%ptr);
1079}
1080
1081# Function which applies filter on pb build files
1082sub pb_filter_file_pb {
1083
1084my $f=shift;
1085my $ptr=shift;
1086my %filter=%$ptr;
1087my $destfile=shift;
1088my $dtype=shift;
1089my $pbsuf=shift;
1090my $pbpkg=shift;
1091my $pbver=shift;
1092my $pbtag=shift;
1093my $pbrev=shift;
1094my $pbdate=shift;
1095my $defpkgdir = shift;
1096my $extpkgdir = shift;
1097my $pbpackager = shift;
1098my $chglog = shift || undef;
1099
1100# For the moment not dynamic
1101my $debug = 0; # Debug level
1102my $LOG = *STDOUT; # Where to log
1103
1104print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
1105pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1106open(DEST,"> $destfile") || die "Unable to create $destfile";
1107open(FILE,"$f") || die "Unable to open $f: $!";
1108while (<FILE>) {
1109 my $line = $_;
1110 foreach my $s (keys %filter) {
1111 # Process single variables
1112 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug >= 1);
1113 my $tmp = $filter{$s};
1114 next if (not defined $tmp);
1115 # Expand variables if any single one found
1116 print $LOG "DEBUG tmp: $tmp\n" if ($debug >= 1);
1117 if ($tmp =~ /\$/) {
1118 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1119 # special case for ChangeLog only for pb
1120 } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
1121 my $p = $defpkgdir->{$pbpkg};
1122 $p = $extpkgdir->{$pbpkg} if (not defined $p);
1123 pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
1124 $tmp = "";
1125 }
1126 $line =~ s|$s|$tmp|;
1127 }
1128 print DEST $line;
1129}
1130close(FILE);
1131close(DEST);
1132}
1133
1134# Function which applies filter on files (external call)
1135sub pb_filter_file {
1136
1137my $f=shift;
1138my $ptr=shift;
1139my %filter=%$ptr;
1140my $destfile=shift;
1141my $pbpkg=shift;
1142my $pbver=shift;
1143my $pbtag=shift;
1144my $pbrev=shift;
1145my $pbdate=shift;
1146my $pbpackager=shift;
1147
1148# For the moment not dynamic
1149my $debug = 0; # Debug level
1150my $LOG = *STDOUT; # Where to log
1151
1152print $LOG "DEBUG: From $f to $destfile\n" if ($debug >= 1);
1153pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1154open(DEST,"> $destfile") || die "Unable to create $destfile";
1155open(FILE,"$f") || die "Unable to open $f: $!";
1156while (<FILE>) {
1157 my $line = $_;
1158 foreach my $s (keys %filter) {
1159 # Process single variables
1160 print $LOG "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
1161 my $tmp = $filter{$s};
1162 next if (not defined $tmp);
1163 # Expand variables if any single one found
1164 if ($tmp =~ /\$/) {
1165 eval { $tmp =~ s/(\$\w+)/$1/eeg };
1166 }
1167 $line =~ s|$s|$tmp|;
1168 }
1169 print DEST $line;
1170}
1171close(FILE);
1172close(DEST);
1173}
1174
1175
11761;
Note: See TracBrowser for help on using the repository browser.