michael@0: #!/usr/bin/perl -w michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: # michael@0: # Create a mapping from symbolic component name to directory name(s). michael@0: # michael@0: # Tue Oct 16 16:48:36 PDT 2001 michael@0: # michael@0: michael@0: use strict; michael@0: michael@0: # For --option1, --option2, ... michael@0: use Getopt::Long; michael@0: Getopt::Long::Configure("bundling_override"); michael@0: Getopt::Long::Configure("auto_abbrev"); michael@0: michael@0: # Globals michael@0: my $list_only_mode = 0; michael@0: my $opt_list_only; michael@0: my $mapfile = ""; michael@0: my %map; michael@0: michael@0: sub PrintUsage { michael@0: die < ... michael@0: END_USAGE michael@0: } michael@0: michael@0: sub parse_map_file($) { michael@0: my ($mapfile) = @_; michael@0: my (%mod_map, $tmp, $dir, $mod, @mod_list); michael@0: michael@0: undef %mod_map; michael@0: open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n"); michael@0: while ($tmp=) { michael@0: chomp ($tmp); michael@0: ($dir, $mod, @mod_list) = split(/:/, $tmp, 3); michael@0: $mod =~ s/[\s]*(\S+)[\s]*/$1/; michael@0: $mod_map{$mod} .= "$dir "; michael@0: } michael@0: close(MAPFILE); michael@0: foreach $mod (sort(keys %mod_map)) { michael@0: my (@dirlist, @trimlist, $found, $tdir); michael@0: @dirlist = split(/\s+/, $mod_map{$mod}); michael@0: $mod_map{$mod} = ""; michael@0: foreach $dir (@dirlist) { michael@0: $found = 0; michael@0: foreach $tdir (@trimlist) { michael@0: $found++, last if ($dir =~ m/^$tdir\// || $dir eq $tdir); michael@0: } michael@0: push @trimlist, $dir if (!$found); michael@0: } michael@0: $map{$mod} = join(" ", @trimlist); michael@0: #print "$mod: $map{$mod}\n"; michael@0: } michael@0: } michael@0: michael@0: sub dir_for_required_component { michael@0: my ($component) = @_; michael@0: my $rv; michael@0: my $dir; michael@0: michael@0: $dir = $map{$component}; michael@0: if($dir) { michael@0: # prepend "mozilla/" in front of directory names. michael@0: $rv = "mozilla/$dir"; michael@0: $rv =~ s/\s+/ mozilla\//g; # Hack for 2 or more directories. michael@0: } else { michael@0: $rv = 0; michael@0: } michael@0: return $rv; michael@0: } michael@0: michael@0: { michael@0: michael@0: # Add stdin to the commandline. This makes commandline-only mode hang, michael@0: # call it a bug. Not sure how to get around this. michael@0: push (@ARGV, split(' ',)); michael@0: michael@0: PrintUsage() if !GetOptions('list-only' => \$opt_list_only, michael@0: 'mapfile=s' => \$mapfile); michael@0: michael@0: # Pick up arguments, if any. michael@0: if($opt_list_only) { michael@0: $list_only_mode = 1; michael@0: } michael@0: michael@0: &parse_map_file($mapfile); michael@0: michael@0: my $arg; michael@0: my $dir; michael@0: while ($arg = shift @ARGV) { michael@0: $dir = dir_for_required_component($arg); michael@0: if($dir) { michael@0: if($list_only_mode) { michael@0: print $dir, " "; michael@0: } else { michael@0: print "$arg: ", $dir, "\n"; michael@0: } michael@0: } else { michael@0: # do nothing michael@0: } michael@0: } michael@0: if($dir && $list_only_mode) { michael@0: print "\n"; michael@0: } michael@0: }