source: waflib/Tools/glib2.py @ 904702d

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 904702d was 904702d, checked in by Paul Brossier <piem@piem.org>, 9 years ago

waf, waflib: update to 1.8.7

  • Property mode set to 100644
File size: 10.4 KB
Line 
1#! /usr/bin/env python
2# encoding: utf-8
3# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
4
5import os
6from waflib import Context,Task,Utils,Options,Errors,Logs
7from waflib.TaskGen import taskgen_method,before_method,after_method,feature,extension
8from waflib.Configure import conf
9@taskgen_method
10def add_marshal_file(self,filename,prefix):
11        if not hasattr(self,'marshal_list'):
12                self.marshal_list=[]
13        self.meths.append('process_marshal')
14        self.marshal_list.append((filename,prefix))
15@before_method('process_source')
16def process_marshal(self):
17        for f,prefix in getattr(self,'marshal_list',[]):
18                node=self.path.find_resource(f)
19                if not node:
20                        raise Errors.WafError('file not found %r'%f)
21                h_node=node.change_ext('.h')
22                c_node=node.change_ext('.c')
23                task=self.create_task('glib_genmarshal',node,[h_node,c_node])
24                task.env.GLIB_GENMARSHAL_PREFIX=prefix
25        self.source=self.to_nodes(getattr(self,'source',[]))
26        self.source.append(c_node)
27class glib_genmarshal(Task.Task):
28        def run(self):
29                bld=self.inputs[0].__class__.ctx
30                get=self.env.get_flat
31                cmd1="%s %s --prefix=%s --header > %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[0].abspath())
32                ret=bld.exec_command(cmd1)
33                if ret:return ret
34                c='''#include "%s"\n'''%self.outputs[0].name
35                self.outputs[1].write(c)
36                cmd2="%s %s --prefix=%s --body >> %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[1].abspath())
37                return bld.exec_command(cmd2)
38        vars=['GLIB_GENMARSHAL_PREFIX','GLIB_GENMARSHAL']
39        color='BLUE'
40        ext_out=['.h']
41@taskgen_method
42def add_enums_from_template(self,source='',target='',template='',comments=''):
43        if not hasattr(self,'enums_list'):
44                self.enums_list=[]
45        self.meths.append('process_enums')
46        self.enums_list.append({'source':source,'target':target,'template':template,'file-head':'','file-prod':'','file-tail':'','enum-prod':'','value-head':'','value-prod':'','value-tail':'','comments':comments})
47@taskgen_method
48def add_enums(self,source='',target='',file_head='',file_prod='',file_tail='',enum_prod='',value_head='',value_prod='',value_tail='',comments=''):
49        if not hasattr(self,'enums_list'):
50                self.enums_list=[]
51        self.meths.append('process_enums')
52        self.enums_list.append({'source':source,'template':'','target':target,'file-head':file_head,'file-prod':file_prod,'file-tail':file_tail,'enum-prod':enum_prod,'value-head':value_head,'value-prod':value_prod,'value-tail':value_tail,'comments':comments})
53@before_method('process_source')
54def process_enums(self):
55        for enum in getattr(self,'enums_list',[]):
56                task=self.create_task('glib_mkenums')
57                env=task.env
58                inputs=[]
59                source_list=self.to_list(enum['source'])
60                if not source_list:
61                        raise Errors.WafError('missing source '+str(enum))
62                source_list=[self.path.find_resource(k)for k in source_list]
63                inputs+=source_list
64                env['GLIB_MKENUMS_SOURCE']=[k.abspath()for k in source_list]
65                if not enum['target']:
66                        raise Errors.WafError('missing target '+str(enum))
67                tgt_node=self.path.find_or_declare(enum['target'])
68                if tgt_node.name.endswith('.c'):
69                        self.source.append(tgt_node)
70                env['GLIB_MKENUMS_TARGET']=tgt_node.abspath()
71                options=[]
72                if enum['template']:
73                        template_node=self.path.find_resource(enum['template'])
74                        options.append('--template %s'%(template_node.abspath()))
75                        inputs.append(template_node)
76                params={'file-head':'--fhead','file-prod':'--fprod','file-tail':'--ftail','enum-prod':'--eprod','value-head':'--vhead','value-prod':'--vprod','value-tail':'--vtail','comments':'--comments'}
77                for param,option in params.items():
78                        if enum[param]:
79                                options.append('%s %r'%(option,enum[param]))
80                env['GLIB_MKENUMS_OPTIONS']=' '.join(options)
81                task.set_inputs(inputs)
82                task.set_outputs(tgt_node)
83class glib_mkenums(Task.Task):
84        run_str='${GLIB_MKENUMS} ${GLIB_MKENUMS_OPTIONS} ${GLIB_MKENUMS_SOURCE} > ${GLIB_MKENUMS_TARGET}'
85        color='PINK'
86        ext_out=['.h']
87@taskgen_method
88def add_settings_schemas(self,filename_list):
89        if not hasattr(self,'settings_schema_files'):
90                self.settings_schema_files=[]
91        if not isinstance(filename_list,list):
92                filename_list=[filename_list]
93        self.settings_schema_files.extend(filename_list)
94@taskgen_method
95def add_settings_enums(self,namespace,filename_list):
96        if hasattr(self,'settings_enum_namespace'):
97                raise Errors.WafError("Tried to add gsettings enums to '%s' more than once"%self.name)
98        self.settings_enum_namespace=namespace
99        if type(filename_list)!='list':
100                filename_list=[filename_list]
101        self.settings_enum_files=filename_list
102@feature('glib2')
103def process_settings(self):
104        enums_tgt_node=[]
105        install_files=[]
106        settings_schema_files=getattr(self,'settings_schema_files',[])
107        if settings_schema_files and not self.env['GLIB_COMPILE_SCHEMAS']:
108                raise Errors.WafError("Unable to process GSettings schemas - glib-compile-schemas was not found during configure")
109        if hasattr(self,'settings_enum_files'):
110                enums_task=self.create_task('glib_mkenums')
111                source_list=self.settings_enum_files
112                source_list=[self.path.find_resource(k)for k in source_list]
113                enums_task.set_inputs(source_list)
114                enums_task.env['GLIB_MKENUMS_SOURCE']=[k.abspath()for k in source_list]
115                target=self.settings_enum_namespace+'.enums.xml'
116                tgt_node=self.path.find_or_declare(target)
117                enums_task.set_outputs(tgt_node)
118                enums_task.env['GLIB_MKENUMS_TARGET']=tgt_node.abspath()
119                enums_tgt_node=[tgt_node]
120                install_files.append(tgt_node)
121                options='--comments "<!-- @comment@ -->" --fhead "<schemalist>" --vhead "  <@type@ id=\\"%s.@EnumName@\\">" --vprod "    <value nick=\\"@valuenick@\\" value=\\"@valuenum@\\"/>" --vtail "  </@type@>" --ftail "</schemalist>" '%(self.settings_enum_namespace)
122                enums_task.env['GLIB_MKENUMS_OPTIONS']=options
123        for schema in settings_schema_files:
124                schema_task=self.create_task('glib_validate_schema')
125                schema_node=self.path.find_resource(schema)
126                if not schema_node:
127                        raise Errors.WafError("Cannot find the schema file '%s'"%schema)
128                install_files.append(schema_node)
129                source_list=enums_tgt_node+[schema_node]
130                schema_task.set_inputs(source_list)
131                schema_task.env['GLIB_COMPILE_SCHEMAS_OPTIONS']=[("--schema-file="+k.abspath())for k in source_list]
132                target_node=schema_node.change_ext('.xml.valid')
133                schema_task.set_outputs(target_node)
134                schema_task.env['GLIB_VALIDATE_SCHEMA_OUTPUT']=target_node.abspath()
135        def compile_schemas_callback(bld):
136                if not bld.is_install:return
137                Logs.pprint('YELLOW','Updating GSettings schema cache')
138                command=Utils.subst_vars("${GLIB_COMPILE_SCHEMAS} ${GSETTINGSSCHEMADIR}",bld.env)
139                ret=self.bld.exec_command(command)
140        if self.bld.is_install:
141                if not self.env['GSETTINGSSCHEMADIR']:
142                        raise Errors.WafError('GSETTINGSSCHEMADIR not defined (should have been set up automatically during configure)')
143                if install_files:
144                        self.bld.install_files(self.env['GSETTINGSSCHEMADIR'],install_files)
145                        if not hasattr(self.bld,'_compile_schemas_registered'):
146                                self.bld.add_post_fun(compile_schemas_callback)
147                                self.bld._compile_schemas_registered=True
148class glib_validate_schema(Task.Task):
149        run_str='rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} && ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} && touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}'
150        color='PINK'
151@extension('.gresource.xml')
152def process_gresource_source(self,node):
153        if not self.env['GLIB_COMPILE_RESOURCES']:
154                raise Errors.WafError("Unable to process GResource file - glib-compile-resources was not found during configure")
155        if'gresource'in self.features:
156                return
157        h_node=node.change_ext('_xml.h')
158        c_node=node.change_ext('_xml.c')
159        self.create_task('glib_gresource_source',node,[h_node,c_node])
160        self.source.append(c_node)
161@feature('gresource')
162def process_gresource_bundle(self):
163        for i in self.to_list(self.source):
164                node=self.path.find_resource(i)
165                task=self.create_task('glib_gresource_bundle',node,node.change_ext(''))
166                inst_to=getattr(self,'install_path',None)
167                if inst_to:
168                        self.bld.install_files(inst_to,task.outputs)
169class glib_gresource_base(Task.Task):
170        color='BLUE'
171        base_cmd='${GLIB_COMPILE_RESOURCES} --sourcedir=${SRC[0].parent.srcpath()} --sourcedir=${SRC[0].bld_dir()}'
172        def scan(self):
173                bld=self.generator.bld
174                kw={}
175                try:
176                        if not kw.get('cwd',None):
177                                kw['cwd']=bld.cwd
178                except AttributeError:
179                        bld.cwd=kw['cwd']=bld.variant_dir
180                kw['quiet']=Context.BOTH
181                cmd=Utils.subst_vars('${GLIB_COMPILE_RESOURCES} --sourcedir=%s --sourcedir=%s --generate-dependencies %s'%(self.inputs[0].parent.srcpath(),self.inputs[0].bld_dir(),self.inputs[0].bldpath()),self.env)
182                output=bld.cmd_and_log(cmd,**kw)
183                nodes=[]
184                names=[]
185                for dep in output.splitlines():
186                        if dep:
187                                node=bld.bldnode.find_node(dep)
188                                if node:
189                                        nodes.append(node)
190                                else:
191                                        names.append(dep)
192                return(nodes,names)
193class glib_gresource_source(glib_gresource_base):
194        vars=['GLIB_COMPILE_RESOURCES']
195        fun_h=Task.compile_fun_shell(glib_gresource_base.base_cmd+' --target=${TGT[0].abspath()} --generate-header ${SRC}')
196        fun_c=Task.compile_fun_shell(glib_gresource_base.base_cmd+' --target=${TGT[1].abspath()} --generate-source ${SRC}')
197        ext_out=['.h']
198        def run(self):
199                return self.fun_h[0](self)or self.fun_c[0](self)
200class glib_gresource_bundle(glib_gresource_base):
201        run_str=glib_gresource_base.base_cmd+' --target=${TGT} ${SRC}'
202        shell=True
203@conf
204def find_glib_genmarshal(conf):
205        conf.find_program('glib-genmarshal',var='GLIB_GENMARSHAL')
206@conf
207def find_glib_mkenums(conf):
208        if not conf.env.PERL:
209                conf.find_program('perl',var='PERL')
210        conf.find_program('glib-mkenums',interpreter='PERL',var='GLIB_MKENUMS')
211@conf
212def find_glib_compile_schemas(conf):
213        conf.find_program('glib-compile-schemas',var='GLIB_COMPILE_SCHEMAS')
214        def getstr(varname):
215                return getattr(Options.options,varname,getattr(conf.env,varname,''))
216        gsettingsschemadir=getstr('GSETTINGSSCHEMADIR')
217        if not gsettingsschemadir:
218                datadir=getstr('DATADIR')
219                if not datadir:
220                        prefix=conf.env['PREFIX']
221                        datadir=os.path.join(prefix,'share')
222                gsettingsschemadir=os.path.join(datadir,'glib-2.0','schemas')
223        conf.env['GSETTINGSSCHEMADIR']=gsettingsschemadir
224@conf
225def find_glib_compile_resources(conf):
226        conf.find_program('glib-compile-resources',var='GLIB_COMPILE_RESOURCES')
227def configure(conf):
228        conf.find_glib_genmarshal()
229        conf.find_glib_mkenums()
230        conf.find_glib_compile_schemas(mandatory=False)
231        conf.find_glib_compile_resources(mandatory=False)
232def options(opt):
233        gr=opt.add_option_group('Installation directories')
234        gr.add_option('--gsettingsschemadir',help='GSettings schema location [DATADIR/glib-2.0/schemas]',default='',dest='GSETTINGSSCHEMADIR')
Note: See TracBrowser for help on using the repository browser.