bin/raddepend.pl
author Axel Jacobs <axel@jaloxa.eu>
Tue, 11 Mar 2014 00:29:36 +0000
changeset 60 448b4b706fa5
parent 8 9ed02f081b72
permissions -rwxr-xr-x
ltpict: minor changes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     1
#!/usr/bin/perl
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     2
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     3
# Find scene dependencies in this directory
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     4
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     5
# This a re-write of Greg's raddepend.csh.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     6
# Scene dependencies are now parsed recursively with the fs tree.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     7
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     8
# This (like the old CSH script) relies on the file's atime and
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     9
# will not work if the partition is mounted with the noatime option,
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    10
# or if the file system does not store the files' access time.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    11
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    12
# not-a-bug: https://bugs.launchpad.net/ubuntu/+bug/490500
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    13
# LINUX file systems are now defaulting to relative atime (relatime) which
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    14
# updates the atime only if the previous atime update is older than
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    15
# the mtime or ctime update.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    16
# This effectively renders this script (as well as the old raddepend.csh)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    17
# useless on a LINUX system, unless the fs is mounted with strictatime:
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    18
# $ sudo mount -o remount,strictatime /home
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    19
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    20
# Axel, Oct 2010
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    21
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    22
use strict;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    23
use warnings;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    24
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    25
use File::Find qw/ find /;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    26
use File::Basename;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    27
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    28
# Use path from the first scene file.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    29
#TODO: Use all args, not just first one.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    30
die("$0: Need at least one scene file.\n") unless ($#ARGV >= 0);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    31
my (undef, $dir, undef) = fileparse($ARGV[0]);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    32
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    33
#TODO: Make this a new -t option
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    34
#system("touch -m `find . -type f`");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    35
#sleep (2);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    36
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    37
# Get atimes of all files in this dir and all subdirs.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    38
system("sync");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    39
my %atimes0;   # atimes before genbbox command
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    40
my %atimes1;   # atimes after genbbox command
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    41
find(sub {$atimes0{$File::Find::name} = (stat())[8] if -f;}, $dir);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    42
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    43
my $cmd = 'getbbox -w ' . join(' ', @ARGV) . ' >/dev/null';
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    44
my $exstat = system("$cmd");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    45
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    46
# Use exit status of genbbox command
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    47
exit $exstat unless ($exstat == 0);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    48
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    49
system("sync");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    50
sleep(1);   # atime resolution is 1 second.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    51
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    52
# Compare the atimes before and after genbbox was run
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    53
find(sub {$atimes1{$File::Find::name} = (stat())[8] if -f;}, $dir);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    54
my @touched = ();
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    55
while(my ($key, $value) = each(%atimes0)) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    56
	push(@touched, $key) if ($value < $atimes1{$key});
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    57
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    58
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    59
# @touched should contain at least the file(s) we were called with.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    60
# Exit with error if @touched is empty.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    61
die("$0: Could not determine scene dependencies.\n") unless ($#touched > 0);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    62
#TODO: Print hint with strictatime mount option
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    63
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    64
foreach my $file (@touched) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    65
	# Remove all ARGV files from @touched list to ensure output is
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    66
	# identical to that of the old raddepend.csh script
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    67
	print "$file\n" unless grep($_ eq $file, @ARGV);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    68
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    69
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    70
#EOF