fatpack.pl: Add the ability to whitelist modules
This commit is contained in:
parent
b714731484
commit
b31a3a0e1c
1 changed files with 28 additions and 10 deletions
|
@ -13,22 +13,35 @@ my $outdir;
|
||||||
my $truncate = '';
|
my $truncate = '';
|
||||||
my $inputfile;
|
my $inputfile;
|
||||||
my $usage='';
|
my $usage='';
|
||||||
|
my @whitelist=('io');
|
||||||
|
my @cliwhitelist;
|
||||||
|
|
||||||
GetOptions('output=s' => \$outdir, 'truncate' => \$truncate, 'input=s' => \$inputfile, 'help' => \$usage);
|
GetOptions('output=s' => \$outdir, 'truncate' => \$truncate, 'input=s' => \$inputfile, 'help' => \$usage, 'whitelist=s' => \@cliwhitelist);
|
||||||
|
|
||||||
|
@cliwhitelist = split(/,/, join(',', @cliwhitelist));
|
||||||
|
push @whitelist, @cliwhitelist;
|
||||||
|
@whitelist = uniq(@whitelist);
|
||||||
|
my %whitelisted = map {$_ => 1} @whitelist;
|
||||||
|
|
||||||
if ( $usage
|
if ( $usage
|
||||||
|| ((!$outdir) || (! -d $outdir))
|
|| ((!$outdir) || (! -d $outdir))
|
||||||
|| ((!$inputfile) || (! -f $inputfile))) {
|
|| ((!$inputfile) || (! -f $inputfile))) {
|
||||||
print <<"EOF";
|
print <<"EOF";
|
||||||
$0 --input <file.lua> --output <directory> [--truncate]
|
$0 --input <file.lua> --output <directory> [--truncate] [--whitelist <module>,<module>]
|
||||||
--help Print this help message
|
--help Print this help message
|
||||||
--input file to fatpack. Expects all libs to reside in basedir(file)
|
--input file to fatpack. Expects all libs to reside in basedir(file)
|
||||||
--output output directory for fatpacked files
|
--output output directory for fatpacked files
|
||||||
--truncate unconditionally override in outdir (default=false)
|
--truncate unconditionally override in outdir (default=false)
|
||||||
|
--whitelist modules not to fatpack
|
||||||
EOF
|
EOF
|
||||||
exit -1;
|
exit -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub uniq {
|
||||||
|
my %seen;
|
||||||
|
grep !$seen{$_}++, @_;
|
||||||
|
}
|
||||||
|
|
||||||
sub slurp {
|
sub slurp {
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
return do {
|
return do {
|
||||||
|
@ -123,8 +136,13 @@ sub unslurp {
|
||||||
my $dst = shift;
|
my $dst = shift;
|
||||||
my $content = shift;
|
my $content = shift;
|
||||||
|
|
||||||
open(my $fh, '>', $dst);
|
if (-f $dst && !$truncate) {
|
||||||
print $fh, $content;
|
print STDERR "$dst already exists and --truncate was not specified\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
open(my $fh, '>', $dst) or die "Could not open file '$dst'";
|
||||||
|
print $fh $content;
|
||||||
close $fh;
|
close $fh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +168,7 @@ sub main {
|
||||||
|
|
||||||
# Add all new modules and their contents
|
# Add all new modules and their contents
|
||||||
foreach my $module (@new) {
|
foreach my $module (@new) {
|
||||||
if (! exists $modules->{$module}) {
|
if (! exists $modules->{$module} && ! exists $whitelisted{$module}) {
|
||||||
$modules->{$module} = getModule($includedir, $module);
|
$modules->{$module} = getModule($includedir, $module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +180,7 @@ sub main {
|
||||||
|
|
||||||
my $fat = fatpack($inputmodule, $modules);
|
my $fat = fatpack($inputmodule, $modules);
|
||||||
|
|
||||||
unslurp("$outdir/$mainmodule.lua", $fat);
|
unslurp("$outdir/$inputmodule.lua", $fat);
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
Loading…
Add table
Reference in a new issue