| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
use warnings; |
|---|
| 6 |
use strict; |
|---|
| 7 |
|
|---|
| 8 |
use File::Copy; |
|---|
| 9 |
use File::Copy::Recursive qw(dircopy pathrm pathmk); |
|---|
| 10 |
use File::Find; |
|---|
| 11 |
use Test::Inline::Extract; |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
if(!@ARGV){@ARGV = qw(HoneyClient::Util HoneyClient::Agent HoneyClient::Manager)} |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
my $src_path = "lib"; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
my %inc_dirs = (etc => $src_path . '/etc', |
|---|
| 22 |
bin => $src_path . '/bin', |
|---|
| 23 |
inc => 'thirdparty/inc', |
|---|
| 24 |
'thirdparty' => 'thirdparty', |
|---|
| 25 |
't' => 't', |
|---|
| 26 |
); |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
$src_path =~ s/\/+$//; |
|---|
| 32 |
my $pkg_name; |
|---|
| 33 |
foreach(@ARGV){ |
|---|
| 34 |
|
|---|
| 35 |
$pkg_name = $_; |
|---|
| 36 |
$pkg_name =~ s/::/-/g; |
|---|
| 37 |
|
|---|
| 38 |
l("Packaging $_..."); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
my ($module,@path) = reverse(split(/-/,$pkg_name)); |
|---|
| 42 |
my $path = join('/',reverse(@path)); |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
l("Cleaning house",1); |
|---|
| 46 |
if(-e $pkg_name){ my_pathrm($pkg_name,2) } |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
if(-e 'stub'){ my_pathrm('stub',2) } |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
while(my($name,$path) = each %inc_dirs){ |
|---|
| 53 |
my_dircopy($path,$pkg_name,$name,1); |
|---|
| 54 |
|
|---|
| 55 |
eval { |
|---|
| 56 |
no warnings; |
|---|
| 57 |
find({wanted => \&remove_svn, no_chdir => 0}, "$pkg_name/$name"); |
|---|
| 58 |
}; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
my_pathmk("$pkg_name/lib/$path/$module",1); |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
if(-f "$src_path/$path/$module.pm"){ |
|---|
| 66 |
my($src,$dest) = ("$src_path/$path/$module.pm","$pkg_name/lib/$path"); |
|---|
| 67 |
my_copy($src,$dest,2); |
|---|
| 68 |
} |
|---|
| 69 |
find({wanted => \&process, no_chdir => 1} ,"$src_path/$path/$module"); |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
my_copy("LICENSE",$pkg_name,1); |
|---|
| 73 |
my_copy("INSTALL",$pkg_name,1); |
|---|
| 74 |
|
|---|
| 75 |
l(''); |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
sub remove_svn { |
|---|
| 79 |
if(/\.svn$/) { |
|---|
| 80 |
my_pathrm($_, 2); |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
sub process { |
|---|
| 86 |
|
|---|
| 87 |
if(/\.pm$/){ |
|---|
| 88 |
my $src = $File::Find::name; |
|---|
| 89 |
l("Found $src",3); |
|---|
| 90 |
|
|---|
| 91 |
my @dest = split(/\//,$src); |
|---|
| 92 |
shift(@dest); |
|---|
| 93 |
my $name = pop(@dest); |
|---|
| 94 |
$name =~ s/\.pm$//; |
|---|
| 95 |
unshift(@dest,$pkg_name,'lib'); |
|---|
| 96 |
my $dest = join('/',@dest); |
|---|
| 97 |
if(!-e $dest){ my_pathmk($dest,4) } |
|---|
| 98 |
my_copy($src,$dest,3); |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
sub my_copy { |
|---|
| 118 |
my($src,$dest,$log) = @_; |
|---|
| 119 |
l("Copying $src to $dest",$log); |
|---|
| 120 |
copy($src,$dest) or die "Cannot copy $src to $dest: $!"; |
|---|
| 121 |
} |
|---|
| 122 |
sub my_dircopy { |
|---|
| 123 |
my($src,$dest,$name,$log) = @_; |
|---|
| 124 |
l("Copying $src to $dest as $name",$log); |
|---|
| 125 |
dircopy($src,"$dest/$name") or die "Couldn't copy $src to $dest: $!"; |
|---|
| 126 |
} |
|---|
| 127 |
sub my_pathrm { |
|---|
| 128 |
my($pkg_name,$log) = @_; |
|---|
| 129 |
l("Removing $pkg_name directory",$log); |
|---|
| 130 |
pathrm($pkg_name,1) or die "Can't rmdir $pkg_name: $!"; |
|---|
| 131 |
} |
|---|
| 132 |
sub my_pathmk { |
|---|
| 133 |
my($path,$log) = @_; |
|---|
| 134 |
l("$path does not exist, creating...",$log); |
|---|
| 135 |
pathmk($path) or die "Cannot mkdir $path: $!"; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
sub l { |
|---|
| 140 |
my $string = shift; |
|---|
| 141 |
my $level = shift || 0; |
|---|
| 142 |
while($level-- > 0){ |
|---|
| 143 |
print "\t"; |
|---|
| 144 |
if(!$level){ print "- " } |
|---|
| 145 |
} |
|---|
| 146 |
print "$string\n"; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|