|
| 1 | +# -*- coding: UTF-8 -*- |
| 2 | +"""Tito ad-hoc module for custom git repo -> spec + archive metamorphosis""" |
| 3 | + |
| 4 | +from __future__ import (print_function, unicode_literals, absolute_import, |
| 5 | + division) |
| 6 | + |
| 7 | +__author__ = "Jan Pokorný <[email protected]>" |
| 8 | +__copyright__ = "Copyright 2016 Red Hat, Inc." |
| 9 | +__license__ = "LGPLv2.1+ WITHOUT ANY WARRANTY" |
| 10 | + |
| 11 | + |
| 12 | +from os.path import basename, join |
| 13 | +from shutil import copyfile |
| 14 | + |
| 15 | +from tito.builder.main import BuilderBase |
| 16 | +from tito.builder.fetch import FetchBuilder |
| 17 | +from tito.common import error_out, run_command, get_spec_version_and_release |
| 18 | + |
| 19 | + |
| 20 | +class NativeFetchBuilder(FetchBuilder): |
| 21 | + """ |
| 22 | + A specialized FetchBuilder to just setup the specfile + archive |
| 23 | + using package-native scripts, which currently boils down to a sequence |
| 24 | + that needs to be configured via fetch_prep_command option in builder |
| 25 | + section (e.g., "./autogen.sh && ./configure && make dist foo.spec"). |
| 26 | +
|
| 27 | + Uses code of src/tito/builder/fetch.py from the tito project as a template. |
| 28 | + """ |
| 29 | + REQUIRED_ARGS = [] |
| 30 | + |
| 31 | + def __init__(self, name=None, tag=None, build_dir=None, |
| 32 | + config=None, user_config=None, |
| 33 | + args=None, **kwargs): |
| 34 | + |
| 35 | + BuilderBase.__init__(self, name=name, build_dir=build_dir, |
| 36 | + config=config, |
| 37 | + user_config=user_config, args=args, **kwargs) |
| 38 | + |
| 39 | + if tag: |
| 40 | + error_out("FetchBuilder does not support building specific tags.") |
| 41 | + |
| 42 | + if not config.has_option('builder', 'fetch_prep_command'): |
| 43 | + error_out("NativeFetchBuilder requires fetch_prep_command.") |
| 44 | + |
| 45 | + self.build_tag = '%s-%s' % ( |
| 46 | + self.project_name, |
| 47 | + get_spec_version_and_release(self.start_dir, |
| 48 | + '%s.spec' % self.project_name) |
| 49 | + ) |
| 50 | + |
| 51 | + def tgz(self): |
| 52 | + self.ran_tgz = True |
| 53 | + self._create_build_dirs() |
| 54 | + |
| 55 | + print("Fetching sources...") |
| 56 | + run_command(self.config.get('builder', 'fetch_prep_command')) |
| 57 | + manual_sources = [run_command("ls -1t *.tar.* | head -n1")] |
| 58 | + self.spec_file = self.project_name + '.spec' |
| 59 | + for s in manual_sources: |
| 60 | + base_name = basename(s) |
| 61 | + dest_filepath = join(self.rpmbuild_sourcedir, base_name) |
| 62 | + copyfile(s, dest_filepath) |
| 63 | + self.sources.append(dest_filepath) |
0 commit comments