summaryrefslogtreecommitdiffstats
path: root/scripts/Dpkg/Substvars.pm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/Dpkg/Substvars.pm34
1 files changed, 27 insertions, 7 deletions
diff --git a/scripts/Dpkg/Substvars.pm b/scripts/Dpkg/Substvars.pm
index cf55194..7150c30 100644
--- a/scripts/Dpkg/Substvars.pm
+++ b/scripts/Dpkg/Substvars.pm
@@ -1,4 +1,4 @@
-# Copyright © 2006-2009, 2012-2020, 2022 Guillem Jover <guillem@debian.org>
+# Copyright © 2006-2024 Guillem Jover <guillem@debian.org>
# Copyright © 2007-2010 Raphaël Hertzog <hertzog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@ It provides a class which is able to substitute variables in strings.
=cut
-package Dpkg::Substvars 2.01;
+package Dpkg::Substvars 2.02;
use strict;
use warnings;
@@ -48,6 +48,7 @@ use constant {
SUBSTVAR_ATTR_AGED => 4,
SUBSTVAR_ATTR_OPT => 8,
SUBSTVAR_ATTR_DEEP => 16,
+ SUBSTVAR_ATTR_REQ => 32,
};
=head1 METHODS
@@ -190,13 +191,14 @@ sub parse {
next if m/^\s*\#/ || !m/\S/;
s/\s*\n$//;
- if (! m/^(\w[-:0-9A-Za-z]*)(\?)?\=(.*)$/) {
+ if (! m/^(\w[-:0-9A-Za-z]*)([?!])?\=(.*)$/) {
error(g_('bad line in substvars file %s at line %d'),
$varlistfile, $.);
}
## no critic (RegularExpressions::ProhibitCaptureWithoutTest)
if (defined $2) {
$attr = (SUBSTVAR_ATTR_USED | SUBSTVAR_ATTR_OPT) if $2 eq '?';
+ $attr = (SUBSTVAR_ATTR_REQ) if $2 eq '!';
}
$self->set($1, $3, $attr);
$count++;
@@ -378,9 +380,16 @@ sub warn_about_unused {
# that they are not required in the current situation
# (example: debhelper's misc:Depends in many cases)
next if $self->{vars}{$vn} eq '';
- warning($opts{msg_prefix} .
- g_('substitution variable ${%s} unused, but is defined'),
- $vn);
+
+ if ($self->{attr}{$vn} & SUBSTVAR_ATTR_REQ) {
+ error($opts{msg_prefix} .
+ g_('required substitution variable ${%s} not used'),
+ $vn);
+ } else {
+ warning($opts{msg_prefix} .
+ g_('substitution variable ${%s} unused, but is defined'),
+ $vn);
+ }
}
}
@@ -434,7 +443,14 @@ sub output {
# Store all non-automatic substitutions only
foreach my $vn (sort keys %{$self->{vars}}) {
next if $self->{attr}{$vn} & SUBSTVAR_ATTR_AUTO;
- my $op = $self->{attr}{$vn} & SUBSTVAR_ATTR_OPT ? '?=' : '=';
+ my $op;
+ if ($self->{attr}{$vn} & SUBSTVAR_ATTR_OPT) {
+ $op = '?=';
+ } elsif ($self->{attr}{$vn} & SUBSTVAR_ATTR_REQ) {
+ $op = '!=';
+ } else {
+ $op = '=';
+ }
my $line = "$vn$op" . $self->{vars}{$vn} . "\n";
print { $fh } $line if defined $fh;
$str .= $line;
@@ -451,6 +467,10 @@ indicated file.
=head1 CHANGES
+=head2 Version 2.02 (dpkg 1.22.7)
+
+New feature: Add support for required substitution variables.
+
=head2 Version 2.01 (dpkg 1.21.8)
New feature: Add support for optional substitution variables.