summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <hun@n-dimensional.de>2008-02-13 01:45:50 +0100
committerHans Ulrich Niedermann <hun@n-dimensional.de>2008-02-13 01:45:50 +0100
commit788c3bc868ad8a0fb4610882b758216bdaa9644c (patch)
treebf0b35a201a610e126b991ca41c90c6ffd82a9eb
parent3340dae58ab24669eab437b2147f756a6e93012e (diff)
downloadndim-git-utils-788c3bc868ad8a0fb4610882b758216bdaa9644c.tar.gz
ndim-git-utils-788c3bc868ad8a0fb4610882b758216bdaa9644c.tar.xz
ndim-git-utils-788c3bc868ad8a0fb4610882b758216bdaa9644c.zip
Implement basic buildsystem handling
-rw-r--r--nbb/nbb_lib.in159
1 files changed, 139 insertions, 20 deletions
diff --git a/nbb/nbb_lib.in b/nbb/nbb_lib.in
index 9bf49a0..87ffc12 100644
--- a/nbb/nbb_lib.in
+++ b/nbb/nbb_lib.in
@@ -2,11 +2,16 @@ import sys
import os
import getopt
-from subprocess import Popen
import subprocess
-
import urlparse
+"""nbb_lib - moo
+
+TODO:
+ * VCS config support
+ * Build system support: automake/autoconf, cmake
+"""
+
########################################################################
# Utility functions
@@ -14,11 +19,118 @@ import urlparse
def prog_stdout(call_list):
- p = Popen(call_list, stdout=subprocess.PIPE)
- stdout, stderr = p.communicate()
+ p = subprocess.Popen(call_list,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ stdout, stderr = p.communicate(input=None)
return stdout.strip()
+def prog_run(call_list):
+ print "RUN:", call_list
+ print " in", os.getcwd()
+ return None
+ p = subprocess.Popen(call_list)
+ stdout, stderr = p.communicate(input=None)
+ return None # FIXME: Exit code
+
+
+class AbstractConfig(object):
+ def __init__(self, srcdir, nick):
+ self.srcdir = srcdir
+ self.nick = nick
+ def srcdir(self):
+ return os.path.join(self.srcdir)
+ def builddir(self):
+ return os.path.join(self.srcdir, "_build", self.nick)
+ def installdir(self):
+ return os.path.join(self.srcdir, "_install", self.nick)
+
+
+########################################################################
+# Buildsystem Source Tree plugin system
+########################################################################
+# Plugin architecture (metaclass tricks) by Marty Alchin from
+# http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/
+########################################################################
+
+class NotABSSourceTree(Exception): pass
+
+class BSSourceTreeMeta(type):
+ def __init__(cls, name, bases, attrs):
+ if not hasattr(cls, 'plugins'):
+ cls.plugins = []
+ else:
+ cls.plugins.append(cls)
+
+
+class BSSourceTree(object):
+ __metaclass__ = BSSourceTreeMeta
+
+ def detect(cls, vcs_tree):
+ """Find BS tree type and return it"""
+ if len(BSSourceTree.plugins) < 1:
+ raise "No BS source tree classes registered"
+ def check_class(klass):
+ try:
+ t = klass(vcs_tree)
+ return t
+ except NotABSSourceTree:
+ return None
+ matches = filter(lambda x:x, map(check_class, BSSourceTree.plugins))
+ if len(matches) > 1:
+ raise ("More than one source tree type detected for '%s': %s"
+ % (vcs_tree, ", ".join(map(lambda x:str(x), matches))))
+ elif len(matches) < 1:
+ raise "Source tree type for '%s' not detected" % (vcs_tree,)
+ return matches[0]
+ detect = classmethod(detect)
+
+ def __str__(self):
+ return "BS-Source-Tree(%s, %s)" % (self.bs_name,
+ repr(self.tree_root()))
+
+
+class AutomakeSourceTree(BSSourceTree):
+ bs_name = 'automake'
+ def __init__(self, vcs_tree):
+ srcdir = vcs_tree.tree_root()
+ self.config = vcs_tree.get_config()
+ flag = False
+ for f in [ os.path.join(srcdir, 'configure.ac'),
+ os.path.join(srcdir, 'configure.in'),
+ ]:
+ if os.path.exists(f):
+ flag = True
+ break
+ if not flag:
+ raise NotABSSourceTree()
+ self.srcdir = srcdir
+
+ def tree_root(self):
+ return self.srcdir
+
+ def init(self):
+ """'autoreconf'"""
+ prog_run(["autoreconf", "-v", "-i", "-s", self.srcdir])
+ def configure(self):
+ """'configure --prefix'"""
+ builddir = self.config.builddir()
+ if not os.path.exists(builddir): os.makedirs(builddir)
+ os.chdir(builddir)
+ prog_run(["%s/configure" % self.srcdir,
+ "--prefix=%s" % self.config.installdir()
+ ])
+ def build(self):
+ """'make'"""
+ os.chdir(self.config.builddir())
+ prog_run(["make", ])
+ def install(self):
+ """'make install'"""
+ os.chdir(self.config.builddir())
+ prog_run(["make", "install", "INSTALL=/usr/bin/install -p"])
+
+
########################################################################
# VCS Source Tree plugin system
########################################################################
@@ -26,11 +138,10 @@ def prog_stdout(call_list):
# http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/
########################################################################
-class NotASourceTree(Exception):
+class NotAVCSourceTree(Exception):
pass
class VCSourceTreeMeta(type):
- vc_srctree_classes = []
def __init__(cls, name, bases, attrs):
if not hasattr(cls, 'plugins'):
# This branch only executes when processing the mount point itself.
@@ -55,32 +166,32 @@ class VCSourceTree(object):
vcs_name attribute
The text to be displayed, describing the version control system
__init__ function
- Must raise NotASourceTree() if it is not a VCS source tree
+ Must raise NotAVCSourceTree() if it is not a VCS source tree
"""
__metaclass__ = VCSourceTreeMeta
def detect(cls, srcdir):
"""Find VCS tree type and return it"""
+ if len(VCSourceTree.plugins) < 1:
+ raise "No VC source tree classes registered"
def check_class(klass):
try:
t = klass(srcdir)
- #print "t:", t
return t
- except NotASourceTree:
+ except NotAVCSourceTree:
return None
- if len(VCSourceTree.plugins) < 1:
- raise "No VC source tree classes registered"
- t_matches = [check_class(k) for k in VCSourceTree.plugins]
- matches = [x for x in t_matches if x]
+ matches = filter(lambda x:x, map(check_class, VCSourceTree.plugins))
if len(matches) > 1:
raise ("More than one source tree type detected for '%s': %s"
% (srcdir, ", ".join(map(lambda x:str(x), matches))))
elif len(matches) < 1:
raise "Source tree type for '%s' not detected" % (srcdir,)
- print "returning match:", matches[0]
return matches[0]
detect = classmethod(detect)
+ def get_config(self):
+ return AbstractConfig(self.tree_root(), self.branch_name())
+
def tree_root(self):
raise NotImplementedError()
@@ -106,8 +217,9 @@ class GitSourceTree(VCSourceTree):
os.chdir(srcdir)
if "true" != prog_stdout(["git", "rev-parse",
"--is-inside-work-tree"]):
- raise NotASourceTree()
- self.__tree_root = srcdir
+ raise NotAVCSourceTree()
+ os.chdir(prog_stdout(["git", "rev-parse", "--show-cdup"]))
+ self.__tree_root = os.getcwd()
def tree_root(self):
return self.__tree_root
@@ -128,9 +240,9 @@ class BzrSourceTree(VCSourceTree):
import bzrlib.workingtree
wt,b = bzrlib.workingtree.WorkingTree.open_containing(srcdir)
except bzrlib.errors.NotBranchError:
- raise NotASourceTree()
+ raise NotAVCSourceTree()
except ImportError:
- raise NotASourceTree()
+ raise NotAVCSourceTree()
self.wt = wt
#print "wt:", wt
#print "wt:", dir(wt)
@@ -159,8 +271,15 @@ class NBB(object):
def __init__(self, srcdir=None):
if srcdir is None:
srcdir = os.getcwd()
- self.sourcetree = VCSourceTree.detect(os.path.abspath(srcdir))
- print "sourcetree: %s" % str(self.sourcetree)
+ absdir = os.path.abspath(srcdir)
+ self.vcs_sourcetree = VCSourceTree.detect(absdir)
+ print str(self.vcs_sourcetree)
+ self.bs_sourcetree = BSSourceTree.detect(self.vcs_sourcetree)
+ print str(self.bs_sourcetree)
+ self.bs_sourcetree.init()
+ self.bs_sourcetree.configure()
+ self.bs_sourcetree.build()
+ self.bs_sourcetree.install()
#print "sourcetree:", dir(self.sourcetree)