Skip to content

Commit

Permalink
Add script to generate bundled provides
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Oct 30, 2023
1 parent 05acc0b commit 754d007
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions release_management/gen_bundled_provides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/python3
#
# Copyright 2023 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Generate vendored provides list from vendor tarfile.
"""

# isort: STDLIB
import argparse
import os
import sys
import tarfile
import tomllib


def main():
"""
Main function
"""

parser = argparse.ArgumentParser(
description=(
"Generate a list of bundled provides suitable for including in an "
"rpm spec file. Include in the list only those dependencies which "
"have source code in the vendor tarfile. Prints list to stdout."
)
)

parser.add_argument(
"vendor_tarfile",
action="store",
help="path to vendor tarfile",
type=os.path.abspath,
)

namespace = parser.parse_args()

with tarfile.open(namespace.vendor_tarfile, "r") as tar:
for member in tar.getmembers():
components = member.name.split("/")

if (
len(components) == 3
and components[0] == "vendor"
and components[2] == "Cargo.toml"
):
manifest = tar.extractfile(member)
metadata = tomllib.load(manifest)
cargo_name = components[1]
package = metadata["package"]
package_version = package["version"]
continue

if (
len(components) == 4
and components[0] == "vendor"
and components[2] == "src"
and components[3] == "lib.rs"
):
size = member.size
if size != 0:
if cargo_name == components[1]:
print(
f"Provides: bundled(crate({components[1]})) = {package_version}"
)
else:
raise RuntimeError(
"Found an entry for bundled provides, but no version information"
)

return 0


if __name__ == "__main__":
try:
main()
except Exception as err: # pylint: disable=broad-except
print(err)
sys.exit(1)

0 comments on commit 754d007

Please sign in to comment.