From 2ca8bcbc63782fd0b70de15e4207b3c474a2fd00 Mon Sep 17 00:00:00 2001 From: espie Date: Sun, 11 Sep 2022 08:40:40 +0000 Subject: [PATCH] refactor by adding an extra "factory" class in order not to overload things horribly. No actual functional change --- infrastructure/bin/build-debug-info | 13 ++--- infrastructure/bin/update-plist | 4 +- infrastructure/lib/OpenBSD/BasePlistReader.pm | 21 +++++++- .../lib/OpenBSD/UpdatePlistReader.pm | 52 +++++++++++-------- 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/infrastructure/bin/build-debug-info b/infrastructure/bin/build-debug-info index 965e1b05cc6..c1e1acb901b 100755 --- a/infrastructure/bin/build-debug-info +++ b/infrastructure/bin/build-debug-info @@ -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 # # 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}; diff --git a/infrastructure/bin/update-plist b/infrastructure/bin/update-plist index 7224f8d6c5b..b9f0fe82a8d 100755 --- a/infrastructure/bin/update-plist +++ b/infrastructure/bin/update-plist @@ -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 # # 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; diff --git a/infrastructure/lib/OpenBSD/BasePlistReader.pm b/infrastructure/lib/OpenBSD/BasePlistReader.pm index ca94263de62..d4c1215e89f 100644 --- a/infrastructure/lib/OpenBSD/BasePlistReader.pm +++ b/infrastructure/lib/OpenBSD/BasePlistReader.pm @@ -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 # # 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; diff --git a/infrastructure/lib/OpenBSD/UpdatePlistReader.pm b/infrastructure/lib/OpenBSD/UpdatePlistReader.pm index d2d1d66762f..e9e10e2ed8f 100644 --- a/infrastructure/lib/OpenBSD/UpdatePlistReader.pm +++ b/infrastructure/lib/OpenBSD/UpdatePlistReader.pm @@ -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 # # 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) = @_;