refactor by adding an extra "factory" class in order not to overload

things horribly. No actual functional change
This commit is contained in:
espie 2022-09-11 08:40:40 +00:00
parent 17d7eeb3df
commit 2ca8bcbc63
4 changed files with 55 additions and 35 deletions

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: build-debug-info,v 1.45 2022/09/11 08:03:08 espie Exp $
# $OpenBSD: build-debug-info,v 1.46 2022/09/11 08:40:40 espie Exp $
# Copyright (c) 2019 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
@ -26,10 +26,8 @@ use lib "$ports1/infrastructure/lib";
use OpenBSD::BaseFS;
use OpenBSD::BasePlistReader;
# PlistReader is "just" a specialized version of PkgCreate algorithm
# that does mimic what PkgCreate reader does with a few specialized methods
package PlistReader;
our @ISA = qw(OpenBSD::BasePlistReader);
package PlistFactory;
our @ISA = qw(OpenBSD::BasePlistFactory);
# note that contrary to update-plist, we never build the "new" plist, but
# write it on the fly (should we use nlist as well here ?)
@ -234,11 +232,11 @@ sub new
my $self = BuildDebugInfo->new;
my $state = $self->{state};
$state->{exitcode} = 0;
PlistReader->parse_args($self);
my $base = PlistFactory->parse_args($self);
use File::Basename;
$self->{mk} = $state->openfile($state->{pkgdir}."/Makefile.new");
print {$self->{mk}} << 'EOPREAMBLE';
# Makefile generated by build-debug-info $OpenBSD: build-debug-info,v 1.45 2022/09/11 08:03:08 espie Exp $
# Makefile generated by build-debug-info $OpenBSD: build-debug-info,v 1.46 2022/09/11 08:40:40 espie Exp $
# No serviceable parts
# Intended to run under the stage area after cd ${WRKINST}
@ -270,7 +268,6 @@ EOPREAMBLE
$self->{linkstash} = {};
$self->{ostash} = {};
for my $l (@{$self->{lists}}) {
my $base = $l->{state}{base};
$self->{empty} = 1;
$self->{dirstash} = {};
$self->{prefix} = $base."/".$l->{state}{prefix};

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: update-plist,v 1.210 2022/09/11 08:28:21 espie Exp $
# $OpenBSD: update-plist,v 1.211 2022/09/11 08:40:40 espie Exp $
# Copyright (c) 2018 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
@ -1427,7 +1427,7 @@ sub try_pkglocate
}
my $self = UpdatePlist->new;
my $base = OpenBSD::UpdatePlistReader->parse_args($self);
my $base = OpenBSD::UpdatePlistFactory->parse_args($self);
$self->known_objects;
$self->scan_fake_dir($base);
$self->zap_debug_files;

View File

@ -1,4 +1,4 @@
# $OpenBSD: BasePlistReader.pm,v 1.2 2022/09/11 08:27:21 espie Exp $
# $OpenBSD: BasePlistReader.pm,v 1.3 2022/09/11 08:40:41 espie Exp $
# Copyright (c) 2019 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
@ -19,6 +19,9 @@
# - handling debug names mogrification
use OpenBSD::PkgCreate;
# PlistReader is "just" a specialized version of the PkgCreate algorithm
# which does mimic what PkgCreate reader does with a few specialized methods
package OpenBSD::BasePlistReader;
our @ISA = qw(OpenBSD::PkgCreate);
@ -34,11 +37,25 @@ sub olist
return $self->{olist};
}
# ... and since we will scan several plists, we build each of them through
# a factory that will repeatedly parse args and scan
package OpenBSD::BasePlistFactory;
sub stateclass
{
return 'OpenBSD::BasePlistReader::State';
}
sub readerclass
{
return 'OpenBSD::BasePlistReader';
}
sub process_next_subpackage
{
my ($self, $o) = @_;
my $r = ref($self)->new;
my $r = $self->readerclass->new;
my $s = $self->stateclass->new($self->command_name, $o->{state});
$r->{state} = $s;

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: UpdatePlistReader.pm,v 1.3 2022/03/07 08:57:10 espie Exp $
# $OpenBSD: UpdatePlistReader.pm,v 1.4 2022/09/11 08:40:41 espie Exp $
# Copyright (c) 2018-2022 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
@ -20,38 +20,23 @@ use warnings;
use OpenBSD::BasePlistReader;
use OpenBSD::ReverseSubst;
# UpdatePlistReader is "just" a specialized version of PkgCreate algorithm
# that does mimic what PkgCreate reader does with a few specialized methods
package OpenBSD::UpdatePlistReader;
our @ISA = qw(OpenBSD::BasePlistReader);
use File::Path qw(make_path);
use File::Basename;
sub new
{
my $class = shift;
my $o = $class->SUPER::new;
$o->{nlist} = OpenBSD::PackingList->new;
return $o;
}
package OpenBSD::UpdatePlistFactory;
our @ISA = qw(OpenBSD::BasePlistFactory);
sub stateclass
{
return 'OpenBSD::UpdatePlistReader::State';
}
sub readerclass
{
return 'OpenBSD::UpdatePlistReader';
}
sub command_name
{
return 'update-plist';
}
sub nlist
{
my $self = shift;
return $self->{nlist};
}
sub process_next_subpackage
{
my ($class, $o) = @_;
@ -69,6 +54,27 @@ sub process_next_subpackage
$r->add_extra_info($r->olist, $r->{state});
}
package OpenBSD::UpdatePlistReader;
our @ISA = qw(OpenBSD::BasePlistReader);
use File::Path qw(make_path);
use File::Basename;
sub new
{
my $class = shift;
my $o = $class->SUPER::new;
$o->{nlist} = OpenBSD::PackingList->new;
return $o;
}
sub nlist
{
my $self = shift;
return $self->{nlist};
}
sub strip_prefix
{
my ($self, $path) = @_;