Changeset 2467 in ProjectBuilder


Ignore:
Timestamp:
Jan 19, 2020, 8:22:44 PM (4 years ago)
Author:
Bruno Cornec
Message:

Use confess instead of die - Fix build2docker by avoiding to go throught the large if in pb_env_init

File:
1 edited

Legend:

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

    r2435 r2467  
    2121use POSIX qw(strftime);
    2222use lib qw (lib);
     23use Carp qw/confess/;
    2324use ProjectBuilder::Version;
    2425use ProjectBuilder::Base;
     
    7879    if (! -f "$dir/.pbrc") {
    7980        pb_log(0, "No existing $ENV{'PBETC'} found, creating one as template\n");
    80         open(PBRC, "> $ENV{'PBETC'}") || die "Unable to create $ENV{'PBETC'}";
     81        open(PBRC, "> $ENV{'PBETC'}") || confess "Unable to create $ENV{'PBETC'}";
    8182        print PBRC << "EOF";
    8283---
     
    190191    }
    191192}
    192 die "No project defined - use env var PBPROJ or -p proj or a pbconfurl entry in $ENV{'PBETC'}" if (not (defined $proj));
     193confess "No project defined - use env var PBPROJ or -p proj or a pbconfurl entry in $ENV{'PBETC'}" if (not (defined $proj));
    193194
    194195# That's always the environment variable that will be used
     
    197198
    198199if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
    199     die "Please create a pbconfurl reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
     200    confess "Please create a pbconfurl reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
    200201}
    201202
     
    273274#
    274275if ((-d $ENV{'PBDESTDIR'}) && ($action !~ /pbinit/)) {
    275     opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
     276    opendir(DIR,$ENV{'PBDESTDIR'}) || confess "Unable to open directory $ENV{'PBDESTDIR'}: $!";
    276277    foreach my $d (readdir(DIR)) {
    277278        next if ($d =~ /^\./);
     
    296297#
    297298
    298 if (($action =~ /^(cms2|sbx2|newver|newproj|pbinit|announce|checkssh|cleanssh|getconf|setupve)/) || ($action =~ /docker$/)) {
     299if ($action =~ /^(cms2|sbx2|newver|newproj|pbinit|announce|checkssh|cleanssh|getconf|setupve)/) {
    299300
    300301    #
     
    311312            pb_log(1,"WARNING: no pbroot defined, using $ENV{'PBROOTDIR'}\n");
    312313            pb_log(1,"         Please use -r release if you want to use another release\n");
    313             die "No directory found under $ENV{'PBCONFDIR'}" if (not defined $ENV{'PBROOTDIR'});
     314            confess "No directory found under $ENV{'PBCONFDIR'}" if (not defined $ENV{'PBROOTDIR'});
    314315        } else {
    315316            my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc.yml","pbroot");
    316317            # That's always the environment variable that will be used
    317             die "Please remove inconsistent $ENV{'PBDESTDIR'}/pbrc.yml" if ((not defined $pbroot) || (not defined $pbroot->{$ENV{'PBPROJ'}}));
     318            confess "Please remove inconsistent $ENV{'PBDESTDIR'}/pbrc.yml" if ((not defined $pbroot) || (not defined $pbroot->{$ENV{'PBPROJ'}}));
    318319            $ENV{'PBROOTDIR'} = $pbroot->{$ENV{'PBPROJ'}};
    319320        }
     
    324325        $ENV{'PBROOTDIR'} = "$ENV{'PBCONFDIR'}" if (($scheme =~ /^git/) && ($scheme !~ /svn/));
    325326        pb_mkdir_p($ENV{'PBROOTDIR'}) if (defined $pbinit);
    326         die "$ENV{'PBROOTDIR'} is not a directory" if (not -d $ENV{'PBROOTDIR'});
     327        confess "$ENV{'PBROOTDIR'} is not a directory" if (not -d $ENV{'PBROOTDIR'});
    327328    }
    328329    pb_log(1,"PBROOTDIR=$ENV{'PBROOTDIR'}\n");
     
    372373                $ENV{'PBPROJVER'}=$pkgv->{$ENV{'PBPROJ'}};
    373374            } else {
    374                 die "No projver found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
     375                confess "No projver found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
    375376            }
    376377        }
    377         die "Invalid version name $ENV{'PBPROJVER'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml" if (($ENV{'PBPROJVER'} !~ /[0-9.]+/) && (defined $version) && ($ENV{'PBPROJVER'} =~ /$version{$ENV{'PBPROJ'}}/));
     378        confess "Invalid version name $ENV{'PBPROJVER'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml" if (($ENV{'PBPROJVER'} !~ /[0-9.]+/) && (defined $version) && ($ENV{'PBPROJVER'} =~ /$version{$ENV{'PBPROJ'}}/));
    378379       
    379380        if (not defined $ENV{'PBPROJTAG'}) {
     
    381382                $ENV{'PBPROJTAG'}=$pkgt->{$ENV{'PBPROJ'}};
    382383            } else {
    383                 die "No projtag found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
     384                confess "No projtag found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
    384385            }
    385386        }
    386         die "Invalid tag name $ENV{'PBPROJTAG'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml" if ($ENV{'PBPROJTAG'} !~ /[0-9.]+/);
     387        confess "Invalid tag name $ENV{'PBPROJTAG'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml" if ($ENV{'PBPROJTAG'} !~ /[0-9.]+/);
    387388
    388389        if (not defined $ENV{'PBPACKAGER'}) {
     
    390391                $ENV{'PBPACKAGER'}=$pbpackager->{$ENV{'PBPROJ'}};
    391392            } else {
    392                 die "No pbpackager found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
     393                confess "No pbpackager found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
    393394            }
    394395        }
     
    405406            my $msg = "Project $ENV{'PBPROJ'} structure creation";
    406407            pb_vcs_checkin($pbconf{$ENV{'PBPROJ'}},"$ENV{'PBROOTDIR'}",$msg);
    407             open(CONF,"> $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml") || die "Unable to create $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
     408            open(CONF,"> $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
    408409            print CONF << "EOF";
    409410---
     
    604605            close(CONF);
    605606            pb_mkdir_p("$ENV{'PBROOTDIR'}/pbfilter");
    606             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/all.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/all.yml";
     607            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/all.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/all.yml";
    607608            print CONF << "EOF";
    608609---
     
    676677EOF
    677678            close(CONF);
    678             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/rpm.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/rpm.yml";
     679            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/rpm.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/rpm.yml";
    679680            print CONF << "EOF";
    680681---
     
    710711EOF
    711712            close(CONF);
    712             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora.yml";
     713            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora.yml";
    713714            print CONF << "EOF";
    714715---
     
    741742            close(CONF);
    742743            foreach my $i (1..7) {
    743                 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.yml";
     744                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/fedora-$i.yml";
    744745                print CONF << "EOF";
    745746---
     
    755756                close(CONF);
    756757            }
    757             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/deb.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/deb.yml";
     758            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/deb.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/deb.yml";
    758759            print CONF << "EOF";
    759760---
     
    784785EOF
    785786            close(CONF);
    786             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-3.1.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-3.1.yml";
     787            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-3.1.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-3.1.yml";
    787788            print CONF << "EOF";
    788789---
     
    800801EOF
    801802            close(CONF);
    802             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.yml";
     803            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-4.0.yml";
    803804            print CONF << "EOF";
    804805---
     
    816817EOF
    817818            close(CONF);
    818             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.yml";
     819            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-5.0.yml";
    819820            print CONF << "EOF";
    820821---
     
    832833EOF
    833834            close(CONF);
    834             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-6.0.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-6.0.yml";
     835            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian-6.0.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian-6.0.yml";
    835836            print CONF << "EOF";
    836837---
     
    848849EOF
    849850            close(CONF);
    850             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian.yml";
     851            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/debian.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/debian.yml";
    851852            print CONF << "EOF";
    852853---
     
    865866            close(CONF);
    866867            foreach my $ubv ("ubuntu-6.06.yml","ubuntu-7.04.yml","ubuntu-7.10.yml") {
    867                 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
     868                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    868869                print CONF << "EOF";
    869870---
     
    883884            }
    884885            foreach my $ubv ("ubuntu-8.04.yml","ubuntu-8.10.yml") {
    885                 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
     886                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    886887                print CONF << "EOF";
    887888---
     
    901902            }
    902903            foreach my $ubv ("ubuntu-9.04.yml") {
    903                 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
     904                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    904905                print CONF << "EOF";
    905906---
     
    920921            # 9.10+
    921922            foreach my $ubv ("ubuntu.yml") {
    922                 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
     923                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/$ubv") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/$ubv";
    923924                print CONF << "EOF";
    924925---
     
    937938                close(CONF);
    938939            }
    939             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/md.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/md.yml";
     940            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/md.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/md.yml";
    940941            print CONF << "EOF";
    941942---
     
    954955EOF
    955956            close(CONF);
    956             open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/novell.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/novell.yml";
     957            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/novell.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/novell.yml";
    957958            print CONF << "EOF";
    958959---
     
    973974            foreach my $pp (@pkgs) {
    974975                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/deb");
    975                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/control") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/control";
     976                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/control") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/control";
    976977                print CONF << "EOF";
    977978Source: PBPKG
     
    10001001EOF
    10011002                close(CONF);
    1002                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/copyright") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/copyright";
     1003                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/copyright") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/copyright";
    10031004                print CONF << "EOF";
    10041005This package is debianized by PBPACKAGER
     
    10311032EOF
    10321033                close(CONF);
    1033                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/changelog") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/changelog";
     1034                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/changelog") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/changelog";
    10341035                print CONF << "EOF";
    10351036PBLOG
    10361037EOF
    10371038                close(CONF);
    1038                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/compat") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/compat";
     1039                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/compat") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/compat";
    10391040                print CONF << "EOF";
    10401041PBDEBCOMP
    10411042EOF
    10421043                close(CONF);
    1043                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs";
    1044                 print CONF << "EOF";
    1045 EOF
    1046                 close(CONF);
    1047                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs";
     1044                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs";
     1045                print CONF << "EOF";
     1046EOF
     1047                close(CONF);
     1048                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs";
    10481049                print CONF << "EOF";
    10491050INSTALL
     
    10541055EOF
    10551056                close(CONF);
    1056                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/rules") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/rules";
     1057                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/rules") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/rules";
    10571058                print CONF << 'EOF';
    10581059#!/usr/bin/make -f
     
    11911192                close(CONF);
    11921193                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/rpm");
    1193                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec";
     1194                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec";
    11941195                print CONF << 'EOF';
    11951196#
     
    12471248EOF
    12481249                close(CONF);
    1249                 open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/pkg.yml") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/pkg.yml";
     1250                open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/pkg.yml") || confess "Unable to create $ENV{'PBROOTDIR'}/pbfilter/pkg.yml";
    12501251                print CONF << "EOF";
    12511252---
     
    12631264                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pbfilter");
    12641265                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pkg");
    1265                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo";
     1266                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pkginfo";
    12661267                print CONF << 'EOF';
    12671268#
     
    12801281EOF
    12811282                close(CONF);
    1282                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild";
     1283                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/pbbuild";
    12831284                print CONF << 'EOF';
    12841285#
     
    12911292EOF
    12921293                close(CONF);
    1293                 open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/depend") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/depend";
     1294                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/pkg/depend") || confess "Unable to create $ENV{'PBROOTDIR'}/$pp/pkg/depend";
    12941295                print CONF << 'EOF';
    12951296#
     
    13071308            pb_log(0,"ERROR: no pbroot defined, used $ENV{'PBROOTDIR'}, without finding $ENV{'PBPROJ'}.yml in it\n");
    13081309            pb_log(0,"       Please use -r release in order to be able to initialize your environment correctly\n");
    1309             die "Unable to open $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
     1310            confess "Unable to open $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.yml";
    13101311        }
    13111312    }
Note: See TracChangeset for help on using the changeset viewer.