Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / config / module2dir.pl
blob9c77580ddf623b2a1df103c6dad0fa60327ccf45
1 #!/usr/bin/perl -w
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>
13 use strict;
15 # For --option1, --option2, ...
16 use Getopt::Long;
17 Getopt::Long::Configure("bundling_override");
18 Getopt::Long::Configure("auto_abbrev");
20 # Globals
21 my $list_only_mode = 0;
22 my $opt_list_only;
23 my $mapfile = "";
24 my %map;
26 sub PrintUsage {
27 die <<END_USAGE
28 Prints out directories needed for a given list of components.
29 usage: module2dir.pl [--list-only] [--mapfile mapfile] <component-name1> <component-name2> ...
30 END_USAGE
33 sub parse_map_file($) {
34 my ($mapfile) = @_;
35 my (%mod_map, $tmp, $dir, $mod, @mod_list);
37 undef %mod_map;
38 open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n");
39 while ($tmp=<MAPFILE>) {
40 chomp ($tmp);
41 ($dir, $mod, @mod_list) = split(/:/, $tmp, 3);
42 $mod =~ s/[\s]*(\S+)[\s]*/$1/;
43 $mod_map{$mod} .= "$dir ";
45 close(MAPFILE);
46 foreach $mod (sort(keys %mod_map)) {
47 my (@dirlist, @trimlist, $found, $tdir);
48 @dirlist = split(/\s+/, $mod_map{$mod});
49 $mod_map{$mod} = "";
50 foreach $dir (@dirlist) {
51 $found = 0;
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 {
63 my ($component) = @_;
64 my $rv;
65 my $dir;
67 $dir = $map{$component};
68 if($dir) {
69 # prepend "mozilla/" in front of directory names.
70 $rv = "mozilla/$dir";
71 $rv =~ s/\s+/ mozilla\//g; # Hack for 2 or more directories.
72 } else {
73 $rv = 0;
75 return $rv;
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.
88 if($opt_list_only) {
89 $list_only_mode = 1;
92 &parse_map_file($mapfile);
94 my $arg;
95 my $dir;
96 while ($arg = shift @ARGV) {
97 $dir = dir_for_required_component($arg);
98 if($dir) {
99 if($list_only_mode) {
100 print $dir, " ";
101 } else {
102 print "$arg: ", $dir, "\n";
104 } else {
105 # do nothing
108 if($dir && $list_only_mode) {
109 print "\n";