Changeset 2312 in ProjectBuilder


Ignore:
Timestamp:
Sep 6, 2017, 9:08:46 PM (7 years ago)
Author:
Bruno Cornec
Message:

pb_cms_init becomes pb_vcs_init to be used in env_init

Location:
devel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/VCS.pm

    r2308 r2312  
    3636 
    3737our @ISA = qw(Exporter);
    38 our @EXPORT = qw(pb_vcs_export pb_vcs_get_uri pb_vcs_copy pb_vcs_checkout pb_vcs_up pb_vcs_checkin pb_vcs_isdiff pb_vcs_add pb_vcs_add_if_not_in pb_vcs_cmd pb_vcs_compliant pb_vcs_conf_update_v0);
     38our @EXPORT = qw(pb_vcs_init pb_vcs_export pb_vcs_get_uri pb_vcs_copy pb_vcs_checkout pb_vcs_up pb_vcs_checkin pb_vcs_isdiff pb_vcs_add pb_vcs_add_if_not_in pb_vcs_cmd pb_vcs_compliant pb_vcs_conf_update_v0);
    3939($VERSION,$REVISION) = pb_version_init();
    4040
     
    5252
    5353=over 4
     54
     55
     56=item B<pb_vcs_init>
     57
     58This function setup the environment for the VCS system related to the URL given by the pbprojurl configuration parameter.
     59The potential parameter indicates whether we should inititate the context or not.
     60It sets up environement variables (PBPROJDIR, PBDIR, PBREVISION, PBCMSLOGFILE)
     61
     62=cut
     63
     64sub pb_vcs_init {
     65
     66my $pbinit = shift;
     67my $param = shift;
     68
     69my ($pbprojurl) = pb_conf_get("pbprojurl");
     70confess "Undefined pbprojurl for $ENV{'PBPROJ'}\n" if ((not defined $pbprojurl) or (not defined $pbprojurl->{$ENV{'PBPROJ'}}));
     71pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pbprojurl->{$ENV{'PBPROJ'}}\n");
     72my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbprojurl->{$ENV{'PBPROJ'}});
     73my $vcscmd = pb_vcs_cmd($scheme);
     74
     75my ($pbprojdir) = pb_conf_get_if("pbprojdir");
     76
     77if ((defined $pbprojdir) && (defined $pbprojdir->{$ENV{'PBPROJ'}})) {
     78    $ENV{'PBPROJDIR'} = $pbprojdir->{$ENV{'PBPROJ'}};
     79} else {
     80    $ENV{'PBPROJDIR'} = "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}";
     81}
     82# Expand potential env variable in it to allow string replacement
     83eval { $ENV{'PBPROJDIR'} =~ s/(\$ENV.+\})/$1/eeg };
     84
     85
     86# Computing the default dir for PBDIR.
     87# what we have is PBPROJDIR so work from that.
     88# Tree identical between PBCONFDIR and PBROOTDIR on one side and
     89# PBPROJDIR and PBDIR on the other side.
     90
     91my $tmp = $ENV{'PBROOTDIR'};
     92$tmp =~ s|^$ENV{'PBCONFDIR'}/||;
     93# If no subdir, then replace again
     94$tmp =~ s|^$ENV{'PBCONFDIR'}||;
     95
     96#
     97# Check project cms compliance
     98#
     99my $turl = "$pbprojurl->{$ENV{'PBPROJ'}}/$tmp";
     100$turl = $pbprojurl->{$ENV{'PBPROJ'}} if ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)|(git)\b/o);
     101# git svn is like svn
     102$turl = "$pbprojurl->{$ENV{'PBPROJ'}}/$tmp"  if ($scheme =~ /^git\+svn/o);
     103pb_vcs_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$turl,$pbinit);
     104
     105
     106if ($scheme =~ /^hg/) {
     107    $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd identify )`;
     108    chomp($tmp);
     109    $tmp =~ s/^.* //;
     110    $ENV{'PBREVISION'}=$tmp;
     111    $ENV{'PBCMSLOGFILE'}="hg.log";
     112} elsif ($scheme =~ /^git/) {
     113    if ($scheme =~ /svn/) {
     114        $tmp = `(cd "$ENV{'PBDIR'}" ; LANGUAGE=C $vcscmd info | grep -E '^Revision:' | cut -d: -f2)`;
     115        $tmp =~ s/\s+//;
     116    } else {
     117        $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd log | head -1 | cut -f2)`;
     118        $tmp =~ s/^.* //;
     119        # Reduce length of commit id to 8 digit
     120        $tmp = substr($tmp,1,8);
     121    }
     122    chomp($tmp);
     123    $ENV{'PBREVISION'}=$tmp;
     124    $ENV{'PBCMSLOGFILE'}="git.log";
     125} elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)\b/o) {
     126    $ENV{'PBREVISION'}="flat";
     127    $ENV{'PBCMSLOGFILE'}="flat.log";
     128} elsif ($scheme =~ /^svn/) {
     129    # svnversion more precise than svn info if sbx
     130    if ((defined $param) && ($param eq "CMS")) {
     131        $tmp = `(LANGUAGE=C $vcscmd info $pbprojurl->{$ENV{'PBPROJ'}} | grep -E '^Revision:' | cut -d: -f2)`;
     132        $tmp =~ s/\s+//;
     133    } else {
     134        $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd"version" .)`;
     135    }
     136    chomp($tmp);
     137    $ENV{'PBREVISION'}=$tmp;
     138    $ENV{'PBCMSLOGFILE'}="svn.log";
     139} elsif ($scheme =~ /^svk/) {
     140    $tmp = `(cd "$ENV{'PBDIR'}" ; LANGUAGE=C $vcscmd info . | grep -E '^Revision:' | cut -d: -f2)`;
     141    $tmp =~ s/\s+//;
     142    chomp($tmp);
     143    $ENV{'PBREVISION'}=$tmp;
     144    $ENV{'PBCMSLOGFILE'}="svk.log";
     145} elsif ($scheme =~ /^cvs/) {
     146    # Way too slow
     147    #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOTDIR'}" ; cvs rannotate  -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
     148    #chomp($ENV{'PBREVISION'});
     149    $ENV{'PBREVISION'}="cvs";
     150    $ENV{'PBCMSLOGFILE'}="cvs.log";
     151    $ENV{'CVS_RSH'} = "ssh" if ($scheme =~ /ssh/);
     152} else {
     153    die "cms $scheme unknown";
     154}
     155
     156pb_log(1,"pb_vcs_init returns $scheme,$pbprojurl->{$ENV{'PBPROJ'}}\n");
     157return($scheme,$pbprojurl->{$ENV{'PBPROJ'}});
     158}
     159
    54160
    55161=item B<pb_vcs_export>
     
    660766The second parameter is the environment variable this key will populate.
    661767The third parameter is the location of the pbconf dir.
    662 The fourth parameter is the URI of the CMS content related to the pbconf dir.
     768The fourth parameter is the URI of the VCS content related to the pbconf dir.
    663769The fifth parameter indicates whether we should inititate the context or not.
    664770
  • devel/pb/bin/pb

    r2303 r2312  
    11811181    }
    11821182
    1183     my ($scheme, $uri) = pb_cms_init($pbinit,$param);
     1183    my ($scheme, $uri) = pb_vcs_init($pbinit,$param);
    11841184
    11851185    # We need 2 lines here
     
    35383538
    35393539    # Need this call for PBDIR
    3540     my ($scheme2,$uri) = pb_cms_init($pbinit);
     3540    my ($scheme2,$uri) = pb_vcs_init($pbinit);
    35413541
    35423542    my ($pbconf,$pbprojurl) = pb_conf_get("pbconfurl","pbprojurl");
     
    43004300            my $chglog;
    43014301
    4302             pb_cms_init($pbinit);
     4302            pb_vcs_init($pbinit);
    43034303            # Get project info on log file and generate tmp files used later on
    43044304            $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
  • devel/pb/lib/ProjectBuilder/CMS.pm

    r2300 r2312  
    3535 
    3636our @ISA = qw(Exporter);
    37 our @EXPORT = qw(pb_cms_init pb_cms_get_pkg pb_cms_get_real_pkg pb_cms_log);
     37our @EXPORT = qw(pb_cms_get_pkg pb_cms_get_real_pkg pb_cms_log);
    3838($VERSION,$REVISION) = pb_version_init();
    3939
     
    5151
    5252=over 4
    53 
    54 =item B<pb_cms_init>
    55 
    56 This function setup the environment for the CMS system related to the URL given by the pbprojurl configuration parameter.
    57 The potential parameter indicates whether we should inititate the context or not.
    58 It sets up environement variables (PBPROJDIR, PBDIR, PBREVISION, PBCMSLOGFILE)
    59 
    60 =cut
    61 
    62 sub pb_cms_init {
    63 
    64 my $pbinit = shift;
    65 my $param = shift;
    66 
    67 my ($pbprojurl) = pb_conf_get("pbprojurl");
    68 confess "Undefined pbprojurl for $ENV{'PBPROJ'}\n" if ((not defined $pbprojurl) or (not defined $pbprojurl->{$ENV{'PBPROJ'}}));
    69 pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pbprojurl->{$ENV{'PBPROJ'}}\n");
    70 my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbprojurl->{$ENV{'PBPROJ'}});
    71 my $vcscmd = pb_vcs_cmd($scheme);
    72 
    73 my ($pbprojdir) = pb_conf_get_if("pbprojdir");
    74 
    75 if ((defined $pbprojdir) && (defined $pbprojdir->{$ENV{'PBPROJ'}})) {
    76     $ENV{'PBPROJDIR'} = $pbprojdir->{$ENV{'PBPROJ'}};
    77 } else {
    78     $ENV{'PBPROJDIR'} = "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}";
    79 }
    80 # Expand potential env variable in it to allow string replacement
    81 eval { $ENV{'PBPROJDIR'} =~ s/(\$ENV.+\})/$1/eeg };
    82 
    83 
    84 # Computing the default dir for PBDIR.
    85 # what we have is PBPROJDIR so work from that.
    86 # Tree identical between PBCONFDIR and PBROOTDIR on one side and
    87 # PBPROJDIR and PBDIR on the other side.
    88 
    89 my $tmp = $ENV{'PBROOTDIR'};
    90 $tmp =~ s|^$ENV{'PBCONFDIR'}/||;
    91 # If no subdir, then replace again
    92 $tmp =~ s|^$ENV{'PBCONFDIR'}||;
    93 
    94 #
    95 # Check project cms compliance
    96 #
    97 my $turl = "$pbprojurl->{$ENV{'PBPROJ'}}/$tmp";
    98 $turl = $pbprojurl->{$ENV{'PBPROJ'}} if ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)|(git)\b/o);
    99 # git svn is like svn
    100 $turl = "$pbprojurl->{$ENV{'PBPROJ'}}/$tmp"  if ($scheme =~ /^git\+svn/o);
    101 pb_vcs_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$turl,$pbinit);
    102 
    103 
    104 if ($scheme =~ /^hg/) {
    105     $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd identify )`;
    106     chomp($tmp);
    107     $tmp =~ s/^.* //;
    108     $ENV{'PBREVISION'}=$tmp;
    109     $ENV{'PBCMSLOGFILE'}="hg.log";
    110 } elsif ($scheme =~ /^git/) {
    111     if ($scheme =~ /svn/) {
    112         $tmp = `(cd "$ENV{'PBDIR'}" ; LANGUAGE=C $vcscmd info | grep -E '^Revision:' | cut -d: -f2)`;
    113         $tmp =~ s/\s+//;
    114     } else {
    115         $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd log | head -1 | cut -f2)`;
    116         $tmp =~ s/^.* //;
    117         # Reduce length of commit id to 8 digit
    118         $tmp = substr($tmp,1,8);
    119     }
    120     chomp($tmp);
    121     $ENV{'PBREVISION'}=$tmp;
    122     $ENV{'PBCMSLOGFILE'}="git.log";
    123 } elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)\b/o) {
    124     $ENV{'PBREVISION'}="flat";
    125     $ENV{'PBCMSLOGFILE'}="flat.log";
    126 } elsif ($scheme =~ /^svn/) {
    127     # svnversion more precise than svn info if sbx
    128     if ((defined $param) && ($param eq "CMS")) {
    129         $tmp = `(LANGUAGE=C $vcscmd info $pbprojurl->{$ENV{'PBPROJ'}} | grep -E '^Revision:' | cut -d: -f2)`;
    130         $tmp =~ s/\s+//;
    131     } else {
    132         $tmp = `(cd "$ENV{'PBDIR'}" ; $vcscmd"version" .)`;
    133     }
    134     chomp($tmp);
    135     $ENV{'PBREVISION'}=$tmp;
    136     $ENV{'PBCMSLOGFILE'}="svn.log";
    137 } elsif ($scheme =~ /^svk/) {
    138     $tmp = `(cd "$ENV{'PBDIR'}" ; LANGUAGE=C $vcscmd info . | grep -E '^Revision:' | cut -d: -f2)`;
    139     $tmp =~ s/\s+//;
    140     chomp($tmp);
    141     $ENV{'PBREVISION'}=$tmp;
    142     $ENV{'PBCMSLOGFILE'}="svk.log";
    143 } elsif ($scheme =~ /^cvs/) {
    144     # Way too slow
    145     #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOTDIR'}" ; cvs rannotate  -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
    146     #chomp($ENV{'PBREVISION'});
    147     $ENV{'PBREVISION'}="cvs";
    148     $ENV{'PBCMSLOGFILE'}="cvs.log";
    149     $ENV{'CVS_RSH'} = "ssh" if ($scheme =~ /ssh/);
    150 } else {
    151     die "cms $scheme unknown";
    152 }
    153 
    154 pb_log(1,"pb_cms_init returns $scheme,$pbprojurl->{$ENV{'PBPROJ'}}\n");
    155 return($scheme,$pbprojurl->{$ENV{'PBPROJ'}});
    156 }
    15753
    15854=item B<pb_cms_get_pkg>
Note: See TracChangeset for help on using the changeset viewer.