2016-04-20 10:10:43 +08:00
|
|
|
#! /usr/bin/env perl
|
2018-03-20 21:00:17 +08:00
|
|
|
# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
#
|
2018-12-06 20:03:50 +08:00
|
|
|
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-04-20 10:10:43 +08:00
|
|
|
# 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
|
|
|
|
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
# Reads one or more template files and runs it through Text::Template
|
|
|
|
#
|
|
|
|
# It is assumed that this scripts is called with -Mconfigdata, a module
|
|
|
|
# that holds configuration data in %config
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2016-01-22 19:40:49 +08:00
|
|
|
|
2019-09-09 17:51:01 +08:00
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/perl";
|
2019-08-25 16:44:41 +08:00
|
|
|
use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
|
|
|
|
use Getopt::Std;
|
|
|
|
use OpenSSL::Template;
|
2016-01-26 04:19:59 +08:00
|
|
|
|
2019-10-13 05:45:56 +08:00
|
|
|
# We expect to get a lot of information from configdata, so check that
|
|
|
|
# it was part of our commandline.
|
2019-08-25 16:44:41 +08:00
|
|
|
die "You must run this script with -Mconfigdata\n"
|
|
|
|
if !exists($config{target});
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
|
2016-01-26 04:19:59 +08:00
|
|
|
# Check options ######################################################
|
|
|
|
|
|
|
|
# -o ORIGINATOR
|
|
|
|
# declares ORIGINATOR as the originating script.
|
2019-10-13 05:45:56 +08:00
|
|
|
# -i .ext Like Perl's edit-in-place -i flag
|
|
|
|
my %opts = ();
|
|
|
|
getopt('oi', \%opts);
|
2016-01-26 04:19:59 +08:00
|
|
|
|
2019-10-13 05:45:56 +08:00
|
|
|
my @autowarntext = (
|
|
|
|
"WARNING: do not edit!",
|
|
|
|
"Generated"
|
|
|
|
. (defined($opts{o}) ? " by $opts{o}" : "")
|
|
|
|
. (scalar(@ARGV) > 0 ? " from " .join(", ", @ARGV) : "")
|
|
|
|
);
|
|
|
|
|
2019-10-13 05:45:56 +08:00
|
|
|
if (defined($opts{s})) {
|
|
|
|
local $/ = undef;
|
|
|
|
open VARS, $opts{s} or die "Couldn't open $opts{s}, $!";
|
|
|
|
my $contents = <VARS>;
|
|
|
|
close VARS;
|
|
|
|
eval $contents;
|
|
|
|
die $@ if $@;
|
|
|
|
}
|
2019-10-13 05:45:56 +08:00
|
|
|
die "Must have input files"
|
|
|
|
if defined($opts{i}) and scalar(@ARGV) == 0;
|
2016-01-26 04:19:59 +08:00
|
|
|
|
2019-08-25 16:44:41 +08:00
|
|
|
# Template setup #####################################################
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
|
2019-08-25 16:44:41 +08:00
|
|
|
my @template_settings =
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
@ARGV
|
2019-08-25 16:44:41 +08:00
|
|
|
? map { { TYPE => 'FILE', SOURCE => $_, FILENAME => $_ } } @ARGV
|
|
|
|
: ( { TYPE => 'FILEHANDLE', SOURCE => \*STDIN, FILENAME => '<stdin>' } );
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
|
2019-10-13 05:45:56 +08:00
|
|
|
# Error callback; print message, set status, return "stop processing"
|
|
|
|
my $failed = 0;
|
|
|
|
sub errorcallback {
|
|
|
|
my %args = @_;
|
|
|
|
print STDERR $args{error};
|
|
|
|
$failed++;
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
Refactor file writing - introduce template driven file writing
apps/CA.pl and tools/c_rehash are built from template files. So far,
this was done by Configure, which created its own problems as it
forced everyone to reconfigure just because one of the template files
had changed.
Instead, have those files created as part of the normal build in apps/
and in tools/.
Furthermore, this prepares for a future where Configure may produce
entirely other build files than Makefile, and the latter can't be
guaranteed to be the holder of all information for other scripts.
Instead, configdata.pm (described below) becomes the center of
configuration information.
This introduces a few new things:
%config a hash table to hold all kinds of configuration data
that can be used by any other script.
configdata.pm a perl module that Configure writes. It currently
holds the hash tables %config and %target.
util/dofile.pl a script that takes a template on STDIN and outputs
the result after applying configuration data on it.
It's supposed to be called like this:
perl -I$(TOP) -Mconfigdata < template > result
or
perl -I$(TOP) -Mconfigdata templ1 templ2 ... > result
Note: util/dofile.pl requires Text::Template.
As part of this changed, remove a number of variables that are really
just copies of entries in %target, and use %target directly. The
exceptions are $target{cflags} and $target{lflags}, they do get copied
to $cflags and $lflags. The reason for this is that those variable
potentially go through a lot of changes and would rather deserve a
place in %config. That, however, is for another commit.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
2015-05-19 04:35:23 +08:00
|
|
|
# Engage! ############################################################
|
|
|
|
|
2019-08-25 16:44:41 +08:00
|
|
|
my $prepend = <<"_____";
|
2018-10-23 20:14:48 +08:00
|
|
|
use File::Spec::Functions;
|
2019-08-25 16:44:41 +08:00
|
|
|
use lib "$FindBin::Bin/../Configurations";
|
2018-10-23 20:14:48 +08:00
|
|
|
use lib '$config{builddir}';
|
|
|
|
use platform;
|
2019-08-25 16:44:41 +08:00
|
|
|
_____
|
|
|
|
|
|
|
|
foreach (@template_settings) {
|
|
|
|
my $template = OpenSSL::Template->new(%$_);
|
2019-10-13 05:45:56 +08:00
|
|
|
die "Couldn't create template: $Text::Template::ERROR"
|
|
|
|
if !defined($template);
|
|
|
|
|
|
|
|
my $result = $template->fill_in(%$_,
|
2019-08-25 16:44:41 +08:00
|
|
|
HASH => { config => \%config,
|
|
|
|
target => \%target,
|
|
|
|
disabled => \%disabled,
|
|
|
|
withargs => \%withargs,
|
|
|
|
unified_info => \%unified_info,
|
|
|
|
autowarntext => \@autowarntext },
|
2019-10-13 05:45:56 +08:00
|
|
|
BROKEN => \&errorcallback,
|
2019-08-25 16:44:41 +08:00
|
|
|
PREPEND => $prepend,
|
|
|
|
# To ensure that global variables and functions
|
|
|
|
# defined in one template stick around for the
|
|
|
|
# next, making them combinable
|
|
|
|
PACKAGE => 'OpenSSL::safe');
|
2019-10-13 05:45:56 +08:00
|
|
|
exit 1 if $failed;
|
|
|
|
|
|
|
|
if (defined($opts{i})) {
|
|
|
|
my $in = $_->{FILENAME};
|
|
|
|
my $out = $in;
|
|
|
|
$out =~ s/$opts{i}$//;
|
|
|
|
die "Cannot replace file in-place $in"
|
|
|
|
if $in eq $out;
|
|
|
|
open OFH, ">$out"
|
|
|
|
or die "Can't open $out, $!";
|
|
|
|
print OFH $result;
|
|
|
|
close OFH;
|
|
|
|
} else {
|
|
|
|
print $result;
|
|
|
|
}
|
2016-01-30 10:21:39 +08:00
|
|
|
}
|