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

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

Review of newproj to have a correct netperf doc

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