From c9eb50e10b2d5bada64f67259f64360d50f4dc2f Mon Sep 17 00:00:00 2001 From: u Date: Mar 22 2025 08:50:59 +0000 Subject: [PATCH 1/6] update --- diff --git a/obs-rust2rpm.py b/obs-rust2rpm.py index 38b77ee..cc4fdd4 100644 --- a/obs-rust2rpm.py +++ b/obs-rust2rpm.py @@ -1,61 +1,224 @@ #!/usr/bin/python3 - -# This file is part of obs-service-rust2rpm -# Author: Neal Gompa -# -# Fedora-License-Identifier: MIT -# SPDX-License-Identifier: MIT -# Please see LICENSE for the full details of the license terms -# -# This file is a wrapper script around rust2rpm for consumption by OBS - import argparse -import os -import pathlib -import shutil -import subprocess import sys +from os import environ + +def parse_args(args=None): + # Initialize the argument parser + parser = argparse.ArgumentParser( + description="Generate RPM packages for Rust crates" + ) + + parser.add_argument( + "--packager", + help="Packager identity (in the form of 'Name: email')", + nargs="*" + ) + + parser.add_argument( + "--name", + help="Name of crate on crates.io" + ) + + parser.add_argument( + "--version", + help="Version of crate on crates.io" + ) + + parser.add_argument( + '--pkgid', + help="Crate on crates.io, or crate@version for specific versions, or @version to auto-detect the crate name." + ) + + parser.add_argument( + '--config-file', + # default='./rust2rpm.toml', + help="Path to rust2rpm.toml config file (default: ./rust2rpm.toml)" + ) + + parser.add_argument( + '--outdir', + default='.', + help="Target directory for any created files." + ) + + parser.add_argument( + '--noop', + choices=['enable', 'disable'], + default='disable', + help="Do nothing (enable or disable)." + ) + + parser.add_argument( + '--path', + help="Path to local project directory or Cargo.toml file to check instead of crates.io." + ) + + parser.add_argument( + '--target', + choices=['fedora', 'opensuse', 'epel8', 'mageia', 'plain'], + help="Distribution target." + ) + + parser.add_argument( + '--vendor', + choices=['off', 'auto', 'manual'], + # default='off', + help="Write a spec for building with vendored dependencies (default: off)." + ) + + parser.add_argument( + '--rpmautospec', + choices=['enable', 'disable'], + default='disable', + help="Use autorelease and autochangelog features." + ) + + parser.add_argument( + '--no-rpmautospec', + choices=['enable', 'disable'], + default='disable', + help="Do not use rpmautospec." + ) + + parser.add_argument( + '--compat', + choices=['enable', 'disable'], + default='disable', + help="Create a compat package with appropriate version suffix." + ) + + parser.add_argument( + '--no-existence-check', + choices=['enable', 'disable'], + default='enable', + help="Do not check whether the package already exists in dist-git." + ) + + parser.add_argument( + '--offline', + choices=['enable', 'disable'], + default='disable', + help="Skip network queries to crates.io and/or src.fedoraproject.org." + ) + + parser.add_argument( + '--patch', + choices=['enable', 'disable'], + default='disable', + help="Do manual patching of Cargo.toml." + ) -parser = argparse.ArgumentParser(description="Generate Rust crate source package content") + parser.add_argument( + '--no-patch-foreign', + choices=['enable', 'disable'], + default='disable', + help="Do not automatically drop foreign dependencies in Cargo.toml." + ) -parser.add_argument("-n", "--name", help="Name of crate on crates.io", required=True) -parser.add_argument("-v", "--version", help="Version of crate to fetch", default=None) -parser.add_argument("-t", "--type", help="Type of distribution package (default: %(default)s)", choices=["plain", "fedora", "mageia", "opensuse"], default="opensuse") -parser.add_argument("-p", "--packager", help="Packager identity (in the form of 'Name: email')", nargs="*", default=None) -parser.add_argument("-o", "--outdir", help="Directory to generate packaging content", required=True) + parser.add_argument( + '--reuse-patch', + choices=['enable', 'disable'], + default='disable', + help="Attempt to re-apply existing Cargo.toml patch." + ) -args = parser.parse_args() + parser.add_argument( + '--store-crate', + choices=['enable', 'disable'], + default='enable', + help="Store crate in the current directory." + ) -# Then, check for rust2rpm -rust2rpm = shutil.which("rust2rpm") + parser.add_argument( + '--validate-only', + choices=['enable', 'disable'], + default='disable', + help="Validate rust2rpm.toml config file and exit." + ) -# Bomb out early if rust2rpm is missing -if rust2rpm is None: - sys.exit("Missing rust2rpm, check if it is installed.") + # Parse the arguments + args = parser.parse_args(args) + return args -# Build rust2rpm command -rust2rpm_cmd = [rust2rpm, "--no-auto-changelog-entry", "--store-crate", "--target", args.type, args.name] +dc = parse_args() -if args.version is not None: - rust2rpm_cmd += [args.version] +if dc.noop == 'enable': + sys.exit(0) -# Adjust environment for source service rust2rpm run -rust2rpm_runenv = dict(os.environ) +args = [] -if pathlib.Path("/var/cache/obs/rust2rpm").is_dir() and os.access("/var/cache/obs/rust2rpm", os.W_OK): - rust2rpm_runenv["XDG_CACHE_HOME"] = "/var/cache/obs" +if dc.pkgid: + args.append(dc.pkgid) +else: + pkgid = '' + if dc.name: + pkgid += dc.name + if dc.version + pkgid += '@' + dc.version + if pkgid: + args.append(pkgid) -if args.packager is None or args.packager == []: - rust2rpm_runenv["RUST2RPM_NO_DETECT_PACKAGER"] = "true" +if not dc.packager: + environ["RUST2RPM_NO_DETECT_PACKAGER"] = "true" else: - rust2rpm_packager = " ".join(args.packager) - if ":" not in rust2rpm_packager: - sys.exit("Packager information formatted incorrectly") - rust2rpm_packager = rust2rpm_packager.split(":") - rust2rpm_runenv["RUST2RPM_PACKAGER"] = "{} <{}>".format(rust2rpm_packager[0].strip(), rust2rpm_packager[1].strip()) - -# Run rust2rpm command -try: - subprocess.check_call(rust2rpm_cmd, cwd=args.outdir, env=rust2rpm_runenv) -except subprocess.CalledProcessError as rust2rpm_err: - sys.exit("rust2rpm failed with error code: {}".format(rust2rpm_err.returncode)) + packager = " ".join(dc.packager)) + packager_split = packager.split(":") + if len(packager_split) >= 2: + environ["RUST2RPM_PACKAGER"] = "{} <{}>".format(packager_split[0].strip(), packager_split[1].strip()) + else: + environ["RUST2RPM_PACKAGER"] = packager.strip() + +if dc.config_file: + args.extend(('--config-file', dc.config_file)) + +args.extend(('--output-directory', dc.outdir)) + +if dc.path: + args.extend(('--path', dc.path)) + +if dc.target: + args.extend(('--target', dc.target)) + +if dc.vendor: + args.extend(('--vendor', dc.vendor)) + +if dc.rpmautospec == 'enable': + args.append('--rpmautospec') + +if dc.no_rpmautospec == 'enable': + args.append('--no-rpmautospec') + +if dc.compat =='enable': + args.append('--compat') + +if dc.no_existence_check == 'enable': + args.append('--no-existence-check') + +if dc.offline == 'enable': + args.append('--offline') + +if dc.patch == 'enable': + args.append('--patch') + +if dc.no_patch_foreign == 'enable': + args.append('--no-patch-foreign') + +if dc.reuse_patch == 'enable': + args.append('--reuse-patch') + +if dc.store_crate == 'enable': + args.append('--store-crate') + +if dc.validate_only == 'enable': + args.append('--validate-only') + +import re +from rust2rpm.__main__ import main + +argv = ['rust2rpm'] +argv.extend(args) +print(argv) +sys.argv = argv +sys.exit(main()) + diff --git a/obs-rust2rpm.service b/obs-rust2rpm.service index a94cf78..bdafd96 100644 --- a/obs-rust2rpm.service +++ b/obs-rust2rpm.service @@ -1,22 +1,118 @@ - Generate RPM packaging for Rust crates - This service is simply runs rust2rpm for a given Rust crate on crates.io to generate RPM packaging to build packages for crates. - - The name of the crate. - + Use of the rust2rpm command + Generate RPM packages for Rust crates + + + + Crate on crates.io, or crate@version for specific versions, or @version to auto-detect the crate name. + - - The version of the crate, uses latest if not set. + + + + Path to rust2rpm.toml config file (default: ./rust2rpm.toml) + - - Target distribution type for packaging, defaults to 'opensuse' if not set. - plain + + + + Target directory for any created files. + + + + + + Do nothing + + enable + disable + + + + + Path to local project directory or Cargo.toml file to check instead of crates.io. + + + + + + Distribution target. + fedora - mageia opensuse + epel8 + mageia + plain - - Packager identity (in the form of 'Name: email'), uses distribution fallback if not set. + + + + Write a spec for building with vendored dependencies (default: off). + + off + auto + manual + + + + + Use autorelease and autochangelog features. + + enable + disable - + + + Do not use rpmautospec. + + + + + + Create a compat package with appropriate version suffix. + + + + + + Do not check whether the package already exists in dist-git. + + + + + + Skip network queries to crates.io and/or src.fedoraproject.org. + + + + + + Do manual patching of Cargo.toml. + + + + + + Do not automatically drop foreign dependencies in Cargo.toml. + + + + + + Attempt to re-apply existing Cargo.toml patch. + + + + + + Store crate in the current directory. + + + + + + Validate rust2rpm.toml config file and exit. + + + From 33cc7be087def908efcfcc73226364b03e54a294 Mon Sep 17 00:00:00 2001 From: u Date: Mar 22 2025 08:53:21 +0000 Subject: [PATCH 2/6] update --- diff --git a/obs-rust2rpm.py b/obs-rust2rpm.py index cc4fdd4..49ed99a 100644 --- a/obs-rust2rpm.py +++ b/obs-rust2rpm.py @@ -1,4 +1,14 @@ #!/usr/bin/python3 + +# This file is part of obs-service-rust2rpm +# Author: Neal Gompa +# +# Fedora-License-Identifier: MIT +# SPDX-License-Identifier: MIT +# Please see LICENSE for the full details of the license terms +# +# This file is a wrapper script around rust2rpm for consumption by OBS + import argparse import sys from os import environ From 1a2b3c2842e0127c17b8c4f05a58b3fa98ca528f Mon Sep 17 00:00:00 2001 From: u Date: Mar 22 2025 08:58:03 +0000 Subject: [PATCH 3/6] update --- diff --git a/obs-rust2rpm.service b/obs-rust2rpm.service index bdafd96..eaadc60 100644 --- a/obs-rust2rpm.service +++ b/obs-rust2rpm.service @@ -8,6 +8,24 @@ + + + The name of the crate. + + + + + + The version of the crate, uses latest if not set. + + + + + + Packager identity (in the form of 'Name: email'), uses distribution fallback if not set. + + + Path to rust2rpm.toml config file (default: ./rust2rpm.toml) From 432b507300d6171f614216bd39b5551fe1b7a1c2 Mon Sep 17 00:00:00 2001 From: u Date: Mar 22 2025 09:00:34 +0000 Subject: [PATCH 4/6] update --- diff --git a/obs-rust2rpm.py b/obs-rust2rpm.py index 49ed99a..54cd685 100644 --- a/obs-rust2rpm.py +++ b/obs-rust2rpm.py @@ -65,7 +65,7 @@ def parse_args(args=None): ) parser.add_argument( - '--target', + '--type', choices=['fedora', 'opensuse', 'epel8', 'mageia', 'plain'], help="Distribution target." ) @@ -187,8 +187,8 @@ args.extend(('--output-directory', dc.outdir)) if dc.path: args.extend(('--path', dc.path)) -if dc.target: - args.extend(('--target', dc.target)) +if dc.type: + args.extend(('--target', dc.type)) if dc.vendor: args.extend(('--vendor', dc.vendor)) diff --git a/obs-rust2rpm.service b/obs-rust2rpm.service index eaadc60..6a8383c 100644 --- a/obs-rust2rpm.service +++ b/obs-rust2rpm.service @@ -52,7 +52,7 @@ - + Distribution target. From 707875e5da0f03f766020ebb7f36cc07b32c8cd2 Mon Sep 17 00:00:00 2001 From: u Date: Mar 22 2025 09:02:44 +0000 Subject: [PATCH 5/6] update --- diff --git a/obs-rust2rpm.py b/obs-rust2rpm.py index 54cd685..542779f 100644 --- a/obs-rust2rpm.py +++ b/obs-rust2rpm.py @@ -20,18 +20,18 @@ def parse_args(args=None): ) parser.add_argument( - "--packager", + "-p", "--packager", help="Packager identity (in the form of 'Name: email')", nargs="*" ) parser.add_argument( - "--name", + "-n", "--name", help="Name of crate on crates.io" ) parser.add_argument( - "--version", + "-v", "--version", help="Version of crate on crates.io" ) @@ -47,7 +47,7 @@ def parse_args(args=None): ) parser.add_argument( - '--outdir', + "-o", '--outdir', default='.', help="Target directory for any created files." ) @@ -65,7 +65,7 @@ def parse_args(args=None): ) parser.add_argument( - '--type', + "-t", '--type', choices=['fedora', 'opensuse', 'epel8', 'mageia', 'plain'], help="Distribution target." ) From c03d661e99ad561173fe652192796f9a92ca2a30 Mon Sep 17 00:00:00 2001 From: u Date: Mar 22 2025 09:29:34 +0000 Subject: [PATCH 6/6] update --- diff --git a/obs-rust2rpm.py b/obs-rust2rpm.py index 542779f..ae9311b 100644 --- a/obs-rust2rpm.py +++ b/obs-rust2rpm.py @@ -164,7 +164,7 @@ else: pkgid = '' if dc.name: pkgid += dc.name - if dc.version + if dc.version: pkgid += '@' + dc.version if pkgid: args.append(pkgid) @@ -172,7 +172,7 @@ else: if not dc.packager: environ["RUST2RPM_NO_DETECT_PACKAGER"] = "true" else: - packager = " ".join(dc.packager)) + packager = " ".join(dc.packager) packager_split = packager.split(":") if len(packager_split) >= 2: environ["RUST2RPM_PACKAGER"] = "{} <{}>".format(packager_split[0].strip(), packager_split[1].strip())