[SCM] Debian package checker branch, master, updated. 2.5.14-46-g6a63aed
The following commit has been merged in the master branch:
commit 6a63aed026ed5a2e3bb34875de810a56e129b225
Author: Niels Thykier <niels@thykier.net>
Date: Sat Jul 6 12:17:55 2013 +0200
L::Util: Give detailed line information from dctrl files
Change parse_dpkg_control and visit_dpkg_control to use a hashref
instead of a single integer for line number information. The hashref
records the line number of each field individually as well as the line
number of the first field (via the "START-OF-PARAGRAPH" key).
Updated c/source-copyright.pm to cope with this change and use more
precise line numbers where possible.
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/checks/source-copyright.pm b/checks/source-copyright.pm
index 5be124d..2c5025c 100644
--- a/checks/source-copyright.pm
+++ b/checks/source-copyright.pm
@@ -158,25 +158,28 @@ if (@dep5) {
for my $field (keys %{$first_para}) {
my $renamed_to = $dep5_renamed_fields{$field};
if (defined $renamed_to) {
- tag 'obsolete-field-in-dep5-copyright', $field, $renamed_to, "(paragraph at line $lines[0])";
+ tag 'obsolete-field-in-dep5-copyright', $field,
+ $renamed_to, "(line $lines[0]{$field})";
}
}
if (not defined $first_para->{'format'} and not defined $first_para->{'format-specification'}) {
- tag 'missing-field-in-dep5-copyright', 'format', "(paragraph at line $lines[0])";
+ tag 'missing-field-in-dep5-copyright', 'format',
+ "(line $lines[0]{'format'})";
}
for my $license (split_licenses($first_para->{'license'})) {
$required_standalone_licenses{$license} = 1;
}
- my $commas_in_files = 0;
+ my @commas_in_files;
my $i = 0;
for my $para (@dep5) {
$i++;
+ my ($files_fname, $files) = get_field($para, 'files', $lines[$i]);
my $license = get_field ($para, 'license', $lines[$i]);
- my $files = get_field ($para, 'files', $lines[$i]);
my $copyright = get_field ($para, 'copyright', $lines[$i]);
if (not defined $files and defined $license and defined $copyright) {
- tag 'ambiguous-paragraph-in-dep5-copyright', "paragraph at line $lines[$i]";
+ tag 'ambiguous-paragraph-in-dep5-copyright',
+ "paragraph at line $lines[$i]{'START-OF-PARAGRAPH'}";
# If it is the first paragraph, it might be an instance of
# the (no-longer) optional "first Files-field".
$files = '*' if $i == 1;
@@ -185,7 +188,9 @@ if (@dep5) {
if (defined $license and not defined $files) {
# Standalone license paragraph
if (not $license =~ m/\n/) {
- tag 'missing-license-text-in-dep5-copyright', lc $license, "(paragraph at line $lines[$i])";
+ tag 'missing-license-text-in-dep5-copyright',
+ lc $license,
+ "(paragraph at line $lines[$i]{'START-OF-PARAGRAPH'})";
}
($license, undef) = split /\n/, $license, 2;
for (split_licenses($license)) {
@@ -194,35 +199,45 @@ if (@dep5) {
}
elsif (defined $files) {
# Files paragraph
- $commas_in_files = $i if not $commas_in_files and $files =~ /,/;
+ if (not @commas_in_files and $files =~ /,/) {
+ @commas_in_files = ($i, $files_fname);
+ }
if (defined $license) {
for (split_licenses($license)) {
$required_standalone_licenses{$_} = $i;
}
}
else {
- tag 'missing-field-in-dep5-copyright', "license (paragraph at line $lines[$i])";
+ tag 'missing-field-in-dep5-copyright', 'license',
+ "(paragraph at line $lines[$i]{'START-OF-PARAGRAPH'})";
}
if (not defined $copyright) {
- tag 'missing-field-in-dep5-copyright', "copyright (paragraph at line $lines[$i])";
+ tag 'missing-field-in-dep5-copyright', 'copyright',
+ "(paragraph at line $lines[$i]{'START-OF-PARAGRAPH'})";
}
}
else {
- tag 'unknown-paragraph-in-dep5-copyright', 'paragraph at line', $lines[$i];
+ tag 'unknown-paragraph-in-dep5-copyright', 'paragraph at line',
+ $lines[$i]{'START-OF-PARAGRAPH'};
}
}
- if ($commas_in_files) {
- tag 'comma-separated-files-in-dep5-copyright', 'paragraph at line', $lines[$commas_in_files]
- unless any {m/,/} $info->sorted_index;
+ if (@commas_in_files) {
+ my ($paragraph_no, $field_name) = @commas_in_files;
+ if (not any { m/,/xsm } $info->sorted_index) {
+ tag 'comma-separated-files-in-dep5-copyright', 'paragraph at line',
+ $lines[$paragraph_no]{$field_name};
+ }
}
while ((my $license, $i) = each %required_standalone_licenses) {
if (not defined $standalone_licenses{$license}) {
- tag 'missing-license-paragraph-in-dep5-copyright', $license, "(paragraph at line $lines[$i])";
+ tag 'missing-license-paragraph-in-dep5-copyright', $license,
+ "(paragraph at line $lines[$i]{'START-OF-PARAGRAPH'})";
}
}
while ((my $license, $i) = each %standalone_licenses) {
if (not defined $required_standalone_licenses{$license}) {
- tag 'unused-license-paragraph-in-dep5-copyright', $license, "(paragraph at line $lines[$i])";
+ tag 'unused-license-paragraph-in-dep5-copyright', $license,
+ "(paragraph at line $lines[$i]{'START-OF-PARAGRAPH'})";
}
}
}
@@ -240,12 +255,17 @@ sub split_licenses {
sub get_field {
my ($para, $field, $line) = @_;
- return $para->{$field} if exists $para->{$field};
+ if (exists $para->{$field}) {
+ return $para->{$field} unless wantarray;
+ return ($field, $para->{$field});
+ }
# Fall back to a "likely misspelling" of the field.
foreach my $f (sort keys %$para) {
if (distance ($field, $f) < 3) {
- tag 'field-name-typo-in-dep5-copyright', $f, '->', $field, "(paragraph at line $line)";
- return $para->{$f};
+ tag 'field-name-typo-in-dep5-copyright', $f, '->', $field,
+ "(line $line->{$f})";
+ return $para->{$f} unless wantarray;
+ return ($f, $para->{$f});
}
}
return;
diff --git a/debian/changelog b/debian/changelog
index db47900..c171c5d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -20,6 +20,9 @@ lintian (2.5.15) UNRELEASED; urgency=low
+ [NT] Apply patch from Bastien Roucariès to test for
manpages named after their build path.
(Closes: #713884)
+ * checks/source-copyright.pm:
+ + [NT] Some tags now refer to the line number of the field
+ with an issue instead of the line number of the paragraph.
* checks/systemd.{desc,pm}:
+ [NT] New check for systemd related files. Thanks to
Michael Stapelberg for providing the check and the
@@ -72,6 +75,10 @@ lintian (2.5.15) UNRELEASED; urgency=low
was passed on the command line before the .changes file.
Thanks to Salvo Tomaselli for reporting the bug.
(Closes: #714437)
+ * lib/Lintian/Util.pm:
+ + [NT] Have parse_dpkg_control and visit_dpkg_control
+ give a more detailed line number information about
+ paragraphs.
* reporting/harness:
+ [NT] Clear some variables before running Lintian in the
diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index f1945c5..3b94b8d 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -213,9 +213,12 @@ refer to L</CONSTANTS> for the list of constants and their meaning.
The default value for FLAGS is 0.
If LINES is given, it should be a reference to an empty list. On
-return, LINES will be populated to the line numbers where a given
-paragraph "started" (i.e. the line number of first field in the
-paragraph).
+return, LINES will be populated with a hashref for each paragraph (in
+the same order as the returned list). Each hashref will also have a
+special key "I<START-OF-PARAGRAPH>" that gives the line number of the
+first field in that paragraph. These hashrefs will map the field name
+of the given paragraph to the line number where the field name
+appeared.
This is a convenience sub around L</visit_dpkg_paragraph> and can
therefore produce the same errors as it. Please see
@@ -275,12 +278,13 @@ invoked as the following:
=over 4
-=item CODE->(PARA, STARTLINE)
+=item CODE->(PARA, LINE_NUMBERS)
The first argument, PARA, is a hashref to the most recent paragraph
-parsed. The second argument, STARTLINE, is the line number where the
-paragraph "started" (i.e. the line number of first field in the
-paragraph).
+parsed. The second argument, LINE_NUMBERS, is a hashref mapping each
+of the field names to the line number where the field name appeared.
+LINE_NUMBERS will also have a special key "I<START-OF-PARAGRAPH>" that
+gives the line number of the first field in that paragraph.
The return value of CODE is ignored.
@@ -370,7 +374,7 @@ present.
sub visit_dpkg_paragraph {
my ($code, $CONTROL, $flags) = @_;
$flags//=0;
- my $sline = -1;
+ my $lines = {};
my $section = {};
my $open_section = 0;
my $last_tag;
@@ -391,8 +395,9 @@ sub visit_dpkg_paragraph {
if ((!$debconf && m/^\s*$/) or ($debconf && $_ eq '')) {
if ($open_section) { # end of current section
# pass the current section to the handler
- $code->($section, $sline);
+ $code->($section, $lines);
$section = {};
+ $lines = {};
$open_section = 0;
}
}
@@ -448,7 +453,7 @@ sub visit_dpkg_paragraph {
die "syntax error at line $.: Expected at most one signed message" .
" (previous at line $signed)\n"
}
- if ($sline > -1) {
+ if ($last_tag) {
# NB: If you remove this, keep in mind that it may allow two paragraphs to
# merge. Consider:
#
@@ -493,17 +498,18 @@ sub visit_dpkg_paragraph {
}
# new empty field?
elsif (m/^([^: \t]+):\s*$/o) {
- $sline = $. if not $open_section;
+ $lines->{'START-OF-PARAGRAPH'} = $. if not $open_section;
$open_section = 1;
my ($tag) = (lc $1);
$section->{$tag} = '';
+ $lines->{$tag} = $.;
$last_tag = $tag;
}
# new field?
elsif (m/^([^: \t]+):\s*(.*)$/o) {
- $sline = $. if not $open_section;
+ $lines->{'START-OF-PARAGRAPH'} = $. if not $open_section;
$open_section = 1;
# Policy: Horizontal whitespace (spaces and tabs) may occur
@@ -516,6 +522,7 @@ sub visit_dpkg_paragraph {
die "syntax error at line $.: Duplicate field $tag.\n";
}
$section->{$tag} = $value;
+ $lines->{$tag} = $.;
$last_tag = $tag;
}
@@ -544,7 +551,7 @@ sub visit_dpkg_paragraph {
}
}
# pass the last section (if not already done).
- $code->($section, $sline) if $open_section;
+ $code->($section, $lines) if $open_section;
# Given the API, we cannot use this check to prevent any paragraphs from being
# emitted to the code argument, so we might as well just do this last.
diff --git a/t/tests/source-copyright-dep5-general/tags b/t/tests/source-copyright-dep5-general/tags
index 1b4962e..25c4b4a 100644
--- a/t/tests/source-copyright-dep5-general/tags
+++ b/t/tests/source-copyright-dep5-general/tags
@@ -7,5 +7,5 @@ W: source-copyright-dep5-general source: missing-field-in-dep5-copyright license
W: source-copyright-dep5-general source: missing-license-paragraph-in-dep5-copyright mit (paragraph at line 18)
W: source-copyright-dep5-general source: missing-license-text-in-dep5-copyright bsd-3 (paragraph at line 22)
W: source-copyright-dep5-general source: missing-license-text-in-dep5-copyright gpl-3 (paragraph at line 42)
-W: source-copyright-dep5-general source: obsolete-field-in-dep5-copyright upstream-maintainer upstream-contact (paragraph at line 1)
+W: source-copyright-dep5-general source: obsolete-field-in-dep5-copyright upstream-maintainer upstream-contact (line 3)
W: source-copyright-dep5-general source: unknown-paragraph-in-dep5-copyright paragraph at line 6
diff --git a/t/tests/source-copyright-typo-field/tags b/t/tests/source-copyright-typo-field/tags
index 14dae3a..28dde53 100644
--- a/t/tests/source-copyright-typo-field/tags
+++ b/t/tests/source-copyright-typo-field/tags
@@ -1,3 +1,3 @@
-W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright copyrigth -> copyright (paragraph at line 6)
-W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright file -> files (paragraph at line 6)
-W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright licens -> license (paragraph at line 6)
+W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright copyrigth -> copyright (line 7)
+W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright file -> files (line 6)
+W: source-copyright-typo-field source: field-name-typo-in-dep5-copyright licens -> license (line 8)
--
Debian package checker
Reply to: