ostbuild: Separate metadata discovery, kill wrapper scripts

Add a simple KEY=VALUE metadata file format, and rather than
assuming 'basename' at a low level, allow passing e.g. NAME=gtk3
to override "gtk+".

The wrapper scripts are annoying...for now let's just remove them.
This commit is contained in:
Colin Walters 2011-12-21 10:52:57 -05:00
parent 835e0eae59
commit 0b8754d47c
6 changed files with 102 additions and 60 deletions

View File

@ -15,9 +15,9 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
bin_SCRIPTS += src/ostbuild/ostbuild-compile-one \
bin_SCRIPTS += \
src/ostbuild/ostbuild-autodiscover-meta \
src/ostbuild/ostbuild-compile-one-impl \
src/ostbuild/ostbuild-chroot-compile-one \
src/ostbuild/ostbuild-chroot-compile-one-impl \
src/ostbuild/ostbuild-nice-and-log-output \
$(NULL)

View File

@ -0,0 +1,71 @@
#!/usr/bin/python
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
import os,sys,re,subprocess,tempfile,shutil
import argparse
parser = argparse.ArgumentParser(description="Discover source metadata from current directory")
parser.add_argument('--meta')
args = parser.parse_args()
AUTODISCOVERED_KEYS = {}
KEYS = {}
def _register_discover_func(key, func):
if key not in AUTODISCOVERED_KEYS:
AUTODISCOVERED_KEYS[key] = []
AUTODISCOVERED_KEYS[key].append(func)
def _discover_name_from_cwd():
return os.path.basename(os.getcwd())
_register_discover_func('NAME', _discover_name_from_cwd)
def _discover_version_from_git():
if os.path.isdir('.git'):
try:
version = subprocess.check_output(['git', 'describe'])
except subprocess.CalledProcessError, e:
version = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
return version.strip()
return None
_register_discover_func('VERSION', _discover_version_from_git)
if args.meta:
f = open(args.meta)
for line in f.readlines():
(k,v) = line.split('=', 1)
KEYS[k.strip()] = v.strip()
f.close()
for (key,hooks) in AUTODISCOVERED_KEYS.iteritems():
if key in KEYS:
continue
for func in hooks:
value = func()
if value is None:
continue
KEYS[key] = value
break
for (key,value) in KEYS.iteritems():
print "%s=%s" % (key, value)

View File

@ -1,24 +0,0 @@
#!/bin/sh
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# Author: Colin Walters <walters@verbum.org>
bn=$(basename $(pwd))
ostbuild-nice-and-log-output "compile-${bn}.log" ostbuild-chroot-compile-one-impl "$@"

View File

@ -20,6 +20,8 @@
import os,sys,re,subprocess,tempfile,shutil
import argparse
sys.path
def get_build_env():
return {'HOME' : '/',
'HOSTNAME' : 'ostbuild',
@ -36,6 +38,7 @@ parser = argparse.ArgumentParser(description="Build a module in a given root")
parser.add_argument('--repo')
parser.add_argument('--resultdir')
parser.add_argument('--branch')
parser.add_argument('--meta')
parser.add_argument('--debug-shell', type=bool)
args = parser.parse_args()

View File

@ -1,23 +0,0 @@
#!/bin/sh
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# Author: Colin Walters <walters@verbum.org>
bn=$(basename $(pwd))
ostbuild-nice-and-log-output "compile-${bn}.log" ostbuild-compile-one-impl "$@"

View File

@ -21,6 +21,7 @@
# http://people.gnome.org/~walters/docs/build-api.txt
import os,sys,subprocess,tempfile,re
from StringIO import StringIO
from multiprocessing import cpu_count
import select,time
@ -71,15 +72,35 @@ makeargs = ['make']
top_srcdir=os.getcwd()
ostbuild_resultdir=top_srcdir
ostbuild_meta=None
for arg in sys.argv[1:]:
if arg.startswith('OSTBUILD_RESULTDIR='):
ostbuild_resultdir=arg[len('OSTBUILD_RESULTDIR='):]
elif arg.startswith('OSTBUILD_META='):
ostbuild_meta=arg[len('OSTBUILD_META='):]
elif arg.startswith('--'):
configargs.append(arg)
else:
makeargs.append(arg)
metadata = {}
if ostbuild_meta is None:
output = subprocess.check_output(['ostbuild-autodiscover-meta'])
ostbuild_meta_f = StringIO(output)
else:
ostbuild_meta_f = open(ostbuild_meta)
for line in ostbuild_meta_f:
(k,v) = line.split('=', 1)
metadata[k.strip()] = v.strip()
for k in ['NAME', 'VERSION']:
if k not in metadata:
sys.stderr.write('Missing required key "%s" in metadata' % (k, ))
sys.exit(1)
def log(msg):
fullmsg = '%s: %s\n' % (sys.argv[0], msg)
sys.stdout.write(fullmsg)
@ -269,19 +290,13 @@ def make_artifact(name, from_files, tempdir=None, resultdir=None):
log("created: %s" % (os.path.abspath (result_path), ))
def phase_make_artifacts(builddir=None):
basename=os.path.basename(os.getcwd())
name = metadata['NAME']
version = metadata['VERSION']
assert ',' not in version
try:
version = subprocess.check_output(['git', 'describe'])
except subprocess.CalledProcessError, e:
version = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
version = version.strip()
artifact_prefix='artifact-%s-%s,%s' % (build_target, name, version)
version = version.replace(',', '_')
artifact_prefix='artifact-%s-%s,%s' % (build_target, basename, version)
tempdir = tempfile.mkdtemp(prefix='ostree-build-%s-' % (basename,))
tempdir = tempfile.mkdtemp(prefix='ostree-build-%s-' % (name,))
tempfiles.append(tempdir)
args = ['make', 'install', 'DESTDIR=' + tempdir]
run_sync(args, cwd=builddir)