[openssl] master update
Richard Levitte
levitte at openssl.org
Thu Sep 12 16:20:21 UTC 2019
The branch master has been updated
via 1f86b8228b49938e0e368f361202570d7eab5806 (commit)
via 486f149131e94c970da1b89ebe8c66ab88e5d343 (commit)
from d4830d018dfdab5d5d497d88207ee8f1761cf878 (commit)
- Log -----------------------------------------------------------------
commit 1f86b8228b49938e0e368f361202570d7eab5806
Author: Richard Levitte <levitte at openssl.org>
Date: Sun Aug 25 10:46:22 2019 +0200
confdata.pm.in: New template for configdata.pm
To have the configdata.pm text embedded in Configure was kind of ugly,
and becomes clearer if put into a template file, configdata.pm.in. We
can then use OpenSSL::Template to generate it.
We also modify configdata.pm to be the build file generator, and run
it from Configure. The benefit with that is that developers who
tinker and play with the build file can do a "factory reset" without
having to go through the configuration process, i.e. they can re-use
the config data the already have.
Reviewed-by: Matt Caswell <matt at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9693)
commit 486f149131e94c970da1b89ebe8c66ab88e5d343
Author: Richard Levitte <levitte at openssl.org>
Date: Sun Aug 25 10:44:41 2019 +0200
util/dofile.pl, util/perl/OpenSSL/Template.pm: move parts of dofile.pl
We make a module OpenSSL::Template from the central parts of
util/dofile.pl, and also reduce the amount of ugly code with more
proper use of Text::Template. OpenSSL::Template is a simply subclass
of Text::Template.
Reviewed-by: Matt Caswell <matt at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9693)
-----------------------------------------------------------------------
Summary of changes:
Configure | 495 ++++--------------------------------------
configdata.pm.in | 418 +++++++++++++++++++++++++++++++++++
util/dofile.pl | 204 +++--------------
util/perl/OpenSSL/Template.pm | 195 +++++++++++++++++
4 files changed, 684 insertions(+), 628 deletions(-)
create mode 100644 configdata.pm.in
create mode 100644 util/perl/OpenSSL/Template.pm
diff --git a/Configure b/Configure
index 652d13ea16..92c9d4e4d9 100755
--- a/Configure
+++ b/Configure
@@ -19,6 +19,7 @@ use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs splitdir/;
use File::Path qw/mkpath/;
use OpenSSL::fallback "$FindBin::Bin/external/perl/MODULES.txt";
use OpenSSL::Glob;
+use OpenSSL::Template;
# see INSTALL for instructions.
@@ -2387,452 +2388,50 @@ foreach (grep /_(asm|aux)_src$/, keys %target) {
# Write down our configuration where it fits #########################
-print "Creating configdata.pm\n";
-open(OUT,">configdata.pm") || die "unable to create configdata.pm: $!\n";
-print OUT <<"EOF";
-#! $config{HASHBANGPERL}
-
-package configdata;
-
-use strict;
-use warnings;
-
-use Exporter;
-#use vars qw(\@ISA \@EXPORT);
-our \@ISA = qw(Exporter);
-our \@EXPORT = qw(\%config \%target \%disabled \%withargs \%unified_info \@disablables \@disablables_int);
-
-EOF
-print OUT "our %config = (\n";
-foreach (sort keys %config) {
- if (ref($config{$_}) eq "ARRAY") {
- print OUT " ", $_, " => [ ", join(", ",
- map { quotify("perl", $_) }
- @{$config{$_}}), " ],\n";
- } elsif (ref($config{$_}) eq "HASH") {
- print OUT " ", $_, " => {";
- if (scalar keys %{$config{$_}} > 0) {
- print OUT "\n";
- foreach my $key (sort keys %{$config{$_}}) {
- print OUT " ",
- join(" => ",
- quotify("perl", $key),
- defined $config{$_}->{$key}
- ? quotify("perl", $config{$_}->{$key})
- : "undef");
- print OUT ",\n";
- }
- print OUT " ";
- }
- print OUT "},\n";
- } else {
- print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n"
- }
-}
-print OUT <<"EOF";
-);
-
-EOF
-print OUT "our %target = (\n";
-foreach (sort keys %target) {
- if (ref($target{$_}) eq "ARRAY") {
- print OUT " ", $_, " => [ ", join(", ",
- map { quotify("perl", $_) }
- @{$target{$_}}), " ],\n";
- } else {
- print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n"
- }
-}
-print OUT <<"EOF";
+my %template_vars = (
+ config => \%config,
+ target => \%target,
+ disablables => \@disablables,
+ disablables_int => \@disablables_int,
+ disabled => \%disabled,
+ withargs => \%withargs,
+ unified_info => \%unified_info,
+ tls => \@tls,
+ dtls => \@dtls,
+ makevars => [ sort keys %user ],
+ disabled_info => \%disabled_info,
+ user_crossable => \@user_crossable,
);
-
-EOF
-print OUT "our \%available_protocols = (\n";
-print OUT " tls => [ ", join(", ", map { quotify("perl", $_) } @tls), " ],\n";
-print OUT " dtls => [ ", join(", ", map { quotify("perl", $_) } @dtls), " ],\n";
-print OUT <<"EOF";
-);
-
-EOF
-print OUT "our \@disablables = (\n";
-foreach (@disablables) {
- print OUT " ", quotify("perl", $_), ",\n";
-}
-print OUT <<"EOF";
-);
-
-EOF
-print OUT "# The following come from Configure's @disablables_int\n";
-print OUT "our \@disablables_int = (\n";
-foreach (@disablables_int) {
- print OUT " ", quotify("perl", $_), ",\n";
-}
-print OUT <<"EOF";
-);
-
-EOF
-print OUT "our \%disabled = (\n";
-foreach (sort keys %disabled) {
- print OUT " ", quotify("perl", $_), " => ", quotify("perl", $disabled{$_}), ",\n";
-}
-print OUT <<"EOF";
-);
-
-EOF
-print OUT "our %withargs = (\n";
-foreach (sort keys %withargs) {
- if (ref($withargs{$_}) eq "ARRAY") {
- print OUT " ", $_, " => [ ", join(", ",
- map { quotify("perl", $_) }
- @{$withargs{$_}}), " ],\n";
- } else {
- print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n"
- }
-}
-print OUT <<"EOF";
-);
-
-EOF
-if ($builder eq "unified") {
- my $recurse;
- $recurse = sub {
- my $indent = shift;
- foreach (@_) {
- if (ref $_ eq "ARRAY") {
- print OUT " "x$indent, "[\n";
- foreach (@$_) {
- $recurse->($indent + 4, $_);
- }
- print OUT " "x$indent, "],\n";
- } elsif (ref $_ eq "HASH") {
- my %h = %$_;
- print OUT " "x$indent, "{\n";
- foreach (sort keys %h) {
- if (ref $h{$_} eq "") {
- print OUT " "x($indent + 4), quotify("perl", $_), " => ", quotify("perl", $h{$_}), ",\n";
- } else {
- print OUT " "x($indent + 4), quotify("perl", $_), " =>\n";
- $recurse->($indent + 8, $h{$_});
- }
- }
- print OUT " "x$indent, "},\n";
- } else {
- print OUT " "x$indent, quotify("perl", $_), ",\n";
- }
- }
- };
- print OUT "our %unified_info = (\n";
- foreach (sort keys %unified_info) {
- if (ref $unified_info{$_} eq "") {
- print OUT " "x4, quotify("perl", $_), " => ", quotify("perl", $unified_info{$_}), ",\n";
- } else {
- print OUT " "x4, quotify("perl", $_), " =>\n";
- $recurse->(8, $unified_info{$_});
- }
- }
- print OUT <<"EOF";
-);
-
-EOF
-}
-print OUT
- "# The following data is only used when this files is use as a script\n";
-print OUT "my \@makevars = (\n";
-foreach (sort keys %user) {
- print OUT " '",$_,"',\n";
-}
-print OUT ");\n";
-print OUT "my \%disabled_info = (\n";
-foreach my $what (sort keys %disabled_info) {
- print OUT " '$what' => {\n";
- foreach my $info (sort keys %{$disabled_info{$what}}) {
- if (ref $disabled_info{$what}->{$info} eq 'ARRAY') {
- print OUT " $info => [ ",
- join(', ', map { "'$_'" } @{$disabled_info{$what}->{$info}}),
- " ],\n";
- } else {
- print OUT " $info => '", $disabled_info{$what}->{$info},
- "',\n";
- }
- }
- print OUT " },\n";
-}
-print OUT ");\n";
-print OUT 'my @user_crossable = qw( ', join (' ', @user_crossable), " );\n";
-print OUT << 'EOF';
-# If run directly, we can give some answers, and even reconfigure
-unless (caller) {
- use Getopt::Long;
- use File::Spec::Functions;
- use File::Basename;
- use Pod::Usage;
-
- my $here = dirname($0);
-
- my $dump = undef;
- my $cmdline = undef;
- my $options = undef;
- my $target = undef;
- my $envvars = undef;
- my $makevars = undef;
- my $buildparams = undef;
- my $reconf = undef;
- my $verbose = undef;
- my $help = undef;
- my $man = undef;
- GetOptions('dump|d' => \$dump,
- 'command-line|c' => \$cmdline,
- 'options|o' => \$options,
- 'target|t' => \$target,
- 'environment|e' => \$envvars,
- 'make-variables|m' => \$makevars,
- 'build-parameters|b' => \$buildparams,
- 'reconfigure|reconf|r' => \$reconf,
- 'verbose|v' => \$verbose,
- 'help' => \$help,
- 'man' => \$man)
- or die "Errors in command line arguments\n";
-
- unless ($dump || $cmdline || $options || $target || $envvars || $makevars
- || $buildparams || $reconf || $verbose || $help || $man) {
- print STDERR <<"_____";
-You must give at least one option.
-For more information, do '$0 --help'
-_____
- exit(2);
- }
-
- if ($help) {
- pod2usage(-exitval => 0,
- -verbose => 1);
- }
- if ($man) {
- pod2usage(-exitval => 0,
- -verbose => 2);
- }
- if ($dump || $cmdline) {
- print "\nCommand line (with current working directory = $here):\n\n";
- print ' ',join(' ',
- $config{PERL},
- catfile($config{sourcedir}, 'Configure'),
- @{$config{perlargv}}), "\n";
- print "\nPerl information:\n\n";
- print ' ',$config{perl_cmd},"\n";
- print ' ',$config{perl_version},' for ',$config{perl_archname},"\n";
- }
- if ($dump || $options) {
- my $longest = 0;
- my $longest2 = 0;
- foreach my $what (@disablables) {
- $longest = length($what) if $longest < length($what);
- $longest2 = length($disabled{$what})
- if $disabled{$what} && $longest2 < length($disabled{$what});
- }
- print "\nEnabled features:\n\n";
- foreach my $what (@disablables) {
- print " $what\n" unless $disabled{$what};
- }
- print "\nDisabled features:\n\n";
- foreach my $what (@disablables) {
- if ($disabled{$what}) {
- print " $what", ' ' x ($longest - length($what) + 1),
- "[$disabled{$what}]", ' ' x ($longest2 - length($disabled{$what}) + 1);
- print $disabled_info{$what}->{macro}
- if $disabled_info{$what}->{macro};
- print ' (skip ',
- join(', ', @{$disabled_info{$what}->{skipped}}),
- ')'
- if $disabled_info{$what}->{skipped};
- print "\n";
- }
- }
- }
- if ($dump || $target) {
- print "\nConfig target attributes:\n\n";
- foreach (sort keys %target) {
- next if $_ =~ m|^_| || $_ eq 'template';
- my $quotify = sub {
- map { (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\""} @_;
- };
- print ' ', $_, ' => ';
- if (ref($target{$_}) eq "ARRAY") {
- print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n";
- } else {
- print $quotify->($target{$_}), ",\n"
- }
- }
- }
- if ($dump || $envvars) {
- print "\nRecorded environment:\n\n";
- foreach (sort keys %{$config{perlenv}}) {
- print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n";
- }
- }
- if ($dump || $makevars) {
- print "\nMakevars:\n\n";
- foreach my $var (@makevars) {
- my $prefix = '';
- $prefix = $config{CROSS_COMPILE}
- if grep { $var eq $_ } @user_crossable;
- $prefix //= '';
- print ' ',$var,' ' x (16 - length $var),'= ',
- (ref $config{$var} eq 'ARRAY'
- ? join(' ', @{$config{$var}})
- : $prefix.$config{$var}),
- "\n"
- if defined $config{$var};
- }
-
- my @buildfile = ($config{builddir}, $config{build_file});
- unshift @buildfile, $here
- unless file_name_is_absolute($config{builddir});
- my $buildfile = canonpath(catdir(@buildfile));
- print <<"_____";
-
-NOTE: These variables only represent the configuration view. The build file
-template may have processed these variables further, please have a look at the
-build file for more exact data:
- $buildfile
-_____
- }
- if ($dump || $buildparams) {
- my @buildfile = ($config{builddir}, $config{build_file});
- unshift @buildfile, $here
- unless file_name_is_absolute($config{builddir});
- print "\nbuild file:\n\n";
- print " ", canonpath(catfile(@buildfile)),"\n";
-
- print "\nbuild file templates:\n\n";
- foreach (@{$config{build_file_templates}}) {
- my @tmpl = ($_);
- unshift @tmpl, $here
- unless file_name_is_absolute($config{sourcedir});
- print ' ',canonpath(catfile(@tmpl)),"\n";
- }
- }
- if ($reconf) {
- if ($verbose) {
- print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n";
- foreach (sort keys %{$config{perlenv}}) {
- print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n";
- }
- }
-
- chdir $here;
- exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf';
- }
-}
-
-1;
-
-__END__
-
-=head1 NAME
-
-configdata.pm - configuration data for OpenSSL builds
-
-=head1 SYNOPSIS
-
-Interactive:
-
- perl configdata.pm [options]
-
-As data bank module:
-
- use configdata;
-
-=head1 DESCRIPTION
-
-This module can be used in two modes, interactively and as a module containing
-all the data recorded by OpenSSL's Configure script.
-
-When used interactively, simply run it as any perl script, with at least one
-option, and you will get the information you ask for. See L</OPTIONS> below.
-
-When loaded as a module, you get a few databanks with useful information to
-perform build related tasks. The databanks are:
-
- %config Configured things.
- %target The OpenSSL config target with all inheritances
- resolved.
- %disabled The features that are disabled.
- @disablables The list of features that can be disabled.
- %withargs All data given through --with-THING options.
- %unified_info All information that was computed from the build.info
- files.
-
-=head1 OPTIONS
-
-=over 4
-
-=item B<--help>
-
-Print a brief help message and exit.
-
-=item B<--man>
-
-Print the manual page and exit.
-
-=item B<--dump> | B<-d>
-
-Print all relevant configuration data. This is equivalent to B<--command-line>
-B<--options> B<--target> B<--environment> B<--make-variables>
-B<--build-parameters>.
-
-=item B<--command-line> | B<-c>
-
-Print the current configuration command line.
-
-=item B<--options> | B<-o>
-
-Print the features, both enabled and disabled, and display defined macro and
-skipped directories where applicable.
-
-=item B<--target> | B<-t>
-
-Print the config attributes for this config target.
-
-=item B<--environment> | B<-e>
-
-Print the environment variables and their values at the time of configuration.
-
-=item B<--make-variables> | B<-m>
-
-Print the main make variables generated in the current configuration
-
-=item B<--build-parameters> | B<-b>
-
-Print the build parameters, i.e. build file and build file templates.
-
-=item B<--reconfigure> | B<--reconf> | B<-r>
-
-Redo the configuration.
-
-=item B<--verbose> | B<-v>
-
-Verbose output.
-
-=back
-
-=cut
-
-EOF
-close(OUT);
+my $configdata_outname = 'configdata.pm';
+print "Creating $configdata_outname\n";
+open CONFIGDATA, ">$configdata_outname.new"
+ or die "Trying to create $configdata_outname.new: $!";
+my $configdata_tmplname = cleanfile($srcdir, "configdata.pm.in", $blddir);
+my $configdata_tmpl =
+ OpenSSL::Template->new(TYPE => 'FILE', SOURCE => $configdata_tmplname);
+$configdata_tmpl->fill_in(
+ FILENAME => $configdata_tmplname,
+ OUTPUT => \*CONFIGDATA,
+ HASH => { %template_vars,
+ autowarntext => [
+ 'WARNING: do not edit!',
+ "Generated by Configure from $configdata_tmplname",
+ ] }
+) or die $Text::Template::ERROR;
+close CONFIGDATA;
+rename "$configdata_outname.new", $configdata_outname;
if ($builder_platform eq 'unix') {
my $mode = (0755 & ~umask);
chmod $mode, 'configdata.pm'
or warn sprintf("WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s\n",$mode,$!);
}
-my %builders = (
- unified => sub {
- print 'Creating ',$target{build_file},"\n";
- run_dofile(catfile($blddir, $target{build_file}),
- @{$config{build_file_templates}});
- },
- );
-
-$builders{$builder}->($builder_platform, @builder_opts);
+print "Running $configdata_outname\n";
+my $perlcmd = (quotify("maybeshell", $config{PERL}))[0];
+my $cmd = "$perlcmd $configdata_outname";
+#print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
+system($cmd);
+exit 1 if $? != 0;
$SIG{__DIE__} = $orig_death_handler;
@@ -3223,24 +2822,6 @@ sub usage
exit(1);
}
-sub run_dofile
-{
- my $out = shift;
- my @templates = @_;
-
- unlink $out || warn "Can't remove $out, $!"
- if -f $out;
- foreach (@templates) {
- die "Can't open $_, $!" unless -f $_;
- }
- my $perlcmd = (quotify("maybeshell", $config{PERL}))[0];
- my $cmd = "$perlcmd \"-I.\" \"-Mconfigdata\" \"$dofile\" -o\"Configure\" \"".join("\" \"", at templates)."\" > \"$out.new\"";
- #print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
- system($cmd);
- exit 1 if $? != 0;
- rename("$out.new", $out) || die "Can't rename $out.new, $!";
-}
-
sub compiler_predefined {
state %predefined;
my $cc = shift;
diff --git a/configdata.pm.in b/configdata.pm.in
new file mode 100644
index 0000000000..6e5c1ad4f6
--- /dev/null
+++ b/configdata.pm.in
@@ -0,0 +1,418 @@
+#! {- $config{HASHBANGPERL} -}
+# -*- mode: perl -*-
+{-
+ sub out_item {
+ my $ref = shift;
+ # Available options:
+ # indent => callers indentation (int)
+ # delimiters => 1 if outer delimiters should be added
+ my %opts = @_;
+
+ my $indent = $opts{indent} // 0;
+ # Indentation of the whole structure, where applicable
+ my $nlindent1 = "\n" . ' ' x $indent;
+ # Indentation of individual items, where applicable
+ my $nlindent2 = "\n" . ' ' x ($indent + 4);
+
+ my $product; # Finished product, or reference to a function that
+ # produces a string, given $_
+ # The following are only used when $product is a function reference
+ my $delim_l; # Left delimiter of structure
+ my $delim_r; # Right delimiter of structure
+ my $separator; # Item separator
+ my @items; # Items to iterate over
+
+ if (ref($ref) eq "ARRAY") {
+ if (scalar @$ref == 0) {
+ $product = $opts{delimiters} ? '[]' : '';
+ } else {
+ $product = sub {
+ out_item(\$_, delimiters => 1, indent => $indent + 4)
+ };
+ $delim_l = ($opts{delimiters} ? '[' : '').$nlindent2;
+ $delim_r = $nlindent1.($opts{delimiters} ? ']' : '');
+ $separator = ",$nlindent2";
+ @items = @$ref;
+ }
+ } elsif (ref($ref) eq "HASH") {
+ if (scalar keys %$ref == 0) {
+ $product = $opts{delimiters} ? '{}' : '';
+ } else {
+ $product = sub {
+ quotify1($_) . " => "
+ . out_item($ref->{$_}, delimiters => 1, indent => $indent + 4)
+ };
+ $delim_l = ($opts{delimiters} ? '{' : '').$nlindent2;
+ $delim_r = $nlindent1.($opts{delimiters} ? '}' : '');
+ $separator = ",$nlindent2";
+ @items = sort keys %$ref;
+ }
+ } elsif (ref($ref) eq "SCALAR") {
+ $product = defined $$ref ? quotify1 $$ref : "undef";
+ } else {
+ $product = defined $ref ? quotify1 $ref : "undef";
+ }
+
+ if (ref($product) eq "CODE") {
+ $delim_l . join($separator, map { &$product } @items) . $delim_r;
+ } else {
+ $product;
+ }
+ }
+
+ # We must make sourcedir() return an absolute path, because configdata.pm
+ # may be loaded as a module from any script in any directory, making
+ # relative paths untrustable. Because the result is used with 'use lib',
+ # we must ensure that it returns a Unix style path. Cwd::abs_path does
+ # that (File::Spec::Functions::rel2abs return O/S specific paths)
+ use File::Spec::Functions;
+ use Cwd qw(abs_path);
+ sub sourcedir {
+ return abs_path(catdir($config{sourcedir}, @_));
+ }
+ sub sourcefile {
+ return abs_path(catfile($config{sourcedir}, @_));
+ }
+-}
+package configdata;
+
+use strict;
+use warnings;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(
+ %config %target %disabled %withargs %unified_info
+ @disablables @disablables_int
+);
+
+our %config = ({- out_item(\%config); -});
+our %target = ({- out_item(\%target); -});
+our @disablables = ({- out_item(\@disablables) -});
+our @disablables_int = ({- out_item(\@disablables_int) -});
+our %disabled = ({- out_item(\%disabled); -});
+our %withargs = ({- out_item(\%withargs); -});
+our %unified_info = ({- out_item(\%unified_info); -});
+
+# Unexported, only used by OpenSSL::Test::Utils::available_protocols()
+our %available_protocols = (
+ tls => [{- out_item(\@tls) -}],
+ dtls => [{- out_item(\@dtls) -}],
+);
+
+# The following data is only used when this files is use as a script
+my @makevars = ({- out_item(\@makevars); -});
+my %disabled_info = ({- out_item(\%disabled_info); -});
+my @user_crossable = qw( {- join (' ', @user_crossable) -} );
+
+# If run directly, we can give some answers, and even reconfigure
+unless (caller) {
+ use Getopt::Long;
+ use File::Spec::Functions;
+ use File::Basename;
+ use Pod::Usage;
+
+ 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 = <<"_____";
+use File::Spec::Functions;
+use lib '{- sourcedir('util', 'perl') -}';
+_____
+ $prepend .= <<"_____" if defined $target{perl_platform};
+use lib '{- sourcedir('Configurations') -}';
+use lib '{- $config{builddir} -}';
+use platform;
+_____
+
+ my @autowarntext = (
+ 'WARNING: do not edit!',
+ "Generated by configdata.pm from "
+ .join(", ", @{$config{build_file_templates}})
+ );
+
+ print 'Creating ',$target{build_file},"\n";
+ open BUILDFILE, ">$target{build_file}.new"
+ or die "Trying to create $target{build_file}.new: $!";
+ foreach (@{$config{build_file_templates}}) {
+ my $tmpl = OpenSSL::Template->new(TYPE => 'FILE',
+ SOURCE => $_);
+ $tmpl->fill_in(FILENAME => $_,
+ OUTPUT => \*BUILDFILE,
+ HASH => { config => \%config,
+ target => \%target,
+ disabled => \%disabled,
+ withargs => \%withargs,
+ unified_info => \%unified_info,
+ autowarntext => \@autowarntext },
+ PREPEND => $prepend,
+ # To ensure that global variables and functions
+ # defined in one template stick around for the
+ # next, making them combinable
+ PACKAGE => 'OpenSSL::safe')
+ or die $Text::Template::ERROR;
+ }
+ close BUILDFILE;
+ rename("$target{build_file}.new", $target{build_file})
+ or die "Trying to rename $target{build_file}.new to $target{build_file}: $!";
+
+ exit(0);
+ }
+
+ my $dump = undef;
+ my $cmdline = undef;
+ my $options = undef;
+ my $target = undef;
+ my $envvars = undef;
+ my $makevars = undef;
+ my $buildparams = undef;
+ my $reconf = undef;
+ my $verbose = undef;
+ my $help = undef;
+ my $man = undef;
+ GetOptions('dump|d' => \$dump,
+ 'command-line|c' => \$cmdline,
+ 'options|o' => \$options,
+ 'target|t' => \$target,
+ 'environment|e' => \$envvars,
+ 'make-variables|m' => \$makevars,
+ 'build-parameters|b' => \$buildparams,
+ 'reconfigure|reconf|r' => \$reconf,
+ 'verbose|v' => \$verbose,
+ 'help' => \$help,
+ 'man' => \$man)
+ or die "Errors in command line arguments\n";
+
+ if (scalar @ARGV > 0) {
+ print STDERR <<"_____";
+Unrecognised arguments.
+For more information, do '$0 --help'
+_____
+ exit(2);
+ }
+
+ if ($help) {
+ pod2usage(-exitval => 0,
+ -verbose => 1);
+ }
+ if ($man) {
+ pod2usage(-exitval => 0,
+ -verbose => 2);
+ }
+ if ($dump || $cmdline) {
+ print "\nCommand line (with current working directory = $here):\n\n";
+ print ' ',join(' ',
+ $config{PERL},
+ catfile($config{sourcedir}, 'Configure'),
+ @{$config{perlargv}}), "\n";
+ print "\nPerl information:\n\n";
+ print ' ',$config{perl_cmd},"\n";
+ print ' ',$config{perl_version},' for ',$config{perl_archname},"\n";
+ }
+ if ($dump || $options) {
+ my $longest = 0;
+ my $longest2 = 0;
+ foreach my $what (@disablables) {
+ $longest = length($what) if $longest < length($what);
+ $longest2 = length($disabled{$what})
+ if $disabled{$what} && $longest2 < length($disabled{$what});
+ }
+ print "\nEnabled features:\n\n";
+ foreach my $what (@disablables) {
+ print " $what\n" unless $disabled{$what};
+ }
+ print "\nDisabled features:\n\n";
+ foreach my $what (@disablables) {
+ if ($disabled{$what}) {
+ print " $what", ' ' x ($longest - length($what) + 1),
+ "[$disabled{$what}]", ' ' x ($longest2 - length($disabled{$what}) + 1);
+ print $disabled_info{$what}->{macro}
+ if $disabled_info{$what}->{macro};
+ print ' (skip ',
+ join(', ', @{$disabled_info{$what}->{skipped}}),
+ ')'
+ if $disabled_info{$what}->{skipped};
+ print "\n";
+ }
+ }
+ }
+ if ($dump || $target) {
+ print "\nConfig target attributes:\n\n";
+ foreach (sort keys %target) {
+ next if $_ =~ m|^_| || $_ eq 'template';
+ my $quotify = sub {
+ map { (my $x = $_) =~ s|([\\\$\@"])|\\$1|g; "\"$x\""} @_;
+ };
+ print ' ', $_, ' => ';
+ if (ref($target{$_}) eq "ARRAY") {
+ print '[ ', join(', ', $quotify->(@{$target{$_}})), " ],\n";
+ } else {
+ print $quotify->($target{$_}), ",\n"
+ }
+ }
+ }
+ if ($dump || $envvars) {
+ print "\nRecorded environment:\n\n";
+ foreach (sort keys %{$config{perlenv}}) {
+ print ' ',$_,' = ',($config{perlenv}->{$_} || ''),"\n";
+ }
+ }
+ if ($dump || $makevars) {
+ print "\nMakevars:\n\n";
+ foreach my $var (@makevars) {
+ my $prefix = '';
+ $prefix = $config{CROSS_COMPILE}
+ if grep { $var eq $_ } @user_crossable;
+ $prefix //= '';
+ print ' ',$var,' ' x (16 - length $var),'= ',
+ (ref $config{$var} eq 'ARRAY'
+ ? join(' ', @{$config{$var}})
+ : $prefix.$config{$var}),
+ "\n"
+ if defined $config{$var};
+ }
+
+ my @buildfile = ($config{builddir}, $config{build_file});
+ unshift @buildfile, $here
+ unless file_name_is_absolute($config{builddir});
+ my $buildfile = canonpath(catdir(@buildfile));
+ print <<"_____";
+
+NOTE: These variables only represent the configuration view. The build file
+template may have processed these variables further, please have a look at the
+build file for more exact data:
+ $buildfile
+_____
+ }
+ if ($dump || $buildparams) {
+ my @buildfile = ($config{builddir}, $config{build_file});
+ unshift @buildfile, $here
+ unless file_name_is_absolute($config{builddir});
+ print "\nbuild file:\n\n";
+ print " ", canonpath(catfile(@buildfile)),"\n";
+
+ print "\nbuild file templates:\n\n";
+ foreach (@{$config{build_file_templates}}) {
+ my @tmpl = ($_);
+ unshift @tmpl, $here
+ unless file_name_is_absolute($config{sourcedir});
+ print ' ',canonpath(catfile(@tmpl)),"\n";
+ }
+ }
+ if ($reconf) {
+ if ($verbose) {
+ print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n";
+ foreach (sort keys %{$config{perlenv}}) {
+ print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n";
+ }
+ }
+
+ chdir $here;
+ exec $^X,catfile($config{sourcedir}, 'Configure'),'reconf';
+ }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+configdata.pm - configuration data for OpenSSL builds
+
+=head1 SYNOPSIS
+
+Interactive:
+
+ perl configdata.pm [options]
+
+As data bank module:
+
+ use configdata;
+
+=head1 DESCRIPTION
+
+This module can be used in two modes, interactively and as a module containing
+all the data recorded by OpenSSL's Configure script.
+
+When used interactively, simply run it as any perl script.
+If run with no arguments, it will rebuild the build file (Makefile or
+corresponding).
+With at least one option, it will instead get the information you ask for, or
+re-run the configuration process.
+See L</OPTIONS> below for more information.
+
+When loaded as a module, you get a few databanks with useful information to
+perform build related tasks. The databanks are:
+
+ %config Configured things.
+ %target The OpenSSL config target with all inheritances
+ resolved.
+ %disabled The features that are disabled.
+ @disablables The list of features that can be disabled.
+ %withargs All data given through --with-THING options.
+ %unified_info All information that was computed from the build.info
+ files.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<--help>
+
+Print a brief help message and exit.
+
+=item B<--man>
+
+Print the manual page and exit.
+
+=item B<--dump> | B<-d>
+
+Print all relevant configuration data. This is equivalent to B<--command-line>
+B<--options> B<--target> B<--environment> B<--make-variables>
+B<--build-parameters>.
+
+=item B<--command-line> | B<-c>
+
+Print the current configuration command line.
+
+=item B<--options> | B<-o>
+
+Print the features, both enabled and disabled, and display defined macro and
+skipped directories where applicable.
+
+=item B<--target> | B<-t>
+
+Print the config attributes for this config target.
+
+=item B<--environment> | B<-e>
+
+Print the environment variables and their values at the time of configuration.
+
+=item B<--make-variables> | B<-m>
+
+Print the main make variables generated in the current configuration
+
+=item B<--build-parameters> | B<-b>
+
+Print the build parameters, i.e. build file and build file templates.
+
+=item B<--reconfigure> | B<--reconf> | B<-r>
+
+Re-run the configuration process.
+
+=item B<--verbose> | B<-v>
+
+Verbose output.
+
+=back
+
+=cut
+
+EOF
diff --git a/util/dofile.pl b/util/dofile.pl
index 8cf66cd742..9fa8684549 100644
--- a/util/dofile.pl
+++ b/util/dofile.pl
@@ -14,9 +14,11 @@
use strict;
use warnings;
-use Getopt::Std;
use FindBin;
use lib "$FindBin::Bin/perl";
+use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
+use Getopt::Std;
+use OpenSSL::Template;
# We actually expect to get the following hash tables from configdata:
#
@@ -27,115 +29,8 @@ use lib "$FindBin::Bin/perl";
#
# We just do a minimal test to see that we got what we expected.
# $config{target} must exist as an absolute minimum.
-die "You must run this script with -Mconfigdata\n" if !exists($config{target});
-
-# Make a subclass of Text::Template to override append_text_to_result,
-# as recommended here:
-#
-# http://search.cpan.org/~mjd/Text-Template-1.46/lib/Text/Template.pm#Automatic_postprocessing_of_template_hunks
-
-package OpenSSL::Template;
-
-# Because we know that Text::Template isn't a core Perl module, we use
-# a fallback in case it's not installed on the system
-use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
-use Text::Template 1.46;
-
-#use parent qw/Text::Template/;
-use vars qw/@ISA/;
-push @ISA, qw/Text::Template/;
-
-# Override constructor
-sub new {
- my ($class) = shift;
-
- # Call the constructor of the parent class, Person.
- my $self = $class->SUPER::new( @_ );
- # Add few more attributes
- $self->{_output_off} = 0; # Default to output hunks
- bless $self, $class;
- return $self;
-}
-
-sub append_text_to_output {
- my $self = shift;
-
- if ($self->{_output_off} == 0) {
- $self->SUPER::append_text_to_output(@_);
- }
-
- return;
-}
-
-sub output_reset_on {
- my $self = shift;
- $self->{_output_off} = 0;
-}
-
-sub output_on {
- my $self = shift;
- if (--$self->{_output_off} < 0) {
- $self->{_output_off} = 0;
- }
-}
-
-sub output_off {
- my $self = shift;
- $self->{_output_off}++;
-}
-
-# Come back to main
-
-package main;
-
-# Helper functions for the templates #################################
-
-# It might be practical to quotify some strings and have them protected
-# from possible harm. These functions primarily quote things that might
-# be interpreted wrongly by a perl eval.
-
-# quotify1 STRING
-# This adds quotes (") around the given string, and escapes any $, @, \,
-# " and ' by prepending a \ to them.
-sub quotify1 {
- my $s = shift @_;
- $s =~ s/([\$\@\\"'])/\\$1/g;
- '"'.$s.'"';
-}
-
-# quotify_l LIST
-# For each defined element in LIST (i.e. elements that aren't undef), have
-# it quotified with 'quotify1'
-sub quotify_l {
- map {
- if (!defined($_)) {
- ();
- } else {
- quotify1($_);
- }
- } @_;
-}
-
-# Error reporter #####################################################
-
-# The error reporter uses %lines to figure out exactly which file the
-# error happened and at what line. Not that the line number may be
-# the start of a perl snippet rather than the exact line where it
-# happened. Nothing we can do about that here.
-
-my %lines = ();
-sub broken {
- my %args = @_;
- my $filename = "<STDIN>";
- my $deducelines = 0;
- foreach (sort keys %lines) {
- $filename = $lines{$_};
- last if ($_ > $args{lineno});
- $deducelines += $_;
- }
- print STDERR $args{error}," in $filename, fragment starting at line ",$args{lineno}-$deducelines;
- undef;
-}
+die "You must run this script with -Mconfigdata\n"
+ if !exists($config{target});
# Check options ######################################################
@@ -146,74 +41,41 @@ my %opts = ();
getopt('o', \%opts);
my @autowarntext = ("WARNING: do not edit!",
- "Generated"
- . (defined($opts{o}) ? " by ".$opts{o} : "")
- . (scalar(@ARGV) > 0 ? " from ".join(", ", at ARGV) : ""));
+ "Generated"
+ . (defined($opts{o}) ? " by ".$opts{o} : "")
+ . (scalar(@ARGV) > 0 ? " from ".join(", ", at ARGV) : ""));
-# Template reading ###################################################
+# Template setup #####################################################
-# Read in all the templates into $text, while keeping track of each
-# file and its size in lines, to try to help report errors with the
-# correct file name and line number.
-
-my $prev_linecount = 0;
-my $text =
+my @template_settings =
@ARGV
- ? join("", map { my $x = Text::Template::_load_text($_);
- if (!defined($x)) {
- die $Text::Template::ERROR, "\n";
- }
- $x = "{- output_reset_on() -}" . $x;
- my $linecount = $x =~ tr/\n//;
- $prev_linecount = ($linecount += $prev_linecount);
- $lines{$linecount} = $_;
- $x } @ARGV)
- : join("", <STDIN>);
+ ? map { { TYPE => 'FILE', SOURCE => $_, FILENAME => $_ } } @ARGV
+ : ( { TYPE => 'FILEHANDLE', SOURCE => \*STDIN, FILENAME => '<stdin>' } );
# Engage! ############################################################
-# Load the full template (combination of files) into Text::Template
-# and fill it up with our data. Output goes directly to STDOUT
-
-my $prepend = qq{
+my $prepend = <<"_____";
use File::Spec::Functions;
-use lib catdir('$config{sourcedir}', 'util', 'perl');
-};
-$prepend .= qq{
-use lib catdir('$config{sourcedir}', 'Configurations');
+_____
+$prepend .= <<"_____" if defined $target{perl_platform};
+use lib "$FindBin::Bin/../Configurations";
use lib '$config{builddir}';
use platform;
-} if defined $target{perl_platform};
-
-my $template =
- OpenSSL::Template->new(TYPE => 'STRING',
- SOURCE => $text,
- PREPEND => $prepend);
-
-sub output_reset_on {
- $template->output_reset_on();
- "";
-}
-sub output_on {
- $template->output_on();
- "";
+_____
+
+foreach (@template_settings) {
+ my $template = OpenSSL::Template->new(%$_);
+ $template->fill_in(%$_,
+ OUTPUT => \*STDOUT,
+ HASH => { config => \%config,
+ target => \%target,
+ disabled => \%disabled,
+ withargs => \%withargs,
+ unified_info => \%unified_info,
+ autowarntext => \@autowarntext },
+ PREPEND => $prepend,
+ # To ensure that global variables and functions
+ # defined in one template stick around for the
+ # next, making them combinable
+ PACKAGE => 'OpenSSL::safe');
}
-sub output_off {
- $template->output_off();
- "";
-}
-
-$template->fill_in(OUTPUT => \*STDOUT,
- HASH => { config => \%config,
- target => \%target,
- disabled => \%disabled,
- withargs => \%withargs,
- unified_info => \%unified_info,
- autowarntext => \@autowarntext,
- quotify1 => \"ify1,
- quotify_l => \"ify_l,
- output_reset_on => \&output_reset_on,
- output_on => \&output_on,
- output_off => \&output_off },
- DELIMITERS => [ "{-", "-}" ],
- BROKEN => \&broken);
diff --git a/util/perl/OpenSSL/Template.pm b/util/perl/OpenSSL/Template.pm
new file mode 100644
index 0000000000..ed89d15085
--- /dev/null
+++ b/util/perl/OpenSSL/Template.pm
@@ -0,0 +1,195 @@
+#! /usr/bin/env perl
+# Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the Apache License 2.0 (the "License"). You may not use
+# this file except in compliance with the License. You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+# Implements the functionality to read one or more template files and run
+# them through Text::Template
+
+package OpenSSL::Template;
+
+=head1 NAME
+
+OpenSSL::Template - a private extension of Text::Template
+
+=head1 DESCRIPTION
+
+This provides exactly the functionality from Text::Template, with the
+following additions:
+
+=over 4
+
+=item -
+
+The template perl code delimiters (given with the C<DELIMITER> option)
+are set to C<{-> and C<-}> by default.
+
+=item -
+
+A few extra functions are offered to be used by the template perl code, see
+L</Functions>.
+
+=back
+
+=cut
+
+use File::Basename;
+use File::Spec::Functions;
+use Text::Template 1.46;
+
+our @ISA = qw(Text::Template); # parent
+
+sub new {
+ my $class = shift;
+
+ # Call the constructor of the parent class.
+ my $self = $class->SUPER::new(DELIMITERS => [ '{-', '-}'],
+ @_ );
+
+ # Add few more attributes
+ $self->{_output_off} = 0; # Default to output hunks
+
+ return bless $self, $class;
+}
+
+sub fill_in {
+ my $self = shift;
+ my %opts = @_;
+ my %hash = ( %{$opts{HASH}} );
+ delete $opts{HASH};
+
+ $self->SUPER::fill_in(HASH => { quotify1 => \"ify1,
+ quotify_l => \"ify_l,
+ output_on => sub { $self->output_on() },
+ output_off => sub { $self->output_off() },
+ %hash },
+ %opts);
+}
+
+=head2 Functions
+
+=cut
+
+# Override Text::Template's append_text_to_result, as recommended here:
+#
+# http://search.cpan.org/~mjd/Text-Template-1.46/lib/Text/Template.pm#Automatic_postprocessing_of_template_hunks
+sub append_text_to_output {
+ my $self = shift;
+
+ if ($self->{_output_off} == 0) {
+ $self->SUPER::append_text_to_output(@_);
+ }
+
+ return;
+}
+
+=begin comment
+
+We lie about the OO nature of output_on() and output_off(), 'cause that's
+not how we pass them, see the HASH option used in fill_in() above
+
+=end comment
+
+=over 4
+
+=item output_on()
+
+=item output_off()
+
+Switch on or off template output. Here's an example usage:
+
+=over 4
+
+ {- output_off() if CONDITION -}
+ whatever
+ {- output_on() if CONDITION -}
+
+=back
+
+In this example, C<whatever> will only become part of the template output
+if C<CONDITION> is true.
+
+=back
+
+=cut
+
+sub output_on {
+ my $self = shift;
+ if (--$self->{_output_off} < 0) {
+ $self->{_output_off} = 0;
+ }
+}
+
+sub output_off {
+ my $self = shift;
+ $self->{_output_off}++;
+}
+
+# Helper functions for the templates #################################
+
+# It might be practical to quotify some strings and have them protected
+# from possible harm. These functions primarily quote things that might
+# be interpreted wrongly by a perl eval.
+
+# NOTE THAT THESE AREN'T CLASS METHODS!
+
+=over 4
+
+=item quotify1 STRING
+
+This adds quotes (") around the given string, and escapes any $, @, \,
+" and ' by prepending a \ to them.
+
+=back
+
+=cut
+
+sub quotify1 {
+ my $s = shift @_;
+ $s =~ s/([\$\@\\"'])/\\$1/g;
+ '"'.$s.'"';
+}
+
+=over 4
+
+=item quotify_l LIST
+
+For each defined element in LIST (i.e. elements that aren't undef), have
+it quotified with 'quotify1'.
+Undefined elements are ignored.
+
+=back
+
+=cut
+
+sub quotify_l {
+ map {
+ if (!defined($_)) {
+ ();
+ } else {
+ quotify1($_);
+ }
+ } @_;
+}
+
+=head1 SEE ALSO
+
+L<Text::Template>
+
+=head1 AUTHORS
+
+Richard Levitte E<lt>levitte at openssl.orgE<gt>
+
+=head1 COPYRIGHT
+
+Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
+
+Licensed under the Apache License 2.0 (the "License"). You may not use
+this file except in compliance with the License. You can obtain a copy
+in the file LICENSE in the source distribution or at
+L<https://www.openssl.org/source/license.html>.
+
+=cut
More information about the openssl-commits
mailing list