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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
2008-03-11 16:18:02 +01:00
|
|
|
import re
|
2006-07-14 19:39:46 +02:00
|
|
|
import sys
|
|
|
|
from tempfile import NamedTemporaryFile
|
2009-06-03 12:10:51 +02:00
|
|
|
from shutil import rmtree
|
2006-07-14 19:39:46 +02:00
|
|
|
from osc.fetch import *
|
2008-01-07 15:54:31 +01:00
|
|
|
from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig
|
2006-10-10 16:04:34 +02:00
|
|
|
import osc.conf
|
2008-06-20 15:37:49 +02:00
|
|
|
import oscerr
|
2008-10-11 22:26:45 +02:00
|
|
|
import subprocess
|
2007-03-12 21:00:47 +01:00
|
|
|
try:
|
|
|
|
from xml.etree import cElementTree as ET
|
|
|
|
except ImportError:
|
|
|
|
import cElementTree as ET
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-02-28 16:56:32 +01:00
|
|
|
from conf import config, cookiejar
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
change_personality = {
|
2008-11-22 17:38:40 +01:00
|
|
|
'i686': 'linux32',
|
|
|
|
'i586': 'linux32',
|
|
|
|
'i386': 'linux32',
|
|
|
|
'ppc': 'powerpc32',
|
|
|
|
's390': 's390',
|
|
|
|
}
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
can_also_build = {
|
2009-02-06 05:30:21 +01:00
|
|
|
'armv4l': [ 'armv4l' ],
|
|
|
|
'armv5el':[ 'armv4l', 'armv5el' ],
|
2009-05-04 23:44:44 +02:00
|
|
|
'armv6l' :[ 'armv4l', 'armv5el' ],
|
2009-02-06 05:30:21 +01:00
|
|
|
'armv7el':[ 'armv4l', 'armv5el', 'armv7el' ],
|
2009-05-04 23:44:44 +02:00
|
|
|
'armv7l' :[ 'armv4l', 'armv5el', 'armv7el' ],
|
2009-02-06 05:30:21 +01:00
|
|
|
's390x': ['s390' ],
|
|
|
|
'ppc64': [ 'ppc', 'ppc64', ],
|
|
|
|
'i386': [ 'i586', 'armv4l', 'armv5el', 'armv7el', 'sh4' ],
|
|
|
|
'i586': [ 'i386', 'armv4l', 'armv5el', 'armv7el', 'sh4' ],
|
|
|
|
'i686': [ 'i586', 'armv4l', 'armv5el', 'armv7el', 'sh4' ],
|
|
|
|
'x86_64': ['i686', 'i586', 'i386', 'armv4l', 'armv5el', 'armv7el', 'sh4' ],
|
2008-11-22 17:38:40 +01:00
|
|
|
}
|
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]
|
|
|
|
if hostarch == 'i686': # FIXME
|
|
|
|
hostarch = 'i586'
|
|
|
|
|
|
|
|
|
|
|
|
class Buildinfo:
|
|
|
|
"""represent the contents of a buildinfo file"""
|
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
def __init__(self, filename, apiurl, buildtype = 'spec', localpkgs = []):
|
2006-10-10 16:04:34 +02:00
|
|
|
try:
|
|
|
|
tree = ET.parse(filename)
|
|
|
|
except:
|
2008-07-04 14:56:32 +02:00
|
|
|
print >>sys.stderr, 'could not parse the buildinfo:'
|
2007-04-25 23:10:49 +02:00
|
|
|
print >>sys.stderr, open(filename).read()
|
2006-10-10 16:04:34 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
root = tree.getroot()
|
|
|
|
|
|
|
|
if root.find('error') != 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
|
|
|
|
sys.stderr.write(error + '\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-02-24 00:29:32 +01:00
|
|
|
if not (apiurl.startswith('https://') or apiurl.startswith('http://')):
|
|
|
|
raise urllib2.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
|
|
|
|
|
|
|
|
# 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'
|
2009-08-04 18:01:02 +02:00
|
|
|
if self.buildtype == 'dsc':
|
|
|
|
self.pacsuffix = 'deb'
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
self.buildarch = root.find('arch').text
|
2009-08-20 12:45:39 +02:00
|
|
|
self.release = "0"
|
|
|
|
if root.find('release') != None:
|
|
|
|
self.release = root.find('release').text
|
2009-02-20 10:36:20 +01:00
|
|
|
self.downloadurl = root.get('downloadurl')
|
2008-12-10 23:38:00 +01:00
|
|
|
self.debuginfo = 0
|
2008-10-31 16:41:19 +01:00
|
|
|
if root.find('debuginfo') != 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 = []
|
|
|
|
for node in root.findall('bdep'):
|
2009-09-10 14:18:07 +02:00
|
|
|
p = Pac(node, self.buildarch, self.pacsuffix,
|
|
|
|
apiurl, localpkgs)
|
2006-07-14 19:39:46 +02:00
|
|
|
self.deps.append(p)
|
|
|
|
|
2009-02-20 14:45:00 +01:00
|
|
|
self.vminstall_list = [ dep.name for dep in self.deps if dep.vminstall ]
|
2007-03-29 01:37:34 +02:00
|
|
|
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 ]
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2008-11-22 11:55:33 +01:00
|
|
|
|
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):
|
|
|
|
for i in self.deps:
|
|
|
|
if i.name == name:
|
|
|
|
self.deps.remove(i)
|
|
|
|
return True
|
|
|
|
return False
|
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
|
|
|
|
"""
|
2009-09-10 14:18:07 +02:00
|
|
|
def __init__(self, node, buildarch, pacsuffix, apiurl, localpkgs = []):
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
self.mp = {}
|
2008-11-22 11:55:33 +01:00
|
|
|
for i in ['name', 'package',
|
|
|
|
'version', 'release',
|
|
|
|
'project', 'repository',
|
2009-02-20 14:45:00 +01:00
|
|
|
'preinstall', 'vminstall', 'noinstall', 'runscripts',
|
2008-11-22 11:55:33 +01:00
|
|
|
]:
|
|
|
|
self.mp[i] = node.get(i)
|
|
|
|
|
|
|
|
self.mp['buildarch'] = buildarch
|
|
|
|
self.mp['pacsuffix'] = pacsuffix
|
|
|
|
|
2009-03-13 16:58:55 +01:00
|
|
|
self.mp['arch'] = node.get('arch') or self.mp['buildarch']
|
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
|
|
|
|
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.'
|
2009-09-09 10:17:13 +02:00
|
|
|
% self.mp['name'] )
|
|
|
|
|
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(
|
|
|
|
"buildinfo for package %s/%s/%s is incomplete"
|
|
|
|
% (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
|
|
|
|
2009-09-13 18:57:40 +02:00
|
|
|
if self.mp['release']:
|
|
|
|
self.filename = '%(name)s-%(version)s-%(release)s.%(arch)s.%(pacsuffix)s' % self.mp
|
|
|
|
else:
|
|
|
|
self.filename = '%(name)s-%(version)s.%(arch)s.%(pacsuffix)s' % self.mp
|
2009-07-15 21:48:16 +02:00
|
|
|
self.partname = '%s.part' % self.filename
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
self.mp['filename'] = self.filename
|
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:
|
|
|
|
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):
|
|
|
|
|
|
|
|
self.urllist = []
|
|
|
|
|
|
|
|
# build up local URL
|
|
|
|
# by using the urlgrabber with local urls, we basically build up a cache.
|
|
|
|
# the cache has no validation, since the package servers don't support etags,
|
|
|
|
# or if-modified-since, so the caching is simply name-based (on the assumption
|
|
|
|
# that the filename is suitable as identifier)
|
|
|
|
self.localdir = '%s/%s/%s/%s' % (cachedir, self.project, self.repository, self.arch)
|
2009-07-15 21:48:16 +02:00
|
|
|
self.fullfilename = os.path.join(self.localdir, self.filename)
|
|
|
|
self.fullpartname = os.path.join(self.localdir, self.partname)
|
2006-07-14 19:39:46 +02:00
|
|
|
self.url_local = 'file://%s/' % self.fullfilename
|
|
|
|
|
|
|
|
# first, add the local URL
|
|
|
|
self.urllist.append(self.url_local)
|
|
|
|
|
|
|
|
# remote URLs
|
|
|
|
for url in urllist:
|
|
|
|
self.urllist.append(url % self.mp)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
def __repr__(self):
|
|
|
|
return "%s" % self.name
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_built_files(pacdir, pactype):
|
|
|
|
if pactype == 'rpm':
|
2008-11-14 23:32:39 +01:00
|
|
|
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()
|
2009-04-20 15:07:43 +02:00
|
|
|
elif pactype == 'kiwi':
|
|
|
|
b_built = subprocess.Popen(['find', os.path.join(pacdir, 'KIWI'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2006-07-14 19:39:46 +02:00
|
|
|
else:
|
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-04-27 13:44:38 +02:00
|
|
|
s_built = subprocess.Popen(['find', os.path.join(pacdir, 'SOURCES.DEB'),
|
|
|
|
'-type', 'f'],
|
|
|
|
stdout=subprocess.PIPE).stdout.read().strip()
|
2006-07-14 19:39:46 +02:00
|
|
|
return s_built, b_built
|
|
|
|
|
|
|
|
|
2009-09-13 01:55:56 +02:00
|
|
|
def get_prefer_pkgs(dirs, wanted_arch, type):
|
2007-05-02 15:49:57 +02:00
|
|
|
import glob
|
2009-09-13 01:55:56 +02:00
|
|
|
from util import packagequery, cpio
|
|
|
|
# map debian arches to common obs arches
|
|
|
|
arch_map = {'i386': ['i586', 'i686'], 'amd64': ['x86_64']}
|
2007-05-02 15:49:57 +02:00
|
|
|
paths = []
|
2009-09-13 01:55:56 +02:00
|
|
|
suffix = '*.rpm'
|
|
|
|
if type == 'dsc':
|
|
|
|
suffix = '*.deb'
|
2007-05-02 15:49:57 +02:00
|
|
|
for dir in dirs:
|
2009-09-13 01:55:56 +02:00
|
|
|
paths += glob.glob(os.path.join(os.path.abspath(dir), suffix))
|
2009-09-21 19:29:20 +02:00
|
|
|
prefer_pkgs = {}
|
|
|
|
pkgqs = {}
|
2007-05-02 15:49:57 +02:00
|
|
|
for path in paths:
|
|
|
|
if path.endswith('src.rpm'):
|
|
|
|
continue
|
|
|
|
if path.find('-debuginfo-') > 0:
|
|
|
|
continue
|
2009-09-13 01:55:56 +02:00
|
|
|
pkgq = packagequery.PackageQuery.query(path)
|
|
|
|
arch = pkgq.arch()
|
|
|
|
name = pkgq.name()
|
2008-10-11 22:26:45 +02:00
|
|
|
# instead of thip assumption, we should probably rather take the
|
2007-05-02 15:49:57 +02:00
|
|
|
# requested arch for this package from buildinfo
|
|
|
|
# also, it will ignore i686 packages, how to handle those?
|
2009-09-13 01:55:56 +02:00
|
|
|
if arch in [wanted_arch, 'noarch', 'all'] or wanted_arch in arch_map.get(arch, []):
|
2009-09-21 19:29:20 +02:00
|
|
|
curpkgq = pkgqs.get(name)
|
|
|
|
if curpkgq is not None and curpkgq.vercmp(pkgq) > 0:
|
|
|
|
continue
|
|
|
|
prefer_pkgs[name] = path
|
|
|
|
pkgqs[name] = pkgq
|
|
|
|
depfile = create_deps(pkgqs.values())
|
2009-09-10 14:18:07 +02:00
|
|
|
cpio = cpio.CpioWrite()
|
|
|
|
cpio.add('deps', '\n'.join(depfile))
|
2009-09-21 19:29:20 +02:00
|
|
|
return prefer_pkgs, cpio
|
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):
|
|
|
|
"""
|
|
|
|
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
|
2007-05-02 15:49:57 +02:00
|
|
|
|
|
|
|
|
2007-04-25 13:22:40 +02:00
|
|
|
def main(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 = []
|
2008-11-22 11:55:33 +01:00
|
|
|
|
|
|
|
build_type = os.path.splitext(build_descr)[1][1:]
|
|
|
|
if build_type not in ['spec', 'dsc', 'kiwi']:
|
|
|
|
raise oscerr.WrongArgs(
|
|
|
|
"Unknown build type: '%s'. Build description should end in .spec, .dsc or .kiwi." \
|
|
|
|
% build_type)
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
buildargs = []
|
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')
|
|
|
|
if opts.noinit:
|
|
|
|
buildargs.append('--noinit')
|
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')
|
2008-04-24 11:00:23 +02:00
|
|
|
if opts.jobs:
|
|
|
|
buildargs.append('--jobs %s' % opts.jobs)
|
2009-09-20 17:59:46 +02:00
|
|
|
else:
|
|
|
|
smp_mflags = os.sysconf('SC_NPROCESSORS_ONLN')
|
|
|
|
if smp_mflags > 1:
|
|
|
|
buildargs.append('--jobs %s' % smp_mflags)
|
2008-12-11 12:36:07 +01:00
|
|
|
if opts.icecream:
|
|
|
|
buildargs.append('--icecream %s' % opts.icecream)
|
|
|
|
xp.append('icecream')
|
2009-04-14 13:33:50 +02:00
|
|
|
xp.append('gcc-c++')
|
2008-12-11 12:36:07 +01:00
|
|
|
if opts.ccache:
|
|
|
|
buildargs.append('--ccache')
|
|
|
|
xp.append('ccache')
|
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:
|
|
|
|
buildargs.append('--with %s' % opts._with)
|
|
|
|
if opts.without:
|
|
|
|
buildargs.append('--without %s' % opts.without)
|
|
|
|
# FIXME: quoting
|
|
|
|
# if opts.define:
|
|
|
|
# buildargs.append('--define "%s"' % opts.define)
|
2007-05-02 15:49:57 +02:00
|
|
|
|
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
|
|
|
apiurl = config['apiurl']
|
|
|
|
else:
|
|
|
|
prj = store_read_project(os.curdir)
|
2009-03-09 00:43:26 +01:00
|
|
|
if opts.local_package:
|
|
|
|
pac = '_repository'
|
|
|
|
else:
|
|
|
|
pac = store_read_package(os.curdir)
|
2008-10-14 12:38:22 +02:00
|
|
|
apiurl = store_read_apiurl(os.curdir)
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2008-11-22 11:55:33 +01:00
|
|
|
if not os.path.exists(build_descr):
|
|
|
|
print >>sys.stderr, 'Error: build description named \'%s\' does not exist.' % build_descr
|
2007-05-02 15:49:57 +02:00
|
|
|
return 1
|
|
|
|
|
2006-10-10 16:04:34 +02:00
|
|
|
# make it possible to override configuration of the rc file
|
2008-04-09 20:45:59 +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:
|
|
|
|
if var.startswith('OSC_'): var = var[4:]
|
|
|
|
var = var.lower().replace('_', '-')
|
|
|
|
if config.has_key(var):
|
|
|
|
print 'Overriding config value for %s=\'%s\' with \'%s\'' % (var, config[var], val)
|
|
|
|
config[var] = val
|
|
|
|
|
2009-01-09 17:12:45 +01:00
|
|
|
config['build-root'] = config['build-root'] % { 'repo': repo, 'arch': arch,
|
|
|
|
'project' : prj, 'package' : pac
|
|
|
|
}
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2008-07-12 14:06:23 +02:00
|
|
|
if not opts.extra_pkgs:
|
|
|
|
extra_pkgs = config['extra-pkgs']
|
|
|
|
elif opts.extra_pkgs == ['']:
|
|
|
|
extra_pkgs = None
|
|
|
|
else:
|
|
|
|
extra_pkgs = opts.extra_pkgs
|
|
|
|
|
2008-12-11 12:36:07 +01:00
|
|
|
if xp:
|
|
|
|
extra_pkgs += xp
|
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
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)
|
2009-09-13 01:55:56 +02:00
|
|
|
prefer_pkgs, cpio = get_prefer_pkgs(opts.prefer_pkgs, arch, build_type)
|
2009-09-10 14:18:07 +02:00
|
|
|
cpio.add(os.path.basename(build_descr), build_descr_data)
|
|
|
|
build_descr_data = cpio.get()
|
2008-12-11 12:36:07 +01:00
|
|
|
|
2009-10-20 10:43:52 +02:00
|
|
|
bi_file_name = '.buildinfo.xml'
|
|
|
|
bi_file = None
|
2007-05-09 11:36:55 +02:00
|
|
|
try:
|
2009-10-20 10:43:52 +02:00
|
|
|
if opts.noinit:
|
|
|
|
if not os.path.isfile(bi_file_name):
|
|
|
|
print >>sys.stderr, '--noinit is not possible, no local build info file'
|
|
|
|
sys.exit(1)
|
|
|
|
print 'Use local .buildinfo.xml file as build description'
|
|
|
|
bi_file = open(bi_file_name, 'r')
|
|
|
|
else:
|
|
|
|
print 'Getting buildinfo from server and store to local directory as .buildinfo.xml'
|
|
|
|
bi_file = open(bi_file_name, 'w+')
|
|
|
|
bi_text = ''.join(get_buildinfo(apiurl,
|
|
|
|
prj,
|
|
|
|
pac,
|
|
|
|
repo,
|
|
|
|
arch,
|
|
|
|
specfile=build_descr_data,
|
|
|
|
addlist=extra_pkgs))
|
|
|
|
bi_file.write(bi_text)
|
|
|
|
bi_file.flush()
|
2008-01-07 15:54:31 +01:00
|
|
|
except urllib2.HTTPError, e:
|
|
|
|
if e.code == 404:
|
|
|
|
# check what caused the 404
|
|
|
|
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):
|
2008-10-14 12:38:22 +02:00
|
|
|
if pac == '_repository' or meta_exists(metatype='pkg', path_args=(quote_plus(prj), quote_plus(pac)),
|
2009-09-13 01:58:56 +02:00
|
|
|
template_args=None, create_new=False, apiurl=apiurl):
|
2008-01-07 15:54:31 +01:00
|
|
|
print >>sys.stderr, 'wrong repo/arch?'
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'The package \'%s\' does not exists - please ' \
|
|
|
|
'rerun with \'--local-package\'' % pac
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, 'The project \'%s\' does not exists - please ' \
|
|
|
|
'rerun with \'--alternative-project <alternative_project>\'' % prj
|
|
|
|
sys.exit(1)
|
2008-06-12 14:12:29 +02:00
|
|
|
else:
|
|
|
|
raise
|
2007-05-09 11:36:55 +02:00
|
|
|
|
2009-09-10 14:18:07 +02:00
|
|
|
bi = Buildinfo(bi_file.name, apiurl, build_type, prefer_pkgs.keys())
|
2009-04-17 10:39:04 +02:00
|
|
|
if bi.debuginfo and not opts.disable_debuginfo:
|
2008-10-31 16:41:19 +01:00
|
|
|
buildargs.append('--debug')
|
|
|
|
buildargs = ' '.join(set(buildargs))
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2008-08-15 16:04:27 +02:00
|
|
|
# real arch of this machine
|
|
|
|
# vs.
|
|
|
|
# arch we are supposed to build for
|
|
|
|
if hostarch != bi.buildarch:
|
|
|
|
if not bi.buildarch in can_also_build.get(hostarch, []):
|
|
|
|
print >>sys.stderr, 'Error: hostarch \'%s\' cannot build \'%s\'.' % (hostarch, bi.buildarch)
|
|
|
|
return 1
|
|
|
|
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist_prefers = []
|
2009-09-10 14:18:07 +02:00
|
|
|
if prefer_pkgs:
|
2007-05-02 15:49:57 +02:00
|
|
|
print 'Evaluating preferred packages'
|
2007-05-03 17:54:40 +02:00
|
|
|
for name, path in prefer_pkgs.iteritems():
|
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))
|
|
|
|
print ' - %s (%s)' % (name, path)
|
|
|
|
continue
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
print 'Updating cache of required packages'
|
2009-02-20 10:36:20 +01:00
|
|
|
|
|
|
|
urllist = []
|
2009-04-14 13:33:45 +02:00
|
|
|
|
|
|
|
# transform 'url1, url2, url3' form into a list
|
|
|
|
if 'urllist' in config:
|
|
|
|
if type(config['urllist']) == str:
|
|
|
|
re_clist = re.compile('[, ]+')
|
|
|
|
urllist = [ i.strip() for i in re_clist.split(config['urllist'].strip()) ]
|
|
|
|
else:
|
|
|
|
urllist = config['urllist']
|
|
|
|
|
2009-02-20 10:36:20 +01:00
|
|
|
# OBS 1.5 and before has no downloadurl defined in buildinfo
|
|
|
|
if bi.downloadurl:
|
2009-03-13 16:58:55 +01:00
|
|
|
urllist.append(bi.downloadurl + '/%(extproject)s/%(extrepository)s/%(arch)s/%(filename)s')
|
2009-08-06 14:50:53 +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
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
fetcher = Fetcher(cachedir = config['packagecachedir'],
|
2009-02-20 10:36:20 +01:00
|
|
|
urllist = urllist,
|
2008-08-20 11:45:49 +02:00
|
|
|
api_host_options = config['api_host_options'],
|
2009-10-09 13:37:27 +02:00
|
|
|
offline = opts.noinit,
|
2009-02-28 16:56:32 +01:00
|
|
|
http_debug = config['http_debug'],
|
|
|
|
cookiejar=cookiejar)
|
2007-05-02 15:49:57 +02:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
# now update the package cache
|
|
|
|
fetcher.run(bi)
|
|
|
|
|
2009-06-03 13:35:03 +02:00
|
|
|
# Make packages from buildinfo available as repos for kiwi
|
2009-06-03 12:10:51 +02:00
|
|
|
if build_type == 'kiwi':
|
|
|
|
if not os.path.exists('repos'):
|
|
|
|
os.mkdir('repos')
|
|
|
|
else:
|
|
|
|
rmtree('repos')
|
|
|
|
os.mkdir('repos')
|
|
|
|
for i in bi.deps:
|
|
|
|
# project
|
|
|
|
pdir = str(i.extproject).replace(':/', ':')
|
|
|
|
# repo
|
|
|
|
rdir = str(i.extrepository).replace(':/', ':')
|
|
|
|
# arch
|
|
|
|
adir = i.repoarch
|
|
|
|
# project/repo
|
|
|
|
prdir = "repos/"+pdir+"/"+rdir
|
|
|
|
# project/repo/arch
|
|
|
|
pradir = prdir+"/"+adir
|
|
|
|
# source fullfilename
|
|
|
|
sffn = i.fullfilename
|
|
|
|
print "Using package: "+sffn
|
|
|
|
# target fullfilename
|
|
|
|
tffn = pradir+"/"+sffn.split("/")[-1]
|
|
|
|
if not os.path.exists(os.path.join(pradir)):
|
|
|
|
os.makedirs(os.path.join(pradir))
|
|
|
|
if not os.path.exists(tffn):
|
|
|
|
os.symlink(sffn, tffn)
|
2008-11-22 11:55:33 +01:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
if bi.pacsuffix == 'rpm':
|
|
|
|
"""don't know how to verify .deb packages. They are verified on install
|
|
|
|
anyway, I assume... verifying package now saves time though, since we don't
|
|
|
|
even try to set up the buildroot if it wouldn't work."""
|
|
|
|
|
2009-02-20 13:49:17 +01:00
|
|
|
if config['build-type'] == "xen" or config['build-type'] == "kvm":
|
|
|
|
print 'Skipping verification of package signatures due to secure VM build'
|
2009-02-20 15:03:19 +01:00
|
|
|
elif opts.no_verify:
|
2008-01-24 19:06:45 +01:00
|
|
|
print 'Skipping verification of package signatures'
|
|
|
|
else:
|
|
|
|
print 'Verifying integrity of cached packages'
|
|
|
|
verify_pacs([ i.fullfilename for i in bi.deps ])
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
print 'Writing build configuration'
|
|
|
|
|
2008-11-22 11:55:33 +01:00
|
|
|
rpmlist = [ '%s %s\n' % (i.name, i.fullfilename) for i in bi.deps if not i.noinstall ]
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist += [ '%s %s\n' % (i[0], i[1]) for i in rpmlist_prefers ]
|
2006-07-14 19:39:46 +02:00
|
|
|
|
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')
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-05-15 13:40:50 +02:00
|
|
|
tempdir = '/tmp'
|
|
|
|
if sys.platform[:3] == 'win':
|
|
|
|
tempdir = os.getenv('TEMP')
|
|
|
|
rpmlist_file = NamedTemporaryFile(prefix='rpmlist.', dir = tempdir)
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist_file.writelines(rpmlist)
|
|
|
|
rpmlist_file.flush()
|
|
|
|
os.fsync(rpmlist_file)
|
2006-07-14 19:39:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print 'Getting buildconfig from server'
|
2009-05-15 13:40:50 +02:00
|
|
|
tempdir = '/tmp'
|
|
|
|
if sys.platform[:3] == 'win':
|
|
|
|
tempdir = os.getenv('TEMP')
|
|
|
|
bc_file = NamedTemporaryFile(prefix='buildconfig.', dir = tempdir)
|
2008-10-14 12:38:22 +02:00
|
|
|
bc_file.write(get_buildconfig(apiurl, prj, pac, repo, arch))
|
2008-01-07 15:54:31 +01:00
|
|
|
bc_file.flush()
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-02-20 13:49:17 +01:00
|
|
|
vm_options=""
|
|
|
|
if config['build-device'] and config['build-memory'] and config['build-type']:
|
|
|
|
if config['build-type'] == "kvm":
|
|
|
|
vm_options="--kvm " + config['build-device']
|
|
|
|
elif config['build-type'] == "xen":
|
|
|
|
vm_options="--xen " + config['build-device']
|
|
|
|
else:
|
|
|
|
print "ERROR: unknown VM is set ! (" + config['build-type'] + ")"
|
|
|
|
sys.exit(1)
|
|
|
|
if config['build-swap']:
|
|
|
|
vm_options+=" --swap " + config['build-swap']
|
|
|
|
if config['build-memory']:
|
|
|
|
vm_options+=" --memory " + config['build-memory']
|
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
print 'Running build'
|
2009-08-18 23:28:33 +02:00
|
|
|
# special handling for overlay and rsync-src/dest
|
|
|
|
specialcmdopts = " "
|
|
|
|
if opts.rsyncsrc or opts.rsyncdest :
|
|
|
|
if not opts.rsyncsrc or not opts.rsyncdest:
|
|
|
|
print "When using --rsync-{src,dest} both parameters have to be specified."
|
|
|
|
sys.exit(1)
|
|
|
|
myrsyncsrc = os.path.expanduser(os.path.expandvars(opts.rsyncsrc))
|
|
|
|
myrsyncdest = ""
|
|
|
|
if os.path.isdir(myrsyncsrc):
|
|
|
|
myrsyncsrc = os.path.abspath(myrsyncsrc)
|
|
|
|
else:
|
|
|
|
print "--rsync-src " + str(opts.rsyncsrc) + " is no valid directory!"
|
|
|
|
sys.exit(1)
|
|
|
|
# can't check destination - its in the target chroot ;) - but we can check for sanity
|
|
|
|
if not opts.rsyncdest.startswith("/"):
|
|
|
|
print "--rsync-dest " + str(opts.rsyncsrc) + " is no absolute path (starting with '/')!"
|
|
|
|
sys.exit(1)
|
|
|
|
myrsyncdest = os.path.expandvars(opts.rsyncdest)
|
|
|
|
specialcmdopts += '--rsync-src=%s --rsync-dest=%s' \
|
|
|
|
% (myrsyncsrc,
|
|
|
|
myrsyncdest)
|
|
|
|
if opts.overlay:
|
|
|
|
myoverlay = os.path.expanduser(os.path.expandvars(opts.overlay))
|
|
|
|
if not os.path.isdir(myoverlay):
|
|
|
|
print "--overlay " + str(opts.overlay) + " is no valid directory!"
|
|
|
|
sys.exit(1)
|
|
|
|
myoverlay = os.path.abspath(myoverlay)
|
|
|
|
specialcmdopts += '--overlay=%s' \
|
|
|
|
% (myoverlay)
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-20 12:45:39 +02:00
|
|
|
cmd = '%s --root=%s --rpmlist=%s --dist=%s %s --arch=%s --release=%s %s %s %s' \
|
2006-07-14 19:39:46 +02:00
|
|
|
% (config['build-cmd'],
|
2006-09-15 18:13:15 +02:00
|
|
|
config['build-root'],
|
2007-05-02 15:49:57 +02:00
|
|
|
rpmlist_file.name,
|
2006-07-14 19:39:46 +02:00
|
|
|
bc_file.name,
|
2009-08-18 23:28:33 +02:00
|
|
|
specialcmdopts,
|
2008-11-28 20:37:55 +01:00
|
|
|
bi.buildarch,
|
2009-08-20 12:45:39 +02:00
|
|
|
bi.release,
|
2009-02-20 13:49:17 +01:00
|
|
|
vm_options,
|
2008-11-22 11:55:33 +01:00
|
|
|
build_descr,
|
2006-07-14 19:39:46 +02:00
|
|
|
buildargs)
|
|
|
|
|
|
|
|
if config['su-wrapper'].startswith('su '):
|
|
|
|
tmpl = '%s \'%s\''
|
|
|
|
else:
|
|
|
|
tmpl = '%s %s'
|
2008-11-22 17:38:40 +01:00
|
|
|
|
2008-08-15 16:04:27 +02:00
|
|
|
# change personality, if needed
|
2008-11-22 17:38:40 +01:00
|
|
|
cmd = tmpl % (config['su-wrapper'], cmd)
|
2008-11-28 20:37:55 +01:00
|
|
|
if hostarch != bi.buildarch:
|
|
|
|
cmd = (change_personality.get(bi.buildarch, '') + ' ' + cmd).strip()
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2008-10-11 22:26:45 +02:00
|
|
|
rc = subprocess.call(cmd, shell=True)
|
2008-01-24 19:18:03 +01:00
|
|
|
if rc:
|
|
|
|
print
|
|
|
|
print 'The buildroot was:', config['build-root']
|
|
|
|
sys.exit(rc)
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-04-20 15:07:43 +02:00
|
|
|
pacdir = os.path.join(config['build-root'], '.build.packages')
|
|
|
|
if os.path.islink(pacdir):
|
|
|
|
pacdir = os.readlink(pacdir)
|
|
|
|
pacdir = os.path.join(config['build-root'], pacdir)
|
2006-07-14 20:31:35 +02:00
|
|
|
|
2009-04-20 15:07:43 +02:00
|
|
|
if os.path.exists(pacdir):
|
|
|
|
(s_built, b_built) = get_built_files(pacdir, bi.pacsuffix)
|
|
|
|
|
|
|
|
print
|
|
|
|
if s_built: print s_built
|
|
|
|
print
|
|
|
|
print b_built
|
2006-07-14 19:39:46 +02:00
|
|
|
|
2009-04-20 15:07:43 +02:00
|
|
|
if opts.keep_pkgs:
|
|
|
|
for i in b_built.splitlines() + s_built.splitlines():
|
|
|
|
import shutil
|
|
|
|
shutil.copy2(i, os.path.join(opts.keep_pkgs, os.path.basename(i)))
|
2007-05-03 17:54:40 +02:00
|
|
|
|
2006-07-14 19:39:46 +02:00
|
|
|
|