Ugly hack to avoid recompiling the same thing multiple times in parallel.
authorBen Laurie <ben@links.org>
Sun, 5 May 2013 14:06:33 +0000 (15:06 +0100)
committerBen Laurie <ben@links.org>
Sun, 5 May 2013 14:06:33 +0000 (15:06 +0100)
util/pl/unix.pl

index 72d3b441e142cd83ad490931c2a28ce8a9099de5..b76981dc55d1bee5ccd213b8ebdd9c59037d93fe 100644 (file)
@@ -189,13 +189,18 @@ sub fixtests
 
 sub fixdeps
   {
-  my ($str) = @_;
+  my ($str, $fakes) = @_;
 
   my @t = split(/\s+/, $str);
   $str = '';
   foreach my $t (@t)
     {
     $str .= ' ' if $str ne '';
+    if (exists($fakes->{$t}))
+      {
+      $str .= $fakes->{$t};
+      next;
+      }
     if ($t =~ /^[^\/]+$/)
       {
       $str .= '$(TEST_D)/' . $t;
@@ -265,6 +270,7 @@ sub get_tests
   my %deps;
   my %tests;
   my %alltests;
+  my %fakes;
   while (my $line = <M>)
     {
     chomp $line;
@@ -287,7 +293,22 @@ sub get_tests
        || $line =~ /^(?<t>test_(ss|gen) .*):(?<d>.*)/)
       {
       my $t = $+{t};
-      $deps{$t} = $+{d};
+      my $d = $+{d};
+      # If there are multiple targets stupid FreeBSD make runs the
+      # rules once for each dependency that matches one of the
+      # targets. Running the same rule twice concurrently causes
+      # breakage, so replace with a fake target.
+      if ($t =~ /\s/)
+        {
+       ++$fake;
+       my @targets = split /\s+/, $t;
+       $t = "_fake$fake";
+       foreach my $f (@targets)
+         {
+         $fakes{$f} = $t;
+         }
+       }
+      $deps{$t} = $d;
       $deps{$t} =~ s/#.*$//;
       for (;;)
        {
@@ -326,7 +347,7 @@ sub get_tests
     $d =~ s/\.\.\/apps/\$(BIN_D)/g;
     $d =~ s/\.\.\/util/\$(TEST_D)/g;
     $d = fixtests($d, \%tests);
-    $d = fixdeps($d);
+    $d = fixdeps($d, \%fakes);
 
     my $r = $targets{$t};
     $r =~ s/\.\.\/apps/..\/\$(BIN_D)/g;
@@ -392,7 +413,18 @@ sub get_tests
   $scripts .= "\nocsp:\n\tcp -R test/ocsp-tests \$(TEST_D)\n";
   $scripts .= "\smime:\n\tcp -R test/smime-certs \$(TEST_D)\n";
 
-  my $all = 'test: ' . join(' ', keys %alltests);
+  my $all = 'test:';
+  foreach my $t (keys %alltests)
+    {
+    if (exists($fakes{$t}))
+      {
+      $all .= " $fakes{$t}";
+      }
+    else
+      {
+      $all .= " $t";
+      }
+    }
 
   return "$scripts\n$copies\n$tests\n$all\n\n$each";
   }