11# ! /usr/bin/env perl
22# -*- mode: perl; -*-
3- # Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
3+ # Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
44#
55# Licensed under the Apache License 2.0 (the "License"). You may not use
66# this file except in compliance with the License. You can obtain a copy
@@ -17,6 +17,7 @@ use lib "$FindBin::Bin/util/perl";
1717use File::Basename;
1818use File::Spec::Functions qw/ :DEFAULT abs2rel rel2abs splitdir/ ;
1919use File::Path qw/ mkpath/ ;
20+ use File::Compare qw( compare_text) ;
2021use OpenSSL::fallback " $FindBin::Bin /external/perl/MODULES.txt" ;
2122use OpenSSL::Glob;
2223use OpenSSL::Template;
@@ -2214,9 +2215,10 @@ if ($builder eq "unified") {
22142215 \$ attributes{depends}, $ +{ATTRIBS},
22152216 tokenize($expand_variables ->($ +{VALUE})))
22162217 if !@skip || $skip [$ #skip] > 0; },
2217- qr/^\s * GENERATE ${index_re} \s * = \s * ${value_re} \s * $ /x
2218+ qr/^\s * GENERATE ${index_re} ${attribs_re} \s * = \s * ${value_re} \s * $ /x
22182219 => sub { $push_to ->(\% generate, $expand_variables ->($ +{INDEX}),
2219- undef, undef, $expand_variables ->($ +{VALUE}))
2220+ \$ attributes{generate}, $ +{ATTRIBS},
2221+ $expand_variables ->($ +{VALUE}))
22202222 if !@skip || $skip [$ #skip] > 0; },
22212223 qr/^\s * (?:\# .*)? $ /x => sub { },
22222224 "OTHERWISE" => sub { die "Something wrong with this line:\n $_ \n at $sourced /$f " },
@@ -2384,6 +2386,10 @@ EOF
23842386 $check_generate {$ddest }-> {$generator [0]}++;
23852387
23862388 $unified_info {generate }-> {$ddest } = [ @generator ];
2389+ # Fix up associated attributes
2390+ $unified_info {attributes }-> {generate }-> {$ddest } =
2391+ $attributes {generate }-> {$dest }-> {$gen }
2392+ if defined $attributes {generate }-> {$dest }-> {$gen };
23872393 }
23882394
23892395 foreach (keys %depends ) {
@@ -2774,7 +2780,7 @@ EOF
27742780 keys %{$unified_info {htmldocs } // {}}),
27752781 (map { @{$unified_info {mandocs }-> {$_ } // []} }
27762782 keys %{$unified_info {mandocs } // {}}) ] );
2777- foreach my $type (keys %loopinfo ) {
2783+ foreach my $type (sort keys %loopinfo ) {
27782784 foreach my $product (@{$loopinfo {$type }}) {
27792785 my %dirs = ();
27802786 my $pd = dirname($product );
@@ -2795,7 +2801,7 @@ EOF
27952801 push @{$unified_info {dirinfo }-> {$d }-> {deps }}, $_
27962802 if $d ne $pd ;
27972803 }
2798- foreach (keys %dirs ) {
2804+ foreach (sort keys %dirs ) {
27992805 push @{$unified_info {dirinfo }-> {$_ }-> {products }-> {$type }},
28002806 $product ;
28012807 }
@@ -2830,7 +2836,6 @@ my %template_vars = (
28302836 user_crossable => \@user_crossable ,
28312837);
28322838my $configdata_outname = ' configdata.pm' ;
2833- print " Creating $configdata_outname \n " ;
28342839open CONFIGDATA, " >$configdata_outname .new"
28352840 or die " Trying to create $configdata_outname .new: $! " ;
28362841my $configdata_tmplname = cleanfile($srcdir , " configdata.pm.in" , $blddir );
@@ -2846,19 +2851,60 @@ $configdata_tmpl->fill_in(
28462851 ] }
28472852) or die $Text::Template::ERROR ;
28482853close CONFIGDATA;
2849- rename " $configdata_outname .new" , $configdata_outname ;
2850- if ($builder_platform eq ' unix' ) {
2851- my $mode = (0755 & ~umask );
2852- chmod $mode , ' configdata.pm'
2853- or warn sprintf (" WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s \n " ,$mode ,$! );
2854- }
2855-
2856- print " Running $configdata_outname \n " ;
2857- my $perlcmd = (quotify(" maybeshell" , $config {PERL }))[0];
2858- my $cmd = " $perlcmd $configdata_outname " ;
2859- # print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
2860- system ($cmd );
2861- exit 1 if $? != 0;
2854+
2855+ # When using stat() on Windows, we can get it to perform better by avoid some
2856+ # data. This doesn't affect the mtime field, so we're not losing anything...
2857+ ${^WIN32_SLOPPY_STAT} = 1;
2858+
2859+ my $update_configdata = 0;
2860+ my $run_configdata = 0;
2861+ if (-f $configdata_outname ) {
2862+ my $Configure_mtime = (stat ($0 ))[9];
2863+ my $configdata_mtime = (stat ($configdata_outname ))[9];
2864+
2865+ # If this script was updated after the last configdata.pm, or if
2866+ # configdata.pm.new differs from configdata.pm, we update configdata.pm
2867+ if ($configdata_mtime < $Configure_mtime
2868+ || compare_text(" $configdata_outname .new" , $configdata_outname ) != 0) {
2869+ $update_configdata = 1;
2870+ } else {
2871+ # If nothing has changed, let's just drop the new one and pretend
2872+ # like nothing happened
2873+ unlink " $configdata_outname .new" ;
2874+
2875+ # We still run configdata.pm if one of the build file (Makefile) or
2876+ # the configuration header file are missing
2877+ $run_configdata =
2878+ !( -f $target {build_file } )
2879+ || !( -f catfile(' include' , ' openssl' , ' configuration.h' ) );
2880+ }
2881+ } else {
2882+ $update_configdata = 1;
2883+ }
2884+
2885+ if ($update_configdata ) {
2886+ # If something did change, or there was no previous configdata.pm, we
2887+ # rename the new one, set permissions as needed, and run it.
2888+ rename " $configdata_outname .new" , $configdata_outname ;
2889+ if ($builder_platform eq ' unix' ) {
2890+ my $mode = (0755 & ~umask );
2891+ chmod $mode , ' configdata.pm'
2892+ or warn sprintf (" WARNING: Couldn't change mode for 'configdata.pm' to 0%03o: %s \n " ,$mode ,$! );
2893+ }
2894+ $run_configdata = 1;
2895+ print " Created $configdata_outname \n " ;
2896+ }
2897+
2898+ if ($run_configdata ) {
2899+ print " Running $configdata_outname \n " ;
2900+ my $perlcmd = (quotify(" maybeshell" , $config {PERL }))[0];
2901+ my $cmd = " $perlcmd $configdata_outname " ;
2902+ # print STDERR "DEBUG[run_dofile]: \$cmd = $cmd\n";
2903+ system ($cmd );
2904+ exit 1 if $? != 0;
2905+ } else {
2906+ print " No changes in $configdata_outname , no need to run it\n " ;
2907+ }
28622908
28632909$SIG {__DIE__ } = $orig_death_handler ;
28642910
0 commit comments