[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 | #
|
---|
| 9 | # Copyright B. Cornec 2007
|
---|
| 10 | # Provided under the GPL v2
|
---|
| 11 |
|
---|
[405] | 12 | package ProjectBuilder::CMS;
|
---|
[9] | 13 |
|
---|
[18] | 14 | use strict 'vars';
|
---|
[9] | 15 | use Data::Dumper;
|
---|
| 16 | use English;
|
---|
[16] | 17 | use File::Basename;
|
---|
[500] | 18 | use File::Copy;
|
---|
[13] | 19 | use POSIX qw(strftime);
|
---|
[17] | 20 | use lib qw (lib);
|
---|
[318] | 21 | use ProjectBuilder::Base;
|
---|
[405] | 22 | use ProjectBuilder::Conf;
|
---|
[5] | 23 |
|
---|
[405] | 24 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 25 |
|
---|
| 26 | use Exporter;
|
---|
| 27 |
|
---|
| 28 | # Export, by default, all the functions into the namespace of
|
---|
| 29 | # any code which uses this module.
|
---|
| 30 |
|
---|
| 31 | our @ISA = qw(Exporter);
|
---|
[539] | 32 | our @EXPORT = qw(pb_cms_init pb_cms_export pb_cms_get_uri pb_cms_copy pb_cms_checkout pb_cms_up pb_cms_checkin pb_cms_isdiff pb_cms_get_pkg pb_cms_get_real_pkg pb_cms_compliant pb_cms_log pb_cms_add);
|
---|
[5] | 33 |
|
---|
[331] | 34 | =pod
|
---|
| 35 |
|
---|
| 36 | =head1 NAME
|
---|
| 37 |
|
---|
[409] | 38 | ProjectBuilder::CMS, part of the project-builder.org
|
---|
[331] | 39 |
|
---|
| 40 | =head1 DESCRIPTION
|
---|
| 41 |
|
---|
[405] | 42 | This modules provides configuration management system functions suitable for pbinit calls.
|
---|
[331] | 43 |
|
---|
[409] | 44 | =head1 USAGE
|
---|
| 45 |
|
---|
| 46 | =over 4
|
---|
| 47 |
|
---|
| 48 | =item B<pb_cms_init>
|
---|
| 49 |
|
---|
| 50 | This function setup the environment for the CMS system related to the URL given by the pburl configuration parameter.
|
---|
| 51 | The potential parameter indicates whether we should inititate the context or not.
|
---|
| 52 | It sets up environement variables (PBPROJDIR, PBDIR, PBREVISION, PBCMSLOGFILE)
|
---|
| 53 |
|
---|
[331] | 54 | =cut
|
---|
| 55 |
|
---|
[395] | 56 | sub pb_cms_init {
|
---|
| 57 |
|
---|
| 58 | my $pbinit = shift || undef;
|
---|
| 59 |
|
---|
| 60 | my ($pburl) = pb_conf_get("pburl");
|
---|
| 61 | pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pburl->{$ENV{'PBPROJ'}}\n");
|
---|
| 62 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
|
---|
| 63 |
|
---|
| 64 | my ($pbprojdir) = pb_conf_get_if("pbprojdir");
|
---|
| 65 |
|
---|
| 66 | if ((defined $pbprojdir) && (defined $pbprojdir->{$ENV{'PBPROJ'}})) {
|
---|
| 67 | $ENV{'PBPROJDIR'} = $pbprojdir->{$ENV{'PBPROJ'}};
|
---|
| 68 | } else {
|
---|
| 69 | $ENV{'PBPROJDIR'} = "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}";
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | # Computing the default dir for PBDIR.
|
---|
| 73 | # what we have is PBPROJDIR so work from that.
|
---|
| 74 | # Tree identical between PBCONFDIR and PBROOTDIR on one side and
|
---|
| 75 | # PBPROJDIR and PBDIR on the other side.
|
---|
| 76 |
|
---|
| 77 | my $tmp = $ENV{'PBROOTDIR'};
|
---|
| 78 | $tmp =~ s|^$ENV{'PBCONFDIR'}||;
|
---|
| 79 |
|
---|
| 80 | #
|
---|
| 81 | # Check project cms compliance
|
---|
| 82 | #
|
---|
| 83 | pb_cms_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$pburl->{$ENV{'PBPROJ'}},$pbinit);
|
---|
| 84 |
|
---|
[612] | 85 | if ($scheme =~ /^hg/) {
|
---|
[395] | 86 | # svnversion more precise than svn info
|
---|
[612] | 87 | $tmp = `(cd "$ENV{'PBDIR'}" ; hg identify )`;
|
---|
[395] | 88 | chomp($tmp);
|
---|
[612] | 89 | $tmp =~ s/^.* //;
|
---|
[395] | 90 | $ENV{'PBREVISION'}=$tmp;
|
---|
[612] | 91 | $ENV{'PBCMSLOGFILE'}="hg.log";
|
---|
[395] | 92 | } elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 93 | $ENV{'PBREVISION'}="flat";
|
---|
| 94 | $ENV{'PBCMSLOGFILE'}="flat.log";
|
---|
[612] | 95 | } elsif ($scheme =~ /^svn/) {
|
---|
| 96 | $tmp = `(cd "$ENV{'PBDIR'}" ; svnversion .)`;
|
---|
| 97 | chomp($tmp);
|
---|
| 98 | $ENV{'PBREVISION'}=$tmp;
|
---|
| 99 | $ENV{'PBCMSLOGFILE'}="svn.log";
|
---|
[395] | 100 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 101 | # Way too slow
|
---|
| 102 | #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOTDIR'}" ; cvs rannotate -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
|
---|
| 103 | #chomp($ENV{'PBREVISION'});
|
---|
| 104 | $ENV{'PBREVISION'}="cvs";
|
---|
| 105 | $ENV{'PBCMSLOGFILE'}="cvs.log";
|
---|
| 106 | $ENV{'CVS_RSH'} = "ssh" if ($scheme =~ /ssh/);
|
---|
| 107 | } else {
|
---|
| 108 | die "cms $scheme unknown";
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | return($scheme,$pburl->{$ENV{'PBPROJ'}});
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[409] | 114 | =item B<pb_cms_export>
|
---|
| 115 |
|
---|
| 116 | This function exports a CMS content to a directory.
|
---|
| 117 | The first parameter is the URL of the CMS content.
|
---|
[500] | 118 | The second parameter is the directory in which it is locally exposed (result of a checkout). If undef, then use the original CMS content.
|
---|
[409] | 119 | The third parameter is the directory where we want to deliver it (result of export).
|
---|
[537] | 120 | It returns the original tar file if we need to preserve it and undef if we use the produced one.
|
---|
[409] | 121 |
|
---|
| 122 | =cut
|
---|
| 123 |
|
---|
[395] | 124 | sub pb_cms_export {
|
---|
| 125 |
|
---|
| 126 | my $uri = shift;
|
---|
| 127 | my $source = shift;
|
---|
| 128 | my $destdir = shift;
|
---|
| 129 | my $tmp;
|
---|
| 130 | my $tmp1;
|
---|
| 131 |
|
---|
| 132 | my @date = pb_get_date();
|
---|
| 133 | # If it's not flat, then we have a real uri as source
|
---|
| 134 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
| 135 |
|
---|
| 136 | if ($scheme =~ /^svn/) {
|
---|
[500] | 137 | if (defined $source) {
|
---|
| 138 | if (-d $source) {
|
---|
| 139 | $tmp = $destdir;
|
---|
| 140 | } else {
|
---|
| 141 | $tmp = "$destdir/".basename($source);
|
---|
| 142 | }
|
---|
[600] | 143 | $source = pb_cms_mod_svn_http($source);
|
---|
[590] | 144 | pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp ");
|
---|
[395] | 145 | } else {
|
---|
[600] | 146 | $uri = pb_cms_mod_svn_http($uri);
|
---|
[590] | 147 | pb_system("svn export $uri $destdir","Exporting $uri from SVN to $destdir ");
|
---|
[395] | 148 | }
|
---|
| 149 | } elsif ($scheme eq "dir") {
|
---|
[590] | 150 | pb_system("cp -a $path $destdir","Copying $uri from DIR to $destdir ");
|
---|
[395] | 151 | } elsif (($scheme eq "http") || ($scheme eq "ftp")) {
|
---|
| 152 | my $f = basename($path);
|
---|
| 153 | unlink "$ENV{'PBTMP'}/$f";
|
---|
| 154 | if (-x "/usr/bin/wget") {
|
---|
| 155 | pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri"," ");
|
---|
| 156 | } elsif (-x "/usr/bin/curl") {
|
---|
| 157 | pb_system("/usr/bin/curl $uri -o $ENV{'PBTMP'}/$f","Downloading $uri with curl to $ENV{'PBTMP'}/$f\n");
|
---|
| 158 | } else {
|
---|
| 159 | die "Unable to download $uri.\nNo wget/curl available, please install one of those";
|
---|
| 160 | }
|
---|
[537] | 161 | # We want to preserve the original tar file
|
---|
[395] | 162 | pb_cms_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
|
---|
[537] | 163 | return("$ENV{'PBTMP'}/$f");
|
---|
[395] | 164 | } elsif ($scheme eq "file") {
|
---|
| 165 | use File::MimeInfo;
|
---|
| 166 | my $mm = mimetype($path);
|
---|
| 167 | pb_log(2,"mimetype: $mm\n");
|
---|
| 168 |
|
---|
[500] | 169 | if (defined $source) {
|
---|
| 170 | # Check whether the file is well formed
|
---|
| 171 | # (containing already a directory with the project-version name)
|
---|
[537] | 172 | #
|
---|
| 173 | # If it's not the case, we try to adapt, but distro needing
|
---|
| 174 | # to verify the checksum will have issues (Fedora)
|
---|
| 175 | # Then upstream should be notified that they need to change their rules
|
---|
[500] | 176 | my ($pbwf) = pb_conf_get_if("pbwf");
|
---|
| 177 | if ((defined $pbwf) && (defined $pbwf->{$ENV{'PBPROJ'}})) {
|
---|
| 178 | $destdir = dirname($destdir);
|
---|
| 179 | }
|
---|
[395] | 180 | }
|
---|
[537] | 181 | pb_mkdir_p($destdir);
|
---|
[395] | 182 |
|
---|
| 183 | if ($mm =~ /\/x-bzip-compressed-tar$/) {
|
---|
| 184 | # tar+bzip2
|
---|
[590] | 185 | pb_system("cd $destdir ; tar xfj $path","Extracting $path in $destdir ");
|
---|
[395] | 186 | } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
|
---|
| 187 | # tar+lzma
|
---|
[590] | 188 | pb_system("cd $destdir ; tar xfY $path","Extracting $path in $destdir ");
|
---|
[395] | 189 | } elsif ($mm =~ /\/x-compressed-tar$/) {
|
---|
| 190 | # tar+gzip
|
---|
[590] | 191 | pb_system("cd $destdir ; tar xfz $path","Extracting $path in $destdir ");
|
---|
[395] | 192 | } elsif ($mm =~ /\/x-tar$/) {
|
---|
| 193 | # tar
|
---|
[590] | 194 | pb_system("cd $destdir ; tar xf $path","Extracting $path in $destdir ");
|
---|
[395] | 195 | } elsif ($mm =~ /\/zip$/) {
|
---|
| 196 | # zip
|
---|
[590] | 197 | pb_system("cd $destdir ; unzip $path","Extracting $path in $destdir ");
|
---|
[500] | 198 | } else {
|
---|
| 199 | # simple file: copy it (patch e.g.)
|
---|
| 200 | copy($path,$destdir);
|
---|
[395] | 201 | }
|
---|
[612] | 202 | } elsif ($scheme =~ /^hg/) {
|
---|
| 203 | if (defined $source) {
|
---|
| 204 | if (-d $source) {
|
---|
| 205 | $tmp = $destdir;
|
---|
| 206 | } else {
|
---|
| 207 | $tmp = "$destdir/".basename($source);
|
---|
| 208 | }
|
---|
| 209 | $source = pb_cms_mod_hg_http($source);
|
---|
| 210 | pb_system("hg export $source $tmp","Exporting $source from Mercurial to $tmp ");
|
---|
| 211 | } else {
|
---|
| 212 | $uri = pb_cms_mod_hg_http($uri);
|
---|
| 213 | pb_system("hg export $uri $destdir","Exporting $uri from Mercurial to $destdir ");
|
---|
| 214 | }
|
---|
[395] | 215 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 216 | # CVS needs a relative path !
|
---|
| 217 | my $dir=dirname($destdir);
|
---|
| 218 | my $base=basename($destdir);
|
---|
[500] | 219 | if (defined $source) {
|
---|
| 220 | # CVS also needs a modules name not a dir
|
---|
[395] | 221 | $tmp1 = basename($source);
|
---|
[500] | 222 | } else {
|
---|
| 223 | # Probably not right, should be checked, but that way I'll notice it :-)
|
---|
| 224 | $tmp1 = $uri;
|
---|
| 225 | }
|
---|
[395] | 226 | # If we're working on the CVS itself
|
---|
| 227 | my $cvstag = basename($ENV{'PBROOTDIR'});
|
---|
| 228 | my $cvsopt = "";
|
---|
| 229 | if ($cvstag eq "cvs") {
|
---|
| 230 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
| 231 | $cvsopt = "-D \"$pbdate\"";
|
---|
| 232 | } else {
|
---|
| 233 | # we're working on a tag which should be the last part of PBROOTDIR
|
---|
| 234 | $cvsopt = "-r $cvstag";
|
---|
| 235 | }
|
---|
[590] | 236 | pb_system("cd $dir ; cvs -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir ");
|
---|
[395] | 237 | } else {
|
---|
| 238 | die "cms $scheme unknown";
|
---|
| 239 | }
|
---|
[537] | 240 | return(undef);
|
---|
[395] | 241 | }
|
---|
| 242 |
|
---|
[409] | 243 | =item B<pb_cms_get_uri>
|
---|
| 244 |
|
---|
| 245 | This function is only called with a real CMS system and gives the URL stored in the checked out directory.
|
---|
| 246 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 247 | The second parameter is the directory in which it is locally exposed (result of a checkout).
|
---|
| 248 |
|
---|
| 249 | =cut
|
---|
| 250 |
|
---|
[395] | 251 | sub pb_cms_get_uri {
|
---|
| 252 |
|
---|
| 253 | my $scheme = shift;
|
---|
| 254 | my $dir = shift;
|
---|
| 255 |
|
---|
| 256 | my $res = "";
|
---|
| 257 | my $void = "";
|
---|
| 258 |
|
---|
| 259 | if ($scheme =~ /^svn/) {
|
---|
| 260 | open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
|
---|
| 261 | while (<PIPE>) {
|
---|
| 262 | ($void,$res) = split(/^URL:/) if (/^URL:/);
|
---|
| 263 | }
|
---|
| 264 | $res =~ s/^\s*//;
|
---|
| 265 | close(PIPE);
|
---|
| 266 | chomp($res);
|
---|
[612] | 267 | } elsif ($scheme =~ /^hg/) {
|
---|
| 268 | open(HGRC,".hg/hgrc/") || return("");
|
---|
| 269 | while (<HGRC>) {
|
---|
| 270 | ($void,$res) = split(/^default.*=/) if (/^default.*=/);
|
---|
| 271 | }
|
---|
| 272 | close(HGRC);
|
---|
| 273 | chomp($res);
|
---|
[395] | 274 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 275 | # This path is always the root path of CVS, but we may be below
|
---|
| 276 | open(FILE,"$dir/CVS/Root") || die "$dir isn't CVS controlled";
|
---|
| 277 | $res = <FILE>;
|
---|
| 278 | chomp($res);
|
---|
| 279 | close(FILE);
|
---|
| 280 | # Find where we are in the tree
|
---|
| 281 | my $rdir = $dir;
|
---|
| 282 | while ((! -d "$rdir/CVSROOT") && ($rdir ne "/")) {
|
---|
| 283 | $rdir = dirname($rdir);
|
---|
| 284 | }
|
---|
| 285 | die "Unable to find a CVSROOT dir in the parents of $dir" if (! -d "$rdir/CVSROOT");
|
---|
| 286 | #compute our place under that root dir - should be a relative path
|
---|
| 287 | $dir =~ s|^$rdir||;
|
---|
| 288 | my $suffix = "";
|
---|
| 289 | $suffix = "$dir" if ($dir ne "");
|
---|
| 290 |
|
---|
| 291 | my $prefix = "";
|
---|
| 292 | if ($scheme =~ /ssh/) {
|
---|
| 293 | $prefix = "cvs+ssh://";
|
---|
| 294 | } else {
|
---|
| 295 | $prefix = "cvs://";
|
---|
| 296 | }
|
---|
| 297 | $res = $prefix.$res.$suffix;
|
---|
| 298 | } else {
|
---|
| 299 | die "cms $scheme unknown";
|
---|
| 300 | }
|
---|
| 301 | pb_log(2,"Found CMS info: $res\n");
|
---|
| 302 | return($res);
|
---|
| 303 | }
|
---|
| 304 |
|
---|
[409] | 305 | =item B<pb_cms_copy>
|
---|
| 306 |
|
---|
| 307 | This function copies a CMS content to another.
|
---|
| 308 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 309 | The second parameter is the URL of the original CMS content.
|
---|
| 310 | The third parameter is the URL of the destination CMS content.
|
---|
| 311 |
|
---|
[612] | 312 | Only coded for SVN now as used for pbconf itself not the project
|
---|
[409] | 313 |
|
---|
| 314 | =cut
|
---|
| 315 |
|
---|
[395] | 316 | sub pb_cms_copy {
|
---|
| 317 | my $scheme = shift;
|
---|
| 318 | my $oldurl = shift;
|
---|
| 319 | my $newurl = shift;
|
---|
| 320 |
|
---|
| 321 | if ($scheme =~ /^svn/) {
|
---|
[600] | 322 | $oldurl = pb_cms_mod_svn_http($oldurl);
|
---|
| 323 | $newurl = pb_cms_mod_svn_http($newurl);
|
---|
[395] | 324 | pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
|
---|
| 325 | } elsif ($scheme eq "flat") {
|
---|
| 326 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 327 | } else {
|
---|
| 328 | die "cms $scheme unknown";
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[409] | 332 | =item B<pb_cms_checkout>
|
---|
| 333 |
|
---|
| 334 | This function checks a CMS content out to a directory.
|
---|
| 335 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 336 | The second parameter is the URL of the CMS content.
|
---|
| 337 | The third parameter is the directory where we want to deliver it (result of export).
|
---|
| 338 |
|
---|
| 339 | =cut
|
---|
| 340 |
|
---|
[395] | 341 | sub pb_cms_checkout {
|
---|
| 342 | my $scheme = shift;
|
---|
| 343 | my $url = shift;
|
---|
| 344 | my $destination = shift;
|
---|
| 345 |
|
---|
| 346 | if ($scheme =~ /^svn/) {
|
---|
[600] | 347 | $url = pb_cms_mod_svn_http($url);
|
---|
[395] | 348 | pb_system("svn co $url $destination","Checking out $url to $destination ");
|
---|
[612] | 349 | } elsif ($scheme =~ /^hg/) {
|
---|
| 350 | $url = pb_cms_mod_hg_http($url);
|
---|
| 351 | pb_system("hg clone $url $destination","Checking out $url to $destination ");
|
---|
[395] | 352 | } elsif (($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
| 353 | return;
|
---|
| 354 | } elsif ($scheme =~ /^cvs/) {
|
---|
[527] | 355 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($url);
|
---|
| 356 |
|
---|
| 357 | # If we're working on the CVS itself
|
---|
| 358 | my $cvstag = basename($ENV{'PBROOTDIR'});
|
---|
| 359 | my $cvsopt = "";
|
---|
| 360 | if ($cvstag eq "cvs") {
|
---|
| 361 | my @date = pb_get_date();
|
---|
| 362 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
| 363 | $cvsopt = "-D \"$pbdate\"";
|
---|
| 364 | } else {
|
---|
| 365 | # we're working on a tag which should be the last part of PBROOTDIR
|
---|
| 366 | $cvsopt = "-r $cvstag";
|
---|
| 367 | }
|
---|
| 368 | pb_mkdir_p("$destination");
|
---|
[590] | 369 | pb_system("cd $destination ; cvs -d $account\@$host:$path co $cvsopt .","Checking out $url to $destination ");
|
---|
[500] | 370 | } elsif ($scheme =~ /^file/) {
|
---|
| 371 | pb_cms_export($url,undef,$destination);
|
---|
[395] | 372 | } else {
|
---|
| 373 | die "cms $scheme unknown";
|
---|
| 374 | }
|
---|
| 375 | }
|
---|
| 376 |
|
---|
[409] | 377 | =item B<pb_cms_up>
|
---|
| 378 |
|
---|
| 379 | This function updates a local directory with the CMS content.
|
---|
| 380 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 381 | The second parameter is the directory to update.
|
---|
| 382 |
|
---|
| 383 | =cut
|
---|
| 384 |
|
---|
[395] | 385 | sub pb_cms_up {
|
---|
| 386 | my $scheme = shift;
|
---|
| 387 | my $dir = shift;
|
---|
| 388 |
|
---|
| 389 | if ($scheme =~ /^svn/) {
|
---|
[590] | 390 | pb_system("svn up $dir","Updating $dir ");
|
---|
[395] | 391 | } elsif ($scheme eq "flat") {
|
---|
[612] | 392 | } elsif ($scheme =~ /^hg/) {
|
---|
| 393 | pb_system("cd $dir ; hg up","Updating $dir ");
|
---|
[395] | 394 | } elsif ($scheme =~ /^cvs/) {
|
---|
[590] | 395 | pb_system("cvs up $dir","Updating $dir ");
|
---|
[395] | 396 | } else {
|
---|
| 397 | die "cms $scheme unknown";
|
---|
| 398 | }
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[409] | 401 | =item B<pb_cms_checkin>
|
---|
| 402 |
|
---|
| 403 | This function updates a CMS content from a local directory.
|
---|
| 404 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 405 | The second parameter is the directory to update from.
|
---|
[452] | 406 | The third parameter indicates if we are in a new version creation (undef) or in a new project creation (1)
|
---|
[409] | 407 |
|
---|
| 408 | =cut
|
---|
| 409 |
|
---|
[395] | 410 | sub pb_cms_checkin {
|
---|
| 411 | my $scheme = shift;
|
---|
| 412 | my $dir = shift;
|
---|
[452] | 413 | my $pbinit = shift || undef;
|
---|
[395] | 414 |
|
---|
| 415 | my $ver = basename($dir);
|
---|
[452] | 416 | my $msg = "updated to $ver";
|
---|
| 417 | $msg = "Project $ENV{PBPROJ} creation" if (defined $pbinit);
|
---|
| 418 |
|
---|
[395] | 419 | if ($scheme =~ /^svn/) {
|
---|
[590] | 420 | pb_system("svn ci -m \"$msg\" $dir","Checking in $dir ");
|
---|
[395] | 421 | } elsif ($scheme eq "flat") {
|
---|
[612] | 422 | } elsif ($scheme =~ /^hg/) {
|
---|
| 423 | pb_system("hg ci -m \"$msg\" $dir","Checking in $dir ");
|
---|
[395] | 424 | } elsif ($scheme =~ /^cvs/) {
|
---|
[590] | 425 | pb_system("cvs ci -m \"$msg\" $dir","Checking in $dir ");
|
---|
[395] | 426 | } else {
|
---|
| 427 | die "cms $scheme unknown";
|
---|
| 428 | }
|
---|
| 429 | pb_cms_up($scheme,$dir);
|
---|
| 430 | }
|
---|
| 431 |
|
---|
[452] | 432 | =item B<pb_cms_add>
|
---|
| 433 |
|
---|
| 434 | This function adds to a CMS content from a local directory.
|
---|
| 435 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 436 | The second parameter is the directory/file to add.
|
---|
| 437 |
|
---|
| 438 | =cut
|
---|
| 439 |
|
---|
| 440 | sub pb_cms_add {
|
---|
| 441 | my $scheme = shift;
|
---|
| 442 | my $f = shift;
|
---|
| 443 |
|
---|
| 444 | if ($scheme =~ /^svn/) {
|
---|
[590] | 445 | pb_system("svn add $f","Adding $f to SVN ");
|
---|
[452] | 446 | } elsif ($scheme eq "flat") {
|
---|
[612] | 447 | } elsif ($scheme =~ /^hg/) {
|
---|
| 448 | pb_system("hg add $f","Adding $f to Mercurial ");
|
---|
[452] | 449 | } elsif ($scheme =~ /^cvs/) {
|
---|
[590] | 450 | pb_system("cvs add $f","Adding $f to CVS ");
|
---|
[452] | 451 | } else {
|
---|
| 452 | die "cms $scheme unknown";
|
---|
| 453 | }
|
---|
| 454 | pb_cms_up($scheme,$f);
|
---|
| 455 | }
|
---|
| 456 |
|
---|
[409] | 457 | =item B<pb_cms_isdiff>
|
---|
| 458 |
|
---|
| 459 | This function returns a integer indicating the number f differences between the CMS content and the local directory where it's checked out.
|
---|
| 460 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 461 | The second parameter is the directory to consider.
|
---|
| 462 |
|
---|
| 463 | =cut
|
---|
| 464 |
|
---|
[395] | 465 | sub pb_cms_isdiff {
|
---|
| 466 | my $scheme = shift;
|
---|
| 467 | my $dir =shift;
|
---|
| 468 |
|
---|
| 469 | if ($scheme =~ /^svn/) {
|
---|
| 470 | open(PIPE,"svn diff $dir |") || die "Unable to get svn diff from $dir";
|
---|
| 471 | my $l = 0;
|
---|
| 472 | while (<PIPE>) {
|
---|
| 473 | $l++;
|
---|
| 474 | }
|
---|
| 475 | return($l);
|
---|
[612] | 476 | } elsif ($scheme =~ /^hg/) {
|
---|
| 477 | open(PIPE,"hg diff $dir |") || die "Unable to get hg diff from $dir";
|
---|
| 478 | my $l = 0;
|
---|
| 479 | while (<PIPE>) {
|
---|
| 480 | $l++;
|
---|
| 481 | }
|
---|
| 482 | return($l);
|
---|
[395] | 483 | } elsif ($scheme eq "flat") {
|
---|
| 484 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 485 | open(PIPE,"cvs diff $dir |") || die "Unable to get svn diff from $dir";
|
---|
| 486 | my $l = 0;
|
---|
| 487 | while (<PIPE>) {
|
---|
| 488 | # Skipping normal messages
|
---|
| 489 | next if (/^cvs diff:/);
|
---|
| 490 | $l++;
|
---|
| 491 | }
|
---|
| 492 | return($l);
|
---|
| 493 | } else {
|
---|
| 494 | die "cms $scheme unknown";
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 |
|
---|
[539] | 498 | =item B<pb_cms_get_pkg>
|
---|
[409] | 499 |
|
---|
| 500 | This function returns the list of packages we are working on in a CMS action.
|
---|
| 501 | The first parameter is the default list of packages from the configuration file.
|
---|
| 502 | The second parameter is the optional list of packages from the configuration file.
|
---|
| 503 |
|
---|
| 504 | =cut
|
---|
| 505 |
|
---|
[395] | 506 | sub pb_cms_get_pkg {
|
---|
| 507 |
|
---|
| 508 | my @pkgs = ();
|
---|
| 509 | my $defpkgdir = shift || undef;
|
---|
| 510 | my $extpkgdir = shift || undef;
|
---|
| 511 |
|
---|
| 512 | # Get packages list
|
---|
| 513 | if (not defined $ARGV[0]) {
|
---|
| 514 | @pkgs = keys %$defpkgdir if (defined $defpkgdir);
|
---|
| 515 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
| 516 | @pkgs = keys %$defpkgdir if (defined $defpkgdir);
|
---|
| 517 | push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
|
---|
| 518 | } else {
|
---|
| 519 | @pkgs = @ARGV;
|
---|
| 520 | }
|
---|
| 521 | pb_log(0,"Packages: ".join(',',@pkgs)."\n");
|
---|
| 522 | return(\@pkgs);
|
---|
| 523 | }
|
---|
| 524 |
|
---|
[539] | 525 | =item B<pb_cms_get_real_pkg>
|
---|
| 526 |
|
---|
| 527 | This function returns the real name of a virtual package we are working on in a CMS action.
|
---|
| 528 | It supports the following types: perl.
|
---|
| 529 | The first parameter is the virtual package name
|
---|
| 530 |
|
---|
| 531 | =cut
|
---|
| 532 |
|
---|
| 533 | sub pb_cms_get_real_pkg {
|
---|
| 534 |
|
---|
| 535 | my $pbpkg = shift || undef;
|
---|
| 536 | my $dtype = shift;
|
---|
| 537 | my $pbpkgreal = $pbpkg;
|
---|
| 538 |
|
---|
| 539 | my @nametype = pb_conf_get_if("namingtype");
|
---|
| 540 | my $type = $nametype[0]->{$pbpkg};
|
---|
| 541 | if (defined $type) {
|
---|
| 542 | if ($type eq "perl") {
|
---|
| 543 | if ($dtype eq "rpm") {
|
---|
| 544 | $pbpkgreal = "perl-".$pbpkg;
|
---|
| 545 | } elsif ($dtype eq "deb") {
|
---|
[544] | 546 | # Only lower case allowed in Debian
|
---|
| 547 | # Cf: http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Package
|
---|
[539] | 548 | $pbpkgreal = "lib".lc($pbpkg)."-perl";
|
---|
| 549 | } elsif ($dtype eq "ebuild") {
|
---|
| 550 | $pbpkgreal = $pbpkg;
|
---|
| 551 | } else {
|
---|
| 552 | die "pb_cms_get_real_pkg not implemented for $dtype yet";
|
---|
| 553 | }
|
---|
| 554 | } else {
|
---|
| 555 | die "nametype $type not implemented yet";
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | pb_log(2,"Real Package: $pbpkgreal\n");
|
---|
| 560 | return($pbpkgreal);
|
---|
| 561 | }
|
---|
| 562 |
|
---|
[409] | 563 | =item B<pb_cms_compliant>
|
---|
| 564 |
|
---|
| 565 | This function checks the compliance of the project and the pbconf directory.
|
---|
| 566 | The first parameter is the key name of the value that needs to be read in the configuration file.
|
---|
| 567 | The second parameter is the environment variable this key will populate.
|
---|
| 568 | The third parameter is the location of the pbconf dir.
|
---|
| 569 | The fourth parameter is the URI of the CMS content related to the pbconf dir.
|
---|
| 570 | The fifth parameter indicates whether we should inititate the context or not.
|
---|
| 571 |
|
---|
| 572 | =cut
|
---|
| 573 |
|
---|
[395] | 574 | sub pb_cms_compliant {
|
---|
| 575 |
|
---|
| 576 | my $param = shift;
|
---|
| 577 | my $envar = shift;
|
---|
| 578 | my $defdir = shift;
|
---|
| 579 | my $uri = shift;
|
---|
| 580 | my $pbinit = shift;
|
---|
| 581 | my %pdir;
|
---|
| 582 |
|
---|
| 583 | my ($pdir) = pb_conf_get_if($param) if (defined $param);
|
---|
| 584 | if (defined $pdir) {
|
---|
| 585 | %pdir = %$pdir;
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 |
|
---|
| 589 | if ((defined $pdir) && (%pdir) && (defined $pdir{$ENV{'PBPROJ'}})) {
|
---|
| 590 | # That's always the environment variable that will be used
|
---|
| 591 | $ENV{$envar} = $pdir{$ENV{'PBPROJ'}};
|
---|
| 592 | } else {
|
---|
| 593 | if (defined $param) {
|
---|
| 594 | pb_log(1,"WARNING: no $param defined, using $defdir\n");
|
---|
| 595 | pb_log(1," Please create a $param reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
|
---|
| 596 | pb_log(1," if you want to use another directory\n");
|
---|
| 597 | }
|
---|
| 598 | $ENV{$envar} = "$defdir";
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | # Expand potential env variable in it
|
---|
| 602 | eval { $ENV{$envar} =~ s/(\$ENV.+\})/$1/eeg };
|
---|
| 603 | pb_log(2,"$envar: $ENV{$envar}\n");
|
---|
| 604 |
|
---|
| 605 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
| 606 |
|
---|
| 607 | if ((! -d "$ENV{$envar}") || (defined $pbinit)) {
|
---|
| 608 | if (defined $pbinit) {
|
---|
| 609 | pb_mkdir_p("$ENV{$envar}");
|
---|
| 610 | } else {
|
---|
| 611 | pb_log(1,"Checking out $uri\n");
|
---|
| 612 | pb_cms_checkout($scheme,$uri,$ENV{$envar});
|
---|
| 613 | }
|
---|
[612] | 614 | } elsif (($scheme !~ /^cvs/) || ($scheme !~ /^svn/) || ($scheme !~ /^hg/)) {
|
---|
[395] | 615 | # Do not compare if it's not a real cms
|
---|
| 616 | return;
|
---|
| 617 | } else {
|
---|
| 618 | pb_log(1,"$uri found locally, checking content\n");
|
---|
| 619 | my $cmsurl = pb_cms_get_uri($scheme,$ENV{$envar});
|
---|
| 620 | my ($scheme2, $account2, $host2, $port2, $path2) = pb_get_uri($cmsurl);
|
---|
| 621 | if ($cmsurl ne $uri) {
|
---|
| 622 | # The local content doesn't correpond to the repository
|
---|
| 623 | pb_log(0,"ERROR: Inconsistency detected:\n");
|
---|
| 624 | pb_log(0," * $ENV{$envar} refers to $cmsurl but\n");
|
---|
| 625 | pb_log(0," * $ENV{'PBETC'} refers to $uri\n");
|
---|
| 626 | die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
|
---|
| 627 | } else {
|
---|
| 628 | pb_log(1,"Content correct - doing nothing - you may want to update your repository however\n");
|
---|
| 629 | # they match - do nothing - there may be local changes
|
---|
| 630 | }
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
| 633 |
|
---|
[409] | 634 | =item B<pb_cms_create_authors>
|
---|
| 635 |
|
---|
| 636 | This function creates a AUTHORS files for the project. It call it AUTHORS.pb if an AUTHORS file already exists.
|
---|
| 637 | The first parameter is the source file for authors information.
|
---|
| 638 | The second parameter is the directory where to create the final AUTHORS file.
|
---|
| 639 | The third parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 640 |
|
---|
| 641 | =cut
|
---|
| 642 |
|
---|
[405] | 643 | sub pb_cms_create_authors {
|
---|
[395] | 644 |
|
---|
[405] | 645 | my $authors=shift;
|
---|
| 646 | my $dest=shift;
|
---|
| 647 | my $scheme=shift;
|
---|
[395] | 648 |
|
---|
[405] | 649 | return if ($authors eq "/dev/null");
|
---|
| 650 | open(SAUTH,$authors) || die "Unable to open $authors";
|
---|
[409] | 651 | # Save a potentially existing AUTHORS file and write instead to AUTHORS.pb
|
---|
[405] | 652 | my $ext = "";
|
---|
| 653 | if (-f "$dest/AUTHORS") {
|
---|
| 654 | $ext = ".pb";
|
---|
[395] | 655 | }
|
---|
[405] | 656 | open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
|
---|
| 657 | print DAUTH "Authors of the project are:\n";
|
---|
| 658 | print DAUTH "===========================\n";
|
---|
| 659 | while (<SAUTH>) {
|
---|
| 660 | my ($nick,$gcos) = split(/:/);
|
---|
| 661 | chomp($gcos);
|
---|
| 662 | print DAUTH "$gcos";
|
---|
| 663 | if (defined $scheme) {
|
---|
| 664 | # Do not give a scheme for flat types
|
---|
| 665 | my $endstr="";
|
---|
| 666 | if ("$ENV{'PBREVISION'}" ne "flat") {
|
---|
| 667 | $endstr = " under $scheme";
|
---|
| 668 | }
|
---|
| 669 | print DAUTH " ($nick$endstr)\n";
|
---|
| 670 | } else {
|
---|
| 671 | print DAUTH "\n";
|
---|
| 672 | }
|
---|
[395] | 673 | }
|
---|
[405] | 674 | close(DAUTH);
|
---|
| 675 | close(SAUTH);
|
---|
[395] | 676 | }
|
---|
| 677 |
|
---|
[409] | 678 | =item B<pb_cms_log>
|
---|
| 679 |
|
---|
| 680 | This function creates a ChangeLog file for the project.
|
---|
| 681 | The first parameter is the schema of the CMS systems (svn, cvs, svn+ssh, ...)
|
---|
| 682 | The second parameter is the directory where the CMS content was checked out.
|
---|
| 683 | The third parameter is the directory where to create the final ChangeLog file.
|
---|
| 684 | The fourth parameter is unused.
|
---|
| 685 | The fifth parameter is the source file for authors information.
|
---|
| 686 |
|
---|
| 687 | It may use a tool like svn2cl or cvs2cl to generate it if present, or the log file from the CMS if not.
|
---|
| 688 |
|
---|
| 689 | =cut
|
---|
| 690 |
|
---|
| 691 |
|
---|
[405] | 692 | sub pb_cms_log {
|
---|
[395] | 693 |
|
---|
[405] | 694 | my $scheme = shift;
|
---|
| 695 | my $pkgdir = shift;
|
---|
| 696 | my $dest = shift;
|
---|
| 697 | my $chglog = shift;
|
---|
| 698 | my $authors = shift;
|
---|
[448] | 699 | my $testver = shift || undef;
|
---|
[395] | 700 |
|
---|
[405] | 701 | pb_cms_create_authors($authors,$dest,$scheme);
|
---|
[395] | 702 |
|
---|
[448] | 703 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
| 704 | if (! -f "$dest/ChangeLog") {
|
---|
| 705 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 706 | # We need a minimal version for debian type of build
|
---|
| 707 | print CL "\n";
|
---|
| 708 | print CL "\n";
|
---|
| 709 | print CL "\n";
|
---|
| 710 | print CL "\n";
|
---|
| 711 | print CL "1990-01-01 none\n";
|
---|
| 712 | print CL "\n";
|
---|
| 713 | print CL " * test version\n";
|
---|
| 714 | print CL "\n";
|
---|
| 715 | close(CL);
|
---|
| 716 | pb_log(0,"Generating fake ChangeLog for test version\n");
|
---|
| 717 | open(CL,"> $dest/$ENV{'PBCMSLOGFILE'}") || die "Unable to create $dest/$ENV{'PBCMSLOGFILE'}";
|
---|
| 718 | close(CL);
|
---|
| 719 | }
|
---|
| 720 | }
|
---|
| 721 |
|
---|
[405] | 722 | if ($scheme =~ /^svn/) {
|
---|
| 723 | if (! -f "$dest/ChangeLog") {
|
---|
[448] | 724 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 725 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 726 | close(CL);
|
---|
[405] | 727 | if (-x "/usr/bin/svn2cl") {
|
---|
| 728 | pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
|
---|
[395] | 729 | } else {
|
---|
[405] | 730 | # To be written from pbcl
|
---|
| 731 | pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
|
---|
[395] | 732 | }
|
---|
[405] | 733 | }
|
---|
[612] | 734 | } elsif ($scheme =~ /^hg/) {
|
---|
| 735 | if (! -f "$dest/ChangeLog") {
|
---|
| 736 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 737 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 738 | close(CL);
|
---|
| 739 | pb_system("hg log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
|
---|
| 740 | }
|
---|
[405] | 741 | } elsif (($scheme eq "file") || ($scheme eq "dir") || ($scheme eq "http") || ($scheme eq "ftp")) {
|
---|
| 742 | if (! -f "$dest/ChangeLog") {
|
---|
| 743 | pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
|
---|
| 744 | }
|
---|
| 745 | } elsif ($scheme =~ /^cvs/) {
|
---|
| 746 | my $tmp=basename($pkgdir);
|
---|
| 747 | # CVS needs a relative path !
|
---|
| 748 | if (! -f "$dest/ChangeLog") {
|
---|
[448] | 749 | # In case we have no network, just create an empty one before to allow correct build
|
---|
| 750 | open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
|
---|
| 751 | close(CL);
|
---|
[405] | 752 | if (-x "/usr/bin/cvs2cl") {
|
---|
| 753 | pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
|
---|
[395] | 754 | } else {
|
---|
[405] | 755 | # To be written from pbcl
|
---|
| 756 | pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
|
---|
[395] | 757 | }
|
---|
| 758 | }
|
---|
[405] | 759 | } else {
|
---|
| 760 | die "cms $scheme unknown";
|
---|
[395] | 761 | }
|
---|
| 762 | }
|
---|
[405] | 763 |
|
---|
[600] | 764 | sub pb_cms_mod_svn_http {
|
---|
| 765 |
|
---|
| 766 | my $url = shift;
|
---|
| 767 |
|
---|
| 768 | $url =~ s/^svn\+(http[s]*):/$1:/;
|
---|
| 769 | return($url);
|
---|
| 770 | }
|
---|
| 771 |
|
---|
[612] | 772 | sub pb_cms_mod_hg_http {
|
---|
| 773 |
|
---|
| 774 | my $url = shift;
|
---|
| 775 |
|
---|
| 776 | $url =~ s/^hg\+(http[s]*):/$1:/;
|
---|
| 777 | return($url);
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[409] | 780 | =back
|
---|
| 781 |
|
---|
| 782 | =head1 WEB SITES
|
---|
| 783 |
|
---|
| 784 | 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/>.
|
---|
| 785 |
|
---|
| 786 | =head1 USER MAILING LIST
|
---|
| 787 |
|
---|
| 788 | None exists for the moment.
|
---|
| 789 |
|
---|
| 790 | =head1 AUTHORS
|
---|
| 791 |
|
---|
| 792 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 793 |
|
---|
| 794 | =head1 COPYRIGHT
|
---|
| 795 |
|
---|
| 796 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 797 | described in the file C<COPYING> included with the distribution.
|
---|
| 798 |
|
---|
| 799 | =cut
|
---|
| 800 |
|
---|
[395] | 801 | 1;
|
---|