Skip to content

Commit c335f47

Browse files
committed
build: More refactoring on MSI packaging process
1 parent 933947b commit c335f47

File tree

2 files changed

+111
-125
lines changed

2 files changed

+111
-125
lines changed

contrib/windows/glpi-agent-packaging.pl

Lines changed: 21 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ sub build_app {
9494
service_name => lc($provider).'-agent',
9595
msi_sharedir => 'contrib/windows/packaging',
9696
arch => $bits == 32 ? "x86" : "x64",
97+
_dllsuffix => $bits == 32 ? '_' : '__',
9798
_restore_step => PERL_BUILD_STEPS,
9899
);
99100

@@ -203,23 +204,11 @@ sub _patch_file {
203204
use parent 'Perl::Dist::Strawberry::Step';
204205

205206
use File::Spec::Functions qw(catfile catdir);
207+
use File::Glob qw(:glob);
206208

207209
sub run {
208210
my $self = shift;
209211

210-
# If modules are defined, just install the modules
211-
if ($self->{config}->{modules}) {
212-
my @list = map {
213-
{
214-
module => $_,
215-
skiptest => 1,
216-
install_to => 'site',
217-
}
218-
} @{$self->{config}->{modules}};
219-
$self->install_modlist(@list) or die "FAILED to install test modules\n";
220-
return;
221-
}
222-
223212
# Update PATH to include perl/bin for DLLs loading
224213
my $binpath = catfile($self->global->{image_dir}, 'perl/bin');
225214
$ENV{PATH} .= ":$binpath";
@@ -233,8 +222,16 @@ sub run {
233222
my $rv = $self->execute_standard($makefile_pl_cmd);
234223
die "ERROR: TEST, perl Makefile.PL\n" unless (defined $rv && $rv == 0);
235224

225+
my @test_files = ref($self->{config}->{test_files}) ?
226+
map { bsd_glob($_) } @{$self->{config}->{test_files}} : qw(t/01compile.t);
227+
if (ref($self->{config}->{skip_tests}) && @{$self->{config}->{skip_tests}}) {
228+
my %skip_tests = map { $_ => 1 } @{$self->{config}->{skip_tests}};
229+
@test_files = grep { not $skip_tests{$_} } @test_files;
230+
}
231+
236232
# Only test files compilation
237-
my $make_test_cmd = [ $makebin, "test", "TEST_FILES=t/01compile.t" ];
233+
my $make_test_cmd = [ $makebin, "test" ];
234+
push @{$make_test_cmd}, "TEST_FILES=@test_files" if @test_files;
238235
$self->boss->message(2, "Test: gonna run gmake test");
239236
$rv = $self->execute_standard($make_test_cmd);
240237
die "ERROR: TEST, make test\n" unless (defined $rv && $rv == 0);
@@ -700,9 +697,10 @@ sub ask_about_restorepoint {
700697
return $restorepoint;
701698
}
702699

703-
sub build_job_pre {
704-
my ($self) = @_;
705-
$self->SUPER::build_job_pre();
700+
sub create_buildmachine {
701+
my ($self, $job, $restorepoint) = @_;
702+
703+
$self->SUPER::create_buildmachine($job, $restorepoint);
706704

707705
my $provider = $self->global->{_provider};
708706
my $version = $self->global->{agent_version};
@@ -712,76 +710,13 @@ sub build_job_pre {
712710
$self->global->{output_basename} = "$provider-Agent-$version-$arch" ;
713711
}
714712

715-
sub build_job_post {
716-
my ($self) = @_;
717-
$self->SUPER::build_job_post();
718-
}
719-
720713
sub load_jobfile {
721714
my ($self) = @_;
722715

723-
my $job = build_job($self->global->{arch}, $self->global->{_revision});
724-
push @{$job->{build_job_steps}},
725-
### NEXT STEP ###########################
726-
{
727-
plugin => 'Perl::Dist::GLPI::Agent::Step::Test',
728-
}
729-
unless $self->global->{_no_test} ;
730-
push @{$job->{build_job_steps}}, $self->_other_job_steps();
731-
732-
return $job;
733-
}
734-
735-
sub _other_job_steps {
736-
my ($self) = @_;
737-
return
738-
### NEXT STEP ###########################
739-
{
740-
plugin => 'Perl::Dist::Strawberry::Step::FilesAndDirs',
741-
commands => [
742-
# Cleanup modules and files used for tests
743-
{ do=>'removedir', args=>[ '<image_dir>/perl/site/lib' ] },
744-
{ do=>'createdir', args=>[ '<image_dir>/perl/site/lib' ] },
745-
{ do=>'removefile', args=>[ '<image_dir>/perl/bin/gmake.exe' ] },
746-
# updates for glpi-agent
747-
{ do=>'createdir', args=>[ '<image_dir>/perl/agent' ] },
748-
{ do=>'createdir', args=>[ '<image_dir>/var' ] },
749-
{ do=>'createdir', args=>[ '<image_dir>/logs' ] },
750-
{ do=>'movefile', args=>[ '<image_dir>/perl/bin/perl.exe', '<image_dir>/perl/bin/glpi-agent.exe' ] },
751-
{ do=>'copydir', args=>[ 'lib/GLPI', '<image_dir>/perl/agent/GLPI' ] },
752-
{ do=>'copydir', args=>[ 'lib/GLPI', '<image_dir>/perl/agent/GLPI' ] },
753-
{ do=>'copydir', args=>[ 'etc', '<image_dir>/etc' ] },
754-
{ do=>'createdir', args=>[ '<image_dir>/etc/conf.d' ] },
755-
{ do=>'copydir', args=>[ 'bin', '<image_dir>/perl/bin' ] },
756-
{ do=>'copydir', args=>[ 'share', '<image_dir>/share' ] },
757-
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/setup.pm', '<image_dir>/perl/lib' ] },
758-
],
759-
},
760-
### NEXT STEP ###########################
761-
{
762-
plugin => 'Perl::Dist::GLPI::Agent::Step::Update',
763-
},
764-
### NEXT STEP ###########################
765-
{
766-
plugin => 'Perl::Dist::Strawberry::Step::OutputZIP', # no options needed
767-
},
768-
### NEXT STEP ###########################
769-
{
770-
plugin => 'Perl::Dist::GLPI::Agent::Step::OutputMSI',
771-
exclude => [
772-
#'dirname\subdir1\subdir2',
773-
#'dirname\file.pm',
774-
],
775-
#BEWARE: msi_upgrade_code is a fixed value for all same arch releases (for ever)
776-
msi_upgrade_code => $self->global->{arch} eq 'x64' ? '0DEF72A8-E5EE-4116-97DC-753718E19CD5' : '7F25A9A4-BCAE-4C15-822D-EAFBD752CFEC',
777-
app_publisher => "Teclib'",
778-
url_about => 'https://glpi-project.org/',
779-
url_help => 'https://glpi-project.org/discussions/',
780-
msi_root_dir => 'GLPI-Agent',
781-
msi_main_icon => 'contrib/windows/packaging/glpi-agent.ico',
782-
msi_license_rtf => 'contrib/windows/packaging/gpl-2.0.rtf',
783-
msi_dialog_bmp => 'contrib/windows/packaging/GLPI-Agent_Dialog.bmp',
784-
msi_banner_bmp => 'contrib/windows/packaging/GLPI-Agent_Banner.bmp',
785-
msi_debug => 0,
786-
};
716+
return build_job(
717+
$self->global->{arch},
718+
$self->global->{_revision},
719+
$self->global->{_no_test},
720+
$self->global->{_dllsuffix},
721+
);
787722
}

contrib/windows/packaging/PerlBuildJob.pm

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,30 @@ use ToolchainBuildJob;
77

88
use constant {
99
PERL_VERSION => "5.38.2",
10-
PERL_BUILD_STEPS => 7,
10+
PERL_BUILD_STEPS => 9,
1111
};
1212

1313
our @EXPORT = qw(build_job PERL_VERSION PERL_BUILD_STEPS);
1414

15-
my $ARCH = 'x64';
16-
1715
sub build_job {
18-
my ($arch, $rev) = @_;
16+
my ($arch, $rev, $notest, $dllsuffix) = @_;
1917
### job description for building GLPI Agent
2018

2119
#Available '<..>' macros:
2220
# <package_url> is placeholder for https://strawberryperl.com/package
2321
# <dist_sharedir> is placeholder for Perl::Dist::Strawberry's distribution sharedir
2422
# <image_dir> is placeholder for C:\Strawberry-perl-for-GLPI-Agent
2523

26-
$ARCH = $arch;
24+
my ($MAJOR, $MINOR) = PERL_VERSION =~ /^(\d+)\.(\d+)\./;
2725

2826
return {
2927
app_version => PERL_VERSION.'.'.$rev, #BEWARE: do not use '.0.0' in the last two version digits
3028
bits => $arch eq 'x64' ? 64 : 32,
3129
app_fullname => 'Strawberry Perl'.($arch eq 'x64'?' (64-bit)':''),
3230
app_simplename => 'strawberry-perl',
3331
maketool => 'gmake', # 'dmake' or 'gmake'
34-
build_job_steps => [ _build_steps() ],
35-
}
36-
}
32+
build_job_steps => [
3733

38-
sub _build_steps {
39-
my ($MAJOR, $MINOR) = PERL_VERSION =~ /^(\d+)\.(\d+)\./;
40-
return
4134
### FIRST STEP 0 : Binaries donwloads ##################################
4235
{
4336
plugin => 'Perl::Dist::GLPI::Agent::Step::ToolChain',
@@ -65,7 +58,7 @@ sub _build_steps {
6558
### NEXT STEP 2 Build perl #############################################
6659
{
6760
plugin => 'Perl::Dist::GLPI::Agent::Step::InstallPerlCore',
68-
url => _perl_source_url(),
61+
url => 'https://www.cpan.org/src/5.0/perl-'.PERL_VERSION.'.tar.gz',
6962
cf_email => 'strawberry-perl@project', #IMPORTANT: keep 'strawberry-perl' before @
7063
perl_debug => 0, # can be overridden by --perl_debug=N option
7164
perl_64bitint => 1, # ignored on 64bit, can be overridden by --perl_64bitint | --noperl_64bitint option
@@ -173,9 +166,14 @@ sub _build_steps {
173166
},
174167
### NEXT STEP 7 Install modules for test ###############################
175168
{
176-
plugin => 'Perl::Dist::GLPI::Agent::Step::Test',
177-
modules => [
178-
qw(
169+
plugin => 'Perl::Dist::GLPI::Agent::Step::InstallModules',
170+
modules => [ map {
171+
{
172+
module => $_,
173+
skiptest => 1,
174+
install_to => 'site',
175+
}
176+
} qw(
179177
HTTP::Proxy HTTP::Server::Simple::Authen IO::Capture::Stderr
180178
Test::Compile Test::Deep Test::MockModule Test::MockObject
181179
Test::NoWarnings
@@ -187,45 +185,98 @@ sub _build_steps {
187185
plugin => 'Perl::Dist::Strawberry::Step::FilesAndDirs',
188186
commands => [
189187
{ do=>'createdir', args=>[ '<image_dir>/perl/newbin' ] },
190-
_movebin('libgcc_s_'.(_is64bit()?'seh':'dw2').'-1.dll'),
188+
_movebin('libgcc_s_'.($arch eq 'x64' ? 'seh' : 'dw2').'-1.dll'),
191189
_movebin('libstdc++-6.dll'),
192190
_movebin('libwinpthread-1.dll'),
193191
_movebin('perl.exe'),
194192
_movebin('perl'.$MAJOR.$MINOR.'.dll'),
195193
# Also move DLLs required by modules
196-
_movedll('libxml2-2'),
197-
_movedll('liblzma-5'),
198-
_movedll('libcharset-1'),
199-
_movedll('libiconv-2'),
200-
_movedll('libcrypto-3'),
201-
_movedll('libssl-3'),
202-
_movedll('zlib1'),
203-
_movedll('libssh2-1'),
194+
_movedll('libxml2-2', $dllsuffix),
195+
_movedll('liblzma-5', $dllsuffix),
196+
_movedll('libcharset-1', $dllsuffix),
197+
_movedll('libiconv-2', $dllsuffix),
198+
_movedll('libcrypto-3', $dllsuffix),
199+
_movedll('libssl-3', $dllsuffix),
200+
_movedll('zlib1', $dllsuffix),
201+
_movedll('libssh2-1', $dllsuffix),
204202
{ do=>'removedir', args=>[ '<image_dir>/perl/bin' ] },
205203
{ do=>'movedir', args=>[ '<image_dir>/perl/newbin', '<image_dir>/perl/bin' ] },
206204
{ do=>'movefile', args=>[ '<image_dir>/c/bin/gmake.exe', '<image_dir>/perl/bin/gmake.exe' ] }, # Needed for tests
207205
{ do=>'removedir', args=>[ '<image_dir>/bin' ] },
208206
{ do=>'removedir', args=>[ '<image_dir>/c' ] },
209-
{ do=>'removedir', args=>[ '<image_dir>/'.(_is64bit()?'x86_64':'i686').'-w64-mingw32' ] },
207+
{ do=>'removedir', args=>[ '<image_dir>/'.($arch eq 'x64' ? 'x86_64' : 'i686').'-w64-mingw32' ] },
210208
{ do=>'removedir', args=>[ '<image_dir>/include' ] },
211209
{ do=>'removedir', args=>[ '<image_dir>/lib' ] },
212210
{ do=>'removedir', args=>[ '<image_dir>/libexec' ] },
213211
# Other binaries used by agent
214212
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/x86/dmidecode.exe', '<image_dir>/perl/bin' ] },
215213
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/x86/hdparm.exe', '<image_dir>/perl/bin' ] },
216-
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/'.$ARCH.'/7z.exe', '<image_dir>/perl/bin' ] },
217-
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/'.$ARCH.'/7z.dll', '<image_dir>/perl/bin' ] },
218-
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/'.$ARCH.'/GLPI-AgentMonitor-'.$ARCH.'.exe', '<image_dir>/perl/bin' ] },
214+
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/'.$arch.'/7z.exe', '<image_dir>/perl/bin' ] },
215+
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/'.$arch.'/7z.dll', '<image_dir>/perl/bin' ] },
216+
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/tools/'.$arch.'/GLPI-AgentMonitor-'.$arch.'.exe', '<image_dir>/perl/bin' ] },
219217
],
220-
};
221-
}
222-
223-
sub _is64bit {
224-
return $ARCH eq 'x64' ? 1 : 0;
225-
}
226-
227-
sub _perl_source_url {
228-
return 'https://www.cpan.org/src/5.0/perl-'.PERL_VERSION.'.tar.gz'
218+
},
219+
### NEXT STEP 9 Run GLPI Agent test suite ##############################
220+
{
221+
plugin => 'Perl::Dist::GLPI::Agent::Step::Test',
222+
disable => $notest,
223+
# By default only t/01compile.t is run
224+
test_files => [
225+
#~ qw(t/*.t t/*/*.t t/*/*/*.t t/*/*/*/*.t t/*/*/*/*/*.t t/*/*/*/*/*/*.t)
226+
],
227+
skip_tests => [
228+
# Fails if not run as administrator
229+
#~ qw(t/agent/config.t)
230+
],
231+
},
232+
### NEXT STEP 10 Finalize environment ##################################
233+
{
234+
plugin => 'Perl::Dist::Strawberry::Step::FilesAndDirs',
235+
commands => [
236+
# Cleanup modules and files used for tests
237+
{ do=>'removedir', args=>[ '<image_dir>/perl/site/lib' ] },
238+
{ do=>'createdir', args=>[ '<image_dir>/perl/site/lib' ] },
239+
{ do=>'removefile', args=>[ '<image_dir>/perl/bin/gmake.exe' ] },
240+
# updates for glpi-agent
241+
{ do=>'createdir', args=>[ '<image_dir>/perl/agent' ] },
242+
{ do=>'createdir', args=>[ '<image_dir>/var' ] },
243+
{ do=>'createdir', args=>[ '<image_dir>/logs' ] },
244+
{ do=>'movefile', args=>[ '<image_dir>/perl/bin/perl.exe', '<image_dir>/perl/bin/glpi-agent.exe' ] },
245+
{ do=>'copydir', args=>[ 'lib/GLPI', '<image_dir>/perl/agent/GLPI' ] },
246+
{ do=>'copydir', args=>[ 'lib/GLPI', '<image_dir>/perl/agent/GLPI' ] },
247+
{ do=>'copydir', args=>[ 'etc', '<image_dir>/etc' ] },
248+
{ do=>'createdir', args=>[ '<image_dir>/etc/conf.d' ] },
249+
{ do=>'copydir', args=>[ 'bin', '<image_dir>/perl/bin' ] },
250+
{ do=>'copydir', args=>[ 'share', '<image_dir>/share' ] },
251+
{ do=>'copyfile', args=>[ 'contrib/windows/packaging/setup.pm', '<image_dir>/perl/lib' ] },
252+
],
253+
},
254+
### NEXT STEP 11 Finalize release ######################################
255+
{
256+
plugin => 'Perl::Dist::GLPI::Agent::Step::Update',
257+
},
258+
### NEXT STEP 12 Generate Portable Archive #############################
259+
{
260+
plugin => 'Perl::Dist::Strawberry::Step::OutputZIP',
261+
},
262+
### NEXT STEP 13 Generate MSI Package ##################################
263+
{
264+
plugin => 'Perl::Dist::GLPI::Agent::Step::OutputMSI',
265+
exclude => [],
266+
#BEWARE: msi_upgrade_code is a fixed value for all same arch releases (for ever)
267+
msi_upgrade_code => $arch eq 'x64' ? '0DEF72A8-E5EE-4116-97DC-753718E19CD5' : '7F25A9A4-BCAE-4C15-822D-EAFBD752CFEC',
268+
app_publisher => "Teclib'",
269+
url_about => 'https://glpi-project.org/',
270+
url_help => 'https://glpi-project.org/discussions/',
271+
msi_root_dir => 'GLPI-Agent',
272+
msi_main_icon => 'contrib/windows/packaging/glpi-agent.ico',
273+
msi_license_rtf => 'contrib/windows/packaging/gpl-2.0.rtf',
274+
msi_dialog_bmp => 'contrib/windows/packaging/GLPI-Agent_Dialog.bmp',
275+
msi_banner_bmp => 'contrib/windows/packaging/GLPI-Agent_Banner.bmp',
276+
msi_debug => 0,
277+
}
278+
],
279+
}
229280
}
230281

231282
sub _movebin {
@@ -240,8 +291,8 @@ sub _movebin {
240291
}
241292

242293
sub _movedll {
243-
my ($dll, $to) = @_;
244-
my $file = $dll.(_is64bit()?'__':'_').'.dll';
294+
my ($dll, $suffix) = @_;
295+
my $file = $dll.$suffix.'.dll';
245296
return {
246297
do => 'movefile',
247298
args => [

0 commit comments

Comments
 (0)