mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-04 18:46:17 +01:00
- added support for the "inject local rpmdata" stuff:
* it's possible to use local packages for a build which don't exist in the obs * currently only rpms are supported but debian support will follow soon
This commit is contained in:
parent
e95e8438e4
commit
3b0d879753
75
osc/build.py
75
osc/build.py
@ -53,7 +53,7 @@ if hostarch == 'i686': # FIXME
|
|||||||
class Buildinfo:
|
class Buildinfo:
|
||||||
"""represent the contents of a buildinfo file"""
|
"""represent the contents of a buildinfo file"""
|
||||||
|
|
||||||
def __init__(self, filename, apiurl, buildtype = 'spec'):
|
def __init__(self, filename, apiurl, buildtype = 'spec', localpkgs = []):
|
||||||
try:
|
try:
|
||||||
tree = ET.parse(filename)
|
tree = ET.parse(filename)
|
||||||
except:
|
except:
|
||||||
@ -94,11 +94,8 @@ class Buildinfo:
|
|||||||
|
|
||||||
self.deps = []
|
self.deps = []
|
||||||
for node in root.findall('bdep'):
|
for node in root.findall('bdep'):
|
||||||
p = Pac(node,
|
p = Pac(node, self.buildarch, self.pacsuffix,
|
||||||
self.buildarch, # buildarch is used only for the URL to access the full tree...
|
apiurl, localpkgs)
|
||||||
self.pacsuffix,
|
|
||||||
apiurl)
|
|
||||||
|
|
||||||
self.deps.append(p)
|
self.deps.append(p)
|
||||||
|
|
||||||
self.vminstall_list = [ dep.name for dep in self.deps if dep.vminstall ]
|
self.vminstall_list = [ dep.name for dep in self.deps if dep.vminstall ]
|
||||||
@ -125,7 +122,7 @@ class Pac:
|
|||||||
|
|
||||||
We build a map that's later used to fill our URL templates
|
We build a map that's later used to fill our URL templates
|
||||||
"""
|
"""
|
||||||
def __init__(self, node, buildarch, pacsuffix, apiurl):
|
def __init__(self, node, buildarch, pacsuffix, apiurl, localpkgs = []):
|
||||||
|
|
||||||
self.mp = {}
|
self.mp = {}
|
||||||
for i in ['name', 'package',
|
for i in ['name', 'package',
|
||||||
@ -140,12 +137,15 @@ class Pac:
|
|||||||
|
|
||||||
self.mp['arch'] = node.get('arch') or self.mp['buildarch']
|
self.mp['arch'] = node.get('arch') or self.mp['buildarch']
|
||||||
|
|
||||||
if not node.get('project') or not node.get('repository'):
|
# this is not the ideal place to check if the package is a localdep or not
|
||||||
raise oscerr.APIError( "incomplete information for package %s, may be caused by a broken project configuration."
|
localdep = self.mp['name'] in localpkgs
|
||||||
|
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.'
|
||||||
% self.mp['name'] )
|
% self.mp['name'] )
|
||||||
|
|
||||||
self.mp['extproject'] = node.get('project').replace(':', ':/')
|
if not localdep:
|
||||||
self.mp['extrepository'] = node.get('repository').replace(':', ':/')
|
self.mp['extproject'] = node.get('project').replace(':', ':/')
|
||||||
|
self.mp['extrepository'] = node.get('repository').replace(':', ':/')
|
||||||
self.mp['repopackage'] = node.get('package') or '_repository'
|
self.mp['repopackage'] = node.get('package') or '_repository'
|
||||||
self.mp['repoarch'] = node.get('repoarch') or self.mp['buildarch']
|
self.mp['repoarch'] = node.get('repoarch') or self.mp['buildarch']
|
||||||
|
|
||||||
@ -223,27 +223,45 @@ def get_built_files(pacdir, pactype):
|
|||||||
def get_prefer_pkgs(dirs, wanted_arch):
|
def get_prefer_pkgs(dirs, wanted_arch):
|
||||||
# XXX learn how to do the same for Debian packages
|
# XXX learn how to do the same for Debian packages
|
||||||
import glob
|
import glob
|
||||||
|
from util import rpmquery, cpio
|
||||||
paths = []
|
paths = []
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
paths += glob.glob(os.path.join(os.path.abspath(dir), '*.rpm'))
|
paths += glob.glob(os.path.join(os.path.abspath(dir), '*.rpm'))
|
||||||
prefer_pkgs = []
|
prefer_pkgs = []
|
||||||
|
rpmqs = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if path.endswith('src.rpm'):
|
if path.endswith('src.rpm'):
|
||||||
continue
|
continue
|
||||||
if path.find('-debuginfo-') > 0:
|
if path.find('-debuginfo-') > 0:
|
||||||
continue
|
continue
|
||||||
arch, name = subprocess.Popen(['rpm', '-qp',
|
rpmq = rpmquery.RpmQuery.query(path)
|
||||||
'--nosignature', '--nodigest',
|
arch = rpmq.arch()
|
||||||
'--qf', '%{arch} %{name}\n', path],
|
name = rpmq.name()
|
||||||
stdout=subprocess.PIPE).stdout.read().split()
|
|
||||||
# instead of thip assumption, we should probably rather take the
|
# instead of thip assumption, we should probably rather take the
|
||||||
# requested arch for this package from buildinfo
|
# requested arch for this package from buildinfo
|
||||||
# also, it will ignore i686 packages, how to handle those?
|
# also, it will ignore i686 packages, how to handle those?
|
||||||
|
# XXX: if multiple versions of a package are encountered we have a
|
||||||
|
# kind of "unpredictable" behaviour: should we always take the newest version?
|
||||||
if arch == wanted_arch or arch == 'noarch':
|
if arch == wanted_arch or arch == 'noarch':
|
||||||
prefer_pkgs.append((name, path))
|
prefer_pkgs.append((name, path))
|
||||||
|
rpmqs.append(rpmq)
|
||||||
|
depfile = create_deps(rpmqs)
|
||||||
|
cpio = cpio.CpioWrite()
|
||||||
|
cpio.add('deps', '\n'.join(depfile))
|
||||||
|
return dict(prefer_pkgs), cpio
|
||||||
|
|
||||||
return dict(prefer_pkgs)
|
|
||||||
|
def create_deps(pkgqs):
|
||||||
|
"""
|
||||||
|
creates a list of requires/provides which corresponds to build's internal
|
||||||
|
dependency file format
|
||||||
|
"""
|
||||||
|
depfile = []
|
||||||
|
for p in pkgqs:
|
||||||
|
id = '%s.%s-0/0/0: ' % (p.name(), p.arch())
|
||||||
|
depfile.append('R:%s%s' % (id, ' '.join(p.requires())))
|
||||||
|
depfile.append('P:%s%s' % (id, ' '.join(p.provides())))
|
||||||
|
return depfile
|
||||||
|
|
||||||
|
|
||||||
def main(opts, argv):
|
def main(opts, argv):
|
||||||
@ -331,6 +349,13 @@ def main(opts, argv):
|
|||||||
if xp:
|
if xp:
|
||||||
extra_pkgs += xp
|
extra_pkgs += xp
|
||||||
|
|
||||||
|
prefer_pkgs = {}
|
||||||
|
build_descr_data = open(build_descr).read()
|
||||||
|
if opts.prefer_pkgs:
|
||||||
|
print 'Scanning the following dirs for local packages: %s' % ', '.join(opts.prefer_pkgs)
|
||||||
|
prefer_pkgs, cpio = get_prefer_pkgs(opts.prefer_pkgs, arch)
|
||||||
|
cpio.add(os.path.basename(build_descr), build_descr_data)
|
||||||
|
build_descr_data = cpio.get()
|
||||||
|
|
||||||
print 'Getting buildinfo from server'
|
print 'Getting buildinfo from server'
|
||||||
tempdir = '/tmp'
|
tempdir = '/tmp'
|
||||||
@ -338,12 +363,12 @@ def main(opts, argv):
|
|||||||
tempdir = os.getenv('TEMP')
|
tempdir = os.getenv('TEMP')
|
||||||
bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = tempdir)
|
bi_file = NamedTemporaryFile(suffix='.xml', prefix='buildinfo.', dir = tempdir)
|
||||||
try:
|
try:
|
||||||
bi_text = ''.join(get_buildinfo(apiurl,
|
bi_text = ''.join(get_buildinfo(apiurl,
|
||||||
prj,
|
prj,
|
||||||
pac,
|
pac,
|
||||||
repo,
|
repo,
|
||||||
arch,
|
arch,
|
||||||
specfile=open(build_descr).read(),
|
specfile=build_descr_data,
|
||||||
addlist=extra_pkgs))
|
addlist=extra_pkgs))
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
@ -367,7 +392,7 @@ def main(opts, argv):
|
|||||||
bi_file.write(bi_text)
|
bi_file.write(bi_text)
|
||||||
bi_file.flush()
|
bi_file.flush()
|
||||||
|
|
||||||
bi = Buildinfo(bi_file.name, apiurl, build_type)
|
bi = Buildinfo(bi_file.name, apiurl, build_type, prefer_pkgs.keys())
|
||||||
if bi.debuginfo and not opts.disable_debuginfo:
|
if bi.debuginfo and not opts.disable_debuginfo:
|
||||||
buildargs.append('--debug')
|
buildargs.append('--debug')
|
||||||
buildargs = ' '.join(set(buildargs))
|
buildargs = ' '.join(set(buildargs))
|
||||||
@ -381,12 +406,8 @@ def main(opts, argv):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
rpmlist_prefers = []
|
rpmlist_prefers = []
|
||||||
if opts.prefer_pkgs:
|
if prefer_pkgs:
|
||||||
print 'Evaluating preferred packages'
|
print 'Evaluating preferred packages'
|
||||||
# the resulting dict will also contain packages which are not on the install list
|
|
||||||
# but they won't be installed
|
|
||||||
prefer_pkgs = get_prefer_pkgs(opts.prefer_pkgs, bi.buildarch)
|
|
||||||
|
|
||||||
for name, path in prefer_pkgs.iteritems():
|
for name, path in prefer_pkgs.iteritems():
|
||||||
if bi.has_dep(name):
|
if bi.has_dep(name):
|
||||||
# We remove a preferred package from the buildinfo, so that the
|
# We remove a preferred package from the buildinfo, so that the
|
||||||
|
Loading…
Reference in New Issue
Block a user