fold some of the common logic in write_rule

- do the dir check late, so we don't create .debug dirs if not needed.
- add an emptyness check, so that we can warn if we produce an empty
debug package, and advise to tweak DEBUG_PACKAGES manually if there are
several subpackages involved
This commit is contained in:
espie 2019-12-13 10:17:44 +00:00
parent 353a9aa5c7
commit d8154adcb8

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl #! /usr/bin/perl
# $OpenBSD: build-debug-info,v 1.30 2019/12/13 10:01:55 espie Exp $ # $OpenBSD: build-debug-info,v 1.31 2019/12/13 10:17:44 espie Exp $
# Copyright (c) 2019 Marc Espie <espie@openbsd.org> # Copyright (c) 2019 Marc Espie <espie@openbsd.org>
# #
# Permission to use, copy, modify, and distribute this software for any # Permission to use, copy, modify, and distribute this software for any
@ -108,10 +108,6 @@ sub write_debug_info
my $dbg = $self->mogrify($s); my $dbg = $self->mogrify($s);
my $dir = $dbg; my $dir = $dbg;
$dir =~ s/(\/\.debug\/)[^\/]+/$1/; $dir =~ s/(\/\.debug\/)[^\/]+/$1/;
if (!exists $o->{dirstash}{$dir}) {
print $fh $dir, "\n";
$o->{dirstash}{$dir} = 1;
}
my $path = $self->fullname; my $path = $self->fullname;
if (-l $path) { if (-l $path) {
# turns out we don't need to do anything, egdb follows symlinks # turns out we don't need to do anything, egdb follows symlinks
@ -122,9 +118,8 @@ sub write_debug_info
my $l = $o->{linkstash}{$k}; my $l = $o->{linkstash}{$k};
if (!defined $l) { if (!defined $l) {
$o->{linkstash}{$k} = $dbg; $o->{linkstash}{$k} = $dbg;
print $fh $dbg, "\n"; $self->write_rule($o, $fh, $s, $dbg, $dir,
$self->write_rule($o->{mk}, $s, $dbg, "OBJCOPY_RULE"); "OBJCOPY_RULE");
$o->{ostash}{$dbg} = 1;
return; return;
} }
my $ldir = dirname($l)."/"; my $ldir = dirname($l)."/";
@ -140,9 +135,7 @@ sub write_debug_info
# TODO missing checks to be certain there's no ambiguity, just # TODO missing checks to be certain there's no ambiguity, just
# need to write an actual example and verify I can detect it. # need to write an actual example and verify I can detect it.
return if exists $o->{ostash}{$n}; return if exists $o->{ostash}{$n};
print $fh $n, "\n"; $self->write_rule($o, $fh, $l, $n, $dir, "LINK_RULE");
$self->write_rule($o->{mk}, $l, $n, "LINK_RULE");
$o->{ostash}{$n} = 1;
} else { } else {
$o->{state}->fatal("Error: #1 does not exist", $path); $o->{state}->fatal("Error: #1 does not exist", $path);
} }
@ -150,10 +143,18 @@ sub write_debug_info
sub write_rule sub write_rule
{ {
my ($self, $mk, $s, $dbg, $what) = @_; my ($self, $o, $fh, $s, $dbg, $dir, $what) = @_;
if (!exists $o->{dirstash}{$dir}) {
print $fh $dir, "\n";
$o->{dirstash}{$dir} = 1;
}
print $fh $dbg, "\n";
my $mk = $o->{mk};
print $mk "all: $dbg\n"; print $mk "all: $dbg\n";
print $mk "$dbg: $s\n"; print $mk "$dbg: $s\n";
print $mk "\t\@\$\{$what\}\n\n"; print $mk "\t\@\$\{$what\}\n\n";
$o->{ostash}{$dbg} = 1;
delete $o->{empty};
} }
sub mogrify sub mogrify
@ -228,7 +229,7 @@ PlistReader->parse_args($self);
use File::Basename; use File::Basename;
$self->{mk} = $state->openfile($state->{pkgdir}."/Makefile"); $self->{mk} = $state->openfile($state->{pkgdir}."/Makefile");
print {$self->{mk}} << 'EOPREAMBLE'; print {$self->{mk}} << 'EOPREAMBLE';
# Makefile generated by build-debug-info $OpenBSD: build-debug-info,v 1.30 2019/12/13 10:01:55 espie Exp $ # Makefile generated by build-debug-info $OpenBSD: build-debug-info,v 1.31 2019/12/13 10:17:44 espie Exp $
# No serviceable parts # No serviceable parts
# Intended to run under the stage area after cd ${WRKINST} # Intended to run under the stage area after cd ${WRKINST}
@ -257,6 +258,7 @@ EOPREAMBLE
$self->{linkstash} = {}; $self->{linkstash} = {};
$self->{ostash} = {}; $self->{ostash} = {};
for my $l (@{$self->{lists}}) { for my $l (@{$self->{lists}}) {
$self->{empty} = 1;
$self->{dirstash} = {}; $self->{dirstash} = {};
$self->{destdir} = $l->{state}{base}; $self->{destdir} = $l->{state}{base};
my $name = pop @{$l->{base_plists}}; my $name = pop @{$l->{base_plists}};
@ -265,8 +267,17 @@ for my $l (@{$self->{lists}}) {
$self->{first_cwd} = 1; $self->{first_cwd} = 1;
$l->olist->write_debug_info($fh, $self); $l->olist->write_debug_info($fh, $self);
close($fh) or $state->fatal("Can't write plist: #1", $!); close($fh) or $state->fatal("Can't write plist: #1", $!);
$self->warn_if_empty($state, $l);
} }
close($self->{mk}) or $state->fatal("Can't close Makefile: #1", $!); close($self->{mk}) or $state->fatal("Can't close Makefile: #1", $!);
sub warn_if_empty
{
my ($self, $state, $l) = @_;
$state->errsay("Warning: no debug-info in #1", $l->olist->pkgname);
return if @{$self->{lists}} == 1;
$state->errsay("Set DEBUG_PACKAGES manually ?");
}
exit($state->{exitcode}); exit($state->{exitcode});