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

Last change on this file since 313 was 313, checked in by Bruno Cornec, 16 years ago

WARNING: Modifications in progress. DOES NOT WORK
Addition of a different origin for pbconf WIP

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