[5] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[405] | 3 | # Project Builder CMS module
|
---|
| 4 | # CMS subroutines brought by the the Project-Builder project
|
---|
| 5 | # which can be easily used by pbinit scripts
|
---|
[5] | 6 | #
|
---|
| 7 | # $Id$
|
---|
| 8 | #
|
---|
[2032] | 9 | # Copyright B. Cornec 2007-2016
|
---|
[1560] | 10 | # Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
|
---|
[5] | 11 | # Provided under the GPL v2
|
---|
| 12 |
|
---|
[405] | 13 | package ProjectBuilder::CMS;
|
---|
[9] | 14 |
|
---|
[18] | 15 | use strict 'vars';
|
---|
[1535] | 16 | use Carp 'confess';
|
---|
[9] | 17 | use Data::Dumper;
|
---|
| 18 | use English;
|
---|
[16] | 19 | use File::Basename;
|
---|
[500] | 20 | use File::Copy;
|
---|
[13] | 21 | use POSIX qw(strftime);
|
---|
[17] | 22 | use lib qw (lib);
|
---|
[1148] | 23 | use ProjectBuilder::Version;
|
---|
[318] | 24 | use ProjectBuilder::Base;
|
---|
[405] | 25 | use ProjectBuilder::Conf;
|
---|
[1469] | 26 | use ProjectBuilder::VCS;
|
---|
[5] | 27 |
|
---|
[405] | 28 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 29 |
|
---|
[1156] | 30 | use vars qw($VERSION $REVISION @ISA @EXPORT);
|
---|
[405] | 31 | use Exporter;
|
---|
| 32 |
|
---|
| 33 | # Export, by default, all the functions into the namespace of
|
---|
| 34 | # any code which uses this module.
|
---|
| 35 |
|
---|
| 36 | our @ISA = qw(Exporter);
|
---|
[2312] | 37 | our @EXPORT = qw(pb_cms_get_pkg pb_cms_get_real_pkg pb_cms_log);
|
---|
[1156] | 38 | ($VERSION,$REVISION) = pb_version_init();
|
---|
[5] | 39 |
|
---|
[331] | 40 | =pod
|
---|
| 41 |
|
---|
| 42 | =head1 NAME
|
---|
| 43 |
|
---|
[409] | 44 | ProjectBuilder::CMS, part of the project-builder.org
|
---|
[331] | 45 |
|
---|
| 46 | =head1 DESCRIPTION
|
---|
| 47 |
|
---|
[405] | 48 | This modules provides configuration management system functions suitable for pbinit calls.
|
---|
[331] | 49 |
|
---|
[409] | 50 | =head1 USAGE
|
---|
| 51 |
|
---|
| 52 | =over 4
|
---|
| 53 |
|
---|
[539] | 54 | =item B<pb_cms_get_pkg>
|
---|
[409] | 55 |
|
---|
| 56 | This function returns the list of packages we are working on in a CMS action.
|
---|
| 57 | The first parameter is the default list of packages from the configuration file.
|
---|
| 58 | The second parameter is the optional list of packages from the configuration file.
|
---|
| 59 |
|
---|
| 60 | =cut
|
---|
| 61 |
|
---|
[395] | 62 | sub pb_cms_get_pkg {
|
---|
| 63 |
|
---|
| 64 | my @pkgs = ();
|
---|
[1907] | 65 | my $defpkgdir = shift;
|
---|
| 66 | my $extpkgdir = shift;
|
---|
[395] | 67 |
|
---|
| 68 | # Get packages list
|
---|
| 69 | if (not defined $ARGV[0]) {
|
---|
| 70 | @pkgs = keys %$defpkgdir if (defined $defpkgdir);
|
---|
| 71 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
| 72 | @pkgs = keys %$defpkgdir if (defined $defpkgdir);
|
---|
| 73 | push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
|
---|
| 74 | } else {
|
---|
| 75 | @pkgs = @ARGV;
|
---|
| 76 | }
|
---|
| 77 | return(\@pkgs);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[539] | 80 | =item B<pb_cms_get_real_pkg>
|
---|
| 81 |
|
---|
| 82 | This function returns the real name of a virtual package we are working on in a CMS action.
|
---|
| 83 | It supports the following types: perl.
|
---|
| 84 | The first parameter is the virtual package name
|
---|
| 85 |
|
---|
| 86 | =cut
|
---|
| 87 |
|
---|
| 88 | sub pb_cms_get_real_pkg {
|
---|
| 89 |
|
---|
[1907] | 90 | my $pbpkg = shift;
|
---|
[539] | 91 | my $dtype = shift;
|
---|
| 92 | my $pbpkgreal = $pbpkg;
|
---|
| 93 |
|
---|
| 94 | my @nametype = pb_conf_get_if("namingtype");
|
---|
| 95 | my $type = $nametype[0]->{$pbpkg};
|
---|
| 96 | if (defined $type) {
|
---|
| 97 | if ($type eq "perl") {
|
---|
| 98 | if ($dtype eq "rpm") {
|
---|
| 99 | $pbpkgreal = "perl-".$pbpkg;
|
---|
| 100 | } elsif ($dtype eq "deb") {
|
---|
[544] | 101 | # Only lower case allowed in Debian
|
---|
| 102 | # Cf: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package
|
---|
[539] | 103 | $pbpkgreal = "lib".lc($pbpkg)."-perl";
|
---|
| 104 | } elsif ($dtype eq "ebuild") {
|
---|
| 105 | $pbpkgreal = $pbpkg;
|
---|
[2333] | 106 | } elsif ($dtype eq "apk") {
|
---|
| 107 | $pbpkgreal = $pbpkg;
|
---|
[1174] | 108 | } elsif ($dtype eq "hpux") {
|
---|
| 109 | $pbpkgreal = $pbpkg;
|
---|
[873] | 110 | } elsif ($dtype eq "pkg") {
|
---|
| 111 | $pbpkgreal = "PB$pbpkg";
|
---|
[539] | 112 | } else {
|
---|
| 113 | die "pb_cms_get_real_pkg not implemented for $dtype yet";
|
---|
| 114 | }
|
---|
| 115 | } else {
|
---|
| 116 | die "nametype $type not implemented yet";
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[1551] | 120 | pb_log(2,"pb_cms_get_real_pkg returns $pbpkgreal\n");
|
---|
[539] | 121 | return($pbpkgreal);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[409] | 124 | =item B<pb_cms_create_authors>
|
---|
| 125 |
|
---|
| 126 | This function creates a AUTHORS files for the project. It call it AUTHORS.pb if an AUTHORS file already exists.
|
---|
| 127 | The first parameter is the source file for authors information.
|
---|
| 128 | The second parameter is the directory where to create the final AUTHORS file.
|
---|
| 129 | The third parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 130 |
|
---|
| 131 | =cut
|
---|
| 132 |
|
---|
[405] | 133 | sub pb_cms_create_authors {
|
---|
[395] | 134 |
|
---|
[405] | 135 | my $authors=shift;
|
---|
| 136 | my $dest=shift;
|
---|
| 137 | my $scheme=shift;
|
---|
[395] | 138 |
|
---|
[405] | 139 | return if ($authors eq "/dev/null");
|
---|
| 140 | open(SAUTH,$authors) || die "Unable to open $authors";
|
---|
[409] | 141 | # Save a potentially existing AUTHORS file and write instead to AUTHORS.pb
|
---|
[405] | 142 | my $ext = "";
|
---|
| 143 | if (-f "$dest/AUTHORS") {
|
---|
| 144 | $ext = ".pb";
|
---|
[395] | 145 | }
|
---|
[405] | 146 | open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
|
---|
| 147 | print DAUTH "Authors of the project are:\n";
|
---|
| 148 | print DAUTH "===========================\n";
|
---|
| 149 | while (<SAUTH>) {
|
---|
| 150 | my ($nick,$gcos) = split(/:/);
|
---|
| 151 | chomp($gcos);
|
---|
| 152 | print DAUTH "$gcos";
|
---|
| 153 | if (defined $scheme) {
|
---|
| 154 | # Do not give a scheme for flat types
|
---|
| 155 | my $endstr="";
|
---|
| 156 | if ("$ENV{'PBREVISION'}" ne "flat") {
|
---|
| 157 | $endstr = " under $scheme";
|
---|
| 158 | }
|
---|
| 159 | print DAUTH " ($nick$endstr)\n";
|
---|
| 160 | } else {
|
---|
| 161 | print DAUTH "\n";
|
---|
| 162 | }
|
---|
[395] | 163 | }
|
---|
[405] | 164 | close(DAUTH);
|
---|
| 165 | close(SAUTH);
|
---|
[395] | 166 | }
|
---|
| 167 |
|
---|
[409] | 168 | =item B<pb_cms_log>
|
---|
| 169 |
|
---|
| 170 | This function creates a ChangeLog file for the project.
|
---|
| 171 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 172 | The second parameter is the directory where the CMS content was checked out.
|
---|
| 173 | The third parameter is the directory where to create the final ChangeLog file.
|
---|
| 174 | The fourth parameter is unused.
|
---|
| 175 | The fifth parameter is the source file for authors information.
|
---|
| 176 |
|
---|
| 177 | It may use a tool like svn2cl or cvs2cl to generate it if present, or the log file from the CMS if not.
|
---|
| 178 |
|
---|
| 179 | =cut
|
---|
| 180 |
|
---|
| 181 |
|
---|
[405] | 182 | sub pb_cms_log {
|
---|
[395] | 183 |
|
---|
[405] | 184 | my $scheme = shift;
|
---|
| 185 | my $pkgdir = shift;
|
---|
| 186 | my $dest = shift;
|
---|
| 187 | my $chglog = shift;
|
---|
| 188 | my $authors = shift;
|
---|
[1907] | 189 | my $testver = shift;
|
---|
[395] | 190 |
|
---|
[405] | 191 | pb_cms_create_authors($authors,$dest,$scheme);
|
---|
[1469] | 192 | my $vcscmd = pb_vcs_cmd($scheme);
|
---|
[395] | 193 |
|
---|
[448] | 194 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
| 195 | if (! -f "$dest/ChangeLog") {
|
---|
[1537] | 196 | open(CL,"> $dest/ChangeLog") || confess "Unable to create $dest/ChangeLog";
|
---|
[448] | 197 | # We need a minimal version for debian type of build
|
---|
| 198 | print CL "\n";
|
---|
| 199 | print CL "\n";
|
---|
| 200 | print CL "\n";
|
---|
| 201 | print CL "\n";
|
---|
| 202 | print CL "1990-01-01 none\n";
|
---|
| 203 | print CL "\n";
|
---|
| 204 | print CL " * test version\n";
|
---|
| 205 | print CL "\n";
|
---|
| 206 | close(CL);
|
---|
| 207 | pb_log(0,"Generating fake ChangeLog for test version\n");
|
---|
| 208 | open(CL,"> $dest/$ENV{'PBCMSLOGFILE'}") || die "Unable to create $dest/$ENV{'PBCMSLOGFILE'}";
|
---|
| 209 | close(CL);
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[890] | 213 | if (! -f "$dest/ChangeLog") {
|
---|
| 214 | if ($scheme =~ /^svn/) {
|
---|
[448] | 215 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 216 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 217 | close(CL);
|
---|
[1127] | 218 | my $command = pb_check_req("svn2cl",1);
|
---|
[1421] | 219 | if ((defined $command) && (-x $command)) {
|
---|
[1127] | 220 | pb_system("$command --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
|
---|
[395] | 221 | } else {
|
---|
[405] | 222 | # To be written from pbcl
|
---|
[661] | 223 | pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
|
---|
[395] | 224 | }
|
---|
[890] | 225 | } elsif ($scheme =~ /^svk/) {
|
---|
[780] | 226 | pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVK");
|
---|
[890] | 227 | } elsif ($scheme =~ /^hg/) {
|
---|
[612] | 228 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 229 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 230 | close(CL);
|
---|
[896] | 231 | pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from Mercurial");
|
---|
[890] | 232 | } elsif ($scheme =~ /^git/) {
|
---|
[661] | 233 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 234 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 235 | close(CL);
|
---|
| 236 | pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from GIT");
|
---|
[2169] | 237 | } elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)|(dir)\b/o) {
|
---|
[405] | 238 | pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
|
---|
[890] | 239 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 240 | my $tmp=basename($pkgdir);
|
---|
| 241 | # CVS needs a relative path !
|
---|
[448] | 242 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 243 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 244 | close(CL);
|
---|
[1127] | 245 | my $command = pb_check_req("cvs2cl",1);
|
---|
| 246 | if (-x $command) {
|
---|
| 247 | pb_system("$command --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
|
---|
[395] | 248 | } else {
|
---|
[405] | 249 | # To be written from pbcl
|
---|
[661] | 250 | pb_system("$vcscmd log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
|
---|
[395] | 251 | }
|
---|
[890] | 252 | } else {
|
---|
| 253 | die "cms $scheme unknown";
|
---|
[395] | 254 | }
|
---|
| 255 | }
|
---|
[896] | 256 | if (! -f "$dest/ChangeLog") {
|
---|
| 257 | copy("$dest/$ENV{'PBCMSLOGFILE'}","$dest/ChangeLog");
|
---|
[395] | 258 | }
|
---|
[896] | 259 | }
|
---|
[405] | 260 |
|
---|
[409] | 261 | =back
|
---|
| 262 |
|
---|
| 263 | =head1 WEB SITES
|
---|
| 264 |
|
---|
| 265 | The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
| 266 |
|
---|
| 267 | =head1 USER MAILING LIST
|
---|
| 268 |
|
---|
| 269 | None exists for the moment.
|
---|
| 270 |
|
---|
| 271 | =head1 AUTHORS
|
---|
| 272 |
|
---|
| 273 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 274 |
|
---|
| 275 | =head1 COPYRIGHT
|
---|
| 276 |
|
---|
| 277 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 278 | described in the file C<COPYING> included with the distribution.
|
---|
| 279 |
|
---|
| 280 | =cut
|
---|
| 281 |
|
---|
[395] | 282 | 1;
|
---|