From 841a438c7f67f697dd6710b26cc6536dd76a420a Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 26 Apr 2021 19:41:54 +0200 Subject: Add OpenSSL::Config::Query and use it in configdata.pm OpenSSL::Config::Query is a configuration querying tool that's meant to make it easier to query the diverse configuration data for info. That's much easier than to dig through all the parts of %unified_info. Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/8871) --- configdata.pm.in | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'configdata.pm.in') diff --git a/configdata.pm.in b/configdata.pm.in index 279b8f75c9..3481eab277 100644 --- a/configdata.pm.in +++ b/configdata.pm.in @@ -112,13 +112,14 @@ unless (caller) { use File::Basename; use Pod::Usage; + use lib '{- sourcedir('util', 'perl') -}'; + use OpenSSL::fallback '{- sourcefile('external', 'perl', 'MODULES.txt') -}'; + my $here = dirname($0); if (scalar @ARGV == 0) { # With no arguments, re-create the build file - use lib '{- sourcedir('util', 'perl') -}'; - use OpenSSL::fallback '{- sourcefile('external', 'perl', 'MODULES.txt') -}'; use OpenSSL::Template; my $prepend = <<'_____'; @@ -172,6 +173,7 @@ _____ my $buildparams = undef; my $reconf = undef; my $verbose = undef; + my $query = undef; my $help = undef; my $man = undef; GetOptions('dump|d' => \$dump, @@ -183,6 +185,7 @@ _____ 'build-parameters|b' => \$buildparams, 'reconfigure|reconf|r' => \$reconf, 'verbose|v' => \$verbose, + 'query|q=s' => \$query, 'help' => \$help, 'man' => \$man) or die "Errors in command line arguments\n"; @@ -320,6 +323,25 @@ _____ chdir $here; exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf'; } + if ($query) { + use OpenSSL::Config::Query; + + my $confquery = OpenSSL::Config::Query->new(info => \%unified_info, + config => \%config); + my $result = eval "\$confquery->$query"; + + # We may need a result class with a printing function at some point. + # Until then, we assume that we get a scalar, or a list or a hash table + # with scalar values and simply print them in some orderly fashion. + if (ref $result eq 'ARRAY') { + print "$_\n" foreach @$result; + } elsif (ref $result eq 'HASH') { + print "$_ : \\\n ", join(" \\\n ", @{$result->{$_}}), "\n" + foreach sort keys %$result; + } elsif (ref $result eq 'SCALAR') { + print "$$result\n"; + } + } } 1; -- cgit v1.2.3