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