Changeset 661 in ProjectBuilder for devel


Ignore:
Timestamp:
Feb 5, 2009, 1:57:26 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • Adds GIT support for schroot (initial, works for cms2build)
  • Adds SOCKS support for all VCS commands by adding a new pbsockscmd option in .pbrc (tested with git access behind proxy)
Location:
devel/pb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r658 r661  
    18681868pb_system("useradd $pbac->{$ENV{'PBPROJ'}} -g $pbac->{$ENV{'PBPROJ'}} -m -d /home/$pbac->{$ENV{'PBPROJ'}}","Adding user $pbac->{$ENV{'PBPROJ'}} (group $pbac->{$ENV{'PBPROJ'}} - home /home/$pbac->{$ENV{'PBPROJ'}}");
    18691869}
    1870 
     1870EOF
     1871
     1872    if ($vtype eq "vm") {
     1873        print SCRIPT << "EOF";
    18711874# allow ssh entry to build
    18721875#
     
    18781881
    18791882EOF
     1883}
    18801884    print SCRIPT << 'EOF';
    18811885# No passwd for build account only keys
  • devel/pb/lib/ProjectBuilder/CMS.pm

    r626 r661  
    6161pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pburl->{$ENV{'PBPROJ'}}\n");
    6262my ($scheme, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
     63my $vcscmd = pb_cms_cmd($scheme);
    6364
    6465my ($pbprojdir) = pb_conf_get_if("pbprojdir");
     
    8384pb_cms_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$pburl->{$ENV{'PBPROJ'}},$pbinit);
    8485
     86
    8587if ($scheme =~ /^hg/) {
    86     $tmp = `(cd "$ENV{'PBDIR'}" ; hg identify )`;
     88    $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd identify )`;
    8789    chomp($tmp);
    8890    $tmp =~ s/^.* //;
    8991    $ENV{'PBREVISION'}=$tmp;
    9092    $ENV{'PBCMSLOGFILE'}="hg.log";
     93} elsif ($scheme =~ /^git/) {
     94    $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd log | head -1 | cut -f2)`;
     95    chomp($tmp);
     96    $tmp =~ s/^.* //;
     97    $ENV{'PBREVISION'}=$tmp;
     98    $ENV{'PBCMSLOGFILE'}="git.log";
    9199} elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
    92100    $ENV{'PBREVISION'}="flat";
     
    94102} elsif ($scheme =~ /^svn/) {
    95103    # svnversion more precise than svn info
    96     $tmp = `(cd "$ENV{'PBDIR'}" ; svnversion .)`;
     104    $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd"version" .)`;
    97105    chomp($tmp);
    98106    $ENV{'PBREVISION'}=$tmp;
     
    133141# If it's not flat, then we have a real uri as source
    134142my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
     143my $vcscmd = pb_cms_cmd($scheme);
     144$uri = pb_cms_mod_socks($uri);
    135145
    136146if ($scheme =~ /^svn/) {
     
    141151            $tmp = "$destdir/".basename($source);
    142152        }
    143         $source = pb_cms_mod_svn_http($source);
    144         pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp ");
    145     } else {
    146         $uri = pb_cms_mod_svn_http($uri);
    147         pb_system("svn export $uri $destdir","Exporting $uri from SVN to $destdir ");
     153        $source = pb_cms_mod_http($source,"svn");
     154        pb_system("$vcscmd export $source $tmp","Exporting $source from SVN to $tmp ");
     155    } else {
     156        $uri = pb_cms_mod_http($uri,"svn");
     157        pb_system("$vcscmd export $uri $destdir","Exporting $uri from SVN to $destdir ");
    148158    }
    149159} elsif ($scheme eq "dir") {
     
    152162    my $f = basename($path);
    153163    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     }
     164    pb_system("$vcscmd $ENV{'PBTMP'}/$f $uri","Downloading $uri with $vcscmd to $ENV{'PBTMP'}/$f\n");
    161165    # We want to preserve the original tar file
    162166    pb_cms_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
     
    207211            $tmp = "$destdir/".basename($source);
    208212        }
    209         $source = pb_cms_mod_hg_http($source);
    210         pb_system("cd $source ; hg archive $tmp","Exporting $source from Mercurial to $tmp ");
    211     } else {
    212         $uri = pb_cms_mod_hg_http($uri);
    213         pb_system("hg clone $uri $destdir","Exporting $uri from Mercurial to $destdir ");
     213        $source = pb_cms_mod_http($source,"hg");
     214        pb_system("cd $source ; $vcscmd archive $tmp","Exporting $source from Mercurial to $tmp ");
     215    } else {
     216        $uri = pb_cms_mod_http($uri,"hg");
     217        pb_system("$vcscmd clone $uri $destdir","Exporting $uri from Mercurial to $destdir ");
     218    }
     219} elsif ($scheme =~ /^git/) {
     220    if (defined $source) {
     221        if (-d $source) {
     222            $tmp = $destdir;
     223        } else {
     224            $tmp = "$destdir/".basename($source);
     225        }
     226        $source = pb_cms_mod_http($source,"git");
     227        pb_system("cd $source ; $vcscmd archive --format=tar HEAD | (mkdir $tmp && cd $tmp && tar xf -)","Exporting $source/HEAD from GIT to $tmp ");
     228    } else {
     229        $uri = pb_cms_mod_http($uri,"git");
     230        pb_system("$vcscmd clone $uri $destdir","Exporting $uri from GIT to $destdir ");
    214231    }
    215232} elsif ($scheme =~ /^cvs/) {
     
    234251        $cvsopt = "-r $cvstag";
    235252    }
    236     pb_system("cd $dir ; cvs -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir ");
     253    pb_system("cd $dir ; $vcscmd -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir ");
    237254} else {
    238255    die "cms $scheme unknown";
     
    256273my $res = "";
    257274my $void = "";
     275my $vcscmd = pb_cms_cmd($scheme);
    258276
    259277if ($scheme =~ /^svn/) {
    260     open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
     278    open(PIPE,"LANGUAGE=C $vcscmd info $dir |") || return("");
    261279    while (<PIPE>) {
    262280        ($void,$res) = split(/^URL:/) if (/^URL:/);
     
    271289    }
    272290    close(HGRC);
     291    chomp($res);
     292} elsif ($scheme =~ /^git/) {
     293    open(GITRC,".git/gitrc/") || return("");
     294    while (<GITRC>) {
     295        ($void,$res) = split(/^default.*=/) if (/^default.*=/);
     296    }
     297    close(GITRC);
    273298    chomp($res);
    274299} elsif ($scheme =~ /^cvs/) {
     
    318343my $oldurl = shift;
    319344my $newurl = shift;
     345my $vcscmd = pb_cms_cmd($scheme);
     346$oldurl = pb_cms_mod_socks($oldurl);
     347$newurl = pb_cms_mod_socks($newurl);
    320348
    321349if ($scheme =~ /^svn/) {
    322     $oldurl = pb_cms_mod_svn_http($oldurl);
    323     $newurl = pb_cms_mod_svn_http($newurl);
    324     pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
     350    $oldurl = pb_cms_mod_http($oldurl,"svn");
     351    $newurl = pb_cms_mod_http($newurl,"svn");
     352    pb_system("$vcscmd copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
    325353} elsif ($scheme eq "flat") {
    326354} elsif ($scheme =~ /^cvs/) {
     
    343371my $url = shift;
    344372my $destination = shift;
     373my $vcscmd = pb_cms_cmd($scheme);
     374$url = pb_cms_mod_socks($url);
    345375
    346376if ($scheme =~ /^svn/) {
    347     $url = pb_cms_mod_svn_http($url);
    348     pb_system("svn co $url $destination","Checking out $url to $destination ");
     377    $url = pb_cms_mod_http($url,"svn");
     378    pb_system("$vcscmd co $url $destination","Checking out $url to $destination ");
    349379} elsif ($scheme =~ /^hg/) {
    350     $url = pb_cms_mod_hg_http($url);
    351     pb_system("hg clone $url $destination","Checking out $url to $destination ");
     380    $url = pb_cms_mod_http($url,"hg");
     381    pb_system("$vcscmd clone $url $destination","Checking out $url to $destination ");
     382} elsif ($scheme =~ /^git/) {
     383    $url = pb_cms_mod_http($url,"git");
     384    pb_system("$vcscmd clone $url $destination","Checking out $url to $destination ");
    352385} elsif (($scheme eq "ftp") || ($scheme eq "http")) {
    353386    return;
     
    367400    }
    368401    pb_mkdir_p("$destination");
    369     pb_system("cd $destination ; cvs -d $account\@$host:$path co $cvsopt .","Checking out $url to $destination ");
     402    pb_system("cd $destination ; $vcscmd -d $account\@$host:$path co $cvsopt .","Checking out $url to $destination ");
    370403} elsif ($scheme =~ /^file/) {
    371404    pb_cms_export($url,undef,$destination);
     
    386419my $scheme = shift;
    387420my $dir = shift;
    388 
    389 if ($scheme =~ /^svn/) {
    390     pb_system("svn up $dir","Updating $dir ");
     421my $vcscmd = pb_cms_cmd($scheme);
     422
     423if (($scheme =~ /^svn/) || ($scheme =~ /^hg/) || ($scheme =~ /^git/) || ($scheme =~ /^cvs/)) {
     424    pb_system("$vcscmd up $dir","Updating $dir ");
    391425} elsif ($scheme eq "flat") {
    392 } elsif ($scheme =~ /^hg/) {
    393     pb_system("cd $dir ; hg up","Updating $dir ");
    394 } elsif ($scheme =~ /^cvs/) {
    395     pb_system("cvs up $dir","Updating $dir ");
    396426} else {
    397427    die "cms $scheme unknown";
     
    412442my $dir = shift;
    413443my $pbinit = shift || undef;
     444my $vcscmd = pb_cms_cmd($scheme);
    414445
    415446my $ver = basename($dir);
     
    417448$msg = "Project $ENV{PBPROJ} creation" if (defined $pbinit);
    418449
    419 if ($scheme =~ /^svn/) {
    420     pb_system("svn ci -m \"$msg\" $dir","Checking in $dir ");
     450if (($scheme =~ /^svn/) || ($scheme =~ /^hg/) || ($scheme =~ /^git/) || ($scheme =~ /^cvs/)) {
     451    pb_system("cd $dir ; $vcscmd ci -m \"$msg\" .","Checking in $dir ");
    421452} elsif ($scheme eq "flat") {
    422 } elsif ($scheme =~ /^hg/) {
    423     pb_system("cd $dir ; hg ci -m \"$msg\" .","Checking in $dir ");
    424 } elsif ($scheme =~ /^cvs/) {
    425     pb_system("cvs ci -m \"$msg\" $dir","Checking in $dir ");
    426453} else {
    427454    die "cms $scheme unknown";
     
    441468my $scheme = shift;
    442469my $f = shift;
    443 
    444 if ($scheme =~ /^svn/) {
    445     pb_system("svn add $f","Adding $f to SVN ");
     470my $vcscmd = pb_cms_cmd($scheme);
     471
     472if (($scheme =~ /^svn/) || ($scheme =~ /^hg/) || ($scheme =~ /^git/) || ($scheme =~ /^cvs/)) {
     473    pb_system("$vcscmd add $f","Adding $f to VCS ");
    446474} elsif ($scheme eq "flat") {
    447 } elsif ($scheme =~ /^hg/) {
    448     pb_system("hg add $f","Adding $f to Mercurial ");
    449 } elsif ($scheme =~ /^cvs/) {
    450     pb_system("cvs add $f","Adding $f to CVS ");
    451475} else {
    452476    die "cms $scheme unknown";
     
    466490my $scheme = shift;
    467491my $dir =shift;
    468 
    469 if ($scheme =~ /^svn/) {
    470     open(PIPE,"svn diff $dir |") || die "Unable to get svn diff from $dir";
     492my $vcscmd = pb_cms_cmd($scheme);
     493
     494if (($scheme =~ /^svn/) || ($scheme =~ /^hg/) || ($scheme =~ /^git/) || ($scheme =~ /^cvs/)) {
     495    open(PIPE,"$vcscmd diff $dir |") || die "Unable to get $vcscmd diff from $dir";
    471496    my $l = 0;
    472497    while (<PIPE>) {
    473         $l++;
    474     }
    475     return($l);
    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>) {
     498        # Skipping normal messages in case of CVS
     499        next if (/^cvs diff:/);
    480500        $l++;
    481501    }
    482502    return($l);
    483503} 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);
    493504} else {
    494505    die "cms $scheme unknown";
     
    612623        pb_cms_checkout($scheme,$uri,$ENV{$envar});
    613624    }
    614 } elsif (($scheme !~ /^cvs/) || ($scheme !~ /^svn/)  || ($scheme !~ /^hg/)) {
     625} elsif (($scheme !~ /^cvs/) || ($scheme !~ /^svn/) || ($scheme !~ /^hg/) || ($scheme !~ /^git/) ) {
    615626    # Do not compare if it's not a real cms
    616627    return;
     
    700711
    701712pb_cms_create_authors($authors,$dest,$scheme);
     713my $vcscmd = pb_cms_cmd($scheme);
    702714
    703715if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
     
    729741        } else {
    730742            # To be written from pbcl
    731             pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
     743            pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
    732744        }
    733745    }
     
    737749        open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
    738750        close(CL);
    739         pb_system("hg log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
     751        pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
     752        }
     753} elsif ($scheme =~ /^git/) {
     754    if (! -f "$dest/ChangeLog") {
     755        # In case we have no network, just create an empty one before to allow correct build
     756        open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
     757        close(CL);
     758        pb_system("$vcscmd log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from GIT");
    740759        }
    741760} elsif (($scheme eq "file") || ($scheme eq "dir") || ($scheme eq "http") || ($scheme eq "ftp")) {
     
    754773        } else {
    755774            # To be written from pbcl
    756             pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
    757         }
    758     }
    759 } else {
    760     die "cms $scheme unknown";
    761 }
    762 }
    763 
    764 sub pb_cms_mod_svn_http {
     775            pb_system("$vcscmd log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
     776        }
     777    }
     778} else {
     779    die "cms $scheme unknown";
     780}
     781}
     782
     783sub pb_cms_mod_http {
    765784
    766785my $url = shift;
    767 
    768 $url =~ s/^svn\+(http[s]*):/$1:/;
     786my $proto = shift;
     787
     788$url =~ s/^$proto\+(http[s]*):/$1:/;
    769789return($url);
    770790}
    771791
    772 sub pb_cms_mod_hg_http {
     792sub pb_cms_mod_socks {
    773793
    774794my $url = shift;
    775795
    776 $url =~ s/^hg\+(http[s]*):/$1:/;
     796$url =~ s/^([A-z0-9]+)\+(socks):/$1:/;
    777797return($url);
    778798}
     799
     800
     801sub pb_cms_cmd {
     802
     803my $scheme = shift;
     804my $cmd = "";
     805
     806# If there is a socks proxy to use
     807if ($scheme =~ /socks/) {
     808    # Get the socks proxy command from the conf file
     809    my ($pbsockcmd) = pb_conf_get("pbsockscmd");
     810    $cmd = "$pbsockcmd->{$ENV{'PBPROJ'}} ";
     811}
     812
     813if ($scheme =~ /hg/) {
     814    return($cmd."hg")
     815} elsif ($scheme =~ /git/) {
     816    return($cmd."git")
     817} elsif ($scheme =~ /svn/) {
     818    return($cmd."svn")
     819} elsif ($scheme =~ /cvs/) {
     820    return($cmd."cvs")
     821} elsif (($scheme =~ /http/) || ($scheme =~ /ftp/)) {
     822    if (-x "/usr/bin/wget") {
     823        return($cmd."/usr/bin/wget -nv -O ");
     824    } elsif (-x "/usr/bin/curl") {
     825        return($cmd."/usr/bin/curl -o ");
     826    } else {
     827        die "Unable to handle $scheme.\nNo wget/curl available, please install one of those";
     828    }
     829} else {
     830    return($cmd);
     831}
     832}
     833
     834   
    779835
    780836=back
Note: See TracChangeset for help on using the changeset viewer.