|
1 | 1 | #!/usr/bin/env perl |
2 | 2 | # |
3 | | -# Copyright (c) 2009-2020 Cisco Systems, Inc. All rights reserved |
| 3 | +# Copyright (c) 2009-2021 Cisco Systems, Inc. All rights reserved |
4 | 4 | # Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. |
5 | 5 | # Copyright (c) 2013 Mellanox Technologies, Inc. |
6 | 6 | # All rights reserved. |
@@ -1137,6 +1137,102 @@ sub in_tarball { |
1137 | 1137 | return $tarball; |
1138 | 1138 | } |
1139 | 1139 |
|
| 1140 | +############################################################################## |
| 1141 | + |
| 1142 | +sub replace_config_sub_guess { |
| 1143 | + # This could be simpler if we could use some Perl modules for this |
| 1144 | + # functionality (e.g., DateTime). But I don't want to introduce |
| 1145 | + # any CPAN dependencies here, so just do sometime simple, even if |
| 1146 | + # it's a bit laborious. Use a few private helper functions for |
| 1147 | + # this kind of functionality. |
| 1148 | + |
| 1149 | + sub _get_timestamp { |
| 1150 | + my $filename = shift; |
| 1151 | + |
| 1152 | + my $ret; |
| 1153 | + if (-x $filename) { |
| 1154 | + my $out = `$filename --version`; |
| 1155 | + $out =~ m/GNU config\.[a-z]+ \((.+)\)/; |
| 1156 | + $ret = $1; |
| 1157 | + } |
| 1158 | + |
| 1159 | + return $ret; |
| 1160 | + } |
| 1161 | + |
| 1162 | + sub _split_timestamp { |
| 1163 | + my $ts = shift; |
| 1164 | + |
| 1165 | + $ts =~ m/(\d+)-(\d+)-(\d+)/; |
| 1166 | + return $1, $2, $3; |
| 1167 | + } |
| 1168 | + |
| 1169 | + # Returns true if timestamp $a > timestamp $b. |
| 1170 | + sub _timestamp_gt { |
| 1171 | + my ($a, $b) = @_; |
| 1172 | + |
| 1173 | + my ($year_a, $month_a, $day_a) = _split_timestamp($a); |
| 1174 | + my ($year_b, $month_b, $day_b) = _split_timestamp($b); |
| 1175 | + |
| 1176 | + # Don't try to be clever -- just do a simple set of explicit |
| 1177 | + # comparisons. |
| 1178 | + if ($year_a > $year_b) { |
| 1179 | + return 1; |
| 1180 | + } elsif ($year_a < $year_b) { |
| 1181 | + return 0; |
| 1182 | + } else { |
| 1183 | + if ($month_a > $month_b) { |
| 1184 | + return 1; |
| 1185 | + } elsif ($month_a < $month_b) { |
| 1186 | + return 0; |
| 1187 | + } else { |
| 1188 | + if ($day_a > $day_b) { |
| 1189 | + return 1; |
| 1190 | + } else { |
| 1191 | + return 0; |
| 1192 | + } |
| 1193 | + } |
| 1194 | + } |
| 1195 | + } |
| 1196 | + |
| 1197 | + my ($topdir) = @_; |
| 1198 | + |
| 1199 | + # Find the stashed known-good files, and get their version |
| 1200 | + # timestamps. |
| 1201 | + my $cached_dir = "$topdir/config/from-savannah"; |
| 1202 | + my @files = qw/config.guess config.sub/; |
| 1203 | + my %known_good_timestamps; |
| 1204 | + foreach my $file (@files) { |
| 1205 | + my $filename = "$cached_dir/upstream-$file"; |
| 1206 | + my_die("Cannot find $filename") |
| 1207 | + if (! -f $filename); |
| 1208 | + |
| 1209 | + my $ts = _get_timestamp($filename); |
| 1210 | + $known_good_timestamps{$file} = $ts; |
| 1211 | + } |
| 1212 | + |
| 1213 | + # Find all config.guess/config.sub files in the tree. If their |
| 1214 | + # versions are older than the stashed known-good files, update |
| 1215 | + # them from the stash. |
| 1216 | + my @files; |
| 1217 | + File::Find::find(sub { |
| 1218 | + push(@files, $File::Find::name) |
| 1219 | + if ($_ eq "config.guess" || |
| 1220 | + $_ eq "config.sub") }, $topdir); |
| 1221 | + |
| 1222 | + foreach my $file (@files) { |
| 1223 | + # Skip anything in the 3rd-party tree |
| 1224 | + next |
| 1225 | + if ($file =~ /\/3rd-party\//); |
| 1226 | + |
| 1227 | + my $base = basename($file); |
| 1228 | + my $ts = _get_timestamp($file); |
| 1229 | + if (_timestamp_gt($known_good_timestamps{$base}, $ts)) { |
| 1230 | + print("=== Replacing $file with newer version\n"); |
| 1231 | + safe_system("cp -f $cached_dir/upstream-$base $file"); |
| 1232 | + } |
| 1233 | + } |
| 1234 | +} |
| 1235 | + |
1140 | 1236 | ############################################################################## |
1141 | 1237 | ############################################################################## |
1142 | 1238 | ## main - do the real work... |
@@ -1458,6 +1554,11 @@ sub in_tarball { |
1458 | 1554 |
|
1459 | 1555 | patch_autotools_output("."); |
1460 | 1556 |
|
| 1557 | +# Per https://github.com/open-mpi/ompi/issues/8410, replace config.sub |
| 1558 | +# and config.guess with known-good versions if the Autoconf-installed |
| 1559 | +# versions are older. |
| 1560 | +replace_config_sub_guess("."); |
| 1561 | + |
1461 | 1562 | #--------------------------------------------------------------------------- |
1462 | 1563 |
|
1463 | 1564 | verbose " |
|
0 commit comments