Fix copy_extra_sources for remote URLs

Fix #387

A build with a remote URL in its `SourceX` will work only with

    %_disable_source_fetch 0

macro defined. It can be done either globally via `~/.rpmmacros` or by
using tito with following parameter

    --rpmbuild-options="--define '%_disable_source_fetch 0'"

IMHO this macro should be set by default but we should also introduce
a switch to turn it off (like e.g. Mock or Copr do). Since it is not
related to fixing #387, I am not doing it in this commit.
This commit is contained in:
Jakub Kadlcik 2020-09-24 00:05:23 +02:00 committed by Jakub Kadlčík
parent d9ed1db7da
commit 5947384f32
2 changed files with 12 additions and 1 deletions

View file

@ -34,7 +34,7 @@ from tito.common import scl_to_rpm_option, get_latest_tagged_version, \
find_cheetah_template_file, render_cheetah, replace_spec_release, \
find_spec_like_file, warn_out, get_commit_timestamp, chdir, mkdir_p, \
find_git_root, info_out, munge_specfile, BUILDCONFIG_SECTION
from tito.compat import getstatusoutput, getoutput
from tito.compat import getstatusoutput, getoutput, urlparse
from tito.exception import RunCommandException
from tito.exception import TitoException
from tito.config_object import ConfigObject
@ -508,6 +508,15 @@ class Builder(ConfigObject, BuilderBase):
if os.path.isfile(dst_file):
debug('Source file "%s" already exists. Skiping.' % dst_file)
continue
parse = urlparse(source)
if parse.scheme and parse.netloc:
# If macro `%_disable_source_fetch 0` is defined, the file will
# be automatically downloaded by rpmbuild to the SOURCES
# directory. We can safely skip it here.
debug('Source "%s" is not a local file. Skiping.' % source)
continue
src = os.path.join(self.rpmbuild_sourcedir, self.tgz_dir, source)
if os.path.islink(src) and os.path.isabs(src):
src = os.path.join(self.start_dir, os.readlink(src))

View file

@ -25,6 +25,7 @@ if PY2:
from ConfigParser import NoOptionError
from ConfigParser import RawConfigParser
from StringIO import StringIO
from urlparse import urlparse
import xmlrpclib
text_type = unicode
binary_type = str
@ -33,6 +34,7 @@ else:
from configparser import NoOptionError
from configparser import RawConfigParser
from io import StringIO
from urllib.parse import urlparse
import xmlrpc.client as xmlrpclib
text_type = str
binary_type = bytes