1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config/module2dir.pl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +#!/usr/bin/perl -w 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 + 1.10 +# 1.11 +# Create a mapping from symbolic component name to directory name(s). 1.12 +# 1.13 +# Tue Oct 16 16:48:36 PDT 2001 1.14 +# <mcafee@netscape.com> 1.15 + 1.16 +use strict; 1.17 + 1.18 +# For --option1, --option2, ... 1.19 +use Getopt::Long; 1.20 +Getopt::Long::Configure("bundling_override"); 1.21 +Getopt::Long::Configure("auto_abbrev"); 1.22 + 1.23 +# Globals 1.24 +my $list_only_mode = 0; 1.25 +my $opt_list_only; 1.26 +my $mapfile = ""; 1.27 +my %map; 1.28 + 1.29 +sub PrintUsage { 1.30 + die <<END_USAGE 1.31 + Prints out directories needed for a given list of components. 1.32 + usage: module2dir.pl [--list-only] [--mapfile mapfile] <component-name1> <component-name2> ... 1.33 +END_USAGE 1.34 +} 1.35 + 1.36 +sub parse_map_file($) { 1.37 + my ($mapfile) = @_; 1.38 + my (%mod_map, $tmp, $dir, $mod, @mod_list); 1.39 + 1.40 + undef %mod_map; 1.41 + open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n"); 1.42 + while ($tmp=<MAPFILE>) { 1.43 + chomp ($tmp); 1.44 + ($dir, $mod, @mod_list) = split(/:/, $tmp, 3); 1.45 + $mod =~ s/[\s]*(\S+)[\s]*/$1/; 1.46 + $mod_map{$mod} .= "$dir "; 1.47 + } 1.48 + close(MAPFILE); 1.49 + foreach $mod (sort(keys %mod_map)) { 1.50 + my (@dirlist, @trimlist, $found, $tdir); 1.51 + @dirlist = split(/\s+/, $mod_map{$mod}); 1.52 + $mod_map{$mod} = ""; 1.53 + foreach $dir (@dirlist) { 1.54 + $found = 0; 1.55 + foreach $tdir (@trimlist) { 1.56 + $found++, last if ($dir =~ m/^$tdir\// || $dir eq $tdir); 1.57 + } 1.58 + push @trimlist, $dir if (!$found); 1.59 + } 1.60 + $map{$mod} = join(" ", @trimlist); 1.61 + #print "$mod: $map{$mod}\n"; 1.62 + } 1.63 +} 1.64 + 1.65 +sub dir_for_required_component { 1.66 + my ($component) = @_; 1.67 + my $rv; 1.68 + my $dir; 1.69 + 1.70 + $dir = $map{$component}; 1.71 + if($dir) { 1.72 + # prepend "mozilla/" in front of directory names. 1.73 + $rv = "mozilla/$dir"; 1.74 + $rv =~ s/\s+/ mozilla\//g; # Hack for 2 or more directories. 1.75 + } else { 1.76 + $rv = 0; 1.77 + } 1.78 + return $rv; 1.79 +} 1.80 + 1.81 +{ 1.82 + 1.83 + # Add stdin to the commandline. This makes commandline-only mode hang, 1.84 + # call it a bug. Not sure how to get around this. 1.85 + push (@ARGV, split(' ',<STDIN>)); 1.86 + 1.87 + PrintUsage() if !GetOptions('list-only' => \$opt_list_only, 1.88 + 'mapfile=s' => \$mapfile); 1.89 + 1.90 + # Pick up arguments, if any. 1.91 + if($opt_list_only) { 1.92 + $list_only_mode = 1; 1.93 + } 1.94 + 1.95 + &parse_map_file($mapfile); 1.96 + 1.97 + my $arg; 1.98 + my $dir; 1.99 + while ($arg = shift @ARGV) { 1.100 + $dir = dir_for_required_component($arg); 1.101 + if($dir) { 1.102 + if($list_only_mode) { 1.103 + print $dir, " "; 1.104 + } else { 1.105 + print "$arg: ", $dir, "\n"; 1.106 + } 1.107 + } else { 1.108 + # do nothing 1.109 + } 1.110 + } 1.111 + if($dir && $list_only_mode) { 1.112 + print "\n"; 1.113 + } 1.114 +}