PR#3498: kiwi: Explicitly use koji-generated description
Merges #3498 https://pagure.io/koji/pull-request/3498 Fixes: #3497 https://pagure.io/koji/issue/3497 kiwi doesn't prefer .kiwi file
This commit is contained in:
commit
6e9a311c12
1 changed files with 19 additions and 21 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
|
@ -13,15 +12,17 @@ class KiwiBuildTask(BuildImageTask):
|
||||||
Methods = ['kiwiBuild']
|
Methods = ['kiwiBuild']
|
||||||
_taskWeight = 4.0
|
_taskWeight = 4.0
|
||||||
|
|
||||||
def get_nvrp(self, desc_path):
|
def get_nvrp(self, cfg):
|
||||||
kiwi_files = glob.glob('%s/*.kiwi' % desc_path)
|
try:
|
||||||
if len(kiwi_files) != 1:
|
newxml = xml.dom.minidom.parse(cfg) # nosec
|
||||||
raise koji.GenericError("Repo must contain only one .kiwi file.")
|
except Exception:
|
||||||
|
raise koji.GenericError(
|
||||||
cfg = kiwi_files[0]
|
f"Kiwi description {os.path.basename(cfg)} can't be parsed as XML.")
|
||||||
|
try:
|
||||||
newxml = xml.dom.minidom.parse(cfg) # nosec
|
image = newxml.getElementsByTagName('image')[0]
|
||||||
image = newxml.getElementsByTagName('image')[0]
|
except IndexError:
|
||||||
|
raise koji.GenericError(
|
||||||
|
f"Kiwi description {os.path.basename(cfg)} doesn't contain <image> tag.")
|
||||||
|
|
||||||
name = image.getAttribute('name')
|
name = image.getAttribute('name')
|
||||||
version = None
|
version = None
|
||||||
|
|
@ -186,13 +187,8 @@ class KiwiCreateImageTask(BaseBuildTask):
|
||||||
_taskWeight = 2.0
|
_taskWeight = 2.0
|
||||||
|
|
||||||
def prepareDescription(self, desc_path, name, version, repos, arch):
|
def prepareDescription(self, desc_path, name, version, repos, arch):
|
||||||
kiwi_files = glob.glob('%s/*.kiwi' % desc_path)
|
# XML errors should have already been caught by parent task
|
||||||
if len(kiwi_files) != 1:
|
newxml = xml.dom.minidom.parse(desc_path) # nosec
|
||||||
raise koji.GenericError("Repo must contain only one .kiwi file.")
|
|
||||||
|
|
||||||
cfg = kiwi_files[0]
|
|
||||||
|
|
||||||
newxml = xml.dom.minidom.parse(cfg) # nosec
|
|
||||||
image = newxml.getElementsByTagName('image')[0]
|
image = newxml.getElementsByTagName('image')[0]
|
||||||
|
|
||||||
# apply includes - kiwi can include only top-level nodes, so we can simply
|
# apply includes - kiwi can include only top-level nodes, so we can simply
|
||||||
|
|
@ -242,13 +238,13 @@ class KiwiCreateImageTask(BaseBuildTask):
|
||||||
types.append(type.getAttribute('image'))
|
types.append(type.getAttribute('image'))
|
||||||
|
|
||||||
# write new file
|
# write new file
|
||||||
newcfg = f'{cfg[:-5]}.{arch}.kiwi'
|
newcfg = os.path.splitext(desc_path)[0] + f'.{arch}.kiwi'
|
||||||
with open(newcfg, 'wt') as f:
|
with open(newcfg, 'wt') as f:
|
||||||
s = newxml.toprettyxml()
|
s = newxml.toprettyxml()
|
||||||
# toprettyxml adds too many whitespaces/newlines
|
# toprettyxml adds too many whitespaces/newlines
|
||||||
s = '\n'.join([x for x in s.splitlines() if x.strip()])
|
s = '\n'.join([x for x in s.splitlines() if x.strip()])
|
||||||
f.write(s)
|
f.write(s)
|
||||||
os.unlink(cfg)
|
os.unlink(desc_path)
|
||||||
|
|
||||||
return newcfg, types
|
return newcfg, types
|
||||||
|
|
||||||
|
|
@ -353,10 +349,11 @@ class KiwiCreateImageTask(BaseBuildTask):
|
||||||
self.logger.debug('BASEURL: %s' % baseurl)
|
self.logger.debug('BASEURL: %s' % baseurl)
|
||||||
repos.append(baseurl)
|
repos.append(baseurl)
|
||||||
|
|
||||||
|
base_path = os.path.dirname(desc_path)
|
||||||
if opts.get('make_prep'):
|
if opts.get('make_prep'):
|
||||||
cmd = ['make', 'prep']
|
cmd = ['make', 'prep']
|
||||||
rv = broot.mock(['--cwd', os.path.join(broot.tmpdir(within=True),
|
rv = broot.mock(['--cwd', os.path.join(broot.tmpdir(within=True),
|
||||||
os.path.basename(scmsrcdir), desc_path),
|
os.path.basename(scmsrcdir), base_path),
|
||||||
'--chroot', '--'] + cmd)
|
'--chroot', '--'] + cmd)
|
||||||
if rv:
|
if rv:
|
||||||
raise koji.GenericError("Preparation step failed")
|
raise koji.GenericError("Preparation step failed")
|
||||||
|
|
@ -370,8 +367,9 @@ class KiwiCreateImageTask(BaseBuildTask):
|
||||||
cmd.extend(['--profile', self.opts['profile']])
|
cmd.extend(['--profile', self.opts['profile']])
|
||||||
target_dir = '/builddir/result/image'
|
target_dir = '/builddir/result/image'
|
||||||
cmd.extend([
|
cmd.extend([
|
||||||
|
'--kiwi-file', os.path.basename(desc), # global option for image/system commands
|
||||||
'system', 'build',
|
'system', 'build',
|
||||||
'--description', os.path.join(os.path.basename(scmsrcdir), desc_path),
|
'--description', os.path.join(os.path.basename(scmsrcdir), base_path),
|
||||||
'--target-dir', target_dir,
|
'--target-dir', target_dir,
|
||||||
])
|
])
|
||||||
rv = broot.mock(['--cwd', broot.tmpdir(within=True), '--chroot', '--'] + cmd)
|
rv = broot.mock(['--cwd', broot.tmpdir(within=True), '--chroot', '--'] + cmd)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue