2000-06-09 10:33:25 +04:00
|
|
|
#!/perl
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
# make-jars [-c] [-v] [-d <destPath>] [-s <srcdir>] < <jar.mn>
|
|
|
|
|
|
|
|
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 @cleanupList = ();
|
|
|
|
my $IS_DIR = 1;
|
|
|
|
my $IS_FILE = 2;
|
|
|
|
|
|
|
|
my $objdir = getcwd;
|
2000-07-28 09:08:08 +04:00
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
getopts("d:s:cv");
|
|
|
|
|
|
|
|
my $usrcdir = undef;
|
|
|
|
if (defined($::opt_s)) {
|
|
|
|
$usrcdir = $::opt_s;
|
|
|
|
}
|
2000-08-05 00:25:42 +04:00
|
|
|
|
2000-09-12 09:10:48 +04:00
|
|
|
my $destPath = ".";
|
2000-09-21 02:45:45 +04:00
|
|
|
if (defined($::opt_d)) {
|
|
|
|
$destPath = $::opt_d;
|
|
|
|
if ( defined($usrcdir) && substr($destPath, 0, 1) ne "/") {
|
|
|
|
$destPath = "$objdir/$destPath";
|
|
|
|
}
|
2000-09-12 09:10:48 +04:00
|
|
|
}
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
my $copyFiles = 0;
|
|
|
|
if (defined($::opt_c)) {
|
|
|
|
$copyFiles = 1;
|
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 02:45:45 +04:00
|
|
|
if ($verbose) {
|
2000-09-20 23:35:24 +04:00
|
|
|
print "make-jars "
|
|
|
|
. ($copyFiles ? "-c " : "")
|
2000-09-21 02:45:45 +04:00
|
|
|
# . ($srcDir ? "-s $srcDir " : "")
|
2000-09-20 23:35:24 +04:00
|
|
|
. "-v -d $destPath\n";
|
|
|
|
}
|
|
|
|
|
2000-08-11 09:16:15 +04:00
|
|
|
sub Cleanup
|
2000-08-04 00:58:31 +04:00
|
|
|
{
|
2000-09-21 02:45:45 +04:00
|
|
|
while (1) {
|
2000-08-11 09:16:15 +04:00
|
|
|
my $isDir = pop(@cleanupList);
|
|
|
|
if ($isDir == undef) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
my $path = pop(@cleanupList);
|
2000-09-21 02:45:45 +04:00
|
|
|
#print "Cleaning up $path\n";
|
2000-08-11 09:16:15 +04:00
|
|
|
if ($isDir == $IS_DIR) {
|
|
|
|
rmdir($path) || die "can't remove dir $path: $!";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unlink($path) || die "can't remove file $path: $!";
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
die ("Error invoking zip: $err\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
sub JarIt
|
|
|
|
{
|
2000-09-12 03:08:41 +04:00
|
|
|
my ($destPath, $jarfile, $copyFiles, $args, $overrides) = @_;
|
2000-09-12 09:10:48 +04:00
|
|
|
|
|
|
|
my $dir = $destPath;
|
|
|
|
if ("$dir/$jarfile" =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
|
|
|
|
$dir = $1;
|
|
|
|
}
|
2000-09-21 02:45:45 +04:00
|
|
|
|
|
|
|
MkDirs($dir, ".", 0);
|
2000-09-12 09:10:48 +04:00
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($copyFiles) {
|
2000-09-12 09:10:48 +04:00
|
|
|
my $indivDir = $jarfile;
|
|
|
|
if ($indivDir =~ /(.*).jar/) {
|
|
|
|
$indivDir = $1;
|
|
|
|
}
|
|
|
|
my $indivPath = "$destPath/$indivDir";
|
2000-09-21 02:45:45 +04:00
|
|
|
MkDirs($indivPath, ".", 0);
|
|
|
|
|
|
|
|
my $file;
|
2000-09-14 08:45:15 +04:00
|
|
|
foreach $file (split(' ', $args)) {
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($verbose) {
|
2000-09-12 09:10:48 +04:00
|
|
|
print "adding individual file $file to dist\n";
|
|
|
|
}
|
2000-09-21 02:45:45 +04:00
|
|
|
EnsureFileInDir("$indivPath/$file", $file, 0, 0);
|
2000-09-14 08:45:15 +04:00
|
|
|
}
|
|
|
|
foreach $file (split(' ', $overrides)) {
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($verbose) {
|
|
|
|
print "override: adding individual file $file to dist\n";
|
2000-09-14 08:45:15 +04:00
|
|
|
}
|
2000-09-21 02:45:45 +04:00
|
|
|
EnsureFileInDir("$indivPath/$file", $file, 0, 1);
|
2000-09-12 03:08:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!($args eq "")) {
|
2000-09-21 02:45:45 +04:00
|
|
|
my $cwd = getcwd;
|
|
|
|
my $err = 0;
|
2000-09-21 07:51:35 +04:00
|
|
|
#print("in $cwd; zip -u $destPath/$jarfile $args\n");
|
2000-09-21 02:45:45 +04:00
|
|
|
system("zip -u $destPath/$jarfile $args") == 0 or
|
|
|
|
$err = $? >> 8;
|
|
|
|
zipErrorCheck($err);
|
2000-09-12 03:08:41 +04:00
|
|
|
}
|
|
|
|
if (!($overrides eq "")) {
|
2000-09-21 02:45:45 +04:00
|
|
|
my $err = 0;
|
2000-09-14 08:45:15 +04:00
|
|
|
print "+++ overriding $overrides\n";
|
2000-09-21 02:45:45 +04:00
|
|
|
system("zip $destPath/$jarfile $overrides\n") == 0 or
|
|
|
|
$err = $? >> 8;
|
|
|
|
zipErrorCheck($err);
|
2000-09-12 03:08:41 +04:00
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub MkDirs
|
|
|
|
{
|
2000-09-12 09:10:48 +04:00
|
|
|
my ($path, $containingDir, $doCleanup) = @_;
|
|
|
|
#print "MkDirs $path $containingDir $doCleanup\n";
|
2000-06-09 10:33:25 +04:00
|
|
|
if ($path =~ /([\w\d.\-]+)[\\\/](.*)/) {
|
|
|
|
my $dir = $1;
|
|
|
|
$path = $2;
|
|
|
|
if (!-e $dir) {
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($verbose) {
|
2000-09-12 09:10:48 +04:00
|
|
|
print "making dir $containingDir/$dir\n";
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($doCleanup) {
|
2000-09-12 09:10:48 +04:00
|
|
|
push(@cleanupList, "$containingDir/$dir");
|
|
|
|
push(@cleanupList, $IS_DIR);
|
|
|
|
}
|
2000-08-11 09:16:15 +04:00
|
|
|
}
|
2000-09-12 09:10:48 +04:00
|
|
|
my $wd = cwd();
|
2000-06-09 10:33:25 +04:00
|
|
|
chdir $dir;
|
2000-09-12 09:10:48 +04:00
|
|
|
MkDirs($path, "$containingDir/$dir", $doCleanup);
|
|
|
|
chdir $wd;
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
my $dir = $path;
|
2000-08-11 09:16:15 +04:00
|
|
|
if ($dir eq "") { return 0; }
|
2000-06-09 10:33:25 +04:00
|
|
|
if (!-e $dir) {
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($verbose) {
|
2000-09-12 09:10:48 +04:00
|
|
|
print "making dir $containingDir/$dir\n";
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($doCleanup) {
|
2000-09-12 09:10:48 +04:00
|
|
|
push(@cleanupList, "$containingDir/$dir");
|
|
|
|
push(@cleanupList, $IS_DIR);
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub CopyFile
|
|
|
|
{
|
2000-09-12 09:10:48 +04:00
|
|
|
my ($from, $to, $doCleanup) = @_;
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($verbose) {
|
2000-09-12 09:10:48 +04:00
|
|
|
print "copying $from to $to\n";
|
|
|
|
}
|
2000-09-21 02:45:45 +04:00
|
|
|
copy("$from", "$to") || die "CopyFile failed: $!\n";
|
2000-08-11 09:16:15 +04:00
|
|
|
|
|
|
|
# fix the mod date so we don't jar everything (is this faster than just jarring everything?)
|
|
|
|
my $atime = stat($from)->atime || die $!;
|
|
|
|
my $mtime = stat($from)->mtime || die $!;
|
|
|
|
utime($atime, $mtime, $to);
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
if ($doCleanup) {
|
2000-09-12 09:10:48 +04:00
|
|
|
push(@cleanupList, "$to");
|
|
|
|
push(@cleanupList, $IS_FILE);
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub EnsureFileInDir
|
|
|
|
{
|
2000-09-14 08:45:15 +04:00
|
|
|
my ($destPath, $srcPath, $doCleanup, $override) = @_;
|
2000-07-11 10:40:09 +04:00
|
|
|
|
2000-09-20 23:35:24 +04:00
|
|
|
#print "EnsureFileInDir($destPath, $srcPath, $doCleanup, $override)\n";
|
|
|
|
my $destStat = stat($destPath);
|
|
|
|
my $destMtime = $destStat ? $destStat->mtime : 0;
|
|
|
|
my $srcStat = stat($srcPath);
|
|
|
|
my $srcMtime = $srcStat ? $srcStat->mtime : 0;
|
|
|
|
#print "destMtime = $destMtime, srcMtime = $srcMtime\n";
|
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;
|
|
|
|
if ($destPath =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
|
|
|
|
$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-21 02:45:45 +04:00
|
|
|
if (defined($usrcdir)) {
|
|
|
|
if (-e "$usrcdir/$file") {
|
|
|
|
$file = "$usrcdir/$file";
|
|
|
|
} else {
|
|
|
|
die "error: file '$usrcdir/$file' doesn't exist\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
die "error: file '$file' doesn't exist\n";
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
}
|
2000-09-12 09:10:48 +04:00
|
|
|
MkDirs($dir, ".", $doCleanup);
|
|
|
|
CopyFile($file, $destPath, $doCleanup);
|
2000-06-09 10:33:25 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2000-09-21 02:45:45 +04:00
|
|
|
# elsif ($doCleanup == 0 && -e $destPath) {
|
2000-09-14 08:45:15 +04:00
|
|
|
# print "!!! file $destPath already exists -- need to add '+' rule to jar.mn\n";
|
|
|
|
# }
|
2000-06-09 10:33:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
if (defined($usrcdir)) {
|
|
|
|
if ( -e "$usrcdir" ) {
|
|
|
|
print "Change to $usrcdir from $objdir\n";
|
|
|
|
chdir($usrcdir) or die "chdir: $!\n";
|
|
|
|
} else {
|
|
|
|
die "srcdir $usrcdir does not exist!\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-20 23:35:24 +04:00
|
|
|
while (<STDIN>) {
|
2000-06-09 10:33:25 +04:00
|
|
|
chomp;
|
|
|
|
start:
|
|
|
|
if (/^([\w\d.\-\\\/]+)\:\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();
|
|
|
|
print "+++ making chrome $cwd => $destPath/$jarfile\n";
|
2000-09-20 23:35:24 +04:00
|
|
|
while (<STDIN>) {
|
2000-07-11 10:40:09 +04:00
|
|
|
if (/^\s+([\w\d.\-\\\/]+)\s*(\([\w\d.\-\\\/]+\))?$\s*/) {
|
2000-08-04 00:58:31 +04:00
|
|
|
my $dest = $1;
|
2000-07-11 10:40:09 +04:00
|
|
|
my $srcPath = $2;
|
|
|
|
|
|
|
|
if ( $srcPath ) {
|
|
|
|
$srcPath = substr($srcPath,1,-1);
|
|
|
|
|
2000-09-21 02:45:45 +04:00
|
|
|
if (defined($usrcdir)) {
|
|
|
|
#print "Chkpt A: Switching to $objdir\n";
|
|
|
|
chdir $objdir or die "chdir: $!\n";
|
|
|
|
$srcPath = "$usrcdir/$srcPath";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EnsureFileInDir($dest, $srcPath, 1);
|
2000-07-11 10:40:09 +04:00
|
|
|
$args = "$args$dest ";
|
2000-09-21 02:45:45 +04:00
|
|
|
JarIt($destPath, $jarfile, $copyFiles, $args, $overrides);
|
|
|
|
|
|
|
|
if ($srcPath && defined($usrcdir)) {
|
|
|
|
#print "Chkpt B: Switching back to $usrcdir\n";
|
|
|
|
chdir $usrcdir or die "chdir: $!\n";
|
|
|
|
}
|
2000-09-12 03:08:41 +04:00
|
|
|
} elsif (/^\+\s+([\w\d.\-\\\/]+)\s*(\([\w\d.\-\\\/]+\))?$\s*/) {
|
|
|
|
my $dest = $1;
|
|
|
|
my $srcPath = $2;
|
|
|
|
|
|
|
|
if ( $srcPath ) {
|
|
|
|
$srcPath = substr($srcPath,1,-1);
|
2000-09-21 02:45:45 +04:00
|
|
|
if (defined($usrcdir)) {
|
|
|
|
#print "Chkpt C: Switching to $objdir\n";
|
|
|
|
chdir $objdir or die "chdir: $!\n";
|
|
|
|
$srcPath = "$usrcdir/$srcPath";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EnsureFileInDir($dest, $srcPath, 1);
|
2000-09-12 03:08:41 +04:00
|
|
|
$overrides = "$overrides$dest ";
|
2000-09-21 02:45:45 +04:00
|
|
|
JarIt($destPath, $jarfile, $copyFiles, $args, $overrides);
|
|
|
|
if ($srcPath && defined($usrcdir)) {
|
|
|
|
#print "Chkpt D: Switching back to $usrcdir\n";
|
|
|
|
chdir $usrcdir or die "chdir: $!\n";
|
|
|
|
}
|
2000-06-09 10:33:25 +04:00
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
# end with blank line
|
|
|
|
last;
|
|
|
|
} else {
|
2000-09-21 02:45:45 +04:00
|
|
|
#print "Chkpt E\n";
|
|
|
|
|
2000-09-12 03:08:41 +04:00
|
|
|
JarIt($destPath, $jarfile, $copyFiles, $args, $overrides);
|
2000-09-21 02:45:45 +04:00
|
|
|
|
|
|
|
#print "Chkpt F\n";
|
|
|
|
|
2000-06-09 10:33:25 +04:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
2000-09-21 07:51:35 +04:00
|
|
|
|
|
|
|
Cleanup();
|