Bug 458440 - Attempt to work around speculative parsing crash. r+sr=dbaron
[mozilla-central.git] / config / add-chrome.pl
blob67bd1ce8d2b1b6e05c66593be2d6c83dd90c815c
1 #!/perl
3 use File::Path;
4 use Getopt::Std;
5 use IO::File;
6 use mozLock;
8 getopts("lxo:");
10 my $installedChromeFile = $ARGV[0];
11 my $disableJarPackaging = $ARGV[1];
12 my $chromeType = $ARGV[2];
13 my $pkgName = $ARGV[3];
14 my $jarFileName = $ARGV[4];
16 my $win32 = ($^O =~ /((MS)?win32)|msys|cygwin|os2/i) ? 1 : 0;
17 my $macos = ($^O =~ /MacOS|darwin/i) ? 1 : 0;
18 my $unix = !($win32 || $macos) ? 1 : 0;
20 sub foreignPlatformFile
22 my ($jarfile) = @_;
24 if (!$win32 && index($jarfile, "-win") != -1) {
25 return 1;
28 if (!$unix && index($jarfile, "-unix") != -1) {
29 return 1;
32 if (!$macos && index($jarfile, "-mac") != -1) {
33 return 1;
36 return 0;
39 sub foreignPlatformPath
41 my ($jarpath) = @_;
43 if (!$win32 && index($jarpath, "-platform/win") != -1) {
44 return 1;
47 if (!$unix && index($jarpath, "-platform/unix") != -1) {
48 return 1;
51 if (!$macos && index($jarpath, "-platform/mac") != -1) {
52 return 1;
55 return 0;
58 #print "add-chrome $installedChromeFile $disableJarPackaging $chromeType $pkgName $jarFileName\n";
60 my $nofilelocks = 0;
61 if (defined($::opt_l)) {
62 $nofilelocks = 1;
65 if (defined($::opt_x)) {
66 $win32 = 0;
67 $macos = 0;
68 $unix = 1;
71 my $force_os;
72 if (defined($::opt_o)) {
73 $force_os = $::opt_o;
76 if (defined($force_os)) {
77 $win32 = 0;
78 $macos = 0;
79 $unix = 0;
80 if ($force_os eq "WINNT") {
81 $win32 = 1;
82 } elsif ($force_os eq "OS2") {
83 $win32 = 1;
84 } elsif ($force_os eq "Darwin") {
85 $macos = 1;
86 } else {
87 $unix = 1;
91 if ($jarFileName =~ /(.*)\.jar/) {
92 $jarFileName = $1;
95 if (!foreignPlatformFile($jarFileName) && !foreignPlatformPath($pkgName)) {
97 my $line;
98 if ($disableJarPackaging) {
99 $line = "$chromeType,install,url,resource:/chrome/$jarFileName/$chromeType/$pkgName/";
101 else {
102 $line = "$chromeType,install,url,jar:resource:/chrome/$jarFileName.jar!/$chromeType/$pkgName/";
105 my $lockfile = "$installedChromeFile.lck";
106 my $err;
108 mozLock($lockfile) if (!$nofilelocks);
109 $err = 0;
110 if (open(FILE, "<$installedChromeFile")) {
111 while (<FILE>) {
112 chomp;
113 if ($_ eq $line) {
114 # line already appears in installed-chrome.txt file
115 # just update the mod date
116 close(FILE) or $err = 1;
117 if ($err) {
118 mozUnlock($lockfile) if (!$nofilelocks);
119 die "error: can't close $installedChromeFile: $!";
121 my $now = time;
122 utime($now, $now, $installedChromeFile) or $err = 1;
123 mozUnlock($lockfile) if (!$nofilelocks);
124 if ($err) {
125 die "couldn't touch $installedChromeFile";
127 print "+++ updating chrome $installedChromeFile\n+++\t$line\n";
128 exit;
131 close(FILE) or $err = 1;
132 if ($err) {
133 mozUnlock($lockfile) if (!$nofilelocks);
134 die "error: can't close $installedChromeFile: $!";
137 mozUnlock($lockfile) if (!$nofilelocks);
139 my $dir = $installedChromeFile;
140 if ("$dir" =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
141 $dir = $1;
143 mkpath($dir, 0, 0755);
145 mozLock($lockfile) if (!$nofilelocks);
146 $err = 0;
147 open(FILE, ">>$installedChromeFile") or $err = 1;
148 if ($err) {
149 mozUnlock($lockfile) if (!$nofilelocks);
150 die "can't open $installedChromeFile: $!";
152 print FILE "$line\n";
153 close(FILE) or $err = 1;
154 mozUnlock($lockfile) if (!$nofilelocks);
155 if ($err) {
156 die "error: can't close $installedChromeFile: $!";
158 print "+++ adding chrome $installedChromeFile\n+++\t$line\n";