2000-06-09 10:33:25 +04:00
|
|
|
#!/perl
|
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
# make-jars [-f] [-v] [-d <chromeDir>] [-s <srcdir>] < <jar.mn>
|
2000-09-21 02:45:45 +04:00
|
|
|
|
|
|
|
use strict;
|
2000-06-09 10:33:25 +04:00
|
|
|
|
2000-07-28 09:08:08 +04:00
|
|
|
use Getopt::Std;
|
|
|
|
use Cwd;
|
2000-08-11 09:16:15 +04:00
|
|
|
use File::stat;
|
|
|
|
use Time::localtime;
|
2000-09-21 02:45:45 +04:00
|
|
|
use Cwd;
|
|
|
|
use File::Copy;
|
|
|
|
use File::Path;
|
|
|
|
|
|
|
|
my $objdir = getcwd;
|
2000-07-28 09:08:08 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
getopts("d:s:vf");
|
2000-09-21 02:45:45 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
my $baseFilesDir = ".";
|
2000-09-21 02:45:45 +04:00
|
|
|
if (defined($::opt_s)) {
|
2000-09-21 11:14:35 +04:00
|
|
|
$baseFilesDir = $::opt_s;
|
2000-09-21 02:45:45 +04:00
|
|
|
}
|
2000-08-05 00:25:42 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
my $chromeDir = ".";
|
2000-09-21 02:45:45 +04:00
|
|
|
if (defined($::opt_d)) {
|
2000-09-21 11:14:35 +04:00
|
|
|
$chromeDir = $::opt_d;
|
2000-09-12 09:10:48 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
my $verbose = 0;
|
|
|
|
if (defined($::opt_v)) {
|
|
|
|
$verbose = 1;
|
2000-09-12 09:10:48 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 10:22:06 +04:00
|
|
|
my $flatfilesonly = 0;
|
|
|
|
if (defined($::opt_f)) {
|
|
|
|
$flatfilesonly = 1;
|
|
|
|
}
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($verbose) {
|
2000-09-20 23:35:24 +04:00
|
|
|
print "make-jars "
|
2000-09-21 11:14:35 +04:00
|
|
|
. "-v -d $chromeDir "
|
|
|
|
. ($flatfilesonly ? "-f " : "")
|
|
|
|
. ($baseFilesDir ? "-s $baseFilesDir " : "")
|
|
|
|
. "\n";
|
2000-08-04 00:58:31 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
sub zipErrorCheck($)
|
|
|
|
{
|
|
|
|
my ($err) = @_;
|
|
|
|
return if ($err == 0 || $err == 12);
|
2000-09-22 04:31:58 +04:00
|
|
|
die ("Error invoking zip: $err");
|
2000-09-21 02:45:45 +04:00
|
|
|
}
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
sub JarIt
|
|
|
|
{
|
2000-09-21 11:14:35 +04:00
|
|
|
my ($destPath, $jarfile, $args, $overrides) = @_;
|
2000-09-12 09:10:48 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
if ($flatfilesonly) {
|
|
|
|
return 0;
|
2000-09-12 09:10:48 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
my $oldDir = cwd();
|
|
|
|
chdir("$destPath/$jarfile");
|
|
|
|
#print "cd $destPath/$jarfile\n";
|
|
|
|
|
|
|
|
if (!($args eq "")) {
|
|
|
|
my $cwd = getcwd;
|
|
|
|
my $err = 0;
|
|
|
|
#print "zip -u ../$jarfile.jar $args\n";
|
2000-09-25 04:36:12 +04:00
|
|
|
|
|
|
|
# Handle posix cmdline limits (4096)
|
|
|
|
while (length($args) > 4000) {
|
|
|
|
#print "Exceeding POSIX cmdline limit: " . length($args) . "\n";
|
|
|
|
my $subargs = substr($args, 0, 3999);
|
|
|
|
my $pos = rindex($subargs, " ");
|
|
|
|
$subargs = substr($args, 0, $pos);
|
|
|
|
$args = substr($args, $pos);
|
|
|
|
|
|
|
|
#print "zip -u ../$jarfile.jar $subargs\n";
|
|
|
|
#print "Length of subargs: " . length($subargs) . "\n";
|
|
|
|
system("zip -u ../$jarfile.jar $subargs") == 0 or
|
|
|
|
$err = $? >> 8;
|
|
|
|
zipErrorCheck($err);
|
|
|
|
}
|
|
|
|
#print "Length of args: " . length($args) . "\n";
|
|
|
|
#print "zip -u ../$jarfile.jar $args\n";
|
2000-09-21 11:14:35 +04:00
|
|
|
system("zip -u ../$jarfile.jar $args") == 0 or
|
|
|
|
$err = $? >> 8;
|
|
|
|
zipErrorCheck($err);
|
2000-09-12 03:08:41 +04:00
|
|
|
}
|
2000-09-25 04:36:12 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
if (!($overrides eq "")) {
|
|
|
|
my $err = 0;
|
|
|
|
print "+++ overriding $overrides\n";
|
2000-09-25 04:36:12 +04:00
|
|
|
|
|
|
|
while (length($args) > 4000) {
|
|
|
|
#print "Exceeding POSIX cmdline limit: " . length($args) . "\n";
|
|
|
|
my $subargs = substr($args, 0, 3999);
|
|
|
|
my $pos = rindex($subargs, " ");
|
|
|
|
$subargs = substr($args, 0, $pos);
|
|
|
|
$args = substr($args, $pos);
|
|
|
|
|
|
|
|
#print "zip ../$jarfile.jar $subargs\n";
|
|
|
|
#print "Length of subargs: " . length($subargs) . "\n";
|
|
|
|
system("zip ../$jarfile.jar $subargs") == 0 or
|
|
|
|
$err = $? >> 8;
|
|
|
|
zipErrorCheck($err);
|
|
|
|
}
|
2000-09-21 21:23:29 +04:00
|
|
|
#print "zip ../$jarfile.jar $overrides\n";
|
2000-09-21 11:14:35 +04:00
|
|
|
system("zip ../$jarfile.jar $overrides\n") == 0 or
|
|
|
|
$err = $? >> 8;
|
|
|
|
zipErrorCheck($err);
|
2000-09-12 03:08:41 +04:00
|
|
|
}
|
2000-09-21 10:22:06 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
chdir($oldDir);
|
|
|
|
#print "cd $oldDir\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
sub EnsureFileInDir
|
2000-06-09 10:33:25 +04:00
|
|
|
{
|
2000-09-21 11:14:35 +04:00
|
|
|
my ($destPath, $srcPath, $destFile, $srcFile, $override) = @_;
|
2000-09-21 08:29:59 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
#print "EnsureFileInDir($destPath, $srcPath, $destFile, $srcFile, $override)\n";
|
2000-09-21 08:29:59 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
my $src = $srcFile;
|
|
|
|
if (defined($src)) {
|
2000-09-27 04:38:38 +04:00
|
|
|
if (! -e $src ) {
|
|
|
|
$src = "$srcPath/$srcFile";
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
2000-09-21 11:14:35 +04:00
|
|
|
else {
|
|
|
|
$src = "$srcPath/$destFile";
|
|
|
|
# check for the complete jar path in the dest dir
|
|
|
|
if (!-e $src) {
|
|
|
|
#else check for just the file name in the dest dir
|
|
|
|
my $dir = "";
|
|
|
|
my $file;
|
|
|
|
if ($destFile =~ /([\w\d.\-\_\\\/]+)[\\\/]([\w\d.\-\_]+)/) {
|
|
|
|
$dir = $1;
|
|
|
|
$file = $2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "file not found: $srcPath/$destFile";
|
|
|
|
}
|
|
|
|
$src = "$srcPath/$file";
|
|
|
|
if (!-e $src) {
|
|
|
|
die "file not found: $srcPath/$destFile";
|
|
|
|
}
|
|
|
|
}
|
2000-09-12 09:10:48 +04:00
|
|
|
}
|
2000-08-11 09:16:15 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
$srcPath = $src;
|
|
|
|
$destPath = "$destPath/$destFile";
|
2000-08-11 09:16:15 +04:00
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
my $srcStat = stat($srcPath);
|
|
|
|
my $srcMtime = $srcStat ? $srcStat->mtime : 0;
|
2000-07-11 10:40:09 +04:00
|
|
|
|
2000-09-20 23:35:24 +04:00
|
|
|
my $destStat = stat($destPath);
|
|
|
|
my $destMtime = $destStat ? $destStat->mtime : 0;
|
|
|
|
#print "destMtime = $destMtime, srcMtime = $srcMtime\n";
|
2000-09-21 11:14:35 +04:00
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
if (!-e $destPath || $destMtime < $srcMtime || $override) {
|
2000-09-20 23:35:24 +04:00
|
|
|
#print "copying $destPath, from $srcPath\n";
|
2000-07-12 11:50:37 +04:00
|
|
|
my $dir = "";
|
|
|
|
my $file;
|
2000-09-21 11:14:35 +04:00
|
|
|
if ($destPath =~ /([\w\d.\-\_\\\/]+)[\\\/]([\w\d.\-\_]+)/) {
|
2000-07-12 11:50:37 +04:00
|
|
|
$dir = $1;
|
|
|
|
$file = $2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$file = $destPath;
|
|
|
|
}
|
2000-07-11 10:40:09 +04:00
|
|
|
|
|
|
|
if ($srcPath) {
|
|
|
|
$file = $srcPath;
|
|
|
|
}
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
if (!-e $file) {
|
2000-09-22 04:31:58 +04:00
|
|
|
die "error: file '$file' doesn't exist";
|
2000-09-21 11:14:35 +04:00
|
|
|
}
|
|
|
|
if (!-e $dir) {
|
2000-09-22 04:31:58 +04:00
|
|
|
mkpath($dir, 0, 0775) || die "can't mkpath $dir: $!";
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
2000-09-21 21:23:29 +04:00
|
|
|
unlink $destPath; # in case we had a symlink on unix
|
2000-09-22 04:31:58 +04:00
|
|
|
copy($file, $destPath) || die "copy($file, $destPath) failed: $!";
|
2000-09-21 11:14:35 +04:00
|
|
|
|
|
|
|
# fix the mod date so we don't jar everything (is this faster than just jarring everything?)
|
|
|
|
my $atime = stat($file)->atime || die $!;
|
|
|
|
my $mtime = stat($file)->mtime || die $!;
|
|
|
|
utime($atime, $mtime, $destPath);
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-09-20 23:35:24 +04:00
|
|
|
while (<STDIN>) {
|
2000-06-09 10:33:25 +04:00
|
|
|
chomp;
|
|
|
|
start:
|
2000-09-21 11:14:35 +04:00
|
|
|
if (/^([\w\d.\-\_\\\/]+).jar\:\s*$/) {
|
2000-09-12 03:08:41 +04:00
|
|
|
my $jarfile = $1;
|
2000-06-09 10:33:25 +04:00
|
|
|
my $args = "";
|
2000-09-12 03:08:41 +04:00
|
|
|
my $overrides = "";
|
2000-09-21 02:45:45 +04:00
|
|
|
my $cwd = cwd();
|
2000-09-21 11:14:35 +04:00
|
|
|
print "+++ making chrome $cwd => $chromeDir/$jarfile.jar\n";
|
2000-09-20 23:35:24 +04:00
|
|
|
while (<STDIN>) {
|
2000-09-21 11:14:35 +04:00
|
|
|
if (/^\s+([\w\d.\-\_\\\/]+)\s*(\([\w\d.\-\_\\\/]+\))?$\s*/) {
|
2000-08-04 00:58:31 +04:00
|
|
|
my $dest = $1;
|
2000-09-21 11:14:35 +04:00
|
|
|
my $srcPath = defined($2) ? substr($2, 1, -1) : $2;
|
2000-09-22 04:31:58 +04:00
|
|
|
EnsureFileInDir("$chromeDir/$jarfile", $baseFilesDir, $dest, $srcPath, 0);
|
2000-07-11 10:40:09 +04:00
|
|
|
$args = "$args$dest ";
|
2000-09-21 11:14:35 +04:00
|
|
|
} elsif (/^\+\s+([\w\d.\-\_\\\/]+)\s*(\([\w\d.\-\_\\\/]+\))?$\s*/) {
|
2000-09-12 03:08:41 +04:00
|
|
|
my $dest = $1;
|
2000-09-21 11:14:35 +04:00
|
|
|
my $srcPath = defined($2) ? substr($2, 1, -1) : $2;
|
2000-09-22 04:31:58 +04:00
|
|
|
EnsureFileInDir("$chromeDir/$jarfile", $baseFilesDir, $dest, $srcPath, 1);
|
2000-09-12 03:08:41 +04:00
|
|
|
$overrides = "$overrides$dest ";
|
2000-06-09 10:33:25 +04:00
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# end with blank line
|
|
|
|
last;
|
|
|
|
} else {
|
2000-09-21 11:14:35 +04:00
|
|
|
JarIt($chromeDir, $jarfile, $args, $overrides);
|
2000-06-09 10:33:25 +04:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
}
|
2000-09-21 11:14:35 +04:00
|
|
|
JarIt($chromeDir, $jarfile, $args, $overrides);
|
2000-08-11 09:16:15 +04:00
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
} elsif (/^\s*\#.*$/) {
|
|
|
|
# skip comments
|
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# skip blank lines
|
|
|
|
} else {
|
|
|
|
close;
|
|
|
|
die "bad jar rule head at: $_";
|
|
|
|
}
|
2000-08-11 09:16:15 +04:00
|
|
|
}
|