conf: warn when extra sources or patches use conflicting numbers

This commit is contained in:
Fabio Valentini 2024-03-08 16:56:31 +01:00
parent 8b378c5b0e
commit d1d25eb684
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF

View file

@ -1,12 +1,13 @@
import os import os
import pathlib import pathlib
import sys import sys
from typing import Optional
from cargo2rpm.semver import Version from cargo2rpm.semver import Version
from rust2rpm import log from rust2rpm import log
from rust2rpm.cli import get_parser from rust2rpm.cli import get_parser
from rust2rpm.conf import load_config from rust2rpm.conf import load_config, TomlConf
from rust2rpm.crate import InvalidProjectError, InvalidVersionError, process_project from rust2rpm.crate import InvalidProjectError, InvalidVersionError, process_project
from rust2rpm.cratesio import NoVersionsError from rust2rpm.cratesio import NoVersionsError
from rust2rpm.distgit import get_package_info from rust2rpm.distgit import get_package_info
@ -23,6 +24,68 @@ from rust2rpm.utils import (
) )
def validate_extra_sources_patches(
tomlconf: TomlConf, vendor_tarball: Optional[str], patch_files: tuple[Optional[str], Optional[str]]
):
if extra_sources := tomlconf.package_extra_sources:
min_source_number = 2 if vendor_tarball else 1
for extra_source in extra_sources:
if extra_source.number == 0:
log.error(
f"Extra source {extra_source.file!r} conflicts with the primary tarball. "
f"Use a number larger than {min_source_number} instead."
)
sys.exit(1)
if extra_source.number == 1 and vendor_tarball:
log.error(
f"Extra source {extra_source.file!r} conflicts with the vendor tarball. "
f"Use a number larger than {min_source_number} instead."
)
sys.exit(1)
# no conflict now, but maybe later
if extra_source.number < 2:
log.warn(
f"Extra source {extra_source.file!r} might conflict with other files in the future. "
"Using source numbers >= 2 is recommended."
)
if extra_patches := tomlconf.package_extra_patches:
min_patch_number = 0
if patch_files[0]:
min_patch_number += 1
if patch_files[1]:
min_patch_number += 1
for extra_patch in extra_patches:
if extra_patch.number == 0 and patch_files[0]:
log.error(
f"Extra patch {extra_patch.file!r} conflicts with the automatically generated patch. "
f"Use a number larger than {min_patch_number} instead."
)
sys.exit(1)
if extra_patch.number == 0 and patch_files[1]:
log.error(
f"Extra patch {extra_patch.file!r} conflicts with the manually created patch. "
f"Use a number larger than {min_patch_number} instead."
)
sys.exit(1)
if extra_patch.number == 1 and patch_files[0] and patch_files[1]:
log.error(
f"Extra patch {extra_patch.file!r} conflicts with the manually created patch. "
f"Use a number larger than {min_patch_number} instead."
)
sys.exit(1)
# no conflict now, but maybe later
if extra_patch.number < 2:
log.warn(
f"Extra patch {extra_patch.file!r} might conflict with other patches in the future. "
"Using patch numbers >= 2 is recommended."
)
@exit_on_common_errors() @exit_on_common_errors()
def main(): def main():
parser = get_parser() parser = get_parser()
@ -121,6 +184,9 @@ def main():
else: else:
tomlconf = load_config(set(), args.target) tomlconf = load_config(set(), args.target)
# basic validation for extra sources and patches
validate_extra_sources_patches(tomlconf, vendor_tarball, patch_files)
# package for a workspace project # package for a workspace project
if metadata.is_workspace(): if metadata.is_workspace():
try: try: