From 0b8754d47c7d5c7bc5c5e30c5106e2e11f90e681 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 21 Dec 2011 10:52:57 -0500 Subject: [PATCH] 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. --- Makefile-ostbuild.am | 4 +- src/ostbuild/ostbuild-autodiscover-meta | 71 +++++++++++++++++++ src/ostbuild/ostbuild-chroot-compile-one | 24 ------- src/ostbuild/ostbuild-chroot-compile-one-impl | 3 + src/ostbuild/ostbuild-compile-one | 23 ------ src/ostbuild/ostbuild-compile-one-impl | 37 +++++++--- 6 files changed, 102 insertions(+), 60 deletions(-) create mode 100755 src/ostbuild/ostbuild-autodiscover-meta delete mode 100755 src/ostbuild/ostbuild-chroot-compile-one delete mode 100755 src/ostbuild/ostbuild-compile-one diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am index 8eff0632..51a2815a 100644 --- a/Makefile-ostbuild.am +++ b/Makefile-ostbuild.am @@ -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) diff --git a/src/ostbuild/ostbuild-autodiscover-meta b/src/ostbuild/ostbuild-autodiscover-meta new file mode 100755 index 00000000..fb8a8099 --- /dev/null +++ b/src/ostbuild/ostbuild-autodiscover-meta @@ -0,0 +1,71 @@ +#!/usr/bin/python +# +# Copyright (C) 2011 Colin Walters +# +# 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) + diff --git a/src/ostbuild/ostbuild-chroot-compile-one b/src/ostbuild/ostbuild-chroot-compile-one deleted file mode 100755 index 2d9a8a84..00000000 --- a/src/ostbuild/ostbuild-chroot-compile-one +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2011 Colin Walters -# -# 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 - - -bn=$(basename $(pwd)) -ostbuild-nice-and-log-output "compile-${bn}.log" ostbuild-chroot-compile-one-impl "$@" diff --git a/src/ostbuild/ostbuild-chroot-compile-one-impl b/src/ostbuild/ostbuild-chroot-compile-one-impl index b26c700c..4a5bc063 100755 --- a/src/ostbuild/ostbuild-chroot-compile-one-impl +++ b/src/ostbuild/ostbuild-chroot-compile-one-impl @@ -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() diff --git a/src/ostbuild/ostbuild-compile-one b/src/ostbuild/ostbuild-compile-one deleted file mode 100755 index 7fa249c8..00000000 --- a/src/ostbuild/ostbuild-compile-one +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2011 Colin Walters -# -# 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 - -bn=$(basename $(pwd)) -ostbuild-nice-and-log-output "compile-${bn}.log" ostbuild-compile-one-impl "$@" diff --git a/src/ostbuild/ostbuild-compile-one-impl b/src/ostbuild/ostbuild-compile-one-impl index 1b46810f..d4e8a50c 100755 --- a/src/ostbuild/ostbuild-compile-one-impl +++ b/src/ostbuild/ostbuild-compile-one-impl @@ -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()) - - try: - version = subprocess.check_output(['git', 'describe']) - except subprocess.CalledProcessError, e: - version = subprocess.check_output(['git', 'rev-parse', 'HEAD']) - version = version.strip() + name = metadata['NAME'] + version = metadata['VERSION'] + assert ',' not in version - version = version.replace(',', '_') + artifact_prefix='artifact-%s-%s,%s' % (build_target, name, version) - 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)