Changeset 2586 in ProjectBuilder


Ignore:
Timestamp:
Apr 3, 2020, 2:02:03 AM (4 years ago)
Author:
Bruno Cornec
Message:

Fix #177 for svn pbconf and tested with one level

Location:
devel/pb-modules/lib/ProjectBuilder
Files:
2 edited

Legend:

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

    r2498 r2586  
    300300
    301301    #
    302     # Check pbconf cms compliance
     302    # Check pbconf cms compliance except when creating a project as this doesn't exist yet
    303303    #
    304304    pb_vcs_compliant("pbconfdir",'PBCONFDIR',"$pbconfpath/pbconf",$pbconf{$ENV{'PBPROJ'}},$pbinit);
     305    confess "No PBCONFDIR variable created" if ((not defined $ENV{'PBCONFDIR'}) || ($ENV{'PBCONFDIR'} eq ""));
     306
    305307    my ($scheme, $account, $host, $port, $path) = pb_get_uri($pbconf{$ENV{'PBPROJ'}});
    306308
     
    327329        confess "$ENV{'PBROOTDIR'} is not a directory" if (not -d $ENV{'PBROOTDIR'});
    328330    }
    329     pb_log(1,"PBROOTDIR=$ENV{'PBROOTDIR'}\n");
     331    pb_log(1,"PBROOTDIR: $ENV{'PBROOTDIR'}\n");
    330332
    331333    # Adds that conf file to the list to consider
    332334    if (-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml") {
    333         pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml") if (-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml");
     335        pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml");
    334336    } elsif (-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") {
    335337        pb_vcs_conf_update_v0("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml");
     
    399401            @pkgs = ("$ENV{'PBPROJ'}") if (not @pkgs);
    400402   
    401             # Case where the parent dir of PBROOTDIR isn't managed yet in VCS
    402             pb_mkdir_p(dirname("$ENV{'PBROOTDIR'}"));
    403             pb_vcs_add_if_not_in($pbconf{$ENV{'PBPROJ'}},dirname("$ENV{'PBROOTDIR'}"));
    404403            pb_mkdir_p("$ENV{'PBROOTDIR'}");
    405             pb_vcs_add_if_not_in($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBROOTDIR'}");
    406             my $msg = "Project $ENV{'PBPROJ'} structure creation";
    407             pb_vcs_checkin($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBROOTDIR'}",$msg);
    408404            open(CONF,"> $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
    409405            print CONF << "EOF";
     
    13021298   
    13031299            }
    1304             pb_vcs_add($pbconf{$ENV{'PBPROJ'}},$ENV{'PBCONFDIR'});
    1305             $msg = "Project $ENV{'PBPROJ'} creation";
    1306             pb_vcs_checkin($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBCONFDIR'}",$msg);
     1300            my $msg = "Project $ENV{'PBPROJ'} structure creation";
     1301            opendir(DIR,$ENV{'PBCONFDIR'}) || confess "Unable to open directory $ENV{'PBCONFDIR'}: $!";
     1302            foreach my $f (readdir(DIR)) {
     1303                next if ($f =~ /^\./);
     1304                pb_vcs_add($scheme,"$ENV{'PBCONFDIR'}/$f");
     1305            }
     1306            closedir(DIR);
     1307            pb_vcs_checkin($scheme,dirname($ENV{'PBCONFDIR'}),$msg);
    13071308        } else {
    13081309            pb_log(0,"ERROR: no pbroot defined, used $ENV{'PBROOTDIR'}, without finding $ENV{'PBPROJ'}.yml in it\n");
  • devel/pb-modules/lib/ProjectBuilder/VCS.pm

    r2498 r2586  
    371371my $vcscmd = pb_vcs_cmd($scheme);
    372372
     373pb_log(3,"scheme: $scheme - dir: $dir - vcscmd: $vcscmd\n");
    373374if ($scheme =~ /^svn/) {
    374375    open(PIPE,"LANGUAGE=C $vcscmd info $dir 2> /dev/null |") || return("");
    375376    while (<PIPE>) {
    376         ($void,$res) = split(/^URL:/) if (/^URL:/);
     377        pb_log(4,"line: $_");
     378        if (/^URL[\s]*:/) {
     379            ($void,$res) = split(/^URL[\s]*:/);
     380            last;
     381        }
    377382    }
    378383    $res =~ s/^\s*//;
    379384    close(PIPE);
    380385    chomp($res);
     386    pb_log(3,"res $res\n");
    381387} elsif ($scheme =~ /^svk/) {
    382388    open(PIPE,"LANGUAGE=C $vcscmd info $dir 2> /dev/null |") || return("");
     
    402408        chdir($cwd) || return("");
    403409        while (<PIPE>) {
    404             ($void,$res) = split(/^URL:/) if (/^URL:/);
     410            ($void,$res) = split(/^URL[\s]*:/) if (/^URL[\s]*:/);
    405411        }
    406412        $res =~ s/^\s*//;
     
    614620sub pb_vcs_add_if_not_in {
    615621my $scheme = shift;
    616 my @f = @_;
    617622my $vcscmd = pb_vcs_cmd($scheme);
    618623
    619624if ($scheme =~ /^((hg)|(git)|(svn)|(svk)|(cvs))/o) {
    620     for my $f (@f) {
     625    for my $f (@_) {
    621626        my $uri = pb_vcs_get_uri($scheme,$f);
    622         pb_vcs_add($scheme,$f) if ($uri !~ /^$scheme/);
     627        pb_log(3,"f: $f - scheme: $scheme - uri: $uri\n");
     628        my ($scheme2, $a, $h, $p, $n) = pb_get_uri($uri);
     629        pb_vcs_add($scheme,$f) if ("$scheme2" ne "$scheme");
    623630    }
    624631} elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)\b/o) {
     
    663670    push(@f1,dirname($f)) if (-f $f);
    664671}
     672# Wrong we need to push instead
    665673pb_vcs_up($scheme,@f1);
    666674}
     
    768776}
    769777
     778=item B<pb_vcs_mkdir>
     779
     780This function makes a VCS directory
     781The first parameter is the schema of the VCS systems (svn, cvs, svn+ssh, ...)
     782The second parameter is the directory to create.
     783The third parameter is the comment to pass during the commit
     784
     785=cut
     786
     787sub pb_vcs_mkdir {
     788my $scheme = shift;
     789my $dir = shift;
     790my $msg = shift;
     791my $vcscmd = pb_vcs_cmd($scheme);
     792
     793if ($scheme =~ /^((svn)|(cvs)|(svk))/o) {
     794    pb_system("$vcscmd mkdir -m \"$msg\" $dir","Making VCS directory $dir");
     795} elsif ($scheme =~ /^git/) {
     796    #pb_system("cd $dir && git init ", "Making VCS directory $dir");
     797    ## + git remote add + git push
     798} elsif ($scheme =~ /^(flat)|(ftp)|(http)|(https)|(file)\b/o) {
     799    # Nothing to do.
     800} else {
     801    confess "cms $scheme unknown";
     802}
     803}
     804
     805
     806
    770807=item B<pb_vcs_compliant>
    771808
     
    777814The fifth parameter indicates whether we should inititate the context or not.
    778815
     816Only called for PBCONFDIR and PBDIR
    779817=cut
    780818
     
    809847eval { $ENV{$envar} =~ s/(\$ENV.+\})/$1/eeg };
    810848pb_log(2,"$envar: $ENV{$envar}\n");
     849my $exportdir = $ENV{$envar};
    811850
    812851my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
     
    816855    pb_log(1,"pb_vcs_compliant useless\n");
    817856    return;
    818 } elsif ((defined $pbinit) || (! -d "$ENV{$envar}")) {
    819     my $exportdir = $ENV{$envar};
     857} elsif ((defined $pbinit) && (! -d "$exportdir")) {
    820858    # Either we have a version in the uri, and it should be the same
    821859    # as the one in the envar. Or we should add the version to the uri
     
    824862        $uri .= "/".basename($exportdir);
    825863    }
    826     if ((defined $pbinit) && ($scheme =~ /git/)) {
    827         # If initializing remove the potential pbconf part if we treat pbconfdir
    828         $exportdir =~ s|pbconf[/]*||;
    829     }
    830     pb_log(1,"Checking out $uri\n");
    831     # Create structure and remove end dir before exporting
     864
    832865    pb_mkdir_p("$exportdir");
    833     pb_rm_rf($exportdir);
     866    # Should only have pbconf
     867    if ((pb_path_nbfiles(dirname($exportdir)) > 1) && ($envar eq 'PBCONFDIR')) {
     868        confess("Directory ".dirname($exportdir)." has content.\nPlease remove it if you want to use that directory\n");
     869    }
     870    if (pb_path_nbfiles("$exportdir") > 0) {
     871        confess("Directory $exportdir has content.\nPlease remove it if you want to use that directory\n");
     872    }
     873    if ($envar eq 'PBCONFDIR') {
     874        # Remove the potential pbconf part if we treat pbconfdir
     875        $exportdir =~ s|/pbconf[/]*||;
     876        $uri =~ s|/pbconf[/]*||;
     877    }
     878    # Don't add content here as it may conflict later on with PBROOT addition
     879    # Done in Env.pm
     880    pb_log(0,"Trying to check out (may fail) ".$uri."\n");
    834881    pb_vcs_checkout($scheme,$uri,$exportdir);
    835     if ((defined $pbinit) && ($scheme =~ /git/)) {
    836         # And now created the potentially missing pbconf dir
    837         pb_mkdir_p("$exportdir/pbconf");
    838     }
     882    if (($envar eq 'PBCONFDIR') && (pb_path_nbfiles("$exportdir/pbconf") == 0)) {
     883        # Export failed, because there is nothing yet in the repo
     884        # we now need to clean stuff before doing mkdir to avoid conflicts
     885        pb_rm_rf($exportdir);
     886        pb_log(0,"Pushing first $uri\n");
     887        pb_vcs_mkdir($scheme,$uri,"Creating structure directory");
     888        pb_vcs_mkdir($scheme,"$uri/pbconf","Creating structure sub directory");
     889        pb_log(0,"Re-Trying to check out again $uri\n");
     890        pb_vcs_up($scheme,$exportdir);
     891    }
     892    pb_log(0,"Done\n");
    839893} else {
    840894    pb_log(1,"$uri found locally, checking content\n");
Note: See TracChangeset for help on using the changeset viewer.