2000-06-09 10:33:25 +04:00
|
|
|
#!/perl
|
|
|
|
|
2001-01-22 10:36:25 +03:00
|
|
|
# make-jars [-f] [-v] [-l] [-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;
|
2001-01-22 07:20:55 +03:00
|
|
|
use Fcntl qw(:DEFAULT :flock);
|
|
|
|
use IO::File;
|
2000-09-21 02:45:45 +04:00
|
|
|
|
|
|
|
my $objdir = getcwd;
|
2000-07-28 09:08:08 +04:00
|
|
|
|
2001-03-24 14:07:15 +03:00
|
|
|
getopts("d:s:f:vl");
|
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
|
|
|
}
|
|
|
|
|
2001-03-24 14:07:15 +03:00
|
|
|
my $fileformat = "jar";
|
2000-09-21 10:22:06 +04:00
|
|
|
if (defined($::opt_f)) {
|
2001-03-24 14:07:15 +03:00
|
|
|
($fileformat = $::opt_f) =~ tr/A-Z/a-z/;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ("$fileformat" ne "jar" &&
|
|
|
|
"$fileformat" ne "flat" &&
|
|
|
|
"$fileformat" ne "both") {
|
|
|
|
print "File format specified by -f option must be one of: jar, flat, or both.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $zipmoveopt = "";
|
|
|
|
if ("$fileformat" eq "jar") {
|
|
|
|
$zipmoveopt = "-m";
|
2000-09-21 10:22:06 +04:00
|
|
|
}
|
|
|
|
|
2001-01-22 10:36:25 +03:00
|
|
|
my $nofilelocks = 0;
|
|
|
|
if (defined($::opt_l)) {
|
|
|
|
$nofilelocks = 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 "
|
2001-03-24 16:44:41 +03:00
|
|
|
. ($fileformat ? "-f $fileformat " : "")
|
2001-01-22 10:36:25 +03:00
|
|
|
. ($nofilelocks ? "-l " : "")
|
2000-09-21 11:14:35 +04:00
|
|
|
. ($baseFilesDir ? "-s $baseFilesDir " : "")
|
|
|
|
. "\n";
|
2000-08-04 00:58:31 +04:00
|
|
|
}
|
|
|
|
|
2001-01-22 07:20:55 +03:00
|
|
|
sub zipErrorCheck($$$)
|
2000-09-21 02:45:45 +04:00
|
|
|
{
|
2001-01-22 07:20:55 +03:00
|
|
|
my ($err,$lockfile,$lockhandle) = @_;
|
2000-09-21 02:45:45 +04:00
|
|
|
return if ($err == 0 || $err == 12);
|
2001-01-22 10:36:25 +03:00
|
|
|
if (!$nofilelocks) {
|
|
|
|
unlink($lockfile);
|
|
|
|
flock($lockhandle, LOCK_UN);
|
|
|
|
}
|
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) = @_;
|
2001-03-24 14:07:15 +03:00
|
|
|
my $oldDir = cwd();
|
|
|
|
chdir("$destPath/$jarfile");
|
2000-09-12 09:10:48 +04:00
|
|
|
|
2001-03-24 14:07:15 +03:00
|
|
|
if ("$fileformat" eq "flat") {
|
|
|
|
unlink("../$jarfile.jar") if ( -e "../$jarfile.jar");
|
|
|
|
chdir($oldDir);
|
2000-09-21 11:14:35 +04:00
|
|
|
return 0;
|
2000-09-12 09:10:48 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 11:14:35 +04:00
|
|
|
#print "cd $destPath/$jarfile\n";
|
2001-01-22 10:36:25 +03:00
|
|
|
|
2001-01-22 07:20:55 +03:00
|
|
|
my $lockfile = "../$jarfile.lck";
|
|
|
|
my $lockhandle = new IO::File;
|
2001-01-22 10:36:25 +03:00
|
|
|
if (!$nofilelocks) {
|
|
|
|
open($lockhandle,">$lockfile") ||
|
|
|
|
die("WARNING: Could not create lockfile for $lockfile. Exiting.\n");
|
|
|
|
flock($lockhandle, LOCK_EX);
|
|
|
|
}
|
2000-09-21 11:14:35 +04:00
|
|
|
|
|
|
|
if (!($args eq "")) {
|
|
|
|
my $cwd = getcwd;
|
2000-12-15 06:50:39 +03:00
|
|
|
my $err = 0;
|
2001-01-22 07:20:55 +03:00
|
|
|
|
2001-03-24 14:07:15 +03:00
|
|
|
#print "zip $zipmoveopt -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);
|
|
|
|
|
2001-03-24 14:07:15 +03:00
|
|
|
#print "zip $zipmoveopt -u ../$jarfile.jar $subargs\n";
|
2000-09-25 04:36:12 +04:00
|
|
|
#print "Length of subargs: " . length($subargs) . "\n";
|
2001-03-24 14:07:15 +03:00
|
|
|
system("zip $zipmoveopt -u ../$jarfile.jar $subargs") == 0 or
|
2000-09-25 04:36:12 +04:00
|
|
|
$err = $? >> 8;
|
2001-01-22 07:20:55 +03:00
|
|
|
zipErrorCheck($err,$lockfile,$lockhandle);
|
2000-09-25 04:36:12 +04:00
|
|
|
}
|
|
|
|
#print "Length of args: " . length($args) . "\n";
|
2001-03-24 14:07:15 +03:00
|
|
|
#print "zip $zipmoveopt -u ../$jarfile.jar $args\n";
|
|
|
|
system("zip $zipmoveopt -u ../$jarfile.jar $args") == 0 or
|
2000-09-21 11:14:35 +04:00
|
|
|
$err = $? >> 8;
|
2001-01-22 07:20:55 +03:00
|
|
|
zipErrorCheck($err,$lockfile,$lockhandle);
|
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);
|
|
|
|
|
2001-03-24 14:07:15 +03:00
|
|
|
#print "zip $zipmoveopt ../$jarfile.jar $subargs\n";
|
2000-09-25 04:36:12 +04:00
|
|
|
#print "Length of subargs: " . length($subargs) . "\n";
|
2001-03-24 14:07:15 +03:00
|
|
|
system("zip $zipmoveopt ../$jarfile.jar $subargs") == 0 or
|
2000-09-25 04:36:12 +04:00
|
|
|
$err = $? >> 8;
|
2001-01-22 07:20:55 +03:00
|
|
|
zipErrorCheck($err,$lockfile,$lockhandle);
|
2000-09-25 04:36:12 +04:00
|
|
|
}
|
2001-03-24 14:07:15 +03:00
|
|
|
#print "zip $zipmoveopt ../$jarfile.jar $overrides\n";
|
|
|
|
system("zip $zipmoveopt ../$jarfile.jar $overrides\n") == 0 or
|
2000-09-21 11:14:35 +04:00
|
|
|
$err = $? >> 8;
|
2001-01-22 07:20:55 +03:00
|
|
|
zipErrorCheck($err,$lockfile,$lockhandle);
|
2000-09-12 03:08:41 +04:00
|
|
|
}
|
2001-01-22 10:36:25 +03:00
|
|
|
if (!$nofilelocks) {
|
|
|
|
unlink("$lockfile");
|
|
|
|
flock($lockhandle, LOCK_UN);
|
|
|
|
}
|
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
|
|
|
}
|