[svn:parrot] r42274 - in trunk: . tools/dev
coke at svn.parrot.org
coke at svn.parrot.org
Thu Nov 5 21:30:44 UTC 2009
Author: coke
Date: Thu Nov 5 21:30:41 2009
New Revision: 42274
URL: https://trac.parrot.org/parrot/changeset/42274
Log:
Add a tool to verify makefile deps based on C #includes.
Can probably go into 'make distro_tests' once we've kicked the tires.
Added:
trunk/tools/dev/checkdepend.pl (contents, props changed)
Modified:
trunk/MANIFEST
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST Thu Nov 5 18:24:33 2009 (r42273)
+++ trunk/MANIFEST Thu Nov 5 21:30:41 2009 (r42274)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov 5 10:31:39 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov 5 20:59:58 2009 UT
#
# See below for documentation on the format of this file.
#
@@ -2085,6 +2085,7 @@
tools/dev/bench_op.pir []
tools/dev/branch_status.pl []
tools/dev/cc_flags.pl []
+tools/dev/checkdepend.pl []
tools/dev/create_language.pl []
tools/dev/debian_docs.sh []
tools/dev/fetch_languages.pl []
Added: trunk/tools/dev/checkdepend.pl
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/tools/dev/checkdepend.pl Thu Nov 5 21:30:41 2009 (r42274)
@@ -0,0 +1,103 @@
+#! perl
+
+# Copyright (C) 2009, Parrot Foundation.
+# $Id$
+
+use strict;
+use warnings;
+
+use Cwd qw(abs_path getcwd realpath);
+use Fatal qw(open);
+use File::Spec;
+use Test::More;
+use Test::Harness;
+
+=for comment
+
+A braindead script to check that every .c file has makefile deps
+on its includes.
+
+Requires: a standard (possibly non -j) make run to generate all
+required C files first.
+
+=cut
+
+my $files = `ack -fa . | grep '\\.c\$'`;
+
+my %deps;
+
+foreach my $file (split /\n/, $files) {
+ open my $fh, '<', $file;
+ my $guts;
+ {
+ local undef $/;
+ $guts = <$fh>;
+ }
+ my @includes = $guts =~ m/#include "(.*)"/g;
+ $file =~ s/\.c$//;
+ $deps{$file} = [ @includes ];
+}
+
+plan('no_plan');
+
+open my $mf, '<', "Makefile";
+my $rules;
+{
+ local undef $/;
+ $rules = <$mf>;
+}
+$rules =~ s/\\\n/ /g;
+$rules =~ s/\Q$(SRC_DIR)\E/src/g;
+$rules =~ s/\Q$(O)\E//g;
+
+foreach my $file (keys %deps) {
+ $rules =~ /^$file\s*:\s*(.*)\s*$/m;
+ my $declared = $1;
+ my $failed = 0;
+ if (!defined($declared)) {
+ $failed = 1;
+ }
+ else
+ {
+ $declared =~ s/\s+/ /g;
+ foreach my $inc (@{$deps{$file}}) {
+ # incs can be relative, but makefile is from top level
+ my $file_dir = (File::Spec->splitpath($file))[1];
+ my $make_dep = collapse_path(File::Spec->catfile($file_dir,$inc));
+
+ if (! defined $make_dep) {
+ # this means we didn't construct the right relative path.
+ # probably looking in include/ instead of .
+ diag "skipping $inc...\n";
+ next;
+ }
+
+ if ($declared !~ /\b\Q$make_dep\E\b/) {
+ # this isn't the actual comparison, just to give nice output
+ # on failure.
+ is($declared,$inc,$file);
+ $failed = 1;
+ }
+ }
+ }
+ pass("$file has proper deps") unless $failed;
+}
+
+sub collapse_path {
+ my $path = shift;
+ return $path unless defined $path;
+
+ my $cwd = getcwd();
+ $path = abs_path($path);
+ return $path unless defined $path;
+
+ $path =~ s/^\Q$cwd\E\///;
+ return $path;
+}
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
More information about the parrot-commits
mailing list