File: wscript

package info (click to toggle)
libdesktop-agnostic 0.3.90-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 4,635
  • sloc: ansic: 30,148; python: 1,069; makefile: 24; xml: 12
file content (127 lines) | stat: -rw-r--r-- 4,299 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/python
# encoding: utf-8
# ---------------
# PyGObject bindings generator (until the gi module is stable)
# copied/modified from gnome-python-desktop

import Task
from TaskGen import extension
import Utils
import misc
import os
import types

GDK_DEFS = lambda bld: os.path.join(bld.env['PYGTK_DEFSDIR'], 'gdk-types.defs')


def configure(conf):
    conf.check_python_headers()
    conf.check_cfg(package='pygobject-2.0', uselib_store='PYGOBJECT',
                   atleast_version='2.12.0', mandatory=True,
                   args='--cflags --libs')
    if not conf.find_program('pygobject-codegen-2.0', var='CODEGEN'):
        if not conf.find_program('pygtk-codegen-2.0', var='CODEGEN'):
            conf.fatal('Could not find the PyGObject/PyGTK code generator ' \
                       'script')
    pkgconfig = 'pkg-config --variable defsdir pygtk-2.0'
    conf.env['PYGTK_DEFSDIR'] = Utils.cmd_output(pkgconfig, silent=1).strip()
    conf.check_cfg(package='pygobject-2.0', uselib_store='PYGLIB',
                   atleast_version='2.15.2')


def run_pyg_codegen(self):
    # stolen from TaskGen.exec_rule
    func, func_vars = Task.compile_fun('', self.generator.rule,
                                       shell=getattr(self.generator, 'shell',
                                                     True))
    func.code = self.generator.rule
    func(self)

Task.task_type_from_func('pyg_codegen', run_pyg_codegen, ext_out='.c')


@extension('.defs')
def defs_hook(self, node):
    override_node = node.parent.find_resource('%s.override' % self.name)
    c_node = node.change_ext('.c')

    sources = [override_node, node]

    rule = ['${CODEGEN}']
    if getattr(self, 'py_ssize_t_clean', True):
        rule += [' --py_ssize_t-clean']
    for load in getattr(self, 'local_load_types', ()):
        sources += [node.parent.find_resource(load)]
        rule += ['--load-types',
                 '${SRC[%i].abspath(env)}' % (len(sources) - 1)]
    for reg in getattr(self, 'local_register', ()):
        sources += [node.parent.find_resource(reg)]
        rule += ['--register', '${SRC[%i].abspath(env)}' % (len(sources) - 1)]
    for reg in getattr(self, 'register', ()):
        rule += ['--register', reg]
    if hasattr(self, 'prefix'):
        rule += ['--prefix', self.prefix]
    else:
        rule += ['--prefix', 'py%s' % self.name]

    rule += ['--override', '${SRC}', '>', '${TGT}']

    self.rule = ' '.join(rule)

    task = self.create_task('pyg_codegen')
    task.inputs = sources
    task.outputs = [c_node]

    self.allnodes.append(c_node)


def pyg_module(bld, module, dependencies, prefix=None, local_register=None):
    pyext = bld.new_task_gen('cc', 'shlib', 'pyext')
    pyext.source = '%s.defs %smodule.c' % (module, module)
    pyext.target = module
    if prefix is not None:
        pyext.prefix = prefix
    pyext.uselib = 'PYEXT PYGOBJECT'
    pyext.uselib_local = dependencies
    if local_register is not None:
        pyext.local_register = local_register
    pyext.includes = '..'
    pyext.install_path = '${PYTHONDIR}/desktopagnostic'

    defs_dir = '${DATADIR}/pygtk/2.0/defs'

    if module == 'desktopagnostic':
        bld.install_files(defs_dir, ['%s.defs' % module])
    else:
        bld.install_as('%s/desktopagnostic_%s.defs' % (defs_dir, module),
                       '%s.defs' % module, env=pyext.env)

    return pyext


def build(bld):
    # Attach the 'codegen' and pyg_module methods to the build context
    bld.pyg_module = types.MethodType(pyg_module, bld)

    pyda = bld.pyg_module('desktopagnostic', 'desktop-agnostic')
    pyda.register = [GDK_DEFS(bld)]
    pyda.uselib += ' GDK'

    modules = (('config', 'cfg', None), ('vfs', 'vfs', None),
               ('fdo', 'fdo', ['vfs.defs']),
               ('ui', 'ui', ['desktopagnostic.defs', 'vfs.defs']))

    for module, dep, lr in modules:
        pyext = bld.pyg_module(module, 'desktop-agnostic-%s' % dep,
                               'pydesktopagnostic_%s' % module, lr)

    init = bld.new_task_gen('subst')
    init.source = '__init__.py.in'
    init.target = '__init__.py'
    init.dict = {
        'VERSION': bld.env['VERSION'],
    }
    init.fun = misc.subst_func
    init.install_path = '${PYTHONDIR}/desktopagnostic'

# vim: set ts=4 sts=4 sw=4 et :