Changeset 2488 in ProjectBuilder for devel/pb-modules


Ignore:
Timestamp:
Mar 30, 2020, 8:21:44 PM (4 years ago)
Author:
Bruno Cornec
Message:

Improve debug messages

  • pb_distro_get_param now an internal function printing name of hash members
  • use pb_distro_guess instead of pb_distro_get
  • pb_distro_get and pb_distro_get_if introduced to replace call to pb_conf_get(_if)* + and old pb_distro_get_param
  • add pb_distro_get_in_conf_if for another use case of old pb_distro_get_param
  • fix all calls to these functions
Location:
devel/pb-modules
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/bin/pbgetparam

    r2279 r2488  
    55# $Id$
    66#
    7 # Copyright B. Cornec 2007-2016
     7# Copyright B. Cornec 2007-today
    88# Provided under the GPL v2
    99
     
    2929pb helps you build various packages directly from your project sources.
    3030pbgetparam is a command from the pb project providing the value of the parameter for the running distribution based on the most precise tuple
    31 It is a CLI version of the pb_distro_get_param function
     31It is a CLI version of the pb_distro_get function
    3232
    3333=head1 SYNOPSIS
  • devel/pb-modules/etc/pb.yml

    r2483 r2488  
    537537#    ubuntu: http://archive.ubuntu.com/ubuntu
    538538#
     539addbuildrepo:
     540  centos-8: ftp://ftp.project-builder.org/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/powertools.repo
     541  rhel-8: ftp://ftp.project-builder.org/centos/8/$pbos->{'arch'}/powertools.repo
    539542
    540543#
     
    690693  rhel-7: wget,make,ntpdate,patch,perl-Date-Manip,rpm-build,diffutils,perl-Module-Build,perl-YAML
    691694  centos-7: wget,make,ntpdate,patch,perl-Date-Manip,rpm-build,diffutils,perl-Module-Build,perl-ExtUtils-MakeMaker,perl-File-MimeInfo,perl-File-BaseDir,perl-YAML
    692   rhel-8: wget,make,ntpdate,patch,perl-Date-Manip,rpm-build,diffutils,perl-Module-Build,perl-ExtUtils-MakeMaker,perl-File-MimeInfo,perl-File-BaseDir,perl-Data-Dumper,perl-YAML
    693   centos-8: wget,make,ntpdate,patch,perl-Date-Manip,rpm-build,diffutils,perl-Module-Build,perl-ExtUtils-MakeMaker,perl-File-MimeInfo,perl-File-BaseDir,perl-Data-Dumper,perl-YAML
     695  rhel-8: wget,make,chrony,patch,perl-Date-Manip,rpm-build,diffutils,perl-Module-Build,perl-ExtUtils-MakeMaker,perl-File-MimeInfo,perl-File-BaseDir,perl-Data-Dumper,perl-YAML
     696  centos-8: wget,make,chrony,patch,perl-Date-Manip,rpm-build,diffutils,perl-Module-Build,perl-ExtUtils-MakeMaker,perl-File-MimeInfo,perl-File-BaseDir,perl-Data-Dumper,perl-YAML
    694697  redhat:
    695698  suse: wget,make,ntp,patch,diffutils
     
    816819oscmdntp:
    817820  default: /usr/sbin/ntpdate
     821  centos-8: /bin/true
     822  rhel-8: /bin/true
     823  fedora: /bin/true
    818824#    opensuse-11.0-i386: sntp -P no -r
    819825#    opensuse-11.0-x86_64: sntp -P no -r
     
    848854  mandriva: ftp://ftp.project-builder.org/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/pb.addmedia
    849855  deb: ftp://ftp.project-builder.org/$pbos->{'name'}/$pbos->{'version'}/pb.sources.list
     856  centos-8: ftp://ftp.project-builder.org/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/pb.repo,ftp://ftp.project-builder.org/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/powertools.repo
     857  rhel-8: ftp://ftp.project-builder.org/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/pb.repo,ftp://ftp.project-builder.org/centos/8/$pbos->{'arch'}/powertools.repo
    850858
    851859# default remote git repo name
  • devel/pb-modules/lib/ProjectBuilder/Conf.pm

    r2484 r2488  
    55# which can be easily used by wahtever perl project
    66#
    7 # Copyright B. Cornec 2007-2016
     7# Copyright B. Cornec 2007-today
    88# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
    99# Provided under the GPL v2
     
    409409my @ptr = ();
    410410
    411 pb_log(2,"DEBUG: pb_conf_get_in_hash_if on params ".join(' ',@params)."\n");
     411pb_log(3,"DEBUG: pb_conf_get_in_hash_if on params ".join(' ',@params)."\n");
    412412foreach my $k (@params) {
    413413    push @ptr,$lh->{$k};
    414414}
    415415
    416 pb_log(2,"DEBUG: pb_conf_get_in_hash_if returns\n".Dumper(@ptr));
     416pb_log(3,"DEBUG: pb_conf_get_in_hash_if returns\n".Dumper(@ptr));
    417417return(@ptr);
    418418}
     
    474474my $p2;
    475475
    476 pb_log(2,"DEBUG: pb_conf_add_last_in_hash params: ".Dumper(@params)."\n");
    477 pb_log(2,"DEBUG: pb_conf_add_last_in_hash current hash: ".Dumper(@h)."\n");
    478 pb_log(2,"DEBUG: pb_conf_add_last_in_hash new inputs: ".Dumper(@ptr)."\n");
     476pb_log(3,"DEBUG: pb_conf_add_last_in_hash params: ".Dumper(@params)."\n");
     477pb_log(3,"DEBUG: pb_conf_add_last_in_hash current hash: ".Dumper(@h)."\n");
     478pb_log(3,"DEBUG: pb_conf_add_last_in_hash new inputs: ".Dumper(@ptr)."\n");
    479479
    480480foreach my $i (0..$#params) {
  • devel/pb-modules/lib/ProjectBuilder/Distribution.pm

    r2468 r2488  
    33# Creates common environment for distributions
    44#
    5 # Copyright B. Cornec 2007-2016
     5# Copyright B. Cornec 2007-today
    66# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
    77# Provided under the GPL v2
     
    3333 
    3434our @ISA = qw(Exporter);
    35 our @EXPORT = qw(pb_distro_init pb_distro_conffile pb_distro_sysconffile pb_distro_api pb_distro_get pb_distro_getlsb pb_distro_installdeps pb_distro_installpkgs pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_setuposrepo pb_distro_setuprepo_gen pb_distro_get_param pb_distro_get_context pb_distro_to_keylist pb_distro_conf_print pb_apply_conf_proxy);
     35our @EXPORT = qw(pb_distro_init pb_distro_conffile pb_distro_sysconffile pb_distro_api pb_distro_get pb_distro_get_if pb_distro_getlsb pb_distro_installdeps pb_distro_installpkgs pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_setuposrepo pb_distro_setuprepo_gen pb_distro_get_context pb_distro_to_keylist pb_distro_conf_print pb_apply_conf_proxy);
    3636($VERSION,$REVISION,$PBCONFVER) = pb_version_init();
    3737
     
    6363  # Return information on the running distro
    6464  #
    65   my ($ddir,$dver) = pb_distro_get();
     65  my ($ddir,$dver) = pb_distro_guess();
    6666
    6767=head1 USAGE
     
    159159
    160160# If we don't know which distribution we're on, then guess it
    161 ($pbos->{'name'},$pbos->{'version'}) = pb_distro_get() if ((not defined $pbos->{'name'}) || (not defined $pbos->{'version'}));
     161($pbos->{'name'},$pbos->{'version'}) = pb_distro_guess() if ((not defined $pbos->{'name'}) || (not defined $pbos->{'version'}));
    162162
    163163# For some rare cases, typically nover ones
     
    174174# Do NOT factorize here, as it won't work as of now for hash creation
    175175# Do NOT change order without caution
    176 $pbos->{'useminor'} = pb_distro_get_param($pbos,pb_conf_get("osuseminorrel"));
    177 $pbos->{'family'} = pb_distro_get_param($pbos,pb_conf_get("osfamily"));
    178 $pbos->{'type'} = pb_distro_get_param($pbos,pb_conf_get("ostype"));
    179 ($pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("os","osins","ossuffix","osnover","osremovedotinver","osupd"));
    180 ($pbos->{'localinstall'}) = pb_distro_get_param($pbos,pb_conf_get_if("oslocalins"));
    181 #($pbos->{'family'},$pbos->{'type'},$pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("osfamily","ostype","os","osins","ossuffix","osnover","osremovedotinver","osupd"));
     176$pbos->{'useminor'} = pb_distro_get($pbos,"osuseminorrel");
     177$pbos->{'family'} = pb_distro_get($pbos,"osfamily");
     178$pbos->{'type'} = pb_distro_get($pbos,"ostype");
     179($pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'update'}) = pb_distro_get($pbos,("os","osins","ossuffix","osupd"));
     180($pbos->{'localinstall'},$pbos->{'nover'},$pbos->{'rmdot'}) = pb_distro_get_if($pbos,"oslocalins","osnover","osremovedotinver");
    182181
    183182# Some OS have no interesting version
     
    204203}
    205204
    206 =item B<pb_distro_get>
     205=item B<pb_distro_guess>
    207206
    208207This function returns a list of 2 parameters indicating the distribution name and version of the underlying Linux distribution. The value of those 2 fields may be "unknown" in case the function was unable to recognize on which distribution it is running.
     
    212211=cut
    213212
    214 sub pb_distro_get {
     213sub pb_distro_guess {
    215214
    216215# 1: List of files that unambiguously indicates what distro we have
     
    360359my ($pbos) = @_;
    361360
    362 my $ftp_proxy = pb_distro_get_param($pbos,pb_conf_get_if("ftp_proxy"));
    363 my $http_proxy = pb_distro_get_param($pbos,pb_conf_get_if("http_proxy"));
    364 my $https_proxy = pb_distro_get_param($pbos,pb_conf_get_if("https_proxy"));
     361my $ftp_proxy = pb_distro_get_if($pbos,"ftp_proxy");
     362my $http_proxy = pb_distro_get_if($pbos,"http_proxy");
     363my $https_proxy = pb_distro_get_if($pbos,"https_proxy");
    365364
    366365# We do not overwrite shell settings
     
    626625# Adds conf file for availability of conf elements either from the local build env or from a VE/VM/RM in which the conf file has been passed
    627626$h = pb_conf_cache(pb_distro_conffile(),$h);
    628 my ($osrepo) = pb_conf_get_in_hash_if($h,"osrepo");
    629 my $repo = pb_distro_get_param($pbos,$osrepo);
     627#my $repo = pb_distro_get_param($pbos,$osrepo);
     628my $repo = pb_distro_get_in_hash_if($pbos,$h,"osrepo");
    630629return(pb_distro_setuprepo_gen($pbos,$repo));
    631630}
     
    649648$h = pb_conf_cache("$ENV{'PBDESTDIR'}/pbrc.yml",$h) if ((defined $ENV{'PBDESTDIR'}) && (-f "$ENV{'PBDESTDIR'}/pbrc.yml"));
    650649
    651 my ($addrepo) = pb_conf_get_in_hash_if($h,"add".$repotype."repo");
    652 my $repo = pb_distro_get_param($pbos,$addrepo);
     650my $repo = pb_distro_get_in_hash_if($pbos,$h,"add".$repotype."repo");
    653651# If no repo then set it up as undef so the return value is correct from pb_distro_setuprepo_gen
    654652$repo = undef if ($repo eq "");
     
    656654    # Give a probable default if nothing is provided to avoid overloading conf files
    657655    #
    658     if ((not defined $addrepo) || (not defined $repo)) {
     656    if (not defined $repo) {
    659657        my ($pbrepo) = pb_conf_get_in_hash_if($h,"pbrepo");
    660658        if (not defined $pbrepo) {
     
    870868=item B<pb_distro_get_param>
    871869
    872 This function gets the parameter in the conf file from the most precise tuple up to default
     870This internal function gets the parameters in the conf file from the most precise tuple up to default
    873871
    874872=cut
     
    876874sub pb_distro_get_param {
    877875
     876my $pbos = shift;
     877my $var = shift;
    878878my @param = ();
    879 my $pbos = shift;
     879my $i = 0;
     880pb_log(3,"var: ".Dumper($var));
    880881
    881882my @keylist = pb_distro_to_keylist($pbos,"default");
    882 pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} for ".Dumper(@_)."\n");
    883 foreach my $opt (@_) {
    884     my $param = "";
     883pb_log(3,"keylist: ".Dumper(@keylist));
     884
     885my $p = $var->{"ptr"};
     886foreach my $opt (@$p) {
     887    pb_log(3,'opt: '.Dumper($opt));
     888    my $param = undef;
     889    my $fkey = undef;
    885890    foreach my $key (@keylist) {
     891        pb_log(3,"key: $key\n");
    886892        if (defined $opt->{$key}) {
    887893            $param = $opt->{$key};
     894            $fkey = $key;
    888895            last;
    889896        }
    890897    }
    891     # Allow replacement of variables inside the parameter such as name, version, arch for rpmbootstrap
    892     # but not shell variable which are backslashed
    893     if ($param =~ /[^\\]\$/) {
    894         pb_log(3,"Expanding variable on $param\n");
    895         eval { $param =~ s/(\$\w+->\{\'\w+\'\})/$1/eeg };
     898    my $field = $var->{"val"};
     899    pb_log(3,"field: ".Dumper($field));
     900    $fkey = "default" if (not defined $fkey);
     901    pb_log(3,"key: $fkey\n");
     902    pb_log(2,"DEBUG: pb_distro_get_if on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} for $field->[$i]".'{'.$fkey.'}'." returns ");
     903    if (defined $param) {
     904        # Allow replacement of variables inside the parameter such as name, version, arch for rpmbootstrap
     905        # but not shell variable which are backslashed
     906        if ($param =~ /[^\\]\$/) {
     907            pb_log(3,"Expanding variable on $param\n");
     908            eval { $param =~ s/(\$\w+->\{\'\w+\'\})/$1/eeg };
     909        }
     910        pb_log(2,"$param\n");
     911    } else {
     912        pb_log(2,"undefined\n");
    896913    }
    897914    push @param,$param;
    898 }
    899 
    900 pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} returns ==".Dumper(@param)."==\n");
     915    $i++;
     916}
    901917
    902918# Return one param if user only asked for one lookup, an array if not.
    903919my $nb = @param;
     920pb_log(3,"Param".Dumper(@param)." has $nb members\n");
    904921if ($nb eq 1) {
     922    pb_log(3,"Retrun Param $param[0]\n");
    905923    return($param[0]);
    906924} else {
    907925    return(@param);
    908926}
     927}
     928
     929
     930=item B<pb_distro_get_if>
     931
     932This function gets the parameters in the conf file from the most precise tuple up to default
     933
     934=cut
     935
     936sub pb_distro_get_if {
     937
     938my $pbos = shift;
     939my @ptr = pb_conf_get_if(@_);
     940my $var;
     941$var->{"ptr"} = \@ptr;
     942$var->{"val"} = \@_;
     943return(pb_distro_get_param($pbos,$var));
     944}
     945
     946=item B<pb_distro_get>
     947
     948This function gets the parameters in the conf file from the most precise tuple up to default.
     949Aborts of one param doesn't exist whereas it should
     950
     951=cut
     952
     953sub pb_distro_get {
     954
     955my $pbos = shift;
     956my @param = @_;
     957my @return = pb_distro_get_if($pbos,@param);
     958
     959foreach my $i (0..$#param) {
     960    confess "No $param[$i] defined for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}" if (not defined $return[$i]);
     961}
     962my $nb = @return;
     963if ($nb eq 1) {
     964    return($return[0]);
     965} else {
     966    return(@return);
     967}
     968}
     969
     970=item B<pb_distro_get_in_hash_if>
     971
     972This function gets the parameters in the conf file passed as hash from the most precise tuple up to default
     973
     974=cut
     975
     976sub pb_distro_get_in_hash_if {
     977
     978my $pbos = shift;
     979my $lh = shift || return(());
     980
     981my @ptr = pb_conf_get_in_hash_if($lh,@_);
     982my $var;
     983$var->{"ptr"} = \@ptr;
     984$var->{"val"} = \@_;
     985return(pb_distro_get_param($pbos,$var));
     986}
     987
     988=item B<pb_distro_get_in_conf_if>
     989
     990This function gets the parameters in the conf file passed as name from the most precise tuple up to default
     991
     992=cut
     993
     994sub pb_distro_get_in_conf_if {
     995
     996my $pbos = shift;
     997my $conffile = shift;
     998
     999my @ptr = pb_conf_read($conffile,@_);
     1000my $var;
     1001$var->{"ptr"} = \@ptr;
     1002$var->{"val"} = \@_;
     1003return(pb_distro_get_param($pbos,$var));
    9091004}
    9101005
     
    9621057my $i = 0;
    9631058# Index on distro
    964 foreach my $r (pb_distro_get_param($pbos,pb_conf_get(@keys))) {
     1059foreach my $r (pb_distro_get($pbos,@keys)) {
    9651060    $rep{$keys[$i]} = $r if (defined $keys[$i]);
    9661061    $i++;
  • devel/pb-modules/lib/ProjectBuilder/VE.pm

    r2428 r2488  
    33# Common functions for virtual environment
    44#
    5 # Copyright B. Cornec 2007-2016
     5# Copyright B. Cornec 2007-today
    66# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
    77# Provided under the GPL v2
     
    119119
    120120    # We can probably only get those params now we have the distro context
    121     my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv");
     121    my ($vesnap,$verebuild) = pb_conf_get_if("vesnap","verebuild");
    122122
    123123    if (((((defined $verebuild) && (defined $verebuild->{$ENV{'PBPROJ'}}) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbstep == 0)) && ($vetype ne "docker"))
     
    147147            }
    148148   
    149             my $postinstall = pb_ve_get_postinstall($pbos,$rbspi,$verpmstyle);
     149            my $postinstall = pb_ve_get_postinstall($pbos,$verpmstyle);
    150150            if ($verpmstyle eq "rinse") {
    151151                # Need to reshape the mirrors generated with local before-post-install script
    152152                my $b4post = "--before-post-install ";
    153                 my $postparam = pb_distro_get_param($pbos,$rbsb4pi);
     153                my $postparam = pb_distro_get_if($pbos,"rbsb4pi");
    154154                if ($postparam eq "") {
    155155                    $b4post = "";
     
    161161                my $addpkgs;
    162162                $postparam = "";
    163                 $postparam .= pb_distro_get_param($pbos,$osmindep);
     163                $postparam .= pb_distro_get_if($pbos,"osmindep");
    164164                if ($postparam eq "") {
    165165                    $addpkgs = "";
     
    187187                my $addpkgs = "";
    188188                my $postparam = "";
    189                 $postparam .= pb_distro_get_param($pbos,$osmindep);
     189                $postparam .= pb_distro_get_if($pbos,"osmindep");
    190190                if ($postparam eq "") {
    191191                    $addpkgs = "";
     
    208208            my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
    209209       
    210             my $codename = pb_distro_get_param($pbos,$oscodename);
     210            my $codename = pb_distro_get_if($pbos,"oscodename");
    211211            my $postparam = "";
    212212            my $addpkgs;
    213             $postparam .= pb_distro_get_param($pbos,$osmindep);
     213            $postparam .= pb_distro_get_if($pbos,"osmindep");
    214214            if ($postparam eq "") {
    215215                $addpkgs = "";
     
    218218            }
    219219            my $debmir = "";
    220             $debmir .= pb_distro_get_param($pbos,$rbsmirrorsrv);
     220            $debmir .= pb_distro_get_if($pbos,"rbsmirrorsrv");
    221221   
    222222            # Get potential rbs option
     
    302302            #
    303303            # We can probably only get those params now we have the distro context
    304             my ($osmindep) = pb_conf_get_if("osmindep");
    305             my $pkgs = pb_distro_get_param($pbos,$osmindep);
     304            my $pkgs = pb_distro_get_if($pbos,"osmindep");
    306305            $pkgs =~ s/,/ /g;
    307306            my $tmpd = "$ENV{'PBTMP'}/Dockerfile";
     
    335334
    336335my $pbos = shift;
    337 my $rbspi = shift;
    338336my $vestyle = shift;
    339337my $post = "";
     
    346344}
    347345
    348 my $postparam = pb_distro_get_param($pbos,$rbspi);
     346my $postparam = pb_distro_get_if($pbos,"rbspi");
    349347if ($postparam eq "") {
    350348    $post = "";
Note: See TracChangeset for help on using the changeset viewer.