From 6dd07a9328950ff8bf3f95ad35caf3a4e1e33a15 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 24 May 2021 14:19:38 +0200 Subject: [PATCH] Build file templates: rework how general dependencies are computed For some types of targets, we pretty much know what kinds of files all the dependencies are. For some, however, we can't assume anything, and are faced with dependencies in platform agnostic form. We need to find those in diverse places in %unified_info, and deduce from there how they should be converted to a platform specific form. Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15436) --- Configurations/descrip.mms.tmpl | 49 ++++++++++++------------- Configurations/unix-Makefile.tmpl | 55 ++++++++++++---------------- Configurations/windows-makefile.tmpl | 54 ++++++++++++--------------- 3 files changed, 71 insertions(+), 87 deletions(-) diff --git a/Configurations/descrip.mms.tmpl b/Configurations/descrip.mms.tmpl index 3e389215e1..cdc341f9e7 100644 --- a/Configurations/descrip.mms.tmpl +++ b/Configurations/descrip.mms.tmpl @@ -762,6 +762,17 @@ reconfigure reconf : use File::Spec::Functions qw/abs2rel rel2abs catfile catdir/; use File::Spec::Unix; + # Helper function to convert dependencies in platform agnostic form to + # dependencies in platform form. + sub compute_platform_depends { + map { my $x = $_; + + grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x) + or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x) + or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x) + or platform->convertext($x); } @_; + } + # Helper function to figure out dependencies on libraries # It takes a list of library names and outputs a list of dependencies sub compute_lib_depends { @@ -852,7 +863,7 @@ EOF sub generatetarget { my %args = @_; - my $deps = join(" ", @{$args{deps}}); + my $deps = join(" ", compute_platform_depends(@{$args{deps}})); return <<"EOF"; $args{target} : $deps EOF @@ -864,7 +875,9 @@ EOF my $gen_args = join('', map { " $_" } @{$args{generator}}[1..$#{$args{generator}}]); my $gen_incs = join("", map { ' "-I'.$_.'"' } @{$args{generator_incs}}); - my $deps = join(", -\n\t\t", @{$args{generator_deps}}, @{$args{deps}}); + my $deps = join(", -\n\t\t", + compute_platform_depends(@{$args{generator_deps}}, + @{$args{deps}})); if ($args{src} =~ /\.html$/) { # @@ -957,38 +970,22 @@ EOF my $dofile = abs2rel(rel2abs(catfile($config{sourcedir}, "util", "dofile.pl")), rel2abs($config{builddir})); - my @modules = ( 'configdata.pm', - grep { $_ =~ m|\.pm$| } @{$args{deps}} ); - my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules; - $deps = join(' ', $deps, @modules); - @modules = map { '"-M'.basename($_, '.pm').'"' } @modules; - my $modules = join(' ', '', sort keys %moduleincs, @modules); + my @perlmodules = ( 'configdata.pm', + grep { $_ =~ m|\.pm$| } @{$args{deps}} ); + my %perlmoduleincs = map { '"-I'.dirname($_).'"' => 1 } @perlmodules; + $deps = join(' ', $deps, compute_platform_depends(@perlmodules)); + @perlmodules = map { '"-M'.basename($_, '.pm').'"' } @perlmodules; + my $perlmodules = join(' ', '', sort keys %perlmoduleincs, @perlmodules); return <<"EOF"; $args{src} : $gen0 $deps - \$(PERL)$modules $dofile "-o$target{build_file}" $gen0$gen_args > \$\@ + \$(PERL)$perlmodules $dofile "-o$target{build_file}" $gen0$gen_args > \$\@ EOF } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) { # # Generic generator using OpenSSL programs # - # Redo $deps, because programs aren't expected to have deps of their - # own. This is a little more tricky, though, because running programs - # may have dependencies on all sorts of files, so we search through - # our database of programs and modules to see if our dependencies - # are one of those. - $deps = join(' ', map { my $x = $_; - if (grep { $x eq $_ } - @{$unified_info{programs}}) { - platform->bin($x); - } elsif (grep { $x eq $_ } - @{$unified_info{modules}}) { - platform->dso($x); - } else { - $x; - } - } @{$args{deps}}); - # Also redo $gen0, to ensure that we have the proper extension + # Redo $gen0, to ensure that we have the proper extension $gen0 = platform->bin($gen0); return <<"EOF"; $args{src} : $gen0 $deps diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index 00bd2d7c55..6895ed373b 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -1457,6 +1457,17 @@ reconfigure reconf: use File::Basename; use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs/; + # Helper function to convert dependencies in platform agnostic form to + # dependencies in platform form. + sub compute_platform_depends { + map { my $x = $_; + + grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x) + or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x) + or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x) + or platform->convertext($x); } @_; + } + # Helper function to figure out dependencies on libraries # It takes a list of library names and outputs a list of dependencies sub compute_lib_depends { @@ -1471,7 +1482,7 @@ reconfigure reconf: sub generatetarget { my %args = @_; - my $deps = join(" ", @{$args{deps}}); + my $deps = join(" ", compute_platform_depends(@{$args{deps}})); return <<"EOF"; $args{target}: $deps EOF @@ -1485,7 +1496,8 @@ EOF my $gen_incs = join("", map { " -I".$_ } @{$args{generator_incs}}); my $incs = join("", map { " -I".$_ } @{$args{incs}}); my $defs = join("", map { " -D".$_ } @{$args{defs}}); - my $deps = join(" ", @{$args{generator_deps}}, @{$args{deps}}); + my $deps = join(" ", compute_platform_depends(@{$args{generator_deps}}, + @{$args{deps}})); if ($args{src} =~ /\.html$/) { # @@ -1562,38 +1574,22 @@ EOF my $dofile = abs2rel(rel2abs(catfile($config{sourcedir}, "util", "dofile.pl")), rel2abs($config{builddir})); - my @modules = ( 'configdata.pm', - grep { $_ =~ m|\.pm$| } @{$args{deps}} ); - my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules; - $deps = join(' ', $deps, @modules); - @modules = map { "-M".basename($_, '.pm') } @modules; - my $modules = join(' ', '', sort keys %moduleincs, @modules); + my @perlmodules = ( 'configdata.pm', + grep { $_ =~ m|\.pm$| } @{$args{deps}} ); + my %perlmoduleincs = map { '"-I'.dirname($_).'"' => 1 } @perlmodules; + $deps = join(' ', $deps, compute_platform_depends(@perlmodules)); + @perlmodules = map { "-M".basename($_, '.pm') } @perlmodules; + my $perlmodules = join(' ', '', sort keys %perlmoduleincs, @perlmodules); return <<"EOF"; $args{src}: $gen0 $deps - \$(PERL)$modules "$dofile" "-o$target{build_file}" $gen0$gen_args > \$@ + \$(PERL)$perlmodules "$dofile" "-o$target{build_file}" $gen0$gen_args > \$@ EOF } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) { # # Generic generator using OpenSSL programs # - # Redo $deps, because programs aren't expected to have deps of their - # own. This is a little more tricky, though, because running programs - # may have dependencies on all sorts of files, so we search through - # our database of programs and modules to see if our dependencies - # are one of those. - $deps = join(' ', map { my $x = $_; - if (grep { $x eq $_ } - @{$unified_info{programs}}) { - platform->bin($x); - } elsif (grep { $x eq $_ } - @{$unified_info{modules}}) { - platform->dso($x); - } else { - $x; - } - } @{$args{deps}}); - # Also redo $gen0, to ensure that we have the proper extension where + # Redo $gen0, to ensure that we have the proper extension where # necessary. $gen0 = platform->bin($gen0); # Use $(PERL) to execute wrap.pl directly to avoid calling env @@ -1940,11 +1936,8 @@ EOF sub generatedir { my %args = @_; my $dir = $args{dir}; - my @deps = map { platform->convertext($_) } @{$args{deps}}; + my @deps = compute_platform_depends(@{$args{deps}}); my @comments = (); - my %extinfo = ( dso => platform->dsoext(), - lib => platform->libext(), - bin => platform->binext() ); # We already have a 'test' target, and the top directory is just plain # silly @@ -1959,7 +1952,7 @@ EOF if ($type ne "lib") { foreach my $prod (@{$unified_info{dirinfo}->{$dir}->{products}->{$type}}) { if (dirname($prod) eq $dir) { - push @deps, $prod.$extinfo{$type}; + push @deps, compute_platform_depends($prod); } else { push @comments, "# No support to produce $type ".join(", ", @{$unified_info{dirinfo}->{$dir}->{products}->{$type}}); } diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl index 984693d817..37f623a4bd 100644 --- a/Configurations/windows-makefile.tmpl +++ b/Configurations/windows-makefile.tmpl @@ -669,6 +669,17 @@ reconfigure reconf: use File::Basename; use File::Spec::Functions qw/:DEFAULT abs2rel rel2abs file_name_is_absolute/; + # Helper function to convert dependencies in platform agnostic form to + # dependencies in platform form. + sub compute_platform_depends { + map { my $x = $_; + + grep { $x eq $_ } @{$unified_info{programs}} and platform->bin($x) + or grep { $x eq $_ } @{$unified_info{modules}} and platform->dso($x) + or grep { $x eq $_ } @{$unified_info{libraries}} and platform->lib($x) + or platform->convertext($x); } @_; + } + # Helper function to figure out dependencies on libraries # It takes a list of library names and outputs a list of dependencies sub compute_lib_depends { @@ -680,7 +691,7 @@ reconfigure reconf: sub generatetarget { my %args = @_; - my $deps = join(" ", @{$args{deps}}); + my $deps = join(" ", compute_platform_depends(@{$args{deps}})); return <<"EOF"; $args{target}: $deps EOF @@ -698,11 +709,10 @@ EOF my $gen_incs = join("", map { " -I\"$_\"" } @{$args{generator_incs}}); my $incs = join("", map { " -I\"$_\"" } @{$args{incs}}); my $defs = join("", map { " -D".$_ } @{$args{defs}}); - my $deps = @{$args{deps}} ? - join(' ', - map { file_name_is_absolute($_) || ($_ =~ m|^../|) ? "\"$_\"" : $_ } - (@{$args{generator_deps}}, @{$args{deps}})) - : ''; + my $deps = join(' ', + map { file_name_is_absolute($_) || ($_ =~ m|^../|) ? "\"$_\"" : $_ } + compute_platform_depends(@{$args{generator_deps}}, + @{$args{deps}})); if ($args{src} =~ /\.html$/) { # @@ -781,38 +791,22 @@ EOF my $dofile = abs2rel(rel2abs(catfile($config{sourcedir}, "util", "dofile.pl")), rel2abs($config{builddir})); - my @modules = ( 'configdata.pm', - grep { $_ =~ m|\.pm$| } @{$args{deps}} ); - my %moduleincs = map { '"-I'.dirname($_).'"' => 1 } @modules; - $deps = join(' ', $deps, @modules); - @modules = map { "-M".basename($_, '.pm') } @modules; - my $modules = join(' ', '', sort keys %moduleincs, @modules); + my @perlmodules = ( 'configdata.pm', + grep { $_ =~ m|\.pm$| } @{$args{deps}} ); + my %perlmoduleincs = map { '"-I'.dirname($_).'"' => 1 } @perlmodules; + $deps = join(' ', $deps, compute_platform_depends(@perlmodules)); + @perlmodules = map { "-M".basename($_, '.pm') } @perlmodules; + my $perlmodules = join(' ', '', sort keys %perlmoduleincs, @perlmodules); return <<"EOF"; $args{src}: "$gen0" $deps - "\$(PERL)"$modules "$dofile" "-o$target{build_file}" "$gen0"$gen_args > \$@ + "\$(PERL)"$perlmodules "$dofile" "-o$target{build_file}" "$gen0"$gen_args > \$@ EOF } elsif (grep { $_ eq $gen0 } @{$unified_info{programs}}) { # # Generic generator using OpenSSL programs # - # Redo $deps, because programs aren't expected to have deps of their - # own. This is a little more tricky, though, because running programs - # may have dependencies on all sorts of files, so we search through - # our database of programs and modules to see if our dependencies - # are one of those. - $deps = join(' ', map { my $x = $_; - if (grep { $x eq $_ } - @{$unified_info{programs}}) { - platform->bin($x); - } elsif (grep { $x eq $_ } - @{$unified_info{modules}}) { - platform->dso($x); - } else { - $x; - } - } @{$args{deps}}); - # Also redo $gen0, to ensure that we have the proper extension. + # Redo $gen0, to ensure that we have the proper extension. $gen0 = platform->bin($gen0); return <<"EOF"; $args{src}: $gen0 $deps "\$(BLDDIR)\\util\\wrap.pl" -- 2.39.2