Skip to content

Commit c32bb7b

Browse files
committed
upgraded perl build script to make a fully distributable zip of the game
1 parent 7684356 commit c32bb7b

File tree

4 files changed

+96
-51
lines changed

4 files changed

+96
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
/cpanfile.snapshot
2929
/perl
3030
/Logfile.CSV
31+
/Microidium.zip

build_perl.pl

Lines changed: 0 additions & 50 deletions
This file was deleted.

build_zip.pl

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use strictures;
2+
3+
# this builds a portable zip with everything needed to run the game on windows
4+
#
5+
# first it builds a portable copy of a windows system perl by scanning a
6+
# procmon log file and copying all files read by perl.exe in the capture
7+
#
8+
# then it zips up all the files, skipping the ones not needed to run the game
9+
10+
use 5.010;
11+
use Text::CSV_XS 'csv';
12+
use IO::All -binary, -utf8;
13+
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
14+
15+
run();
16+
17+
sub status { say scalar( localtime ) . ": " . sprintf( shift, @_ ) }
18+
19+
sub run {
20+
my $start = time;
21+
22+
my $base_path = $ARGV[0] || "c:\\perl";
23+
$base_path .= "\\";
24+
my $base_path_q = quotemeta $base_path;
25+
my $target_base = $ARGV[1] || "perl";
26+
27+
if ( !-d "perl" ) {
28+
status "building portable perl";
29+
my @log = do {
30+
my $data = io( "Logfile.CSV" )->all;
31+
$data =~ s/^.*?\n//;
32+
@{ csv in => \$data };
33+
};
34+
for my $filter (
35+
sub { $_->[1] eq "perl.exe" }, #
36+
sub { $_->[4] eq "CreateFile" },
37+
sub { $_->[7] eq "SUCCESS" },
38+
sub { $_->[6] =~ /^$base_path_q/i },
39+
sub { $_->[6] !~ /\.bs$/ },
40+
sub { -f $_->[6] },
41+
)
42+
{
43+
@log = grep $filter->( $_ ), @log;
44+
}
45+
46+
my %files = map { $_->[6] => 1 } @log;
47+
my @files = sort keys %files;
48+
49+
status "copying %s files", scalar @files;
50+
for my $file ( @files ) {
51+
my $io = io( $file )->file;
52+
my $path = $io->filepath;
53+
$path =~ s/^$base_path_q//i;
54+
my $target_dir = io->catdir( $target_base, $path );
55+
$target_dir->mkpath if !$target_dir->exists;
56+
my $target_file = io->catfile( $target_dir->pathname, $io->filename )->name;
57+
$io->copy( $target_file );
58+
}
59+
}
60+
61+
my $target_file = "Microidium.zip";
62+
if ( !-f $target_file ) {
63+
status "building zip";
64+
65+
my @local_files = map $_->name, io( "." )->All_Files;
66+
status "filtering local files";
67+
68+
my @to_ignore = grep { $_ and $_ !~ /^#/ and $_ ne "/perl" } split "\n", io( ".gitignore" )->all;
69+
push @to_ignore, "generate_colors", map "/$_", qw( .git Changes META
70+
README.PATCHING client.bat server.bat cpanfile dist.ini scratch
71+
t perlcritic.rc ), io( $0 )->filename;
72+
$_ =~ s/^\//^/g for @to_ignore;
73+
$_ =~ s/\./\\./g for @to_ignore;
74+
$_ =~ s/\*/.*/g for @to_ignore;
75+
76+
for my $ignore ( @to_ignore ) {
77+
@local_files = grep { $_ !~ /$ignore/ } @local_files;
78+
}
79+
80+
my $localdir = io( "." )->absolute->filename;
81+
82+
status "zipping %s files", scalar @local_files;
83+
my $zip = Archive::Zip->new;
84+
$zip->addFile( $_, io->catfile( $localdir, $_ )->name, 9 ) for @local_files;
85+
$zip->writeToFileNamed( $target_file );
86+
}
87+
88+
status "done";
89+
90+
status "time taken: %s seconds", time - $start;
91+
92+
return;
93+
}

dist.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ copyright_holder = Christian Walde
55
copyright_year = 2014
66

77
[@MITHALDU]
8-
exclude_match = ^(scratch|nytprof|kryonet|IO-Async-|local|perl|Logfile.CSV)
8+
exclude_match = ^(scratch|nytprof|kryonet|IO-Async-|local|perl|Logfile.CSV|Microidium.zip)
99
gitignore = /local*
1010
gitignore = /nytprof*
1111
gitignore = /kryonet*
1212
gitignore = /IO-Async-*
1313
gitignore = /cpanfile.snapshot
1414
gitignore = /perl
1515
gitignore = /Logfile.CSV
16+
gitignore = /Microidium.zip
1617
skip_prereq = ^Microidium::Client$
1718
skip_prereq = ^IO::Async::Internals::Connector$
1819

0 commit comments

Comments
 (0)