#49 Add RPM generator for bundled Provides
Merged 2 years ago by gotmax23. Opened 2 years ago by gotmax23.
gotmax23/go-rpm-macros bundled_provides  into  master

@@ -0,0 +1,54 @@ 

+ #!/usr/bin/python3 -s

+ 

+ # Parse modules.txt files into rpm .spec file Provides for bundled dependencies.

+ # Written by Fabio "decathorpe" Valentini <decathorpe@fedoraproject.org> for

+ # the fedora syncthing package: https://src.fedoraproject.org/rpms/syncthing

+ # SPDX-License-Identifier: CC0-1.0 OR Unlicense

+ 

+ # Modified by @gotmax23 to be used as a dependency generator

+ # SPDX-License-Identifier: GPL-3.0-or-later

+ # SPDX-FileCopyrightText: 2022 Maxwell G <gotmax@e.email>

+ 

+ import os

+ import re

+ import sys

+ 

+ 

+ def process(path: str):

+     with open(path, encoding="utf-8") as file:

+         contents = file.read()

+ 

+     lines = contents.split("\n")

+ 

+     # dependencies = filter lines for "# package version"

+     dependencies = list(filter(lambda line: line.startswith("# "), lines))

+ 

+     # parse vendored dependencies into (import path, version) pairs

+     vendored = list()

+     # Handle => style replace directives

+     replace_regex = re.compile("^.+( v[0-9-\.]+)? => ")

+     for dep in dependencies:

+         ipath, version = replace_regex.sub("", dep[2:]).split(" ")[:2]

+ 

+         # check for git snapshots

+         if len(version) > 27:

+             # return only 7 digits of git commit hash

+             version = version[-12:-1][0:7]

+         else:

+             # strip off leading "v"

+             version = version.lstrip("v")

+ 

+         vendored.append((ipath, version))

+ 

+     for ipath, version in vendored:

+         print(f"bundled(golang({ipath})) = {version}")

+ 

+ 

+ def main() -> None:

+     files = sys.stdin.read().splitlines()

+     for file in files:

+         process(file)

+ 

+ 

+ if __name__ == "__main__":

+     main()

@@ -0,0 +1,5 @@ 

+ # SPDX-FileCopyrightText: 2022 Maxwell G <gotmax@e.email>

+ # SPDX-License-Identifier: GPL-3.0-or-later

+ 

+ %__go_mod_vendor_path ^%{_defaultlicensedir}(/[^/]+)+/modules.txt$

+ %__go_mod_vendor_provides %{_rpmconfigdir}/redhat/vendor2provides.py

Any modules.txt file within a subdirectory of /usr/share/licenses will
be processed. While this isn't strictly a license file, it contains
information about the other sources that are included in the package.
Packages can include this file alongside the license files from the
vendored libraries as a summary of sorts. Alternatively, the modules.txt
can be marked with %ghost, which is sufficient for the generator.
There are not any other good places to install these files. %_docdir is
not an option, as generators do not search in that directory.

cc @decathorpe. The modifications are licensed under the same license as the project. I can keep it under the UNLICENSE if you really want.

I am fine with you including it as GPLv3.

Though I find it weird to use such a strict license for random scripts :)

I will plan to merge this tomorrow if nobody has any other comments. I am also working on creating an go-rpm-macros-epel package that contains certain macro backports to EPEL. This will be included in that.

Pull-Request has been merged by gotmax23

2 years ago