~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/build/unix/mddepend.pl

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
# This Source Code Form is subject to the terms of the Mozilla Public
 
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
 
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
6
 
 
7
# mddepend.pl - Reads in dependencies generated my -MD flag. Prints list
 
8
#   of objects that need to be rebuilt. These can then be added to the
 
9
#   PHONY target. Using this script copes with the problem of header
 
10
#   files that have been removed from the build.
 
11
#    
 
12
# Usage:
 
13
#   mddepend.pl <output_file> <dependency_files...>
 
14
#
 
15
# Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
 
16
 
 
17
use strict;
 
18
 
 
19
use constant DEBUG => 0;
 
20
 
 
21
my $outfile = shift @ARGV;
 
22
my $silent = $ENV{MAKEFLAGS} =~ /^\w*s|\s-s/;
 
23
 
 
24
my $line = '';
 
25
my %alldeps;
 
26
# Parse dependency files
 
27
while (<>) {
 
28
  s/\r?\n$//; # Handle both unix and DOS line endings
 
29
  $line .= $_;
 
30
  if ($line =~ /\\$/) {
 
31
    chop $line;
 
32
    next;
 
33
  }
 
34
 
 
35
  $line =~ s|\\|/|g;
 
36
 
 
37
  my ($obj,$rest) = split /\s*:\s+/, $line, 2;
 
38
  $line = '';
 
39
  next if !$obj || !$rest;
 
40
 
 
41
  my @deps = split /\s+/, $rest;
 
42
  push @{$alldeps{$obj}}, @deps;
 
43
  if (DEBUG >= 2) {
 
44
    foreach my $dep (@deps) { print STDERR "add $obj $dep\n"; }
 
45
  }
 
46
}
 
47
 
 
48
# Test dependencies
 
49
my %modtimes; # cache
 
50
my @objs;     # force rebuild on these
 
51
OBJ_LOOP: foreach my $obj (keys %alldeps) {
 
52
  my $mtime = (stat $obj)[9] or next;
 
53
 
 
54
  my %not_in_cache;
 
55
  my $deps = $alldeps{$obj};
 
56
  foreach my $dep_file (@{$deps}) {
 
57
    my $dep_mtime = $modtimes{$dep_file};
 
58
    if (not defined $dep_mtime) {
 
59
      print STDERR "Skipping $dep_file for $obj, will stat() later\n" if DEBUG >= 2;
 
60
      $not_in_cache{$dep_file} = 1;
 
61
      next;
 
62
    }
 
63
 
 
64
    print STDERR "Found $dep_file in cache\n" if DEBUG >= 2;
 
65
 
 
66
    if ($dep_mtime > $mtime) {
 
67
      print STDERR "$dep_file($dep_mtime) newer than $obj($mtime)\n" if DEBUG;
 
68
    }
 
69
    elsif ($dep_mtime == -1) {
 
70
      print STDERR "Couldn't stat $dep_file for $obj\n" if DEBUG;
 
71
    }
 
72
    else {
 
73
      print STDERR "$dep_file($dep_mtime) older than $obj($mtime)\n" if DEBUG >= 2;
 
74
      next;
 
75
    }
 
76
 
 
77
    push @objs, $obj; # dependency is missing or newer
 
78
    next OBJ_LOOP; # skip checking the rest of the dependencies
 
79
  }
 
80
 
 
81
  foreach my $dep_file (keys %not_in_cache) {
 
82
    print STDERR "STAT $dep_file for $obj\n" if DEBUG >= 2;
 
83
    my $dep_mtime = $modtimes{$dep_file} = (stat $dep_file)[9] || -1;
 
84
 
 
85
    if ($dep_mtime > $mtime) {
 
86
      print STDERR "$dep_file($dep_mtime) newer than $obj($mtime)\n" if DEBUG;
 
87
    }
 
88
    elsif ($dep_mtime == -1) {
 
89
      print STDERR "Couldn't stat $dep_file for $obj\n" if DEBUG;
 
90
    }
 
91
    else {
 
92
      print STDERR "$dep_file($dep_mtime) older than $obj($mtime)\n" if DEBUG >= 2;
 
93
      next;
 
94
    }
 
95
 
 
96
    push @objs, $obj; # dependency is missing or newer
 
97
    next OBJ_LOOP; # skip checking the rest of the dependencies
 
98
  }
 
99
 
 
100
  # If we get here it means nothing needs to be done for $obj
 
101
}
 
102
 
 
103
# Output objects to rebuild (if needed).
 
104
if ($outfile eq '-') {
 
105
    if (@objs) {
 
106
        print "@objs: FORCE\n";
 
107
    }
 
108
} elsif (@objs) {
 
109
  my $old_output;
 
110
  my $new_output = "@objs: FORCE\n";
 
111
 
 
112
  # Read in the current dependencies file.
 
113
  open(OLD, "<$outfile")
 
114
    and $old_output = <OLD>;
 
115
  close(OLD);
 
116
 
 
117
  # Only write out the dependencies if they are different.
 
118
  if ($new_output ne $old_output) {
 
119
    open(OUT, ">$outfile") and print OUT "$new_output";
 
120
    print "Updating dependencies file, $outfile\n" unless $silent;
 
121
    if (DEBUG) {
 
122
      print "new: $new_output\n";
 
123
      print "was: $old_output\n" if $old_output ne '';
 
124
    }
 
125
  }
 
126
} elsif (-s $outfile) {
 
127
  # Remove the old dependencies because all objects are up to date.
 
128
  print "Removing old dependencies file, $outfile\n" unless $silent;
 
129
 
 
130
  if (DEBUG) {
 
131
    my $old_output;
 
132
    open(OLD, "<$outfile")
 
133
      and $old_output = <OLD>;
 
134
    close(OLD);
 
135
    print "was: $old_output\n";
 
136
  }
 
137
 
 
138
  unlink $outfile;
 
139
}