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