VirtualBox

source: vbox/trunk/src/libs/openssl-3.0.9/util/dofile.pl@ 100906

Last change on this file since 100906 was 100487, checked in by vboxsync, 17 months ago

openssl-3.0.9: Applied and adjusted our OpenSSL changes we made to 3.0.7. bugref:10484

File size: 3.5 KB
Line 
1#! /usr/bin/env perl
2# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the Apache License 2.0 (the "License"). You may not use
5# this file except in compliance with the License. You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
9# Reads one or more template files and runs it through Text::Template
10#
11# It is assumed that this scripts is called with -Mconfigdata, a module
12# that holds configuration data in %config
13
14use strict;
15use warnings;
16
17use FindBin;
18use lib "$FindBin::Bin/perl";
19use OpenSSL::fallback "$FindBin::Bin/../external/perl/MODULES.txt";
20use Getopt::Std;
21use OpenSSL::Template;
22
23use File::Basename; # VBOX addition for basename
24
25# We expect to get a lot of information from configdata, so check that
26# it was part of our commandline.
27die "You must run this script with -Mconfigdata\n"
28 if !exists($config{target});
29
30# Check options ######################################################
31
32# -o ORIGINATOR
33# declares ORIGINATOR as the originating script.
34# -i .ext Like Perl's edit-in-place -i flag
35my %opts = ();
36getopt('oi', \%opts);
37
38my @autowarntext = (
39 "WARNING: do not edit!",
40 "Generated"
41 . (defined($opts{o}) ? " by $opts{o}" : "")
42 . (scalar(@ARGV) > 0 ? " from " .join(", ", basename(@ARGV)) : "") # VBOX modified: added basename()
43);
44
45if (defined($opts{s})) {
46 local $/ = undef;
47 open VARS, $opts{s} or die "Couldn't open $opts{s}, $!";
48 my $contents = <VARS>;
49 close VARS;
50 eval $contents;
51 die $@ if $@;
52}
53die "Must have input files"
54 if defined($opts{i}) and scalar(@ARGV) == 0;
55
56# Template setup #####################################################
57
58my @template_settings =
59 @ARGV
60 ? map { { TYPE => 'FILE', SOURCE => $_, FILENAME => $_ } } @ARGV
61 : ( { TYPE => 'FILEHANDLE', SOURCE => \*STDIN, FILENAME => '<stdin>' } );
62
63# Error callback; print message, set status, return "stop processing"
64my $failed = 0;
65sub errorcallback {
66 my %args = @_;
67 print STDERR $args{error};
68 $failed++;
69 return undef;
70}
71
72# Engage! ############################################################
73
74my $prepend = <<"_____";
75use File::Spec::Functions;
76use lib '$FindBin::Bin/../Configurations';
77use lib '$config{builddir}';
78use platform;
79_____
80
81foreach (@template_settings) {
82 my $template = OpenSSL::Template->new(%$_);
83 die "Couldn't create template: $Text::Template::ERROR"
84 if !defined($template);
85
86 my $result = $template->fill_in(%$_,
87 HASH => { config => \%config,
88 target => \%target,
89 disabled => \%disabled,
90 withargs => \%withargs,
91 unified_info => \%unified_info,
92 autowarntext => \@autowarntext },
93 BROKEN => \&errorcallback,
94 PREPEND => $prepend,
95 # To ensure that global variables and functions
96 # defined in one template stick around for the
97 # next, making them combinable
98 PACKAGE => 'OpenSSL::safe');
99 exit 1 if $failed;
100
101 if (defined($opts{i})) {
102 my $in = $_->{FILENAME};
103 my $out = $in;
104 $out =~ s/$opts{i}$//;
105 die "Cannot replace file in-place $in"
106 if $in eq $out;
107 open OFH, ">$out"
108 or die "Can't open $out, $!";
109 print OFH $result;
110 close OFH;
111 } else {
112 print $result;
113 }
114}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette