зеркало из https://github.com/mozilla/gecko-dev.git
Added command line options (src|dest|file|help|debug|os). Changed to warn if
component directory already exists rather than die.
This commit is contained in:
Родитель
69e203f45c
Коммит
0c6046a865
|
@ -30,40 +30,61 @@
|
|||
# for packaging by the install builder.
|
||||
#
|
||||
#
|
||||
# Things to do:
|
||||
# - use options to specify arguments (i.e. --s <sourcedir>)
|
||||
#
|
||||
|
||||
# load modules
|
||||
use Cwd;
|
||||
use File::Basename;
|
||||
use File::Copy;
|
||||
use File::Find;
|
||||
use File::Path;
|
||||
use Getopt::Long;
|
||||
|
||||
# check Usage
|
||||
if (($#ARGV != 2) || ($ARGV[0] =~ /^-{1,2}h/i))
|
||||
{
|
||||
print_usage();
|
||||
exit (1);
|
||||
}
|
||||
|
||||
# check arguments
|
||||
($srcdir, $destdir, $manifest) = @ARGV;
|
||||
check_arguments();
|
||||
|
||||
# initialize variables
|
||||
$saved_cwd = cwd();
|
||||
$component = "";
|
||||
$altdest = "";
|
||||
$file = "";
|
||||
$srcdir = "";
|
||||
$destdir = "";
|
||||
$package = "";
|
||||
$os = "";
|
||||
$lineno = 0;
|
||||
$batch = 0;
|
||||
$help = 0;
|
||||
$debug = 0;
|
||||
|
||||
|
||||
# get command line options
|
||||
$return = GetOptions( "source|src|s=s", \$srcdir,
|
||||
"destination|dest|d=s", \$destdir,
|
||||
"file|f=s", \$package,
|
||||
"os|o=s", \$os,
|
||||
"help|h", \$help,
|
||||
"debug=i", \$debug,
|
||||
"<>", \&do_badargument
|
||||
);
|
||||
|
||||
# set debug level
|
||||
$debug = abs ($debug);
|
||||
if ($debug) {
|
||||
print "debug level: $debug\n";
|
||||
}
|
||||
|
||||
# check Usage
|
||||
if (! $return)
|
||||
{
|
||||
die "Error: couldn't parse command line options. See \'$0 --help' for options.\nExiting...\n";
|
||||
} else {
|
||||
check_arguments();
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# main loop
|
||||
#
|
||||
|
||||
open (MANIFEST,"<$manifest") ||
|
||||
die "Error: couldn't open file $manifest for reading: $!. Exiting...\n";
|
||||
open (MANIFEST,"<$package") ||
|
||||
die "Error: couldn't open file $package for reading: $!. Exiting...\n";
|
||||
|
||||
LINE: while (<MANIFEST>) {
|
||||
$file = "";
|
||||
|
@ -90,7 +111,7 @@ LINE: while (<MANIFEST>) {
|
|||
|
||||
# make sure a component is defined before doing any copies or deletes.
|
||||
( $component eq "") &&
|
||||
die "Error: item $_ outside a component ($manifest, $lineno). Exiting...\n";
|
||||
die "Error: item $_ outside a component ($package, $lineno). Exiting...\n";
|
||||
|
||||
# delete the file or directory following the '-'
|
||||
/^-/ && do {
|
||||
|
@ -102,7 +123,7 @@ LINE: while (<MANIFEST>) {
|
|||
# file/directory being copied to different target location
|
||||
/\,/ && do {
|
||||
/.*\,.*\,.*/ &&
|
||||
die "Error: multiple commas not allowed ($manifest, $lineno): $_.\n";
|
||||
die "Error: multiple commas not allowed ($package, $lineno): $_.\n";
|
||||
($file, $altdest) = split (/\s*\,\s*/, $_, 2);
|
||||
$file =~ s/\/*$//; # strip any trailing '/'
|
||||
$altdest =~ s/\/*$//; # strip any trailing '/'
|
||||
|
@ -130,7 +151,7 @@ LINE: while (<MANIFEST>) {
|
|||
};
|
||||
|
||||
# if we hit this, dunno what it is. abort! abort!
|
||||
die "Error: $_ unrecognized ($manifest, $lineno). Exiting...\n";
|
||||
die "Error: $_ unrecognized ($package, $lineno). Exiting...\n";
|
||||
|
||||
} # LINE
|
||||
|
||||
|
@ -147,18 +168,20 @@ sub do_delete
|
|||
{
|
||||
local ($target) = $_[0];
|
||||
|
||||
($debug >= 2) && print "do_delete:\n";
|
||||
|
||||
if (-f $target) {
|
||||
!(-w $target) &&
|
||||
die "Error: delete failed: $target not writeable ($manifest, $component, $lineno). Exiting...\n";
|
||||
die "Error: delete failed: $target not writeable ($package, $component, $lineno). Exiting...\n";
|
||||
unlink ($target) ||
|
||||
die "Error: unlink() failed: $!. Exiting...\n";
|
||||
} elsif (-d $target) {
|
||||
!(-w $target) &&
|
||||
die "Error: delete failed: $target not writeable ($manifest, $component, $lineno). Exiting...\n";
|
||||
die "Error: delete failed: $target not writeable ($package, $component, $lineno). Exiting...\n";
|
||||
rmtree ($target, 0, 0) ||
|
||||
die "Error: rmtree() failed: $!. Exiting...\n";
|
||||
} else {
|
||||
die "Error: delete failed: $target is not a file or directory ($manifest, $component, $lineno). Exiting...\n";
|
||||
die "Error: delete failed: $target is not a file or directory ($package, $component, $lineno). Exiting...\n";
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -173,6 +196,8 @@ sub do_copyfile
|
|||
local ($path) = "";
|
||||
my ($srcfile) = "";
|
||||
|
||||
($debug >= 2) && print "do_copyfile:\n";
|
||||
|
||||
# set srcfile correctly depending on how called
|
||||
if ($batch) {
|
||||
$srcfile = $File::Find::name;
|
||||
|
@ -181,7 +206,7 @@ sub do_copyfile
|
|||
}
|
||||
# check that source file is readable
|
||||
(!( -r $srcfile )) &&
|
||||
die "Error: file $srcfile is not readable ($manifest, $component, $lineno).\n";
|
||||
die "Error: file $srcfile is not readable ($package, $component, $lineno).\n";
|
||||
|
||||
# set the destination path, if alternate destination given, use it.
|
||||
if ($altdest ne "") {
|
||||
|
@ -215,11 +240,13 @@ sub do_copyfile
|
|||
};
|
||||
|
||||
if (-f $srcfile) { # don't copy if it's a directory
|
||||
($debug >= 5) && print "\tcopy\t$srcfile => $path/$basefile\n";
|
||||
copy ("$srcfile", "$path/$basefile") ||
|
||||
die "Error: copy of file $srcdir/$file failed ($manifest, $component, $lineno): $!. Exiting...\n";
|
||||
die "Error: copy of file $srcdir/$file failed ($package, $component, $lineno): $!. Exiting...\n";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Expand any wildcards, and recursively copy files and directories specified.
|
||||
#
|
||||
|
@ -228,6 +255,8 @@ sub do_batchcopy
|
|||
my ($entry) = $_[0];
|
||||
my (@list) = ();
|
||||
|
||||
($debug >= 2) && print "do_batchcopy:\n";
|
||||
|
||||
if ($entry =~ /(?:\*|\?)/) { # it's a wildcard,
|
||||
@list = glob($entry); # expand it, and
|
||||
foreach $entry (@list) {
|
||||
|
@ -246,15 +275,19 @@ sub do_batchcopy
|
|||
#
|
||||
sub do_component
|
||||
{
|
||||
($debug >= 2) && print "do_component:\n";
|
||||
|
||||
( $component =~ /^\[.*(?:\s|\[|\])+.*\]/ ) && # no brackets or ws
|
||||
die "Error: malformed component $component. Exiting...\n";
|
||||
$component =~ s/^\[(.*)\]/$1/; # strip []
|
||||
|
||||
# create component directory
|
||||
( -d "$destdir/$component" ) &&
|
||||
die "Error: component directory \"$component\" already exists. Exiting...\n";
|
||||
mkdir ("$destdir/$component", 0755) ||
|
||||
die "Error: couldn't create component directory \"$component\": $!. Exiting...\n";
|
||||
if ( -d "$destdir/$component" ) {
|
||||
warn "Warning: component directory \"$component\" already exists in \"$destdir\".\n";
|
||||
} else {
|
||||
mkdir ("$destdir/$component", 0755) ||
|
||||
die "Error: couldn't create component directory \"$component\": $!. Exiting...\n";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -263,51 +296,131 @@ sub do_component
|
|||
#
|
||||
sub check_arguments
|
||||
{
|
||||
my ($exitval) = 0; # like chmod: src==x, dest==w, manifest==r
|
||||
my ($exitval) = 0;
|
||||
|
||||
$srcdir =~ s/\/$//; # strip trailing /
|
||||
$destdir =~ s/\/$//; # strip trailing /
|
||||
($debug >= 2) && print "check_arguments:\n";
|
||||
|
||||
if (!(-d $srcdir) || !(-r $srcdir))
|
||||
{
|
||||
print "Error: source directory $srcdir is not a directory or is unreadable.\n";
|
||||
# if --help print usage
|
||||
if ($help) {
|
||||
print_usage();
|
||||
exit (1);
|
||||
}
|
||||
|
||||
# make sure required variables are set:
|
||||
# check source directory
|
||||
if ($srcdir eq "") {
|
||||
print "Error: source directory (--source) not specified.\n";
|
||||
$exitval += 8;
|
||||
} elsif (!(-d $srcdir) || !(-r $srcdir)) {
|
||||
print "Error: source directory \"$srcdir\" is not a directory or is unreadable.\n";
|
||||
$exitval = 1;
|
||||
}
|
||||
|
||||
if (!(-d $destdir) || !(-w $destdir))
|
||||
{
|
||||
print "Error: destination directory $destdir is not a directory or is not writeable.\n";
|
||||
# check destination directory
|
||||
if ($destdir eq "") {
|
||||
print "Error: destination directory (--destination) not specified.\n";
|
||||
$exitval += 8;
|
||||
} elsif (!(-d $destdir) || !(-w $destdir)) {
|
||||
print "Error: destination directory \"$destdir\" is not a directory or is not writeable.\n";
|
||||
$exitval += 2;
|
||||
}
|
||||
|
||||
if (!(-f $manifest) || !(-r $manifest))
|
||||
{
|
||||
print "Error: manifest file $manifest is not a file or is unreadable.\n";
|
||||
# check package file
|
||||
if ($package eq "") {
|
||||
print "Error: package file (--file) not specified.\n";
|
||||
$exitval += 8;
|
||||
} elsif (!(-f $package) || !(-r $package)) {
|
||||
print "Error: package file \"$package\" is not a file or is unreadable.\n";
|
||||
$exitval += 4;
|
||||
}
|
||||
|
||||
# check OS == {mac|unix|dos}
|
||||
if ($os eq "") {
|
||||
print "Error: OS type (--os) not specified.\n";
|
||||
$exitval += 8;
|
||||
} elsif ( $os =~ /mac/i ) {
|
||||
$os = "MacOS";
|
||||
} elsif ( $os =~ /dos/i ) {
|
||||
$os = "MSDOS";
|
||||
} elsif ( $os =~ /unix/i ) { # null because Unix is default for
|
||||
$os = ""; # fileparse_set_fstype()
|
||||
} else {
|
||||
print "Error: OS type \"$os\" unknown.\n";
|
||||
$exitval += 16;
|
||||
}
|
||||
|
||||
if ($exitval) {
|
||||
print "\See '$0 --help\' for more information.\n";
|
||||
print "Exiting...\n";
|
||||
exit ($exitval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# This is called by GetOptions when there are extra command line arguments
|
||||
# it doesn't understand.
|
||||
#
|
||||
sub do_badargument
|
||||
{
|
||||
warn "Warning: unknown command line option specified: @_.\n";
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# display usage information
|
||||
#
|
||||
sub print_usage
|
||||
{
|
||||
($debug >= 2) && print "print_usage:\n";
|
||||
|
||||
print <<EOC
|
||||
|
||||
$0
|
||||
Copy files from the source directory to component directories
|
||||
in the destination directory as specified by the package file.
|
||||
|
||||
Usage: $0 <source directory> <destination directory> <manifest file>
|
||||
e.g. $0 /builds/mozilla/dist /h/lithium/install packages-win
|
||||
Options:
|
||||
--source <source directory>
|
||||
Specifies the directory from which to copy the files
|
||||
specified in the file passed via --file. Can also be
|
||||
abbreviated to: --src, --s.
|
||||
Required.
|
||||
|
||||
NOTE: All arguments are required.
|
||||
--destination <destination directory>
|
||||
Specifies the directory in which to create the component
|
||||
directories and copy the files specified in the file passed
|
||||
via --file. Can also be abbreviated to: --dest, --d.
|
||||
Required.
|
||||
|
||||
--file <package file>
|
||||
Specifies the file listing the components to be created in
|
||||
the destination directory and the files to copy from the
|
||||
source directory to each component directory in the
|
||||
destination directory. Can also be abbreviated to: --f.
|
||||
Required.
|
||||
|
||||
--os [dos|mac|unix]
|
||||
Specifies which type of system this is. Used for parsing file
|
||||
specifications from the package file. Can also be abbreviated
|
||||
to: --o.
|
||||
Required.
|
||||
|
||||
--help
|
||||
Prints this information. Can also be abbreviated to: --h
|
||||
Optional.
|
||||
|
||||
--debug [1-10]
|
||||
Controls verbosity of debugging output, 10 being most verbose.
|
||||
Optional.
|
||||
|
||||
e.g.
|
||||
|
||||
$0 --os unix --source /builds/mozilla/dist --destination /h/lithium/install --file packages-win
|
||||
|
||||
Note: options can be specified by either a leading '--' or '-'.
|
||||
|
||||
EOC
|
||||
|
||||
}
|
||||
|
||||
# EOF
|
||||
|
|
Загрузка…
Ссылка в новой задаче