From: Richard Levitte Date: Fri, 1 Dec 2017 14:29:05 +0000 (+0100) Subject: Configure: Add read_eval_file, a general purpose perl file reader/evaluator X-Git-Tag: OpenSSL_1_1_1-pre1~314 X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff_plain;h=3b6c4b07364797566c2c1fd75e499b2d9dd73506 Configure: Add read_eval_file, a general purpose perl file reader/evaluator It will return the last expression from the input file. We also use this in read_config, which slightly changes what's expected of Configurations/*.conf. They do not have to assign %targets specifically. On the other hand, the table of configs MUST be the last expression in each of those files. Reviewed-by: Andy Polyakov Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/4840) --- diff --git a/Configurations/00-base-templates.conf b/Configurations/00-base-templates.conf index f2d7f6aade..ce59fbf296 100644 --- a/Configurations/00-base-templates.conf +++ b/Configurations/00-base-templates.conf @@ -1,5 +1,5 @@ # -*- Mode: perl -*- -%targets=( +my %targets=( DEFAULTS => { template => 1, diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index 28cfd30021..0b07e81fd8 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -144,7 +144,7 @@ sub vms_info { return $vms_info; } -%targets = ( +my %targets = ( #### Basic configs that should work on any 32-bit box "gcc" => { diff --git a/Configurations/50-djgpp.conf b/Configurations/50-djgpp.conf index f532bd16f7..fa8e6625d8 100644 --- a/Configurations/50-djgpp.conf +++ b/Configurations/50-djgpp.conf @@ -2,7 +2,7 @@ # and rely entirely on the OpenSSL community to help is fine # tune and test. -%targets = ( +my %targets = ( "DJGPP" => { inherit_from => [ asm("x86_asm") ], cc => "gcc", diff --git a/Configurations/50-haiku.conf b/Configurations/50-haiku.conf index aea5b2b5cb..b57e148710 100644 --- a/Configurations/50-haiku.conf +++ b/Configurations/50-haiku.conf @@ -1,4 +1,4 @@ -%targets = ( +my %targets = ( "haiku-common" => { template => 1, cc => "cc", diff --git a/Configurations/50-masm.conf b/Configurations/50-masm.conf index 0ec5e95084..e2b54e345c 100644 --- a/Configurations/50-masm.conf +++ b/Configurations/50-masm.conf @@ -7,7 +7,7 @@ # proven to be daunting task. This is experimental target, for # production builds stick with [up-to-date version of] nasm. -%targets = ( +my %targets = ( "VC-WIN64A-masm" => { inherit_from => [ "VC-WIN64-common", asm("x86_64_asm"), sub { $disabled{shared} ? () : "x86_64_uplink" } ], diff --git a/Configurations/90-team.conf b/Configurations/90-team.conf index beb6ad8661..4d57f3fe2f 100644 --- a/Configurations/90-team.conf +++ b/Configurations/90-team.conf @@ -1,7 +1,7 @@ ## -*- mode: perl; -*- ## Build configuration targets for openssl-team members -%targets = ( +my %targets = ( "purify" => { cc => "purify gcc", cflags => "-g -Wall", diff --git a/Configure b/Configure index db191213ad..2c601ad41a 100755 --- a/Configure +++ b/Configure @@ -2292,25 +2292,38 @@ sub add { sub { _add($separator, @_, @x) }; } +sub read_eval_file { + my $fname = shift; + my $content; + my @result; + + open F, "< $fname" or die "Can't open '$fname': $!\n"; + { + undef local $/; + $content = ; + } + close F; + { + local $@; + + @result = ( eval $content ); + warn $@ if $@; + } + return wantarray ? @result : $result[0]; +} + # configuration reader, evaluates the input file as a perl script and expects # it to fill %targets with target configurations. Those are then added to # %table. sub read_config { my $fname = shift; - open(CONFFILE, "< $fname") - or die "Can't open configuration file '$fname'!\n"; - my $x = $/; - undef $/; - my $content = ; - $/ = $x; - close(CONFFILE); - my %targets = (); + my %targets; + { # Protect certain tables from tampering - local %table = %::table; + local %table = (); - eval $content; - warn $@ if $@; + %targets = read_eval_file($fname); } # For each target, check that it's configured with a hash table.