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