2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # Create a mapping from symbolic component name to directory name(s).
10 # Tue Oct 16 16:48:36 PDT 2001
11 # <mcafee@netscape.com>
15 # For --option1, --option2, ...
17 Getopt
::Long
::Configure
("bundling_override");
18 Getopt
::Long
::Configure
("auto_abbrev");
21 my $list_only_mode = 0;
28 Prints out directories needed for a given list of components.
29 usage: module2dir.pl [--list-only] [--mapfile mapfile] <component-name1> <component-name2> ...
33 sub parse_map_file($) {
35 my (%mod_map, $tmp, $dir, $mod, @mod_list);
38 open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n");
39 while ($tmp=<MAPFILE>) {
41 ($dir, $mod, @mod_list) = split(/:/, $tmp, 3);
42 $mod =~ s/[\s]*(\S+)[\s]*/$1/;
43 $mod_map{$mod} .= "$dir ";
46 foreach $mod (sort(keys %mod_map)) {
47 my (@dirlist, @trimlist, $found, $tdir);
48 @dirlist = split(/\s+/, $mod_map{$mod});
50 foreach $dir (@dirlist) {
52 foreach $tdir (@trimlist) {
53 $found++, last if ($dir =~ m/^$tdir\// || $dir eq $tdir);
55 push @trimlist, $dir if (!$found);
57 $map{$mod} = join(" ", @trimlist);
58 #print "$mod: $map{$mod}\n";
62 sub dir_for_required_component {
67 $dir = $map{$component};
69 # prepend "mozilla/" in front of directory names.
71 $rv =~ s/\s+/ mozilla\//g; # Hack for 2 or more directories.
80 # Add stdin to the commandline. This makes commandline-only mode hang,
81 # call it a bug. Not sure how to get around this.
82 push (@ARGV, split(' ',<STDIN>));
84 PrintUsage() if !GetOptions('list-only' => \$opt_list_only,
85 'mapfile=s' => \$mapfile);
87 # Pick up arguments, if any.
92 &parse_map_file($mapfile);
96 while ($arg = shift @ARGV) {
97 $dir = dir_for_required_component($arg);
102 print "$arg: ", $dir, "\n";
108 if($dir && $list_only_mode) {