Commits

Shlomi Fish  committed ea4aaf2

Better dependency tracking.

Filtering more headers.

  • Participants
  • Parent commits f11fff9

Comments (0)

Files changed (2)

File bin/gen-deps-mak.pl

 use IO::All;
 use File::Find::Object::Rule;
 
+use 5.014;
+
 sub _map_wmls_to_deps
 {
     my $files = shift;
     ];
 }
 
+=begin foo
+
+lib/amazon.wml
+lib/camila_ron.wml
+lib/cpan_dists.wml
+lib/dbook.wml
+lib/div2mag.wml
+lib/driver.wml
+lib/footer.wml
+lib/iglu.wml
+lib/lang_switch.wml
+lib/local-defs.wml
+lib/mathjax.wml
+lib/multi-lang.wml
+lib/paypal.wml
+lib/prelude.wml
+lib/render_fortunes_pages.wml
+lib/rest-of-template.wml
+lib/SFresume_base.wml
+lib/share-this.wml
+lib/sponsored_ad.wml
+lib/toc_div.wml
+lib/utils.wml
+lib/vim_include_code.wml
+lib/xml_g_fiction.wml
+
+=end foo
+
+=cut
+
 # Write deps.mak
 {
     my @files =
             ->name('*.wml')
             ->in('t2');
 
+    my $rule = File::Find::Object::Rule->new;
+    my $discard =
+        $rule->new->directory
+        # Temporarily added for debugging:
+        # ->exec(sub { print "$_[2]\n"; })
+        ->name(
+            qr{\A(?:docbook|screenplay-xml|fiction-xml|presentations|MathJax)\z}
+        )
+        ->prune->discard
+        ;
+
+    my @headers =
+        map { ($_ . '') =~ s{\Alib/}{}r }
+        File::Find::Object::Rule
+            ->or($discard,$rule->new())
+            ->name('*.wml')
+            ->in('lib');
+
     my %files_containing_headers =
     (
         map {
             $_ =>
             {
-                re => qr{^\#include *"\Q$_\E\.wml"}ms,
-                files => [],
+                re => qr{^\#include *"\Q$_\E"}ms,
+                files => {},
             },
         }
-        qw(
-            amazon
-            dbook
-            div2mag
-            iglu
-            multi-lang
-            SFresume_base
-            stories/blurbs
-            stories/stories-list
-            toc_div
-            vim_include_code
-            xml_g_fiction
-        ),
+        @headers,
     );
 
     foreach my $fn (@files)
     {
         my $contents = io->file($fn)->slurp;
 
-        foreach my $header (keys(%files_containing_headers))
+        foreach my $match ($contents =~ m{^\#include *"([^"]+)"}gms)
         {
-            if ($contents =~ $files_containing_headers{$header}{re})
+            if (exists($files_containing_headers{$match}))
             {
-                push @{ $files_containing_headers{$header}{files} },
-                    $fn;
+                $files_containing_headers{$match}{files}{$fn} = 1;
             }
         }
     }
 
     foreach my $header (sort { $a cmp $b } keys(%files_containing_headers))
     {
-        $deps_text .=
-            join(' ',
-                @{ _map_wmls_to_deps(
-                        $files_containing_headers{$header}{files}
-                    )
-                }
-            );
+        my $header_deps =
+        [
+            sort { $a cmp $b }
+            keys( %{$files_containing_headers{$header}{files}} )
+        ];
 
-        $deps_text .= ": lib/$header.wml\n\n";
+        if (@$header_deps)
+        {
+            $deps_text .= join(' ', @{ _map_wmls_to_deps($header_deps ) });
+
+            $deps_text .= ": lib/$header\n\n";
+        }
     }
 
     io->file("deps.mak")->print($deps_text);

File gen-helpers.pl

 use File::Find::Object::Rule;
 use IO::All;
 
+use List::MoreUtils;
+
 my $generator =
     HTML::Latemp::GenMakeHelpers->new(
         'hosts' =>
     _my_system($cmd);
 }
 
+=begin removed_duplicate_code
+
+my $wml_deps = io->file("deps.mak");
+
+foreach my $wml_obj (
+    io->dir("t2")->filter(sub { $_->filename =~ qr/\.wml\z/ })->All_Files
+)
+{
+    my $filename = $wml_obj->canonpath;
+    my @deps =
+        grep { $_ ne '../template.wml' }
+    List::MoreUtils::uniq(
+        map { /\A\s*#include (?:'([^']+)'|"([^"]+)"|<([^>]+)>)\s*\z/ ? ($1 || $2 || $3) : () }
+        grep { /\A\s*#include/ } $wml_obj->chomp->getlines);
+
+    foreach my $dep (@deps)
+    {
+        foreach my $dir (".", "lib")
+        {
+            my $full_dep = "$dir/$dep";
+            if (-e $full_dep)
+            {
+                print "$filename: $full_dep\n";
+            }
+        }
+    }
+}
+
+=end removed_duplicate_code
+
+=cut
+
 1;
-