summaryrefslogtreecommitdiffstats
path: root/src/debputy/lsp/lsp_debian_control.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/debputy/lsp/lsp_debian_control.py')
-rw-r--r--src/debputy/lsp/lsp_debian_control.py39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/debputy/lsp/lsp_debian_control.py b/src/debputy/lsp/lsp_debian_control.py
index 370a14f..e91a43e 100644
--- a/src/debputy/lsp/lsp_debian_control.py
+++ b/src/debputy/lsp/lsp_debian_control.py
@@ -959,7 +959,7 @@ def _lint_debian_control(
def _package_range_of_stanza(
lint_state: LintState,
binary_stanzas: List[Tuple[Deb822ParagraphElement, TEPosition]],
-) -> Iterable[Tuple[str, Range]]:
+) -> Iterable[Tuple[str, Optional[str], Range]]:
for stanza, stanza_position in binary_stanzas:
kvpair = stanza.get_kvpair_element("Package")
if kvpair is None:
@@ -971,7 +971,7 @@ def _package_range_of_stanza(
lint_state.lines,
te_range_to_lsp(representation_field_range),
)
- yield stanza["Package"], representation_field_range
+ yield stanza["Package"], stanza.get("Architecture"), representation_field_range
def _detect_misspelled_packaging_files(
@@ -989,7 +989,8 @@ def _detect_misspelled_packaging_files(
debian_dir,
)
stanza_ranges = {
- p: r for p, r in _package_range_of_stanza(lint_state, binary_stanzas_w_pos)
+ p: (a, r)
+ for p, a, r in _package_range_of_stanza(lint_state, binary_stanzas_w_pos)
}
for pkg_file_data in all_pkg_file_data:
@@ -999,13 +1000,15 @@ def _detect_misspelled_packaging_files(
stem = pkg_file_data.get("pkgfile-stem")
if binary_package is None or stem is None:
continue
- diag_range = stanza_ranges.get(binary_package)
+ declared_arch, diag_range = stanza_ranges.get(binary_package)
if diag_range is None:
continue
-
path = pkg_file_data["path"]
likely_typo_of = pkg_file_data.get("likely-typo-of")
+ arch_restriction = pkg_file_data.get("pkgfile-architecture-restriction")
if likely_typo_of is not None:
+ # Handles arch_restriction == 'all' at the same time due to how
+ # the `likely-typo-of` is created
diagnostics.append(
Diagnostic(
diag_range,
@@ -1018,6 +1021,31 @@ def _detect_misspelled_packaging_files(
)
)
continue
+ if declared_arch == "all" and arch_restriction is not None:
+ diagnostics.append(
+ Diagnostic(
+ diag_range,
+ f'The file "{path}" has an architecture restriction but is for an `arch:all` package, so'
+ f" the restriction does not make sense.",
+ severity=DiagnosticSeverity.Warning,
+ source="debputy",
+ data=DiagnosticData(
+ report_for_related_file=path,
+ ),
+ )
+ )
+ elif arch_restriction == "all":
+ diagnostics.append(
+ Diagnostic(
+ diag_range,
+ f'The file "{path}" has an architecture restriction of `all` rather than a real architecture',
+ severity=DiagnosticSeverity.Warning,
+ source="debputy",
+ data=DiagnosticData(
+ report_for_related_file=path,
+ ),
+ )
+ )
if not pkg_file_data.get("pkgfile-is-active-in-build", True):
diagnostics.append(
@@ -1037,7 +1065,6 @@ def _detect_misspelled_packaging_files(
if not explicit_package and name_segment is not None:
basename = os.path.basename(path)
alt_name = f"{binary_package}.{stem}"
- arch_restriction = pkg_file_data.get("pkgfile-architecture-restriction")
if arch_restriction is not None:
alt_name = f"{alt_name}.{arch_restriction}"
diagnostics.append(