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