2009-03-02 15:03:06 +01:00
|
|
|
# Copyright (C) 2006 Novell Inc. All rights reserved.
|
2006-07-14 19:39:46 +02:00
|
|
|
# This program is free software; it may be used, copied, modified
|
|
|
|
# and distributed under the terms of the GNU General Public Licence,
|
|
|
|
# either version 2, or (at your option) any later version.
|
|
|
|
|
2023-05-02 09:50:00 +02:00
|
|
|
import fnmatch
|
2022-09-09 11:46:28 +02:00
|
|
|
import glob
|
2006-07-14 19:39:46 +02:00
|
|
|
import os
|
2008-03-11 16:18:02 +01:00
|
|
|
import re
|
2010-07-13 12:13:25 +02:00
|
|
|
import shutil
|
2008-10-11 22:26:45 +02:00
|
|
|
import subprocess
|
2022-07-28 12:28:33 +02:00
|
|
|
import sys
|
2022-10-07 12:57:09 +02:00
|
|
|
|
2022-07-28 12:28:33 +02:00
|
|
|
from tempfile import NamedTemporaryFile, mkdtemp
|
|
|
|
from urllib.parse import urlsplit
|
|
|
|
from urllib.request import URLError, HTTPError
|
|
|
|
from xml.etree import ElementTree as ET
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-07-28 12:28:33 +02:00
|
|
|
from . import conf
|
2022-02-03 11:11:40 +01:00
|
|
|
from . import connection
|
2022-07-28 21:01:16 +02:00
|
|
|
from . import core
|
2022-07-28 12:28:33 +02:00
|
|
|
from . import oscerr
|
2023-07-25 15:58:21 +02:00
|
|
|
from .core import get_buildinfo, meta_exists, quote_plus, get_buildconfig, dgst
|
2022-07-28 12:28:33 +02:00
|
|
|
from .core import get_binarylist, get_binary_file, run_external, return_external, raw_input
|
2022-07-28 21:01:16 +02:00
|
|
|
from .fetch import Fetcher, OscFileGrabber, verify_pacs
|
2019-01-14 12:03:16 +01:00
|
|
|
from .meter import create_text_meter
|
2022-09-09 11:46:28 +02:00
|
|
|
from .util import cpio
|
|
|
|
from .util import archquery, debquery, packagequery, rpmquery
|
|
|
|
from .util import repodata
|
2022-07-28 12:28:33 +02:00
|
|
|
from .util.helper import decode_it
|
|
|
|
|
2016-06-09 16:24:30 +02:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
change_personality = {
|
2022-09-12 13:43:10 +02:00
|
|
|
'i686': 'linux32',
|
|
|
|
'i586': 'linux32',
|
|
|
|
'i386': 'linux32',
|
|
|
|
'ppc': 'powerpc32',
|
|
|
|
's390': 's390',
|
|
|
|
'sparc': 'linux32',
|
|
|
|
'sparcv8': 'linux32',
|
|
|
|
}
|
2008-11-22 17:38:40 +01:00
|
|
|
|
2009-10-20 16:30:15 +02:00
|
|
|
can_also_build = {
|
2022-09-12 13:43:10 +02:00
|
|
|
'aarch64': ['aarch64'], # only needed due to used heuristics in build parameter evaluation
|
|
|
|
'armv6l': ['armv4l', 'armv5l', 'armv6l', 'armv5el', 'armv6el'],
|
|
|
|
'armv7l': ['armv4l', 'armv5l', 'armv6l', 'armv7l', 'armv5el', 'armv6el', 'armv7el'],
|
|
|
|
'armv5el': ['armv4l', 'armv5l', 'armv5el'], # not existing arch, just for compatibility
|
|
|
|
'armv6el': ['armv4l', 'armv5l', 'armv6l', 'armv5el', 'armv6el'], # not existing arch, just for compatibility
|
|
|
|
'armv6hl': ['armv4l', 'armv5l', 'armv6l', 'armv5el', 'armv6el'],
|
|
|
|
'armv7el': ['armv4l', 'armv5l', 'armv6l', 'armv7l', 'armv5el', 'armv6el', 'armv7el'], # not existing arch, just for compatibility
|
|
|
|
'armv7hl': ['armv7hl'], # not existing arch, just for compatibility
|
|
|
|
'armv8el': ['armv4l', 'armv5el', 'armv6el', 'armv7el', 'armv8el'], # not existing arch, just for compatibility
|
|
|
|
'armv8l': ['armv4l', 'armv5el', 'armv6el', 'armv7el', 'armv8el'], # not existing arch, just for compatibility
|
|
|
|
'armv5tel': ['armv4l', 'armv5el', 'armv5tel'],
|
|
|
|
's390x': ['s390'],
|
|
|
|
'ppc64': ['ppc', 'ppc64', 'ppc64p7', 'ppc64le'],
|
|
|
|
'ppc64le': ['ppc64le', 'ppc64'],
|
|
|
|
'i586': ['i386'],
|
|
|
|
'i686': ['i586', 'i386'],
|
|
|
|
'x86_64': ['i686', 'i586', 'i386'],
|
|
|
|
'sparc64': ['sparc64v', 'sparcv9v', 'sparcv9', 'sparcv8', 'sparc'],
|
|
|
|
'parisc': ['hppa'],
|
|
|
|
}
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2006-07-17 15:53:17 +02:00
|
|
|
# real arch of this machine
|
2006-07-14 19:39:46 +02:00
|
|
|
hostarch = os.uname()[4]
|
2022-09-12 13:43:10 +02:00
|
|
|
if hostarch == 'i686': # FIXME
|
2006-07-14 19:39:46 +02:00
|
|
|
hostarch = 'i586'
|
|
|
|
|
2010-09-06 10:40:24 +02:00
|
|
|
if hostarch == 'parisc':
|
|
|
|
hostarch = 'hppa'
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
class Buildinfo:
|
|
|
|
"""represent the contents of a buildinfo file"""
|
|
|
|
|
2022-08-29 15:32:41 +02:00
|
|
|
def __init__(self, filename, apiurl, buildtype='spec', localpkgs=None, binarytype='rpm'):
|
|
|
|
localpkgs = localpkgs or []
|
2006-10-10 16:04:34 +02:00
|
|
|
try:
|
|
|
|
tree = ET.parse(filename)
|
2022-10-27 00:22:09 +02:00
|
|
|
except ET.ParseError:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('could not parse the buildinfo:', file=sys.stderr)
|
|
|
|
print(open(filename).read(), file=sys.stderr)
|
2006-10-10 16:04:34 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
root = tree.getroot()
|
|
|
|
|
2010-02-24 20:02:52 +01:00
|
|
|
self.apiurl = apiurl
|
2009-06-16 14:46:02 +02:00
|
|
|
|
2022-08-29 12:56:57 +02:00
|
|
|
if root.find('error') is not None:
|
2008-01-11 17:44:08 +01:00
|
|
|
sys.stderr.write('buildinfo is broken... it says:\n')
|
2006-07-14 19:39:46 +02:00
|
|
|
error = root.find('error').text
|
2015-09-23 18:29:51 +02:00
|
|
|
if error.startswith('unresolvable: '):
|
|
|
|
sys.stderr.write('unresolvable: ')
|
|
|
|
sys.stderr.write('\n '.join(error[14:].split(',')))
|
|
|
|
else:
|
|
|
|
sys.stderr.write(error)
|
|
|
|
sys.stderr.write('\n')
|
2006-07-14 19:39:46 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2009-02-24 00:29:32 +01:00
|
|
|
if not (apiurl.startswith('https://') or apiurl.startswith('http://')):
|
2013-04-09 14:03:17 +02:00
|
|
|
raise URLError('invalid protocol for the apiurl: \'%s\'' % apiurl)
|
2008-01-23 20:37:44 +01:00
|
|
|
|
2009-08-04 18:01:02 +02:00
|
|
|
self.buildtype = buildtype
|
2017-09-26 13:57:59 +02:00
|
|
|
self.binarytype = binarytype
|
2010-02-12 10:17:34 +01:00
|
|
|
self.apiurl = apiurl
|
2009-08-04 18:01:02 +02:00
|
|
|
|
|
|
|
# are we building .rpm or .deb?
|
2008-11-13 00:51:43 +01:00
|
|
|
# XXX: shouldn't we deliver the type via the buildinfo?
|
2006-07-14 19:39:46 +02:00
|
|
|
self.pacsuffix = 'rpm'
|
2022-10-27 00:20:00 +02:00
|
|
|
if self.buildtype in ('dsc', 'collax', 'deb'):
|
2009-08-04 18:01:02 +02:00
|
|
|
self.pacsuffix = 'deb'
|
2012-04-03 15:59:42 +02:00
|
|
|
if self.buildtype == 'arch':
|
|
|
|
self.pacsuffix = 'arch'
|
2014-07-08 21:18:01 +02:00
|
|
|
if self.buildtype == 'livebuild':
|
|
|
|
self.pacsuffix = 'deb'
|
2016-07-01 11:15:12 +02:00
|
|
|
if self.buildtype == 'snapcraft':
|
2022-01-31 00:20:16 +01:00
|
|
|
# atm ubuntu is used as base, but we need to be more clever when
|
2016-07-01 11:15:12 +02:00
|
|
|
# snapcraft also supports rpm
|
|
|
|
self.pacsuffix = 'deb'
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2021-05-14 16:01:56 +02:00
|
|
|
# The architectures become a bit mad ...
|
|
|
|
# buildarch: The architecture of the build result (host arch in GNU definition)
|
|
|
|
# hostarch: The architecture of the build environment (build arch in GNU defintion)
|
|
|
|
# crossarch: Same as hostarch, but indicating that a sysroot with an incompatible architecture exists
|
2006-07-14 19:39:46 +02:00
|
|
|
self.buildarch = root.find('arch').text
|
2022-08-29 12:56:57 +02:00
|
|
|
if root.find('crossarch') is not None:
|
2021-05-14 16:01:56 +02:00
|
|
|
self.crossarch = root.find('crossarch').text
|
|
|
|
else:
|
|
|
|
self.crossarch = None
|
2022-08-29 12:56:57 +02:00
|
|
|
if root.find('hostarch') is not None:
|
2012-02-09 15:13:04 +01:00
|
|
|
self.hostarch = root.find('hostarch').text
|
|
|
|
else:
|
|
|
|
self.hostarch = None
|
2021-05-14 16:01:56 +02:00
|
|
|
|
2022-08-29 12:56:57 +02:00
|
|
|
if root.find('release') is not None:
|
2009-10-20 16:30:15 +02:00
|
|
|
self.release = root.find('release').text
|
2009-12-01 14:36:11 +01:00
|
|
|
else:
|
|
|
|
self.release = None
|
2022-10-27 00:20:00 +02:00
|
|
|
if conf.config['api_host_options'][apiurl]['downloadurl']:
|
OBS has a fault where is sends invalid md5s
This causes downloads to come from the api, generally on noarch packages.
However, in countries like australia, due to OBS' high latency, and poor
bandwidth, these faults can cause downloads to take more than an hour, compared
to using a local mirror which can take minutes. There is actually nothing
wrong with the packages it all, OBS just sends the wrong md5.
As a result, ignore the problem and complain about it, because OBS is broken
here, not osc, and this wastes a lot of time.
2022-06-21 02:20:50 +02:00
|
|
|
# Formerly, this was set to False, but we have to set it to True, because a large
|
|
|
|
# number of repos in OBS are misconfigured and don't actually have repos setup - they
|
|
|
|
# are API only.
|
|
|
|
self.enable_cpio = True
|
2022-10-27 00:20:00 +02:00
|
|
|
self.downloadurl = conf.config['api_host_options'][apiurl]['downloadurl'] + "/repositories"
|
|
|
|
if conf.config['http_debug']:
|
|
|
|
print("⚠️ setting dl_url to %s" % conf.config['api_host_options'][apiurl]['downloadurl'])
|
2021-09-10 07:51:17 +02:00
|
|
|
else:
|
|
|
|
self.enable_cpio = True
|
|
|
|
self.downloadurl = root.get('downloadurl')
|
|
|
|
|
2008-12-10 23:38:00 +01:00
|
|
|
self.debuginfo = 0
|
2022-08-29 12:56:57 +02:00
|
|
|
if root.find('debuginfo') is not None:
|
2008-12-10 23:38:00 +01:00
|
|
|
try:
|
2009-03-12 17:35:40 +01:00
|
|
|
self.debuginfo = int(root.find('debuginfo').text)
|
2008-12-10 23:38:00 +01:00
|
|
|
except ValueError:
|
|
|
|
pass
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
self.deps = []
|
2009-06-16 14:46:02 +02:00
|
|
|
self.projects = {}
|
|
|
|
self.keys = []
|
2009-11-11 15:48:25 +01:00
|
|
|
self.prjkeys = []
|
2013-07-04 16:41:59 +02:00
|
|
|
self.pathes = []
|
2021-09-16 16:56:38 +02:00
|
|
|
self.urls = {}
|
2019-12-05 13:03:48 +01:00
|
|
|
self.modules = []
|
|
|
|
for node in root.findall('module'):
|
|
|
|
self.modules.append(node.text)
|
2006-07-14 19:39:46 +02:00
|
|
|
for node in root.findall('bdep'):
|
2021-05-14 16:01:56 +02:00
|
|
|
if node.find('sysroot'):
|
|
|
|
p = Pac(node, self.buildarch, self.pacsuffix,
|
|
|
|
apiurl, localpkgs)
|
|
|
|
else:
|
|
|
|
pac_arch = self.crossarch
|
2022-08-29 12:56:57 +02:00
|
|
|
if pac_arch is None:
|
2022-08-29 13:39:20 +02:00
|
|
|
pac_arch = self.buildarch
|
2021-05-14 16:01:56 +02:00
|
|
|
p = Pac(node, pac_arch, self.pacsuffix,
|
|
|
|
apiurl, localpkgs)
|
2009-06-16 14:46:02 +02:00
|
|
|
if p.project:
|
|
|
|
self.projects[p.project] = 1
|
2006-07-14 19:39:46 +02:00
|
|
|
self.deps.append(p)
|
2013-07-04 16:41:59 +02:00
|
|
|
for node in root.findall('path'):
|
2021-09-16 16:56:38 +02:00
|
|
|
# old simple list for compatibility
|
|
|
|
# XXX: really old? This is currently used for kiwi builds
|
2022-09-12 13:43:10 +02:00
|
|
|
self.pathes.append(node.get('project') + "/" + node.get('repository'))
|
2021-09-16 16:56:38 +02:00
|
|
|
# a hash providing the matching URL for specific repos for newer OBS instances
|
|
|
|
if node.get('url'):
|
2022-05-20 11:53:19 +02:00
|
|
|
baseurl = node.get('url').replace('%', '%%')
|
2022-10-27 00:20:00 +02:00
|
|
|
if conf.config['api_host_options'][apiurl]['downloadurl']:
|
2021-09-10 07:51:17 +02:00
|
|
|
# Add the path element to the download url override.
|
2022-10-27 00:20:00 +02:00
|
|
|
baseurl = conf.config['api_host_options'][apiurl]['downloadurl'] + urlsplit(node.get('url'))[2]
|
2022-09-12 13:43:10 +02:00
|
|
|
self.urls[node.get('project') + "/" + node.get('repository')] = baseurl + '/%(arch)s/%(filename)s'
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
self.vminstall_list = [dep.name for dep in self.deps if dep.vminstall]
|
|
|
|
self.preinstall_list = [dep.name for dep in self.deps if dep.preinstall]
|
|
|
|
self.runscripts_list = [dep.name for dep in self.deps if dep.runscripts]
|
|
|
|
self.noinstall_list = [dep.name for dep in self.deps if dep.noinstall]
|
|
|
|
self.installonly_list = [dep.name for dep in self.deps if dep.installonly]
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-08-29 12:56:57 +02:00
|
|
|
if root.find('preinstallimage') is not None:
|
2016-06-09 16:24:30 +02:00
|
|
|
self.preinstallimage = root.find('preinstallimage')
|
|
|
|
else:
|
|
|
|
self.preinstallimage = None
|
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
def has_dep(self, name):
|
|
|
|
for i in self.deps:
|
|
|
|
if i.name == name:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def remove_dep(self, name):
|
2010-08-19 14:43:20 +02:00
|
|
|
# we need to iterate over all deps because if this a
|
|
|
|
# kiwi build the same package might appear multiple times
|
2012-11-08 09:01:19 +01:00
|
|
|
# NOTE: do not loop and remove items, the second same one would not get catched
|
|
|
|
self.deps = [i for i in self.deps if not i.name == name]
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Pac:
|
2008-11-22 11:55:33 +01:00
|
|
|
"""represent a package to be downloaded
|
|
|
|
|
|
|
|
We build a map that's later used to fill our URL templates
|
|
|
|
"""
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2022-08-29 15:32:41 +02:00
|
|
|
def __init__(self, node, buildarch, pacsuffix, apiurl, localpkgs=None):
|
|
|
|
localpkgs = localpkgs or []
|
2023-01-20 16:16:06 +01:00
|
|
|
|
|
|
|
# set attributes to mute pylint error E1101: Instance of 'Pac' has no '<attr>' member (no-member)
|
|
|
|
self.project = None
|
|
|
|
self.name = None
|
|
|
|
self.canonname = None
|
|
|
|
self.repository = None
|
|
|
|
self.repoarch = None
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
self.mp = {}
|
2012-02-22 11:33:34 +01:00
|
|
|
for i in ['binary', 'package',
|
2014-11-17 12:39:58 +01:00
|
|
|
'epoch', 'version', 'release', 'hdrmd5',
|
2021-05-14 16:01:56 +02:00
|
|
|
'project', 'repository', 'sysroot',
|
2017-05-16 14:02:37 +02:00
|
|
|
'preinstall', 'vminstall', 'runscripts',
|
|
|
|
'noinstall', 'installonly', 'notmeta',
|
2022-09-12 13:43:10 +02:00
|
|
|
]:
|
2008-11-22 11:55:33 +01:00
|
|
|
self.mp[i] = node.get(i)
|
|
|
|
|
2022-04-20 19:22:35 +02:00
|
|
|
self.mp['buildarch'] = buildarch
|
|
|
|
self.mp['pacsuffix'] = pacsuffix
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2009-03-13 16:58:55 +01:00
|
|
|
self.mp['arch'] = node.get('arch') or self.mp['buildarch']
|
2012-02-22 11:33:34 +01:00
|
|
|
self.mp['name'] = node.get('name') or self.mp['binary']
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
# this is not the ideal place to check if the package is a localdep or not
|
2022-09-12 13:43:10 +02:00
|
|
|
localdep = self.mp['name'] in localpkgs # and not self.mp['noinstall']
|
2009-09-10 14:18:07 +02:00
|
|
|
if not localdep and not (node.get('project') and node.get('repository')):
|
|
|
|
raise oscerr.APIError('incomplete information for package %s, may be caused by a broken project configuration.'
|
2022-09-12 13:43:10 +02:00
|
|
|
% self.mp['name'])
|
2009-09-09 10:17:13 +02:00
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
if not localdep:
|
|
|
|
self.mp['extproject'] = node.get('project').replace(':', ':/')
|
|
|
|
self.mp['extrepository'] = node.get('repository').replace(':', ':/')
|
2009-02-20 16:01:16 +01:00
|
|
|
self.mp['repopackage'] = node.get('package') or '_repository'
|
2009-08-09 20:10:13 +02:00
|
|
|
self.mp['repoarch'] = node.get('repoarch') or self.mp['buildarch']
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2009-06-16 14:15:41 +02:00
|
|
|
if pacsuffix == 'deb' and not (self.mp['name'] and self.mp['arch'] and self.mp['version']):
|
2008-11-22 11:55:33 +01:00
|
|
|
raise oscerr.APIError(
|
2009-10-20 16:30:15 +02:00
|
|
|
"buildinfo for package %s/%s/%s is incomplete"
|
2022-09-12 13:43:10 +02:00
|
|
|
% (self.mp['name'], self.mp['arch'], self.mp['version']))
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-02-24 00:29:32 +01:00
|
|
|
self.mp['apiurl'] = apiurl
|
2007-04-25 13:22:40 +02:00
|
|
|
|
2019-07-26 10:45:12 +02:00
|
|
|
if self.mp['epoch'] is None:
|
|
|
|
epoch = None
|
|
|
|
else:
|
|
|
|
epoch = self.mp['epoch'].encode()
|
|
|
|
|
|
|
|
if self.mp['release'] is None:
|
|
|
|
release = None
|
|
|
|
else:
|
|
|
|
release = self.mp['release'].encode()
|
|
|
|
|
2017-05-17 11:20:03 +02:00
|
|
|
if self.mp['name'].startswith('container:'):
|
|
|
|
canonname = self.mp['name'] + '.tar.xz'
|
|
|
|
elif pacsuffix == 'deb':
|
2019-07-26 10:45:12 +02:00
|
|
|
canonname = debquery.DebQuery.filename(self.mp['name'].encode(), epoch, self.mp['version'].encode(), release, self.mp['arch'].encode())
|
2012-04-03 15:59:42 +02:00
|
|
|
elif pacsuffix == 'arch':
|
2019-07-26 10:45:12 +02:00
|
|
|
canonname = archquery.ArchQuery.filename(self.mp['name'].encode(), epoch, self.mp['version'].encode(), release, self.mp['arch'].encode())
|
2009-09-13 18:57:40 +02:00
|
|
|
else:
|
2019-10-21 11:07:27 +02:00
|
|
|
canonname = rpmquery.RpmQuery.filename(self.mp['name'].encode(), epoch, self.mp['version'].encode(), release or b'0', self.mp['arch'].encode())
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2019-07-26 10:45:12 +02:00
|
|
|
self.mp['canonname'] = decode_it(canonname)
|
2015-06-16 17:37:40 +02:00
|
|
|
# maybe we should rename filename key to binary
|
2019-07-26 10:45:12 +02:00
|
|
|
self.mp['filename'] = node.get('binary') or decode_it(canonname)
|
2009-07-15 21:48:16 +02:00
|
|
|
if self.mp['repopackage'] == '_repository':
|
2009-09-03 21:00:09 +02:00
|
|
|
self.mp['repofilename'] = self.mp['name']
|
2009-07-15 21:48:16 +02:00
|
|
|
else:
|
2012-02-22 11:33:34 +01:00
|
|
|
# OBS 2.3 puts binary into product bdeps (noinstall ones)
|
2012-02-22 14:12:06 +01:00
|
|
|
self.mp['repofilename'] = self.mp['filename']
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2008-11-22 11:55:33 +01:00
|
|
|
# make the content of the dictionary accessible as class attributes
|
|
|
|
self.__dict__.update(self.mp)
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
def makeurls(self, cachedir, urllist):
|
2022-07-07 12:30:55 +02:00
|
|
|
self.localdir = '%s/%s/%s/%s' % (cachedir, self.project, self.repository, self.repoarch)
|
2015-06-16 17:37:40 +02:00
|
|
|
self.fullfilename = os.path.join(self.localdir, self.canonname)
|
2022-05-20 11:56:10 +02:00
|
|
|
self.urllist = [url % self.mp for url in urllist]
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2023-01-20 16:16:06 +01:00
|
|
|
return self.name or ""
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return "%s" % self.name
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2020-09-07 18:54:59 +02:00
|
|
|
def get_preinstall_image(apiurl, arch, cache_dir, img_info, offline=False):
|
2016-06-09 16:24:30 +02:00
|
|
|
"""
|
2020-09-07 18:54:59 +02:00
|
|
|
Searches preinstall image according to build info and downloads it to cache
|
2022-01-24 08:57:53 +01:00
|
|
|
(unless offline is set to ``True`` (default: ``False``)).
|
2016-06-09 16:24:30 +02:00
|
|
|
Returns preinstall image path, source and list of image binaries, which can
|
|
|
|
be used to create rpmlist.
|
2022-01-24 08:57:53 +01:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
preinstall image can be used only for new build roots!
|
2016-06-09 16:24:30 +02:00
|
|
|
"""
|
|
|
|
imagefile = ''
|
|
|
|
imagesource = ''
|
|
|
|
img_bins = []
|
|
|
|
for bin in img_info.findall('binary'):
|
|
|
|
img_bins.append(bin.text)
|
|
|
|
|
|
|
|
img_project = img_info.get('project')
|
|
|
|
img_repository = img_info.get('repository')
|
|
|
|
img_arch = arch
|
|
|
|
img_pkg = img_info.get('package')
|
|
|
|
img_file = img_info.get('filename')
|
|
|
|
img_hdrmd5 = img_info.get('hdrmd5')
|
2016-06-09 16:40:39 +02:00
|
|
|
if not img_hdrmd5:
|
|
|
|
img_hdrmd5 = img_file
|
2016-06-09 16:24:30 +02:00
|
|
|
cache_path = '%s/%s/%s/%s' % (cache_dir, img_project, img_repository, img_arch)
|
|
|
|
ifile_path = '%s/%s' % (cache_path, img_file)
|
|
|
|
ifile_path_part = '%s.part' % ifile_path
|
|
|
|
|
|
|
|
imagefile = ifile_path
|
|
|
|
imagesource = "%s/%s/%s [%s]" % (img_project, img_repository, img_pkg, img_hdrmd5)
|
|
|
|
|
|
|
|
if not os.path.exists(ifile_path):
|
2020-09-07 18:54:59 +02:00
|
|
|
if offline:
|
|
|
|
return '', '', []
|
2016-06-09 16:24:30 +02:00
|
|
|
url = "%s/build/%s/%s/%s/%s/%s" % (apiurl, img_project, img_repository, img_arch, img_pkg, img_file)
|
|
|
|
print("downloading preinstall image %s" % imagesource)
|
|
|
|
if not os.path.exists(cache_path):
|
|
|
|
try:
|
|
|
|
os.makedirs(cache_path, mode=0o755)
|
|
|
|
except OSError as e:
|
|
|
|
print('packagecachedir is not writable for you?', file=sys.stderr)
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2019-01-14 12:03:16 +01:00
|
|
|
progress_obj = None
|
|
|
|
if sys.stdout.isatty():
|
|
|
|
progress_obj = create_text_meter(use_pb_fallback=False)
|
2016-06-09 16:24:30 +02:00
|
|
|
gr = OscFileGrabber(progress_obj=progress_obj)
|
|
|
|
try:
|
|
|
|
gr.urlgrab(url, filename=ifile_path_part, text='fetching image')
|
2018-02-02 15:47:17 +01:00
|
|
|
except HTTPError as e:
|
2020-04-01 12:48:12 +02:00
|
|
|
print("Failed to download! ecode:%i reason:%s" % (e.code, e.reason))
|
2016-06-09 16:24:30 +02:00
|
|
|
return ('', '', [])
|
|
|
|
# download ok, rename partial file to final file name
|
|
|
|
os.rename(ifile_path_part, ifile_path)
|
|
|
|
return (imagefile, imagesource, img_bins)
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2014-07-04 16:42:53 +02:00
|
|
|
def get_built_files(pacdir, buildtype):
|
|
|
|
if buildtype == 'spec':
|
2021-12-06 11:18:25 +01:00
|
|
|
debs_dir = os.path.join(pacdir, 'DEBS')
|
|
|
|
sdebs_dir = os.path.join(pacdir, 'SDEBS')
|
|
|
|
if os.path.isdir(debs_dir) or os.path.isdir(sdebs_dir):
|
|
|
|
# (S)DEBS directories detected, list their *.(s)deb files
|
|
|
|
b_built = subprocess.Popen(['find', debs_dir, '-name', '*.deb'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = subprocess.Popen(['find', sdebs_dir, '-name', '*.sdeb'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
else:
|
|
|
|
# default: (S)RPMS directories and their *.rpm files
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'RPMS'),
|
|
|
|
'-name', '*.rpm'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SRPMS'),
|
|
|
|
'-name', '*.rpm'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2014-07-04 16:42:53 +02:00
|
|
|
elif buildtype == 'kiwi':
|
2009-10-20 16:30:15 +02:00
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'KIWI'),
|
2009-04-20 15:07:43 +02:00
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2014-09-09 15:07:35 +02:00
|
|
|
s_built = ''
|
2017-05-16 11:14:52 +02:00
|
|
|
elif buildtype == 'docker':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'DOCKER'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2018-08-14 13:02:16 +02:00
|
|
|
elif buildtype == 'podman':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'DOCKER'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2017-08-01 15:01:53 +02:00
|
|
|
elif buildtype == 'fissile':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'FISSILE'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2022-09-30 14:09:37 +02:00
|
|
|
elif buildtype in ('dsc', 'collax'):
|
2008-11-14 23:32:39 +01:00
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'DEBS'),
|
|
|
|
'-name', '*.deb'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2009-10-20 16:30:15 +02:00
|
|
|
s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SOURCES.DEB'),
|
2009-04-27 13:44:38 +02:00
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2014-07-04 16:42:53 +02:00
|
|
|
elif buildtype == 'arch':
|
2012-08-13 12:54:38 +02:00
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'ARCHPKGS'),
|
|
|
|
'-name', '*.pkg.tar*'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2013-06-03 16:32:39 +02:00
|
|
|
s_built = ''
|
2014-07-08 21:18:01 +02:00
|
|
|
elif buildtype == 'livebuild':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'OTHER'),
|
|
|
|
'-name', '*.iso*'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2022-04-20 17:28:01 +02:00
|
|
|
elif buildtype == 'helm':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'HELM'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2016-06-30 08:06:29 +02:00
|
|
|
elif buildtype == 'snapcraft':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'OTHER'),
|
|
|
|
'-name', '*.snap'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2017-03-15 10:31:51 +01:00
|
|
|
elif buildtype == 'appimage':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'OTHER'),
|
|
|
|
'-name', '*.AppImage'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2019-06-27 15:42:28 +02:00
|
|
|
elif buildtype == 'simpleimage':
|
2021-04-26 08:02:38 +02:00
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'OTHER'),
|
2019-06-27 15:42:28 +02:00
|
|
|
'-type', 'f'],
|
2019-06-27 15:42:28 +02:00
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2020-11-11 18:05:20 +01:00
|
|
|
elif buildtype == 'flatpak':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'OTHER'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2022-01-31 00:20:16 +01:00
|
|
|
elif buildtype == 'preinstallimage':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'OTHER'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
|
|
|
s_built = ''
|
2012-08-13 12:54:38 +02:00
|
|
|
else:
|
2014-07-04 16:42:53 +02:00
|
|
|
print('WARNING: Unknown package type \'%s\'.' % buildtype, file=sys.stderr)
|
2013-06-03 16:32:39 +02:00
|
|
|
b_built = ''
|
|
|
|
s_built = ''
|
2006-07-14 19:39:46 +02:00
|
|
|
return s_built, b_built
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-01-18 16:12:10 +01:00
|
|
|
def get_repo(path):
|
2023-04-27 13:58:13 +02:00
|
|
|
"""
|
|
|
|
Walks up path looking for any repodata directories.
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2022-01-24 08:57:53 +01:00
|
|
|
:param path: path to a directory
|
2023-04-27 13:58:13 +02:00
|
|
|
:return: path to repository directory containing repodata directory with repomd.xml file
|
2022-01-24 08:57:53 +01:00
|
|
|
:rtype: str
|
2010-01-18 16:12:10 +01:00
|
|
|
"""
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2023-04-27 13:58:13 +02:00
|
|
|
for root, dirs, files in os.walk(path):
|
|
|
|
if not "repodata" in dirs:
|
|
|
|
continue
|
|
|
|
if "repomd.xml" in os.listdir(os.path.join(root, "repodata")):
|
|
|
|
return root
|
|
|
|
return None
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2014-11-07 13:41:34 +01:00
|
|
|
def get_prefer_pkgs(dirs, wanted_arch, type, cpio):
|
2007-05-02 15:49:57 +02:00
|
|
|
paths = []
|
2010-02-05 15:14:48 +01:00
|
|
|
repositories = []
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2009-09-13 01:55:56 +02:00
|
|
|
suffix = '*.rpm'
|
2022-09-30 14:09:37 +02:00
|
|
|
if type in ('dsc', 'collax', 'livebuild'):
|
2009-09-13 01:55:56 +02:00
|
|
|
suffix = '*.deb'
|
2014-04-03 17:41:41 +02:00
|
|
|
elif type == 'arch':
|
2020-01-09 15:01:25 +01:00
|
|
|
suffix = '*.pkg.tar.*'
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
for dir in dirs:
|
2010-01-18 16:12:10 +01:00
|
|
|
# check for repodata
|
|
|
|
repository = get_repo(dir)
|
|
|
|
if repository is None:
|
|
|
|
paths += glob.glob(os.path.join(os.path.abspath(dir), suffix))
|
|
|
|
else:
|
|
|
|
repositories.append(repository)
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2010-02-05 15:14:48 +01:00
|
|
|
packageQueries = packagequery.PackageQueries(wanted_arch)
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2010-01-18 16:12:10 +01:00
|
|
|
for repository in repositories:
|
2010-02-05 15:14:48 +01:00
|
|
|
repodataPackageQueries = repodata.queries(repository)
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2010-01-18 16:12:10 +01:00
|
|
|
for packageQuery in repodataPackageQueries:
|
|
|
|
packageQueries.add(packageQuery)
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
for path in paths:
|
2014-11-07 13:41:34 +01:00
|
|
|
if path.endswith('.src.rpm') or path.endswith('.nosrc.rpm'):
|
|
|
|
continue
|
|
|
|
if path.endswith('.patch.rpm') or path.endswith('.delta.rpm'):
|
2007-05-02 15:49:57 +02:00
|
|
|
continue
|
2010-01-18 16:12:10 +01:00
|
|
|
packageQuery = packagequery.PackageQuery.query(path)
|
|
|
|
packageQueries.add(packageQuery)
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2022-07-28 19:11:29 +02:00
|
|
|
prefer_pkgs = {decode_it(name): packageQuery.path()
|
2022-09-12 13:43:10 +02:00
|
|
|
for name, packageQuery in packageQueries.items()}
|
2010-02-28 02:30:13 +01:00
|
|
|
|
2010-01-18 16:12:10 +01:00
|
|
|
depfile = create_deps(packageQueries.values())
|
2018-12-13 15:09:45 +01:00
|
|
|
cpio.add(b'deps', b'\n'.join(depfile))
|
2014-11-07 13:41:34 +01:00
|
|
|
return prefer_pkgs
|
2009-09-10 14:18:07 +02:00
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
def create_deps(pkgqs):
|
|
|
|
"""
|
2014-12-09 13:12:34 +01:00
|
|
|
creates a list of dependencies which corresponds to build's internal
|
2009-09-10 14:18:07 +02:00
|
|
|
dependency file format
|
|
|
|
"""
|
|
|
|
depfile = []
|
|
|
|
for p in pkgqs:
|
2018-12-13 15:09:45 +01:00
|
|
|
id = b'%s.%s-0/0/0: ' % (p.name(), p.arch())
|
|
|
|
depfile.append(b'P:%s%s' % (id, b' '.join(p.provides())))
|
|
|
|
depfile.append(b'R:%s%s' % (id, b' '.join(p.requires())))
|
2014-12-09 13:12:34 +01:00
|
|
|
d = p.conflicts()
|
|
|
|
if d:
|
2018-12-13 15:09:45 +01:00
|
|
|
depfile.append(b'C:%s%s' % (id, b' '.join(d)))
|
2014-12-09 13:12:34 +01:00
|
|
|
d = p.obsoletes()
|
|
|
|
if d:
|
2018-12-13 15:09:45 +01:00
|
|
|
depfile.append(b'O:%s%s' % (id, b' '.join(d)))
|
2017-12-26 23:28:14 +01:00
|
|
|
d = p.recommends()
|
|
|
|
if d:
|
2018-12-13 15:09:45 +01:00
|
|
|
depfile.append(b'r:%s%s' % (id, b' '.join(d)))
|
2017-12-26 23:28:14 +01:00
|
|
|
d = p.supplements()
|
|
|
|
if d:
|
2018-12-13 15:09:45 +01:00
|
|
|
depfile.append(b's:%s%s' % (id, b' '.join(d)))
|
2020-03-15 17:13:21 +01:00
|
|
|
depfile.append(b'I:%s%s-%s 0-%s' % (id, p.name(), p.evr(), p.arch()))
|
2009-09-10 14:18:07 +02:00
|
|
|
return depfile
|
2007-05-02 15:49:57 +02:00
|
|
|
|
|
|
|
|
2010-06-23 14:40:55 +02:00
|
|
|
trustprompt = """Would you like to ...
|
|
|
|
0 - quit (default)
|
2013-07-25 17:19:04 +02:00
|
|
|
1 - always trust packages from '%(project)s'
|
|
|
|
2 - trust packages just this time
|
2010-06-23 14:40:55 +02:00
|
|
|
? """
|
2022-09-12 13:43:10 +02:00
|
|
|
|
|
|
|
|
2023-05-02 09:50:00 +02:00
|
|
|
def check_trusted_projects(apiurl, projects, interactive=True):
|
2022-10-27 00:20:00 +02:00
|
|
|
trusted = conf.config['api_host_options'][apiurl]['trusted_prj']
|
2010-06-23 14:40:55 +02:00
|
|
|
tlen = len(trusted)
|
|
|
|
for prj in projects:
|
2023-05-02 09:50:00 +02:00
|
|
|
is_trusted = False
|
|
|
|
for pattern in trusted:
|
|
|
|
if fnmatch.fnmatch(prj, pattern):
|
|
|
|
is_trusted = True
|
|
|
|
break
|
|
|
|
if not is_trusted:
|
2013-04-09 12:51:28 +02:00
|
|
|
print("\nThe build root needs packages from project '%s'." % prj)
|
|
|
|
print("Note that malicious packages can compromise the build result or even your system.")
|
2023-05-02 09:50:00 +02:00
|
|
|
|
|
|
|
if interactive:
|
|
|
|
r = raw_input(trustprompt % {'project': prj})
|
|
|
|
else:
|
|
|
|
r = "0"
|
|
|
|
|
2010-06-23 14:40:55 +02:00
|
|
|
if r == '1':
|
2017-10-27 11:29:00 +02:00
|
|
|
print("adding '%s' to oscrc: ['%s']['trusted_prj']" % (prj, apiurl))
|
2010-06-23 14:40:55 +02:00
|
|
|
trusted.append(prj)
|
|
|
|
elif r != '2':
|
2020-07-26 13:57:18 +02:00
|
|
|
print("Well, goodbye then :-)")
|
2010-06-23 14:40:55 +02:00
|
|
|
raise oscerr.UserAbort()
|
|
|
|
|
|
|
|
if tlen != len(trusted):
|
2022-10-27 00:20:00 +02:00
|
|
|
conf.config['api_host_options'][apiurl]['trusted_prj'] = trusted
|
2010-06-23 14:40:55 +02:00
|
|
|
conf.config_set_option(apiurl, 'trusted_prj', ' '.join(trusted))
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2020-05-20 11:33:07 +02:00
|
|
|
def get_kiwipath_from_buildinfo(bi, prj, repo):
|
2018-12-13 15:09:45 +01:00
|
|
|
# If the project does not have a path defined we need to get the config
|
|
|
|
# via the repositories in the kiwi file. Unfortunately the buildinfo
|
|
|
|
# does not include a hint if this is the case, so we rely on a heuristic
|
|
|
|
# here: if the path list contains our own repo, it probably does not
|
|
|
|
# come from the kiwi file and thus a path is defined in the config.
|
|
|
|
# It is unlikely that our own repo is included in the kiwi file, as it
|
|
|
|
# contains no packages.
|
|
|
|
myprp = prj + '/' + repo
|
|
|
|
if myprp in bi.pathes:
|
|
|
|
return None
|
|
|
|
kiwipath = bi.pathes
|
|
|
|
kiwipath.insert(0, myprp)
|
|
|
|
return kiwipath
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2023-07-25 15:58:21 +02:00
|
|
|
def calculate_prj_pac(store, opts, descr):
|
|
|
|
project = opts.alternative_project or store.project
|
2019-12-11 14:20:54 +01:00
|
|
|
if opts.local_package:
|
|
|
|
package = os.path.splitext(os.path.basename(descr))[0]
|
|
|
|
else:
|
2023-07-25 15:58:21 +02:00
|
|
|
store.assert_is_package()
|
|
|
|
package = store.package
|
2019-12-11 14:20:54 +01:00
|
|
|
return project, package
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2019-12-11 14:20:54 +01:00
|
|
|
def calculate_build_root(apihost, prj, pac, repo, arch):
|
2022-10-27 00:20:00 +02:00
|
|
|
buildroot = os.environ.get('OSC_BUILD_ROOT', conf.config['build-root']) \
|
2022-09-12 13:43:10 +02:00
|
|
|
% {'repo': repo, 'arch': arch, 'project': prj, 'package': pac, 'apihost': apihost}
|
2019-12-11 14:20:54 +01:00
|
|
|
return buildroot
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2021-03-25 13:37:49 +01:00
|
|
|
def build_as_user():
|
2022-10-27 00:20:00 +02:00
|
|
|
if os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split():
|
2021-03-25 13:37:49 +01:00
|
|
|
return False
|
|
|
|
return True
|
2019-12-11 14:20:54 +01:00
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2021-03-25 13:37:49 +01:00
|
|
|
def su_wrapper(cmd):
|
2022-10-27 00:20:00 +02:00
|
|
|
sucmd = os.environ.get('OSC_SU_WRAPPER', conf.config['su-wrapper']).split()
|
2021-03-19 12:51:56 +01:00
|
|
|
if sucmd:
|
|
|
|
if sucmd[0] == 'su':
|
|
|
|
if sucmd[-1] == '-c':
|
|
|
|
sucmd.pop()
|
|
|
|
cmd = sucmd + ['-s', cmd[0], 'root', '--'] + cmd[1:]
|
|
|
|
else:
|
|
|
|
cmd = sucmd + cmd
|
2021-03-25 13:37:49 +01:00
|
|
|
return cmd
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2021-03-25 13:37:49 +01:00
|
|
|
def run_build(opts, *args):
|
2022-10-27 00:20:00 +02:00
|
|
|
cmd = [conf.config['build-cmd']]
|
2021-03-25 13:37:49 +01:00
|
|
|
cmd += args
|
|
|
|
|
|
|
|
cmd = su_wrapper(cmd)
|
|
|
|
|
2020-01-22 14:24:58 +01:00
|
|
|
if not opts.userootforbuild:
|
|
|
|
cmd.append('--norootforbuild')
|
2019-12-11 14:20:54 +01:00
|
|
|
return run_external(cmd[0], *cmd[1:])
|
|
|
|
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2023-07-25 15:58:21 +02:00
|
|
|
def main(apiurl, store, opts, argv):
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2007-04-25 13:22:40 +02:00
|
|
|
repo = argv[0]
|
|
|
|
arch = argv[1]
|
2008-11-22 11:55:33 +01:00
|
|
|
build_descr = argv[2]
|
2008-12-11 12:36:07 +01:00
|
|
|
xp = []
|
2009-11-23 14:53:59 +01:00
|
|
|
build_root = None
|
2022-04-20 19:22:35 +02:00
|
|
|
cache_dir = None
|
2013-05-27 14:47:16 +02:00
|
|
|
build_uid = ''
|
2022-10-27 00:20:00 +02:00
|
|
|
config = conf.config
|
2021-02-11 10:58:40 +01:00
|
|
|
build_shell_after_fail = config['build-shell-after-fail']
|
2016-11-29 09:07:10 +01:00
|
|
|
vm_memory = config['build-memory']
|
2019-12-03 15:08:41 +01:00
|
|
|
vm_disk_size = config['build-vmdisk-rootsize']
|
2010-04-29 14:27:07 +02:00
|
|
|
vm_type = config['build-type']
|
2015-11-25 14:20:55 +01:00
|
|
|
vm_telnet = None
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2010-01-09 14:25:41 +01:00
|
|
|
build_descr = os.path.abspath(build_descr)
|
2008-11-22 11:55:33 +01:00
|
|
|
build_type = os.path.splitext(build_descr)[1][1:]
|
2012-04-03 15:59:42 +02:00
|
|
|
if os.path.basename(build_descr) == 'PKGBUILD':
|
|
|
|
build_type = 'arch'
|
2015-09-10 11:27:13 +02:00
|
|
|
if os.path.basename(build_descr) == 'build.collax':
|
|
|
|
build_type = 'collax'
|
2017-03-14 15:32:35 +01:00
|
|
|
if os.path.basename(build_descr) == 'appimage.yml':
|
|
|
|
build_type = 'appimage'
|
2022-04-20 17:28:01 +02:00
|
|
|
if os.path.basename(build_descr) == 'Chart.yaml':
|
|
|
|
build_type = 'helm'
|
2016-07-01 11:15:12 +02:00
|
|
|
if os.path.basename(build_descr) == 'snapcraft.yaml':
|
|
|
|
build_type = 'snapcraft'
|
2019-06-27 15:42:28 +02:00
|
|
|
if os.path.basename(build_descr) == 'simpleimage':
|
|
|
|
build_type = 'simpleimage'
|
2017-05-16 11:14:52 +02:00
|
|
|
if os.path.basename(build_descr) == 'Dockerfile':
|
|
|
|
build_type = 'docker'
|
2017-07-21 10:58:33 +02:00
|
|
|
if os.path.basename(build_descr) == 'fissile.yml':
|
|
|
|
build_type = 'fissile'
|
2022-01-31 00:20:16 +01:00
|
|
|
if os.path.basename(build_descr) == '_preinstallimage':
|
|
|
|
build_type = 'preinstallimage'
|
2020-11-11 18:05:20 +01:00
|
|
|
if build_descr.endswith('flatpak.yaml') or build_descr.endswith('flatpak.yml') or build_descr.endswith('flatpak.json'):
|
|
|
|
build_type = 'flatpak'
|
2022-01-31 00:20:16 +01:00
|
|
|
if build_type not in ['spec', 'dsc', 'kiwi', 'arch', 'collax', 'livebuild',
|
2022-04-20 17:28:01 +02:00
|
|
|
'simpleimage', 'snapcraft', 'appimage', 'docker', 'helm',
|
2022-01-31 00:20:16 +01:00
|
|
|
'podman', 'fissile', 'flatpak', 'preinstallimage']:
|
2008-11-22 11:55:33 +01:00
|
|
|
raise oscerr.WrongArgs(
|
2022-04-20 17:28:01 +02:00
|
|
|
'Unknown build type: \'%s\'. '
|
|
|
|
'Build description should end in .spec, .dsc, .kiwi, or .livebuild. '
|
|
|
|
'Or being named PKGBUILD, build.collax, simpleimage, appimage.yml, '
|
|
|
|
'Chart.yaml, snapcraft.yaml, flatpak.json, flatpak.yml, flatpak.yaml, '
|
|
|
|
'preinstallimage or Dockerfile' % build_type)
|
|
|
|
|
2010-01-09 14:25:41 +01:00
|
|
|
if not os.path.isfile(build_descr):
|
|
|
|
raise oscerr.WrongArgs('Error: build description file named \'%s\' does not exist.' % build_descr)
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
buildargs = []
|
2018-04-27 14:59:34 +02:00
|
|
|
buildargs.append('--statistics')
|
2007-05-14 10:29:50 +02:00
|
|
|
if not opts.userootforbuild:
|
|
|
|
buildargs.append('--norootforbuild')
|
2007-04-25 13:22:40 +02:00
|
|
|
if opts.clean:
|
|
|
|
buildargs.append('--clean')
|
2008-07-23 22:05:09 +02:00
|
|
|
if opts.nochecks:
|
|
|
|
buildargs.append('--no-checks')
|
2007-09-03 12:25:18 +02:00
|
|
|
if not opts.no_changelog:
|
2007-08-14 13:26:13 +02:00
|
|
|
buildargs.append('--changelog')
|
2009-11-23 14:53:59 +01:00
|
|
|
if opts.root:
|
|
|
|
build_root = opts.root
|
2013-02-06 17:12:52 +01:00
|
|
|
if opts.target:
|
|
|
|
buildargs.append('--target=%s' % opts.target)
|
2015-03-10 11:58:08 +01:00
|
|
|
if opts.threads:
|
|
|
|
buildargs.append('--threads=%s' % opts.threads)
|
2008-04-24 11:00:23 +02:00
|
|
|
if opts.jobs:
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--jobs=%s' % opts.jobs)
|
2010-02-12 11:55:09 +01:00
|
|
|
elif config['build-jobs'] > 1:
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--jobs=%s' % config['build-jobs'])
|
2010-02-18 18:57:11 +01:00
|
|
|
if opts.icecream or config['icecream'] != '0':
|
2010-02-11 13:47:32 +01:00
|
|
|
if opts.icecream:
|
|
|
|
num = opts.icecream
|
|
|
|
else:
|
|
|
|
num = config['icecream']
|
|
|
|
|
2010-02-18 18:49:22 +01:00
|
|
|
if int(num) > 0:
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--icecream=%s' % num)
|
2010-02-12 11:55:09 +01:00
|
|
|
xp.append('icecream')
|
|
|
|
xp.append('gcc-c++')
|
2020-04-14 06:50:24 +02:00
|
|
|
if opts.ccache or config['ccache']:
|
2008-12-11 12:36:07 +01:00
|
|
|
buildargs.append('--ccache')
|
|
|
|
xp.append('ccache')
|
2020-05-19 14:47:03 +02:00
|
|
|
if opts.pkg_ccache:
|
|
|
|
buildargs.append('--pkg-ccache=%s' % opts.pkg_ccache)
|
|
|
|
xp.append('ccache')
|
2009-12-09 06:53:27 +01:00
|
|
|
if opts.linksources:
|
|
|
|
buildargs.append('--linksources')
|
2008-05-08 14:21:57 +02:00
|
|
|
if opts.baselibs:
|
|
|
|
buildargs.append('--baselibs')
|
2008-09-24 15:13:33 +02:00
|
|
|
if opts.debuginfo:
|
|
|
|
buildargs.append('--debug')
|
2008-12-11 12:36:07 +01:00
|
|
|
if opts._with:
|
2009-11-24 10:49:26 +01:00
|
|
|
for o in opts._with:
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--with=%s' % o)
|
2008-12-11 12:36:07 +01:00
|
|
|
if opts.without:
|
2009-11-24 10:49:26 +01:00
|
|
|
for o in opts.without:
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--without=%s' % o)
|
|
|
|
if opts.define:
|
2010-12-21 16:10:50 +01:00
|
|
|
for o in opts.define:
|
|
|
|
buildargs.append('--define=%s' % o)
|
2010-02-12 22:54:39 +01:00
|
|
|
if config['build-uid']:
|
|
|
|
build_uid = config['build-uid']
|
|
|
|
if opts.build_uid:
|
|
|
|
build_uid = opts.build_uid
|
|
|
|
if build_uid:
|
2018-06-25 22:12:41 +02:00
|
|
|
buildidre = re.compile('^[0-9]+:[0-9]+$')
|
2010-02-12 22:54:39 +01:00
|
|
|
if build_uid == 'caller':
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--uid=%s:%s' % (os.getuid(), os.getgid()))
|
2010-02-12 22:54:39 +01:00
|
|
|
elif buildidre.match(build_uid):
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--uid=%s' % build_uid)
|
2010-02-12 22:54:39 +01:00
|
|
|
else:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Error: build-uid arg must be 2 colon separated numerics: "uid:gid" or "caller"', file=sys.stderr)
|
2010-02-12 22:54:39 +01:00
|
|
|
return 1
|
2021-02-11 10:58:40 +01:00
|
|
|
if opts.shell_after_fail:
|
|
|
|
build_shell_after_fail = opts.shell_after_fail
|
2016-11-29 09:07:10 +01:00
|
|
|
if opts.vm_memory:
|
|
|
|
vm_memory = opts.vm_memory
|
2019-12-03 15:08:41 +01:00
|
|
|
if opts.vm_disk_size:
|
|
|
|
vm_disk_size = opts.vm_disk_size
|
2010-04-29 14:27:29 +02:00
|
|
|
if opts.vm_type:
|
|
|
|
vm_type = opts.vm_type
|
2015-11-25 14:20:55 +01:00
|
|
|
if opts.vm_telnet:
|
|
|
|
vm_telnet = opts.vm_telnet
|
2008-01-07 15:54:31 +01:00
|
|
|
if opts.alternative_project:
|
|
|
|
prj = opts.alternative_project
|
|
|
|
pac = '_repository'
|
2008-10-14 12:38:22 +02:00
|
|
|
else:
|
2023-07-25 15:58:21 +02:00
|
|
|
prj = store.project
|
2009-03-09 00:43:26 +01:00
|
|
|
if opts.local_package:
|
|
|
|
pac = '_repository'
|
|
|
|
else:
|
2023-07-25 15:58:21 +02:00
|
|
|
pac = store.package
|
2017-05-02 10:13:56 +02:00
|
|
|
if opts.multibuild_package:
|
|
|
|
buildargs.append('--buildflavor=%s' % opts.multibuild_package)
|
2019-10-23 11:46:38 +02:00
|
|
|
pac = pac + ":" + opts.multibuild_package
|
2022-09-30 09:20:14 +02:00
|
|
|
if opts.verbose_mode:
|
|
|
|
buildargs.append('--verbose=%s' % opts.verbose_mode)
|
2019-01-09 15:17:06 +01:00
|
|
|
if opts.wipe:
|
|
|
|
buildargs.append("--wipe")
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2014-06-04 15:33:30 +02:00
|
|
|
orig_build_root = config['build-root']
|
2006-10-10 16:04:34 +02:00
|
|
|
# make it possible to override configuration of the rc file
|
2009-10-20 16:30:15 +02:00
|
|
|
for var in ['OSC_PACKAGECACHEDIR', 'OSC_SU_WRAPPER', 'OSC_BUILD_ROOT']:
|
2006-10-10 16:04:34 +02:00
|
|
|
val = os.getenv(var)
|
|
|
|
if val:
|
2022-09-12 13:43:10 +02:00
|
|
|
if var.startswith('OSC_'):
|
|
|
|
var = var[4:]
|
2006-10-10 16:04:34 +02:00
|
|
|
var = var.lower().replace('_', '-')
|
2013-04-09 11:33:25 +02:00
|
|
|
if var in config:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Overriding config value for %s=\'%s\' with \'%s\'' % (var, config[var], val))
|
2006-10-10 16:04:34 +02:00
|
|
|
config[var] = val
|
|
|
|
|
2009-11-17 18:23:30 +01:00
|
|
|
pacname = pac
|
|
|
|
if pacname == '_repository':
|
2010-04-22 09:35:58 +02:00
|
|
|
if not opts.local_package:
|
|
|
|
try:
|
2023-07-25 15:58:21 +02:00
|
|
|
pacname = store.package
|
2010-04-22 09:35:58 +02:00
|
|
|
except oscerr.NoWorkingCopy:
|
|
|
|
opts.local_package = True
|
2010-01-30 00:08:28 +01:00
|
|
|
if opts.local_package:
|
2016-11-14 12:16:16 +01:00
|
|
|
pacname = os.path.splitext(os.path.basename(build_descr))[0]
|
2013-04-09 12:36:42 +02:00
|
|
|
apihost = urlsplit(apiurl)[1]
|
2009-11-23 14:53:59 +01:00
|
|
|
if not build_root:
|
2014-06-04 15:33:30 +02:00
|
|
|
build_root = config['build-root']
|
|
|
|
if build_root == orig_build_root:
|
|
|
|
# ENV var was not set
|
|
|
|
build_root = config['api_host_options'][apiurl].get('build-root', build_root)
|
2013-03-18 17:41:57 +01:00
|
|
|
try:
|
2014-06-04 15:33:30 +02:00
|
|
|
build_root = build_root % {'repo': repo, 'arch': arch,
|
2022-09-12 13:43:10 +02:00
|
|
|
'project': prj, 'package': pacname, 'apihost': apihost}
|
2022-10-27 00:22:09 +02:00
|
|
|
except KeyError:
|
2014-06-04 15:33:30 +02:00
|
|
|
pass
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-03-04 05:10:44 +01:00
|
|
|
# We configure sccache after pacname, so that in default cases we can have an sccache for each
|
|
|
|
# package to prevent cross-cache polutions. It helps to make the local-use case a bit nicer.
|
|
|
|
if opts.sccache_uri or config['sccache_uri'] or opts.sccache or config['sccache']:
|
|
|
|
if opts.pkg_ccache or opts.ccache or config['ccache']:
|
|
|
|
raise oscerr.WrongArgs('Error: sccache and ccache can not be enabled at the same time')
|
|
|
|
sccache_arg = "--sccache-uri=/var/tmp/osbuild-sccache-{pkgname}.tar"
|
|
|
|
if opts.sccache_uri:
|
|
|
|
sccache_arg = '--sccache-uri=%s' % opts.sccache_uri
|
|
|
|
elif config['sccache_uri']:
|
|
|
|
sccache_arg = '--sccache-uri=%s' % config['sccache_uri']
|
|
|
|
# Format the package name.
|
|
|
|
sccache_arg = sccache_arg.format(pkgname=pacname)
|
|
|
|
buildargs.append(sccache_arg)
|
|
|
|
xp.append('sccache')
|
|
|
|
|
2019-12-04 08:41:15 +01:00
|
|
|
# define buildinfo & config local cache
|
|
|
|
bi_file = None
|
|
|
|
bc_file = None
|
|
|
|
bi_filename = '_buildinfo-%s-%s.xml' % (repo, arch)
|
|
|
|
bc_filename = '_buildconfig-%s-%s' % (repo, arch)
|
2023-07-25 15:58:21 +02:00
|
|
|
if store.is_package and os.access(core.store, os.W_OK):
|
2022-07-28 12:28:33 +02:00
|
|
|
bi_filename = os.path.join(os.getcwd(), core.store, bi_filename)
|
|
|
|
bc_filename = os.path.join(os.getcwd(), core.store, bc_filename)
|
2019-12-04 08:41:15 +01:00
|
|
|
elif not os.access('.', os.W_OK):
|
|
|
|
bi_file = NamedTemporaryFile(prefix=bi_filename)
|
|
|
|
bi_filename = bi_file.name
|
|
|
|
bc_file = NamedTemporaryFile(prefix=bc_filename)
|
|
|
|
bc_filename = bc_file.name
|
|
|
|
else:
|
|
|
|
bi_filename = os.path.abspath(bi_filename)
|
|
|
|
bc_filename = os.path.abspath(bc_filename)
|
|
|
|
|
2019-12-02 13:48:59 +01:00
|
|
|
if opts.shell:
|
|
|
|
buildargs.append("--shell")
|
|
|
|
|
2021-02-11 10:58:40 +01:00
|
|
|
if build_shell_after_fail:
|
|
|
|
buildargs.append("--shell-after-fail")
|
|
|
|
|
2020-05-12 09:19:01 +02:00
|
|
|
if opts.shell_cmd:
|
|
|
|
buildargs.append("--shell-cmd")
|
|
|
|
buildargs.append(opts.shell_cmd)
|
|
|
|
|
2019-12-02 13:48:59 +01:00
|
|
|
if opts.noinit:
|
|
|
|
buildargs.append('--noinit')
|
|
|
|
|
2023-07-25 15:58:21 +02:00
|
|
|
if not store.is_package:
|
2021-08-03 09:21:53 +02:00
|
|
|
opts.noservice = True
|
|
|
|
|
2019-12-04 08:41:15 +01:00
|
|
|
# check for source services
|
|
|
|
if not opts.offline and not opts.noservice:
|
2022-07-28 12:28:33 +02:00
|
|
|
p = core.Package(os.curdir)
|
2019-12-04 08:41:15 +01:00
|
|
|
r = p.run_source_services(verbose=True)
|
|
|
|
if r:
|
|
|
|
raise oscerr.ServiceRuntimeError('Source service run failed!')
|
|
|
|
|
2011-04-14 21:54:00 +02:00
|
|
|
cache_dir = config['packagecachedir'] % {'apihost': apihost}
|
|
|
|
|
2009-11-13 14:24:33 +01:00
|
|
|
extra_pkgs = []
|
2008-07-12 14:06:23 +02:00
|
|
|
if not opts.extra_pkgs:
|
2023-01-26 13:42:32 +01:00
|
|
|
extra_pkgs = config.get('extra-pkgs', [])
|
2009-11-13 14:24:33 +01:00
|
|
|
elif opts.extra_pkgs != ['']:
|
2008-07-12 14:06:23 +02:00
|
|
|
extra_pkgs = opts.extra_pkgs
|
|
|
|
|
2022-10-13 00:51:20 +02:00
|
|
|
if opts.extra_pkgs_from:
|
|
|
|
for filename in opts.extra_pkgs_from:
|
|
|
|
with open(filename, encoding="utf-8") as f:
|
|
|
|
for line in f:
|
|
|
|
extra_pkgs.append(line.rstrip('\n'))
|
|
|
|
|
2008-12-11 12:36:07 +01:00
|
|
|
if xp:
|
|
|
|
extra_pkgs += xp
|
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
prefer_pkgs = {}
|
2018-12-13 15:09:45 +01:00
|
|
|
build_descr_data = open(build_descr, 'rb').read()
|
2009-11-24 10:49:53 +01:00
|
|
|
|
|
|
|
# XXX: dirty hack but there's no api to provide custom defines
|
|
|
|
if opts.without:
|
|
|
|
s = ''
|
|
|
|
for i in opts.without:
|
|
|
|
s += "%%define _without_%s 1\n" % i
|
2018-12-13 15:09:45 +01:00
|
|
|
build_descr_data = s.encode() + build_descr_data
|
2009-11-24 10:49:53 +01:00
|
|
|
if opts._with:
|
|
|
|
s = ''
|
|
|
|
for i in opts._with:
|
|
|
|
s += "%%define _with_%s 1\n" % i
|
2018-12-13 15:09:45 +01:00
|
|
|
build_descr_data = s.encode() + build_descr_data
|
2010-12-21 16:10:50 +01:00
|
|
|
if opts.define:
|
|
|
|
s = ''
|
|
|
|
for i in opts.define:
|
|
|
|
s += "%%define %s\n" % i
|
2019-05-25 13:36:10 +02:00
|
|
|
build_descr_data = s.encode() + build_descr_data
|
2009-11-24 10:49:53 +01:00
|
|
|
|
2014-11-07 13:41:34 +01:00
|
|
|
cpiodata = None
|
2015-04-24 09:47:48 +02:00
|
|
|
servicefile = os.path.join(os.path.dirname(build_descr), "_service")
|
|
|
|
if not os.path.isfile(servicefile):
|
|
|
|
servicefile = os.path.join(os.path.dirname(build_descr), "_service")
|
|
|
|
if not os.path.isfile(servicefile):
|
|
|
|
servicefile = None
|
|
|
|
else:
|
|
|
|
print('Using local _service file')
|
2014-11-07 13:41:34 +01:00
|
|
|
buildenvfile = os.path.join(os.path.dirname(build_descr), "_buildenv." + repo + "." + arch)
|
|
|
|
if not os.path.isfile(buildenvfile):
|
|
|
|
buildenvfile = os.path.join(os.path.dirname(build_descr), "_buildenv")
|
|
|
|
if not os.path.isfile(buildenvfile):
|
|
|
|
buildenvfile = None
|
2015-04-24 09:47:48 +02:00
|
|
|
else:
|
|
|
|
print('Using local buildenv file: %s' % os.path.basename(buildenvfile))
|
|
|
|
if buildenvfile or servicefile:
|
2014-11-07 13:41:34 +01:00
|
|
|
if not cpiodata:
|
|
|
|
cpiodata = cpio.CpioWrite()
|
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
if opts.prefer_pkgs:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Scanning the following dirs for local packages: %s' % ', '.join(opts.prefer_pkgs))
|
2014-11-07 13:41:34 +01:00
|
|
|
if not cpiodata:
|
|
|
|
cpiodata = cpio.CpioWrite()
|
|
|
|
prefer_pkgs = get_prefer_pkgs(opts.prefer_pkgs, arch, build_type, cpiodata)
|
|
|
|
|
|
|
|
if cpiodata:
|
2018-12-13 15:09:45 +01:00
|
|
|
cpiodata.add(os.path.basename(build_descr.encode()), build_descr_data)
|
2014-11-07 13:41:34 +01:00
|
|
|
# buildenv must come last for compatibility reasons...
|
|
|
|
if buildenvfile:
|
2018-12-13 15:09:45 +01:00
|
|
|
cpiodata.add(b"buildenv", open(buildenvfile, 'rb').read())
|
2015-04-24 09:47:48 +02:00
|
|
|
if servicefile:
|
2018-12-13 15:09:45 +01:00
|
|
|
cpiodata.add(b"_service", open(servicefile, 'rb').read())
|
2014-11-07 13:41:34 +01:00
|
|
|
build_descr_data = cpiodata.get()
|
2008-12-11 12:36:07 +01:00
|
|
|
|
2010-01-09 14:25:41 +01:00
|
|
|
# special handling for overlay and rsync-src/dest
|
2010-12-07 16:07:20 +01:00
|
|
|
specialcmdopts = []
|
2022-04-20 19:22:35 +02:00
|
|
|
if opts.rsyncsrc or opts.rsyncdest:
|
2010-01-09 14:25:41 +01:00
|
|
|
if not opts.rsyncsrc or not opts.rsyncdest:
|
|
|
|
raise oscerr.WrongOptions('When using --rsync-{src,dest} both parameters have to be specified.')
|
|
|
|
myrsyncsrc = os.path.abspath(os.path.expanduser(os.path.expandvars(opts.rsyncsrc)))
|
|
|
|
if not os.path.isdir(myrsyncsrc):
|
|
|
|
raise oscerr.WrongOptions('--rsync-src %s is no valid directory!' % opts.rsyncsrc)
|
|
|
|
# can't check destination - its in the target chroot ;) - but we can check for sanity
|
|
|
|
myrsyncdest = os.path.expandvars(opts.rsyncdest)
|
|
|
|
if not os.path.isabs(myrsyncdest):
|
|
|
|
raise oscerr.WrongOptions('--rsync-dest %s is no absolute path (starting with \'/\')!' % opts.rsyncdest)
|
2022-09-12 13:43:10 +02:00
|
|
|
specialcmdopts = ['--rsync-src=' + myrsyncsrc, '--rsync-dest=' + myrsyncdest]
|
2010-01-09 14:25:41 +01:00
|
|
|
if opts.overlay:
|
|
|
|
myoverlay = os.path.abspath(os.path.expanduser(os.path.expandvars(opts.overlay)))
|
|
|
|
if not os.path.isdir(myoverlay):
|
|
|
|
raise oscerr.WrongOptions('--overlay %s is no valid directory!' % opts.overlay)
|
2022-09-12 13:43:10 +02:00
|
|
|
specialcmdopts += ['--overlay=' + myoverlay]
|
2010-01-09 14:25:41 +01:00
|
|
|
|
2007-05-09 11:36:55 +02:00
|
|
|
try:
|
2009-10-20 10:43:52 +02:00
|
|
|
if opts.noinit:
|
2009-10-24 14:13:40 +02:00
|
|
|
if not os.path.isfile(bi_filename):
|
2010-01-09 14:25:41 +01:00
|
|
|
raise oscerr.WrongOptions('--noinit is not possible, no local buildinfo file')
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Use local \'%s\' file as buildinfo' % bi_filename)
|
2009-10-24 14:13:40 +02:00
|
|
|
if not os.path.isfile(bc_filename):
|
2010-01-09 14:25:41 +01:00
|
|
|
raise oscerr.WrongOptions('--noinit is not possible, no local buildconfig file')
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Use local \'%s\' file as buildconfig' % bc_filename)
|
2010-04-17 10:53:53 +02:00
|
|
|
elif opts.offline:
|
|
|
|
if not os.path.isfile(bi_filename):
|
|
|
|
raise oscerr.WrongOptions('--offline is not possible, no local buildinfo file')
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Use local \'%s\' file as buildinfo' % bi_filename)
|
2010-04-17 10:53:53 +02:00
|
|
|
if not os.path.isfile(bc_filename):
|
|
|
|
raise oscerr.WrongOptions('--offline is not possible, no local buildconfig file')
|
2009-10-20 10:43:52 +02:00
|
|
|
else:
|
2019-12-03 15:05:48 +01:00
|
|
|
print('Getting buildconfig from server and store to %s' % bc_filename)
|
|
|
|
bc = get_buildconfig(apiurl, prj, repo)
|
|
|
|
if not bc_file:
|
|
|
|
bc_file = open(bc_filename, 'w')
|
|
|
|
bc_file.write(decode_it(bc))
|
|
|
|
bc_file.flush()
|
|
|
|
if os.path.exists('/usr/lib/build/queryconfig') and not opts.nodebugpackages:
|
|
|
|
debug_pkgs = decode_it(return_external('/usr/lib/build/queryconfig', '--dist', bc_filename, 'substitute', 'obs:cli_debug_packages'))
|
|
|
|
if len(debug_pkgs) > 0:
|
2022-10-07 12:57:09 +02:00
|
|
|
extra_pkgs.extend(debug_pkgs.strip().split(" "))
|
2018-12-13 15:09:45 +01:00
|
|
|
|
2019-12-03 15:05:48 +01:00
|
|
|
print('Getting buildinfo from server and store to %s' % bi_filename)
|
2018-12-13 15:09:45 +01:00
|
|
|
bi_text = decode_it(get_buildinfo(apiurl,
|
2022-09-12 13:43:10 +02:00
|
|
|
prj,
|
|
|
|
pac,
|
|
|
|
repo,
|
|
|
|
arch,
|
|
|
|
specfile=build_descr_data,
|
|
|
|
addlist=extra_pkgs))
|
2011-01-20 20:54:38 +01:00
|
|
|
if not bi_file:
|
|
|
|
bi_file = open(bi_filename, 'w')
|
|
|
|
# maybe we should check for errors before saving the file
|
2009-10-20 16:30:15 +02:00
|
|
|
bi_file.write(bi_text)
|
2009-11-26 10:52:26 +01:00
|
|
|
bi_file.flush()
|
2018-12-13 15:09:45 +01:00
|
|
|
kiwipath = None
|
|
|
|
if build_type == 'kiwi':
|
2020-05-20 11:33:07 +02:00
|
|
|
bi = Buildinfo(bi_filename, apiurl, 'kiwi', list(prefer_pkgs.keys()))
|
|
|
|
kiwipath = get_kiwipath_from_buildinfo(bi, prj, repo)
|
2019-12-03 15:05:48 +01:00
|
|
|
bc = get_buildconfig(apiurl, prj, repo, kiwipath)
|
|
|
|
bc_file.seek(0)
|
|
|
|
bc_file.write(decode_it(bc))
|
|
|
|
bc_file.flush()
|
2013-04-09 14:03:17 +02:00
|
|
|
except HTTPError as e:
|
2008-01-07 15:54:31 +01:00
|
|
|
if e.code == 404:
|
2010-03-07 23:07:03 +01:00
|
|
|
# check what caused the 404
|
2008-01-07 15:54:31 +01:00
|
|
|
if meta_exists(metatype='prj', path_args=(quote_plus(prj), ),
|
2009-09-13 01:58:56 +02:00
|
|
|
template_args=None, create_new=False, apiurl=apiurl):
|
2010-03-07 23:07:03 +01:00
|
|
|
pkg_meta_e = None
|
|
|
|
try:
|
|
|
|
# take care, not to run into double trouble.
|
2014-08-12 15:01:16 +02:00
|
|
|
pkg_meta_e = meta_exists(metatype='pkg', path_args=(quote_plus(prj),
|
2022-09-12 13:43:10 +02:00
|
|
|
quote_plus(pac)), template_args=None, create_new=False,
|
|
|
|
apiurl=apiurl)
|
2010-03-07 23:07:03 +01:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-10-09 11:21:53 +02:00
|
|
|
if pkg_meta_e:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('ERROR: Either wrong repo/arch as parameter or a parse error of .spec/.dsc/.kiwi file due to syntax error', file=sys.stderr)
|
2008-01-07 15:54:31 +01:00
|
|
|
else:
|
2022-09-12 13:43:10 +02:00
|
|
|
print('The package \'%s\' does not exist - please '
|
|
|
|
'rerun with \'--local-package\'' % pac, file=sys.stderr)
|
2008-01-07 15:54:31 +01:00
|
|
|
else:
|
2022-09-12 13:43:10 +02:00
|
|
|
print('The project \'%s\' does not exist - please '
|
|
|
|
'rerun with \'--alternative-project <alternative_project>\'' % prj, file=sys.stderr)
|
2009-10-24 14:13:40 +02:00
|
|
|
sys.exit(1)
|
2008-06-12 14:12:29 +02:00
|
|
|
else:
|
|
|
|
raise
|
2007-05-09 11:36:55 +02:00
|
|
|
|
2017-09-26 13:57:59 +02:00
|
|
|
# Set default binary type if cannot be detected
|
|
|
|
binary_type = 'rpm'
|
|
|
|
if os.path.exists('/usr/lib/build/queryconfig'):
|
2018-12-13 15:09:45 +01:00
|
|
|
binary_type = decode_it(return_external('/usr/lib/build/queryconfig', '--dist', bc_filename, 'binarytype')).strip()
|
2017-09-26 13:57:59 +02:00
|
|
|
# If binary type is set to a useless value, reset to 'rpm'
|
|
|
|
if binary_type == 'UNDEFINED':
|
|
|
|
binary_type = 'rpm'
|
|
|
|
|
|
|
|
bi = Buildinfo(bi_filename, apiurl, build_type, list(prefer_pkgs.keys()), binary_type)
|
2009-12-01 14:36:11 +01:00
|
|
|
|
2010-02-18 14:36:41 +01:00
|
|
|
if bi.debuginfo and not (opts.disable_debuginfo or '--debug' in buildargs):
|
2008-10-31 16:41:19 +01:00
|
|
|
buildargs.append('--debug')
|
2009-12-01 14:36:11 +01:00
|
|
|
|
|
|
|
if opts.release:
|
|
|
|
bi.release = opts.release
|
|
|
|
|
|
|
|
if bi.release:
|
2021-02-18 08:56:22 +01:00
|
|
|
buildargs.append('--release')
|
|
|
|
buildargs.append(bi.release)
|
|
|
|
|
|
|
|
if opts.stage:
|
|
|
|
buildargs.append('--stage')
|
|
|
|
buildargs.append(opts.stage)
|
2009-12-01 14:36:11 +01:00
|
|
|
|
2017-04-19 15:33:08 +02:00
|
|
|
if opts.build_opt:
|
|
|
|
buildargs += opts.build_opt
|
|
|
|
|
2023-04-26 09:03:14 +02:00
|
|
|
if opts.buildtool_opt:
|
|
|
|
buildargs += [f"--buildtool-opt={opt}" for opt in opts.buildtool_opt]
|
|
|
|
|
2009-10-20 16:30:15 +02:00
|
|
|
# real arch of this machine
|
2008-08-15 16:04:27 +02:00
|
|
|
# vs.
|
|
|
|
# arch we are supposed to build for
|
2019-12-02 08:35:50 +01:00
|
|
|
if vm_type != "emulator" and vm_type != "qemu":
|
2022-08-29 12:56:57 +02:00
|
|
|
if bi.hostarch is not None:
|
2022-09-12 14:15:34 +02:00
|
|
|
if hostarch != bi.hostarch and bi.hostarch not in can_also_build.get(hostarch, []):
|
2019-12-02 08:35:50 +01:00
|
|
|
print('Error: hostarch \'%s\' is required.' % (bi.hostarch), file=sys.stderr)
|
|
|
|
return 1
|
|
|
|
elif hostarch != bi.buildarch:
|
2022-09-12 14:15:34 +02:00
|
|
|
if bi.buildarch not in can_also_build.get(hostarch, []):
|
2019-12-02 08:35:50 +01:00
|
|
|
print('WARNING: It is guessed to build on hostarch \'%s\' for \'%s\' via QEMU user emulation.' % (hostarch, bi.buildarch), file=sys.stderr)
|
2008-08-15 16:04:27 +02:00
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist_prefers = []
|
2009-09-10 14:18:07 +02:00
|
|
|
if prefer_pkgs:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Evaluating preferred packages')
|
2013-04-22 16:26:31 +02:00
|
|
|
for name, path in prefer_pkgs.items():
|
2007-05-02 15:49:57 +02:00
|
|
|
if bi.has_dep(name):
|
2008-01-07 15:54:31 +01:00
|
|
|
# We remove a preferred package from the buildinfo, so that the
|
|
|
|
# fetcher doesn't take care about them.
|
|
|
|
# Instead, we put it in a list which is appended to the rpmlist later.
|
|
|
|
# At the same time, this will make sure that these packages are
|
|
|
|
# not verified.
|
|
|
|
bi.remove_dep(name)
|
|
|
|
rpmlist_prefers.append((name, path))
|
2013-04-09 12:51:28 +02:00
|
|
|
print(' - %s (%s)' % (name, path))
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Updating cache of required packages')
|
2009-02-20 10:36:20 +01:00
|
|
|
|
|
|
|
urllist = []
|
2010-01-20 09:15:17 +01:00
|
|
|
if not opts.download_api_only:
|
|
|
|
# transform 'url1, url2, url3' form into a list
|
|
|
|
if 'urllist' in config:
|
2013-04-09 11:34:46 +02:00
|
|
|
if isinstance(config['urllist'], str):
|
2010-01-20 09:15:17 +01:00
|
|
|
re_clist = re.compile('[, ]+')
|
2022-09-12 13:43:10 +02:00
|
|
|
urllist = [i.strip() for i in re_clist.split(config['urllist'].strip())]
|
2010-01-20 09:15:17 +01:00
|
|
|
else:
|
|
|
|
urllist = config['urllist']
|
2009-04-14 13:33:45 +02:00
|
|
|
|
2021-09-16 16:56:38 +02:00
|
|
|
# OBS 1.5 and before has no downloadurl defined in buildinfo, but it is obsolete again meanwhile.
|
|
|
|
# we have now specific download repositories per repository. Could be removed IMHO, since the api fallback
|
|
|
|
# is there. In worst case it could fetch the wrong rpm...
|
2010-01-20 09:15:17 +01:00
|
|
|
if bi.downloadurl:
|
2021-12-07 20:26:41 +01:00
|
|
|
urllist.append(bi.downloadurl.replace('%', '%%') + '/%(extproject)s/%(extrepository)s/%(arch)s/%(filename)s')
|
2010-09-07 16:08:05 +02:00
|
|
|
if opts.disable_cpio_bulk_download:
|
2022-09-12 13:43:10 +02:00
|
|
|
urllist.append('%(apiurl)s/build/%(project)s/%(repository)s/%(repoarch)s/%(repopackage)s/%(repofilename)s')
|
2009-02-20 10:36:20 +01:00
|
|
|
|
2011-04-14 21:54:00 +02:00
|
|
|
fetcher = Fetcher(cache_dir,
|
2022-09-12 13:43:10 +02:00
|
|
|
urllist=urllist,
|
|
|
|
offline=opts.noinit or opts.offline,
|
|
|
|
http_debug=config['http_debug'],
|
|
|
|
modules=bi.modules,
|
2021-09-10 07:51:17 +02:00
|
|
|
enable_cpio=not opts.disable_cpio_bulk_download and bi.enable_cpio,
|
2022-10-27 00:20:00 +02:00
|
|
|
cookiejar=connection.CookieJarAuthHandler(apiurl, os.path.expanduser(config["cookiejar"]))._cookiejar,
|
2022-02-18 11:55:56 +01:00
|
|
|
download_api_only=opts.download_api_only)
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2015-05-05 23:39:58 +02:00
|
|
|
if not opts.trust_all_projects:
|
|
|
|
# implicitly trust the project we are building for
|
2022-09-12 13:43:10 +02:00
|
|
|
check_trusted_projects(apiurl, [i for i in bi.projects.keys() if not i == prj])
|
2010-06-23 14:40:55 +02:00
|
|
|
|
2016-06-09 16:24:30 +02:00
|
|
|
imagefile = ''
|
|
|
|
imagesource = ''
|
|
|
|
imagebins = []
|
2021-03-25 13:37:49 +01:00
|
|
|
if build_as_user():
|
2022-04-20 19:22:35 +02:00
|
|
|
# preinstallimage extraction will fail
|
|
|
|
bi.preinstallimage = None
|
2022-01-31 00:20:16 +01:00
|
|
|
if build_type == 'preinstallimage':
|
2022-04-20 19:22:35 +02:00
|
|
|
# preinstallimage would repackage just the previously built preinstallimage
|
|
|
|
bi.preinstallimage = None
|
2022-01-31 00:20:16 +01:00
|
|
|
|
2016-06-09 16:24:30 +02:00
|
|
|
if (not config['no_preinstallimage'] and not opts.nopreinstallimage and
|
|
|
|
bi.preinstallimage and
|
2020-09-07 18:54:59 +02:00
|
|
|
not opts.noinit and
|
2016-06-09 16:24:30 +02:00
|
|
|
(opts.clean or (not os.path.exists(build_root + "/installed-pkg") and
|
|
|
|
not os.path.exists(build_root + "/.build/init_buildsystem.data")))):
|
2020-09-07 18:54:59 +02:00
|
|
|
(imagefile, imagesource, imagebins) = get_preinstall_image(apiurl, arch, cache_dir, bi.preinstallimage,
|
|
|
|
opts.offline)
|
2016-06-09 16:24:30 +02:00
|
|
|
if imagefile:
|
|
|
|
# remove binaries from build deps which are included in preinstall image
|
|
|
|
for i in bi.deps:
|
|
|
|
if i.name in imagebins:
|
|
|
|
bi.remove_dep(i.name)
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
# now update the package cache
|
|
|
|
fetcher.run(bi)
|
|
|
|
|
2010-06-24 10:51:38 +02:00
|
|
|
old_pkg_dir = None
|
|
|
|
if opts.oldpackages:
|
|
|
|
old_pkg_dir = opts.oldpackages
|
|
|
|
if not old_pkg_dir.startswith('/') and not opts.offline:
|
2022-09-12 13:43:10 +02:00
|
|
|
data = [prj, pacname, repo, arch]
|
2010-06-24 10:51:38 +02:00
|
|
|
if old_pkg_dir == '_link':
|
2022-09-13 16:34:54 +02:00
|
|
|
p = core.Package(os.curdir)
|
2010-06-24 10:51:38 +02:00
|
|
|
if not p.islink():
|
|
|
|
raise oscerr.WrongOptions('package is not a link')
|
|
|
|
data[0] = p.linkinfo.project
|
|
|
|
data[1] = p.linkinfo.package
|
2022-07-28 12:28:33 +02:00
|
|
|
repos = core.get_repositories_of_project(apiurl, data[0])
|
2010-06-24 10:51:38 +02:00
|
|
|
# hack for links to e.g. Factory
|
|
|
|
if not data[2] in repos and 'standard' in repos:
|
|
|
|
data[2] = 'standard'
|
|
|
|
elif old_pkg_dir != '' and old_pkg_dir != '_self':
|
|
|
|
a = old_pkg_dir.split('/')
|
|
|
|
for i in range(0, len(a)):
|
|
|
|
data[i] = a[i]
|
|
|
|
|
2011-04-14 21:54:00 +02:00
|
|
|
destdir = os.path.join(cache_dir, data[0], data[2], data[3])
|
2010-06-24 10:51:38 +02:00
|
|
|
old_pkg_dir = None
|
|
|
|
try:
|
2013-04-09 12:51:28 +02:00
|
|
|
print("Downloading previous build from %s ..." % '/'.join(data))
|
2010-06-24 10:51:38 +02:00
|
|
|
binaries = get_binarylist(apiurl, data[0], data[2], data[3], package=data[1], verbose=True)
|
2013-04-09 11:27:02 +02:00
|
|
|
except Exception as e:
|
2013-04-09 12:51:28 +02:00
|
|
|
print("Error: failed to get binaries: %s" % str(e))
|
2010-06-24 10:51:38 +02:00
|
|
|
binaries = []
|
|
|
|
|
|
|
|
if binaries:
|
|
|
|
class mytmpdir:
|
|
|
|
""" temporary directory that removes itself"""
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-06-24 10:51:38 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.name = mkdtemp(*args, **kwargs)
|
2015-01-03 13:06:12 +01:00
|
|
|
_rmtree = staticmethod(shutil.rmtree)
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-06-24 10:51:38 +02:00
|
|
|
def cleanup(self):
|
2015-01-03 13:06:12 +01:00
|
|
|
self._rmtree(self.name)
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-06-24 10:51:38 +02:00
|
|
|
def __del__(self):
|
|
|
|
self.cleanup()
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2023-01-20 16:05:14 +01:00
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
2010-06-24 10:51:38 +02:00
|
|
|
self.cleanup()
|
2022-09-12 13:43:10 +02:00
|
|
|
|
2010-06-24 10:51:38 +02:00
|
|
|
def __str__(self):
|
2023-01-20 16:16:06 +01:00
|
|
|
return self.name or ""
|
2010-06-24 10:51:38 +02:00
|
|
|
|
|
|
|
old_pkg_dir = mytmpdir(prefix='.build.oldpackages', dir=os.path.abspath(os.curdir))
|
|
|
|
if not os.path.exists(destdir):
|
|
|
|
os.makedirs(destdir)
|
|
|
|
for i in binaries:
|
|
|
|
fname = os.path.join(destdir, i.name)
|
|
|
|
os.symlink(fname, os.path.join(str(old_pkg_dir), i.name))
|
|
|
|
if os.path.exists(fname):
|
|
|
|
st = os.stat(fname)
|
|
|
|
if st.st_mtime == i.mtime and st.st_size == i.size:
|
|
|
|
continue
|
|
|
|
get_binary_file(apiurl,
|
|
|
|
data[0],
|
|
|
|
data[2], data[3],
|
|
|
|
i.name,
|
2022-09-12 13:43:10 +02:00
|
|
|
package=data[1],
|
|
|
|
target_filename=fname,
|
|
|
|
target_mtime=i.mtime,
|
|
|
|
progress_meter=True)
|
2010-06-24 10:51:38 +02:00
|
|
|
|
2022-08-29 12:56:57 +02:00
|
|
|
if old_pkg_dir is not None:
|
2010-12-07 16:07:20 +01:00
|
|
|
buildargs.append('--oldpackages=%s' % old_pkg_dir)
|
2010-06-24 10:51:38 +02:00
|
|
|
|
2017-07-21 10:58:33 +02:00
|
|
|
# Make packages from buildinfo available as repos for kiwi/docker/fissile
|
2022-09-30 14:09:37 +02:00
|
|
|
if build_type in ('kiwi', 'docker', 'podman', 'fissile'):
|
2013-07-04 11:04:31 +02:00
|
|
|
if os.path.exists('repos'):
|
2010-07-13 12:13:25 +02:00
|
|
|
shutil.rmtree('repos')
|
2017-05-16 14:02:37 +02:00
|
|
|
if os.path.exists('containers'):
|
|
|
|
shutil.rmtree('containers')
|
2013-07-04 11:04:31 +02:00
|
|
|
os.mkdir('repos')
|
2009-06-03 12:10:51 +02:00
|
|
|
for i in bi.deps:
|
2012-11-08 09:01:19 +01:00
|
|
|
if not i.extproject:
|
|
|
|
# remove
|
|
|
|
bi.deps.remove(i)
|
|
|
|
continue
|
2017-05-16 14:02:37 +02:00
|
|
|
if i.notmeta:
|
|
|
|
continue
|
2009-06-03 12:10:51 +02:00
|
|
|
# project
|
|
|
|
pdir = str(i.extproject).replace(':/', ':')
|
|
|
|
# repo
|
|
|
|
rdir = str(i.extrepository).replace(':/', ':')
|
|
|
|
# arch
|
|
|
|
adir = i.repoarch
|
|
|
|
# source fullfilename
|
|
|
|
sffn = i.fullfilename
|
2013-05-27 14:47:16 +02:00
|
|
|
filename = sffn.split("/")[-1]
|
2017-05-16 14:02:37 +02:00
|
|
|
# project/repo
|
|
|
|
if i.name.startswith("container:"):
|
2022-09-12 13:43:10 +02:00
|
|
|
prdir = "containers/" + pdir + "/" + rdir
|
2017-05-16 14:02:37 +02:00
|
|
|
pradir = prdir
|
|
|
|
filename = filename[10:]
|
|
|
|
if build_type == 'kiwi':
|
|
|
|
buildargs.append('--kiwi-parameter')
|
2017-07-03 13:33:33 +02:00
|
|
|
buildargs.append('--set-container-derived-from=dir://./' + prdir + "/" + filename)
|
2017-05-16 14:02:37 +02:00
|
|
|
else:
|
2022-09-12 13:43:10 +02:00
|
|
|
prdir = "repos/" + pdir + "/" + rdir
|
2017-05-16 14:02:37 +02:00
|
|
|
# project/repo/arch
|
2022-09-12 13:43:10 +02:00
|
|
|
pradir = prdir + "/" + adir
|
2009-06-03 12:10:51 +02:00
|
|
|
# target fullfilename
|
2022-09-12 13:43:10 +02:00
|
|
|
tffn = pradir + "/" + filename
|
2009-06-03 12:10:51 +02:00
|
|
|
if not os.path.exists(os.path.join(pradir)):
|
|
|
|
os.makedirs(os.path.join(pradir))
|
|
|
|
if not os.path.exists(tffn):
|
2022-09-12 13:43:10 +02:00
|
|
|
print("Using package: " + sffn)
|
2009-12-09 06:53:27 +01:00
|
|
|
if opts.linksources:
|
2010-02-27 20:11:15 +01:00
|
|
|
os.link(sffn, tffn)
|
2009-12-09 06:53:27 +01:00
|
|
|
else:
|
2010-02-27 20:11:15 +01:00
|
|
|
os.symlink(sffn, tffn)
|
2012-11-08 09:01:19 +01:00
|
|
|
if prefer_pkgs:
|
2013-04-09 11:25:19 +02:00
|
|
|
for name, path in prefer_pkgs.items():
|
2013-05-27 14:19:44 +02:00
|
|
|
if name == filename:
|
|
|
|
print("Using prefered package: " + path + "/" + filename)
|
|
|
|
os.unlink(tffn)
|
2023-07-31 15:19:15 +02:00
|
|
|
|
|
|
|
if prefer_pkgs:
|
|
|
|
localpkgdir = "repos/_local/"
|
|
|
|
os.mkdir(localpkgdir)
|
|
|
|
buildargs.append("--kiwi-parameter")
|
|
|
|
buildargs.append("--add-repo")
|
|
|
|
buildargs.append("--kiwi-parameter")
|
|
|
|
buildargs.append(f"dir://./{localpkgdir}")
|
|
|
|
buildargs.append("--kiwi-parameter")
|
|
|
|
buildargs.append("--add-repotype")
|
|
|
|
buildargs.append("--kiwi-parameter")
|
|
|
|
buildargs.append("rpm-md")
|
|
|
|
for name, path in prefer_pkgs.items():
|
|
|
|
tffn = os.path.join(localpkgdir, os.path.basename(path))
|
|
|
|
if opts.linksources:
|
|
|
|
os.link(path, tffn)
|
|
|
|
else:
|
|
|
|
os.symlink(path, tffn)
|
2017-05-16 11:14:52 +02:00
|
|
|
|
|
|
|
if build_type == 'kiwi':
|
2013-07-04 16:41:59 +02:00
|
|
|
# Is a obsrepositories tag used?
|
|
|
|
try:
|
|
|
|
tree = ET.parse(build_descr)
|
|
|
|
except:
|
|
|
|
print('could not parse the kiwi file:', file=sys.stderr)
|
|
|
|
print(open(build_descr).read(), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
root = tree.getroot()
|
2019-12-04 14:37:31 +01:00
|
|
|
|
2013-07-04 16:41:59 +02:00
|
|
|
# product
|
2020-02-04 17:26:24 +01:00
|
|
|
if root.find('instsource'):
|
|
|
|
# leads to unsigned media, but avoids build failure
|
|
|
|
buildargs.append('--signdummy')
|
|
|
|
|
2013-07-04 16:41:59 +02:00
|
|
|
for xml in root.findall('instsource'):
|
2019-12-04 14:37:31 +01:00
|
|
|
found_obsrepositories = 0
|
|
|
|
for node in xml.findall('instrepo'):
|
|
|
|
if node and node.find('source').get('path') == 'obsrepositories:/':
|
2022-04-20 19:22:35 +02:00
|
|
|
for path in bi.pathes:
|
|
|
|
found_obsrepositories += 1
|
|
|
|
new_node = ET.SubElement(xml, 'instrepo')
|
|
|
|
new_node.set('name', node.get('name') + "_" + str(found_obsrepositories))
|
|
|
|
new_node.set('priority', node.get('priority'))
|
|
|
|
new_node.set('local', 'true')
|
|
|
|
new_source_node = ET.SubElement(new_node, 'source')
|
|
|
|
new_source_node.set('path', "obs://" + path)
|
|
|
|
xml.remove(node)
|
2019-12-04 14:37:31 +01:00
|
|
|
|
|
|
|
if found_obsrepositories > 0:
|
2022-04-20 19:22:35 +02:00
|
|
|
build_descr = os.getcwd() + '/_service:osc_obsrepositories:' + build_descr.rsplit('/', 1)[-1]
|
|
|
|
tree.write(open(build_descr, 'wb'))
|
2019-12-04 14:37:31 +01:00
|
|
|
|
2013-07-04 16:41:59 +02:00
|
|
|
# appliance
|
2022-04-20 19:22:35 +02:00
|
|
|
expand_obsrepos = None
|
2013-07-04 16:41:59 +02:00
|
|
|
for xml in root.findall('repository'):
|
|
|
|
if xml.find('source').get('path') == 'obsrepositories:/':
|
2022-04-20 19:22:35 +02:00
|
|
|
expand_obsrepos = True
|
2013-08-14 10:56:35 +02:00
|
|
|
if expand_obsrepos:
|
2022-04-20 19:22:35 +02:00
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('--ignore-repos')
|
|
|
|
for xml in root.findall('repository'):
|
|
|
|
if xml.find('source').get('path') == 'obsrepositories:/':
|
|
|
|
for path in bi.pathes:
|
2022-09-12 13:43:10 +02:00
|
|
|
if not os.path.isdir("repos/" + path):
|
2022-04-20 19:22:35 +02:00
|
|
|
continue
|
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('--add-repo')
|
|
|
|
buildargs.append('--kiwi-parameter')
|
2022-09-12 13:43:10 +02:00
|
|
|
buildargs.append("dir://./repos/" + path)
|
2022-04-20 19:22:35 +02:00
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('--add-repotype')
|
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('rpm-md')
|
|
|
|
if xml.get('priority'):
|
|
|
|
buildargs.append('--kiwi-parameter')
|
2022-09-12 13:43:10 +02:00
|
|
|
buildargs.append('--add-repoprio=' + xml.get('priority'))
|
2022-04-20 19:22:35 +02:00
|
|
|
else:
|
|
|
|
m = re.match(r"obs://[^/]+/([^/]+)/(\S+)", xml.find('source').get('path'))
|
|
|
|
if not m:
|
|
|
|
# short path without obs instance name
|
|
|
|
m = re.match(r"obs://([^/]+)/(.+)", xml.find('source').get('path'))
|
|
|
|
project = m.group(1).replace(":", ":/")
|
|
|
|
repo = m.group(2)
|
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('--add-repo')
|
|
|
|
buildargs.append('--kiwi-parameter')
|
2022-09-12 13:43:10 +02:00
|
|
|
buildargs.append("dir://./repos/" + project + "/" + repo)
|
2022-04-20 19:22:35 +02:00
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('--add-repotype')
|
|
|
|
buildargs.append('--kiwi-parameter')
|
|
|
|
buildargs.append('rpm-md')
|
|
|
|
if xml.get('priority'):
|
|
|
|
buildargs.append('--kiwi-parameter')
|
2022-09-12 13:43:10 +02:00
|
|
|
buildargs.append('--add-repopriority=' + xml.get('priority'))
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2022-09-30 14:09:37 +02:00
|
|
|
if vm_type in ('xen', 'kvm', 'lxc', 'nspawn'):
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Skipping verification of package signatures due to secure VM build')
|
2013-02-03 19:07:17 +01:00
|
|
|
elif bi.pacsuffix == 'rpm':
|
2010-06-23 14:40:55 +02:00
|
|
|
if opts.no_verify:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Skipping verification of package signatures')
|
2008-01-24 19:06:45 +01:00
|
|
|
else:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Verifying integrity of cached packages')
|
2010-08-04 15:14:37 +02:00
|
|
|
verify_pacs(bi)
|
2009-11-05 10:11:00 +01:00
|
|
|
elif bi.pacsuffix == 'deb':
|
2013-02-03 19:07:17 +01:00
|
|
|
if opts.no_verify or opts.noinit:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Skipping verification of package signatures')
|
2009-11-05 10:11:00 +01:00
|
|
|
else:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('WARNING: deb packages get not verified, they can compromise your system !')
|
2009-11-05 10:11:00 +01:00
|
|
|
else:
|
2013-04-09 12:51:28 +02:00
|
|
|
print('WARNING: unknown packages get not verified, they can compromise your system !')
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2014-11-17 12:39:58 +01:00
|
|
|
for i in bi.deps:
|
|
|
|
if i.hdrmd5:
|
2023-07-13 13:46:01 +02:00
|
|
|
if not i.name.startswith('container:') and not i.fullfilename.endswith(".rpm"):
|
2021-10-12 10:54:20 +02:00
|
|
|
continue
|
2017-05-17 11:20:03 +02:00
|
|
|
if i.name.startswith('container:'):
|
|
|
|
hdrmd5 = dgst(i.fullfilename)
|
|
|
|
else:
|
|
|
|
hdrmd5 = packagequery.PackageQuery.queryhdrmd5(i.fullfilename)
|
2014-11-17 12:39:58 +01:00
|
|
|
if not hdrmd5:
|
|
|
|
print("Error: cannot get hdrmd5 for %s" % i.fullfilename)
|
|
|
|
sys.exit(1)
|
|
|
|
if hdrmd5 != i.hdrmd5:
|
2023-02-20 14:28:59 +01:00
|
|
|
if conf.config["api_host_options"][apiurl]["disable_hdrmd5_check"]:
|
|
|
|
print(f"Warning: Ignoring a hdrmd5 mismatch for {i.fullfilename}: {hdrmd5} (actual) != {i.hdrmd5} (expected)")
|
|
|
|
else:
|
|
|
|
print(f"Error: hdrmd5 mismatch for {i.fullfilename}: {hdrmd5} (actual) != {i.hdrmd5} (expected)")
|
|
|
|
sys.exit(1)
|
2014-11-17 12:39:58 +01:00
|
|
|
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Writing build configuration')
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-09-30 14:09:37 +02:00
|
|
|
if build_type in ('kiwi', 'docker', 'podman', 'fissile'):
|
2022-04-20 19:22:35 +02:00
|
|
|
rpmlist = ['%s %s\n' % (i.name, i.fullfilename) for i in bi.deps if not i.noinstall]
|
2014-04-30 16:25:31 +02:00
|
|
|
else:
|
2021-05-14 16:01:56 +02:00
|
|
|
rpmlist = []
|
|
|
|
for dep in bi.deps:
|
|
|
|
if dep.sysroot:
|
|
|
|
# packages installed in sysroot subdirectory need to get a prefix for init_buildsystem
|
2022-10-21 10:38:57 +02:00
|
|
|
rpmlist.append("sysroot: %s %s\n" % (dep.name, dep.fullfilename))
|
2021-05-14 16:01:56 +02:00
|
|
|
else:
|
2022-10-21 10:38:57 +02:00
|
|
|
rpmlist.append("%s %s\n" % (dep.name, dep.fullfilename))
|
2016-06-09 16:24:30 +02:00
|
|
|
for i in imagebins:
|
2022-10-21 10:38:57 +02:00
|
|
|
rpmlist.append("%s preinstallimage\n" % i)
|
|
|
|
rpmlist += ["%s %s\n" % (i[0], i[1]) for i in rpmlist_prefers]
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2016-06-09 16:24:30 +02:00
|
|
|
if imagefile:
|
|
|
|
rpmlist.append('preinstallimage: %s\n' % imagefile)
|
|
|
|
if imagesource:
|
|
|
|
rpmlist.append('preinstallimagesource: %s\n' % imagesource)
|
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist.append('preinstall: ' + ' '.join(bi.preinstall_list) + '\n')
|
2009-02-20 14:45:00 +01:00
|
|
|
rpmlist.append('vminstall: ' + ' '.join(bi.vminstall_list) + '\n')
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist.append('runscripts: ' + ' '.join(bi.runscripts_list) + '\n')
|
2018-08-14 13:02:16 +02:00
|
|
|
if build_type != 'kiwi' and build_type != 'docker' and build_type != 'podman' and build_type != 'fissile':
|
2017-07-21 10:58:33 +02:00
|
|
|
if bi.noinstall_list:
|
|
|
|
rpmlist.append('noinstall: ' + ' '.join(bi.noinstall_list) + '\n')
|
|
|
|
if bi.installonly_list:
|
|
|
|
rpmlist.append('installonly: ' + ' '.join(bi.installonly_list) + '\n')
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2018-12-13 15:09:45 +01:00
|
|
|
rpmlist_file = NamedTemporaryFile(mode='w+t', prefix='rpmlist.')
|
2009-10-24 14:13:40 +02:00
|
|
|
rpmlist_filename = rpmlist_file.name
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist_file.writelines(rpmlist)
|
2009-10-24 14:21:30 +02:00
|
|
|
rpmlist_file.flush()
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2022-04-20 19:22:35 +02:00
|
|
|
subst = {'repo': repo, 'arch': arch, 'project': prj, 'package': pacname}
|
2010-12-07 16:07:20 +01:00
|
|
|
vm_options = []
|
2010-03-17 16:48:41 +01:00
|
|
|
# XXX check if build-device present
|
|
|
|
my_build_device = ''
|
|
|
|
if config['build-device']:
|
2010-03-30 11:06:56 +02:00
|
|
|
my_build_device = config['build-device'] % subst
|
|
|
|
else:
|
|
|
|
# obs worker uses /root here but that collides with the
|
|
|
|
# /root directory if the build root was used without vm
|
|
|
|
# before
|
|
|
|
my_build_device = build_root + '/img'
|
|
|
|
|
2010-04-29 14:27:07 +02:00
|
|
|
if vm_type:
|
2010-03-30 11:06:56 +02:00
|
|
|
if config['build-swap']:
|
|
|
|
my_build_swap = config['build-swap'] % subst
|
|
|
|
else:
|
|
|
|
my_build_swap = build_root + '/swap'
|
|
|
|
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options = [f"--vm-type={vm_type}"]
|
2015-11-25 14:20:55 +01:00
|
|
|
if vm_telnet:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vm-telnet={vm_telnet}"]
|
2016-11-29 09:07:10 +01:00
|
|
|
if vm_memory:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--memory={vm_memory}"]
|
2019-11-13 16:30:56 +01:00
|
|
|
if vm_type != 'lxc' and vm_type != 'nspawn':
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vm-disk={my_build_device}"]
|
|
|
|
vm_options += [f"--vm-swap={my_build_swap}"]
|
|
|
|
vm_options += [f"--logfile={build_root}/.build.log"]
|
2010-04-29 14:27:07 +02:00
|
|
|
if vm_type == 'kvm':
|
2014-11-20 17:09:53 +01:00
|
|
|
if config['build-kernel']:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vm-kernel={config['build-kernel']}"]
|
2014-11-20 17:09:53 +01:00
|
|
|
if config['build-initrd']:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vm-initrd={config['build-initrd']}"]
|
2014-11-20 17:09:53 +01:00
|
|
|
|
2010-03-30 11:06:56 +02:00
|
|
|
build_root += '/.mount'
|
2019-12-03 15:08:41 +01:00
|
|
|
if vm_disk_size:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vmdisk-rootsize={vm_disk_size}"]
|
2010-03-17 16:48:41 +01:00
|
|
|
|
2010-03-30 11:06:56 +02:00
|
|
|
if config['build-vmdisk-swapsize']:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vmdisk-swapsize={config['build-vmdisk-swapsize']}"]
|
2012-02-04 17:02:18 +01:00
|
|
|
if config['build-vmdisk-filesystem']:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vmdisk-filesystem={config['build-vmdisk-filesystem']}"]
|
2016-02-18 11:31:59 +01:00
|
|
|
if config['build-vm-user']:
|
2023-08-28 11:29:09 +02:00
|
|
|
vm_options += [f"--vm-user={config['build-vm-user']}"]
|
2009-10-20 16:30:15 +02:00
|
|
|
|
2010-04-17 10:53:53 +02:00
|
|
|
if opts.preload:
|
2013-04-09 12:51:28 +02:00
|
|
|
print("Preload done for selected repo/arch.")
|
2010-04-17 10:53:53 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
2013-04-09 12:51:28 +02:00
|
|
|
print('Running build')
|
2023-08-28 11:29:09 +02:00
|
|
|
cmd = [
|
|
|
|
config['build-cmd'],
|
|
|
|
f"--root={build_root}",
|
|
|
|
f"--rpmlist={rpmlist_filename}",
|
|
|
|
f"--dist={bc_filename}",
|
|
|
|
f"--arch={bi.buildarch}",
|
|
|
|
]
|
2010-12-07 16:07:20 +01:00
|
|
|
cmd += specialcmdopts + vm_options + buildargs
|
2022-09-12 13:43:10 +02:00
|
|
|
cmd += [build_descr]
|
2010-03-30 11:06:56 +02:00
|
|
|
|
2021-03-25 13:37:49 +01:00
|
|
|
cmd = su_wrapper(cmd)
|
2008-11-22 17:38:40 +01:00
|
|
|
|
2008-08-15 16:04:27 +02:00
|
|
|
# change personality, if needed
|
2010-12-07 16:07:20 +01:00
|
|
|
if hostarch != bi.buildarch and bi.buildarch in change_personality:
|
2022-09-12 13:43:10 +02:00
|
|
|
cmd = [change_personality[bi.buildarch]] + cmd
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2019-12-04 09:45:17 +01:00
|
|
|
# record our settings for later builds
|
2023-07-25 15:58:21 +02:00
|
|
|
if store.is_package:
|
|
|
|
store.last_buildroot = repo, arch, vm_type
|
2019-12-04 09:45:17 +01:00
|
|
|
|
2010-06-24 10:51:55 +02:00
|
|
|
try:
|
2013-03-08 00:56:57 +01:00
|
|
|
rc = run_external(cmd[0], *cmd[1:])
|
2010-06-24 10:51:55 +02:00
|
|
|
if rc:
|
2013-04-09 12:51:28 +02:00
|
|
|
print()
|
|
|
|
print('The buildroot was:', build_root)
|
2010-06-24 10:51:55 +02:00
|
|
|
sys.exit(rc)
|
2022-10-21 10:38:57 +02:00
|
|
|
except KeyboardInterrupt as keyboard_interrupt_exception:
|
2013-04-09 12:51:28 +02:00
|
|
|
print("keyboard interrupt, killing build ...")
|
2013-03-08 00:56:57 +01:00
|
|
|
cmd.append('--kill')
|
|
|
|
run_external(cmd[0], *cmd[1:])
|
2022-10-21 10:38:57 +02:00
|
|
|
raise keyboard_interrupt_exception
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-11-23 14:53:59 +01:00
|
|
|
pacdir = os.path.join(build_root, '.build.packages')
|
2009-04-20 15:07:43 +02:00
|
|
|
if os.path.islink(pacdir):
|
|
|
|
pacdir = os.readlink(pacdir)
|
2009-11-23 14:53:59 +01:00
|
|
|
pacdir = os.path.join(build_root, pacdir)
|
2006-07-14 20:31:35 +02:00
|
|
|
|
2009-04-20 15:07:43 +02:00
|
|
|
if os.path.exists(pacdir):
|
2014-07-04 16:42:53 +02:00
|
|
|
(s_built, b_built) = get_built_files(pacdir, bi.buildtype)
|
2009-10-20 16:30:15 +02:00
|
|
|
|
2013-04-09 12:51:28 +02:00
|
|
|
print()
|
2022-09-12 13:43:10 +02:00
|
|
|
if s_built:
|
|
|
|
print(decode_it(s_built))
|
2013-04-09 12:51:28 +02:00
|
|
|
print()
|
2018-12-13 15:09:45 +01:00
|
|
|
print(decode_it(b_built))
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-04-20 15:07:43 +02:00
|
|
|
if opts.keep_pkgs:
|
2013-06-03 16:32:39 +02:00
|
|
|
for i in b_built.splitlines() + s_built.splitlines():
|
2018-12-13 15:09:45 +01:00
|
|
|
shutil.copy2(i, os.path.join(opts.keep_pkgs, os.path.basename(decode_it(i))))
|
2009-11-26 10:52:26 +01:00
|
|
|
|
|
|
|
if bi_file:
|
|
|
|
bi_file.close()
|
|
|
|
if bc_file:
|
|
|
|
bc_file.close()
|
|
|
|
rpmlist_file.close()
|
2010-02-25 09:52:47 +01:00
|
|
|
|
|
|
|
# vim: sw=4 et
|