Clone in a terminal:
Commit c78b54d
schettino72 - 2012-12-22T18:51:43+00:00
c78b54da24edf2bf1cb6884dceaaeccda8da23edschettino72@gmail.com

build. move generi code from dodo.py to separate file

Changed files (2)

Diff

diff --git a/bavala.py b/bavala.pynew file mode 100644index 0000000..598b5be--- /dev/null+++ b/bavala.py@@ -0,0 +1,130 @@+"""bavala is a build-tool for Vala based on doit (http://pydoit.org)"""++import glob+from os.path import join++from doit.action import CmdAction+++def cmd(name, *args):+    """create string for command line"""+    parts = [name]+    for item in args:+        if isinstance(item, basestring):+            parts.append(item)+        elif isinstance(item, dict):+            for param, value in item.iteritems():+                if isinstance(value, basestring):+                    value = [value]+                parts.extend('--{0} {1}'.format(param, v) for v in value)+        else:+            parts.extend(item)+    return ' '.join(parts)++++class Vala(object):+    """helper to generate tasks to compile vala code"""++    def __init__(self, src, build, pkg_libs, library=None, vala_deps=None):+        self.src = src+        self.build = build+        self.library = library+        self.pkg_libs = pkg_libs+        self.vala_deps = vala_deps or []++        self.vala = list(glob.glob(src + '/*.vala'))+        self.cc = [join(build, f.replace('.vala', '.c')) for f in self.vala]+        self.obj = [join(build, f.replace('.vala', '.o')) for f in self.vala]+        if library:+            self.header = join(build, library) + '.h'+            self.vapi = join(build, library) + '.vapi'+            self.so = join(build, src) + '.so'+++    def gen_c(self, opts):+        """translate code from vala to C and create .vapi"""+        options = ['--ccode', '--save-temps']+        options.extend(opts)+        params = {+            'basedir': join(self.build, self.src),+            'vapidir': './',+            'pkg': self.pkg_libs,+            }+        if self.library:+            params['library'] = self.library+            params['vapi'] = self.vapi+            params['header'] = self.header++        dep_vapi = [d.vapi for d in self.vala_deps]+        action = cmd('valac', options, params, dep_vapi, self.vala)+        targets = self.cc[:]+        if self.library:+            targets += [self.header, self.vapi]+        return {+            'name': 'compile_c',+            'actions': [ action ],+            'file_dep': self.vala + dep_vapi,+            'targets': targets,+            }+++    def gen_o(self, opts):+        """compile C files to obj `.o` """+        def compile_cmd(conf, opts, libs, pos):+            flags = [conf[l].strip() for l in libs]+            return cmd('gcc', opts, flags, pos)++        for cc, obj in zip(self.cc, self.obj):+            pos = ["-c " + cc, "-o " + obj ]+            cmd_args = {'libs':self.pkg_libs, 'opts':opts, 'pos':pos}+            action = CmdAction((compile_cmd, [], cmd_args))+            yield {+                'name': obj.rsplit('/')[-1],+                'file_dep': [ cc ],+                'actions': [ action ],+                'getargs': { 'conf': ('pkg_flags', 'out') },+                'targets': [ obj ],+                }+++    def gen_so(self):+        """generate ".so" lib file"""+        def compile_cmd(conf, libs):+            obj_glob = join(self.build, self.src, '*.o')+            opts = ['-shared ' + obj_glob,+                    '-o ' + self.so ]+            flags = [conf[l].strip() for l in libs]+            return cmd('gcc', opts, flags)++        return {+            'name': self.so.rsplit('/')[-1],+            'actions': [ CmdAction((compile_cmd, [], {'libs':self.pkg_libs})) ],+            'getargs': { 'conf': ('pkg_flags', 'out') },+            'file_dep': self.obj,+            'targets': [ self.so ],+            }+++    def gen_bin(self, opts):+        """generate binary"""+        def compile_cmd(conf, opts, libs):+            flags = [conf[l].strip() for l in libs]+            return cmd('gcc', opts, flags)++        bin_path = join(self.build, 'bin')+        target = join(bin_path, self.src)+        opts = (self.cc + opts ++                ['-o ' + target, '-I ' + self.build, '-L ' + self.build] ++                ['-l ' + d.library for d in self.vala_deps])+        action = CmdAction((compile_cmd, [], {'opts':opts, 'libs':self.pkg_libs}))+        yield {+            'name': "bin",+            'actions': [ 'mkdir -p %s' % bin_path, action ],+            'getargs': { 'conf': ('pkg_flags', 'out') },+            'file_dep': self.cc + [ d.so for d in self.vala_deps ],+            'targets': [ target ],+            }+++diff --git a/dodo.py b/dodo.pyindex cc63af0..8424cb3 100644--- a/dodo.py+++ b/dodo.py@@ -1,35 +1,13 @@ import os import glob import subprocess-from os.path import join-  from doit.tools import run_once from doit.action import CmdAction+from bavala import Vala  -############ helpers--def cmd(name, *args):-    """create string for command line"""-    parts = [name]-    for item in args:-        if isinstance(item, basestring):-            parts.append(item)-        elif isinstance(item, dict):-            for param, value in item.iteritems():-                if isinstance(value, basestring):-                    value = [value]-                parts.extend('--{0} {1}'.format(param, v) for v in value)-        else:-            parts.extend(item)-    return ' '.join(parts)---###############################################- DOIT_CONFIG = {-    'verbosity': 2,     'default_tasks': [         'build',         'libbirdfont',@@ -40,6 +18,7 @@ DOIT_CONFIG = {         ],     } +# external Vala libs LIBS = [     'glib-2.0',     'libxml-2.0',@@ -51,17 +30,6 @@ LIBS = [     ]  -def task_pkg_flags():-    """get compiler flags for libs/pkgs """-    for pkg in LIBS:-        cmd = 'pkg-config --cflags --libs {pkg}'-        yield {-            'name': pkg,-            'actions': [CmdAction(cmd.format(pkg=pkg), save_out='out')],-            'uptodate': [run_once],-            }-- def task_build ():     if not os.path.exists ("build/configured"):         print ("Project is not configured")@@ -75,118 +43,19 @@ def task_build ():         }  ---####################### vala build tool---class Vala(object):-    """helper to generate tasks to compile vala code"""--    def __init__(self, src, build, pkg_libs, library=None, vala_deps=None):-        self.src = src-        self.build = build-        self.library = library-        self.pkg_libs = pkg_libs-        self.vala_deps = vala_deps or []--        self.vala = list(glob.glob(src + '/*.vala'))-        self.cc = [join(build, f.replace('.vala', '.c')) for f in self.vala]-        self.obj = [join(build, f.replace('.vala', '.o')) for f in self.vala]-        if library:-            self.header = join(build, library) + '.h'-            self.vapi = join(build, library) + '.vapi'-            self.so = join(build, src) + '.so'---    def gen_c(self, opts):-        """translate code from vala to C and create .vapi"""-        options = ['--ccode', '--save-temps']-        options.extend(opts)-        params = {-            'basedir': join(self.build, self.src),-            'vapidir': './',-            'pkg': self.pkg_libs,-            }-        if self.library:-            params['library'] = self.library-            params['vapi'] = self.vapi-            params['header'] = self.header--        dep_vapi = [d.vapi for d in self.vala_deps]-        action = cmd('valac', options, params, dep_vapi, self.vala)-        targets = self.cc[:]-        if self.library:-            targets += [self.header, self.vapi]-        return {-            'name': 'compile_c',-            'actions': [ action ],-            'file_dep': self.vala + dep_vapi,-            'targets': targets,-            }---    def gen_o(self, opts):-        """compile C files to obj `.o` """-        def compile_cmd(conf, opts, libs, pos):-            flags = [conf[l].strip() for l in libs]-            return cmd('gcc', opts, flags, pos)--        for cc, obj in zip(self.cc, self.obj):-            pos = ["-c " + cc, "-o " + obj ]-            cmd_args = {'libs':self.pkg_libs, 'opts':opts, 'pos':pos}-            action = CmdAction((compile_cmd, [], cmd_args))-            yield {-                'name': obj.rsplit('/')[-1],-                'file_dep': [ cc ],-                'actions': [ action ],-                'getargs': { 'conf': ('pkg_flags', 'out') },-                'targets': [ obj ],-                }--    def gen_so(self):-        """generate ".so" lib file"""-        def compile_cmd(conf, libs):-            obj_glob = join(self.build, self.src, '*.o')-            opts = ['-shared ' + obj_glob,-                    '-o ' + self.so ]-            flags = [conf[l].strip() for l in libs]-            return cmd('gcc', opts, flags)--        return {-            'name': self.so.rsplit('/')[-1],-            'actions': [ CmdAction((compile_cmd, [], {'libs':self.pkg_libs})) ],-            'getargs': { 'conf': ('pkg_flags', 'out') },-            'file_dep': self.obj,-            'targets': [ self.so ],-            }--    def gen_bin(self, opts):-        """generate binary"""-        def compile_cmd(conf, opts, libs):-            flags = [conf[l].strip() for l in libs]-            return cmd('gcc', opts, flags)--        bin_path = join(self.build, 'bin')-        target = join(bin_path, self.src)-        opts = (self.cc + opts +-                ['-o ' + target, '-I ' + self.build, '-L ' + self.build] +-                ['-l ' + d.library for d in self.vala_deps])-        action = CmdAction((compile_cmd, [], {'opts':opts, 'libs':self.pkg_libs}))+def task_pkg_flags():+    """get compiler flags for libs/pkgs """+    for pkg in LIBS:+        cmd = 'pkg-config --cflags --libs {pkg}'         yield {-            'name': "bin",-            'actions': [ 'mkdir -p %s' % bin_path, action ],-            'getargs': { 'conf': ('pkg_flags', 'out') },-            'file_dep': self.cc + [ d.so for d in self.vala_deps ],-            'targets': [ target ],+            'name': pkg,+            'actions': [CmdAction(cmd.format(pkg=pkg), save_out='out')],+            'uptodate': [run_once],             }   -#########  BIRDFONT--libbird = Vala(src='libbirdfont', build='build', library='birdfont',-                pkg_libs=LIBS)+libbird = Vala(src='libbirdfont', build='build', library='birdfont', pkg_libs=LIBS) def task_libbirdfont():     yield libbird.gen_c(['--enable-experimental-non-null', '--thread'])     yield libbird.gen_o(['-fPIC', """-D 'GETTEXT_PACKAGE="birdfont"'"""])@@ -207,6 +76,7 @@ def task_birdfont_export ():   + def task_compile_translations ():     """translate po files"""     for f_name in glob.glob('po/*.po'):

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112