зеркало из https://github.com/mozilla/pjs.git
139 строки
2.9 KiB
Perl
139 строки
2.9 KiB
Perl
#!/perl
|
|
|
|
# make-jars [-d <destPath>] < <manifest.jr>
|
|
|
|
use Getopt::Std;
|
|
use Cwd;
|
|
|
|
sub cleanup
|
|
{
|
|
my ($cleanupArgs) = @_;
|
|
print "+++ removing temp files\n";
|
|
@fileList = split(/ /,$cleanupArgs);
|
|
foreach $file (@fileList) {
|
|
if ($file) {
|
|
unlink($file) || die "error: can't remove '$file' $!";
|
|
}
|
|
}
|
|
}
|
|
|
|
sub JarIt
|
|
{
|
|
my ($jarfile, $args) = @_;
|
|
system "zip -u $jarfile $args\n";
|
|
my $cwd = cwd();
|
|
print "+++ jarred $cwd => $jarfile\n";
|
|
}
|
|
|
|
sub MkDirs
|
|
{
|
|
my ($path) = @_;
|
|
if ($path =~ /([\w\d.\-]+)[\\\/](.*)/) {
|
|
my $dir = $1;
|
|
$path = $2;
|
|
if (!-e $dir) {
|
|
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
|
|
}
|
|
chdir $dir;
|
|
MkDirs($path);
|
|
chdir "..";
|
|
}
|
|
else {
|
|
my $dir = $path;
|
|
if ($dir eq "") { return 0; }
|
|
if (!-e $dir) {
|
|
mkdir($dir, 0777) || die "error: can't create '$dir': $!";
|
|
}
|
|
}
|
|
}
|
|
|
|
sub CopyFile
|
|
{
|
|
my ($from, $to) = @_;
|
|
open(OUT, ">$to") || die "error: can't open '$to': $!";
|
|
open(IN, "<$from") || die "error: can't open '$from': $!";
|
|
while (<IN>) {
|
|
print OUT $_;
|
|
}
|
|
close(IN) || die "error: can't close '$from': $!";
|
|
close(OUT) || die "error: can't close '$to': $!";
|
|
}
|
|
|
|
sub EnsureFileInDir
|
|
{
|
|
my ($destPath, $srcPath) = @_;
|
|
|
|
if (!-e $destPath) {
|
|
my $dir = "";
|
|
my $file;
|
|
if ($destPath =~ /([\w\d.\-\\\/]+)[\\\/]([\w\d.\-]+)/) {
|
|
$dir = $1;
|
|
$file = $2;
|
|
}
|
|
else {
|
|
$file = $destPath;
|
|
}
|
|
|
|
if ($srcPath) {
|
|
$file = $srcPath;
|
|
}
|
|
|
|
if (!-e $file) {
|
|
die "error: file '$file' doesn't exist\n";
|
|
}
|
|
MkDirs($dir);
|
|
CopyFile($file, $destPath);
|
|
$cleanupArgs = "$cleanupArgs $destPath";
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
getopt("d:");
|
|
|
|
my $destPath = ".";
|
|
if (defined($opt_d)) {
|
|
$destPath = $opt_d;
|
|
}
|
|
|
|
while (<>) {
|
|
chomp;
|
|
start:
|
|
if (/^([\w\d.\-\\\/]+)\:\s*$/) {
|
|
my $jarfile = "$destPath/$1";
|
|
|
|
my $args = "";
|
|
$cleanupArgs = "";
|
|
|
|
while (<>) {
|
|
if (/^\s+([\w\d.\-\\\/]+)\s*(\([\w\d.\-\\\/]+\))?$\s*/) {
|
|
my $dest = $1;
|
|
my $srcPath = $2;
|
|
|
|
if ( $srcPath ) {
|
|
$srcPath = substr($srcPath,1,-1);
|
|
}
|
|
|
|
EnsureFileInDir($dest, $srcPath);
|
|
$args = "$args$dest ";
|
|
} elsif (/^\s*$/) {
|
|
# end with blank line
|
|
last;
|
|
} else {
|
|
JarIt($jarfile, $args);
|
|
cleanup($cleanupArgs);
|
|
goto start;
|
|
}
|
|
}
|
|
JarIt($jarfile, $args);
|
|
cleanup($cleanupArgs);
|
|
} elsif (/^\s*\#.*$/) {
|
|
# skip comments
|
|
} elsif (/^\s*$/) {
|
|
# skip blank lines
|
|
} else {
|
|
close;
|
|
die "bad jar rule head at: $_";
|
|
}
|
|
}
|