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 | |
---|
5 | import os.path,shutil,re |
---|
6 | from waflib import Context,Task,Utils,Logs,Options,Errors |
---|
7 | from waflib.TaskGen import extension,taskgen_method |
---|
8 | from waflib.Configure import conf |
---|
9 | class valac(Task.Task): |
---|
10 | vars=["VALAC","VALAC_VERSION","VALAFLAGS"] |
---|
11 | ext_out=['.h'] |
---|
12 | def run(self): |
---|
13 | cmd=[self.env['VALAC']]+self.env['VALAFLAGS'] |
---|
14 | cmd.extend([a.abspath()for a in self.inputs]) |
---|
15 | ret=self.exec_command(cmd,cwd=self.outputs[0].parent.abspath()) |
---|
16 | if ret: |
---|
17 | return ret |
---|
18 | for x in self.outputs: |
---|
19 | if id(x.parent)!=id(self.outputs[0].parent): |
---|
20 | shutil.move(self.outputs[0].parent.abspath()+os.sep+x.name,x.abspath()) |
---|
21 | if self.generator.dump_deps_node: |
---|
22 | self.generator.dump_deps_node.write('\n'.join(self.generator.packages)) |
---|
23 | return ret |
---|
24 | valac=Task.update_outputs(valac) |
---|
25 | @taskgen_method |
---|
26 | def init_vala_task(self): |
---|
27 | self.profile=getattr(self,'profile','gobject') |
---|
28 | if self.profile=='gobject': |
---|
29 | self.uselib=Utils.to_list(getattr(self,'uselib',[])) |
---|
30 | if not'GOBJECT'in self.uselib: |
---|
31 | self.uselib.append('GOBJECT') |
---|
32 | def addflags(flags): |
---|
33 | self.env.append_value('VALAFLAGS',flags) |
---|
34 | if self.profile: |
---|
35 | addflags('--profile=%s'%self.profile) |
---|
36 | if hasattr(self,'threading'): |
---|
37 | if self.profile=='gobject': |
---|
38 | if not'GTHREAD'in self.uselib: |
---|
39 | self.uselib.append('GTHREAD') |
---|
40 | else: |
---|
41 | Logs.warn("Profile %s means no threading support"%self.profile) |
---|
42 | self.threading=False |
---|
43 | if self.threading: |
---|
44 | addflags('--threading') |
---|
45 | valatask=self.valatask |
---|
46 | self.is_lib='cprogram'not in self.features |
---|
47 | if self.is_lib: |
---|
48 | addflags('--library=%s'%self.target) |
---|
49 | h_node=self.path.find_or_declare('%s.h'%self.target) |
---|
50 | valatask.outputs.append(h_node) |
---|
51 | addflags('--header=%s'%h_node.name) |
---|
52 | valatask.outputs.append(self.path.find_or_declare('%s.vapi'%self.target)) |
---|
53 | if getattr(self,'gir',None): |
---|
54 | gir_node=self.path.find_or_declare('%s.gir'%self.gir) |
---|
55 | addflags('--gir=%s'%gir_node.name) |
---|
56 | valatask.outputs.append(gir_node) |
---|
57 | self.vala_target_glib=getattr(self,'vala_target_glib',getattr(Options.options,'vala_target_glib',None)) |
---|
58 | if self.vala_target_glib: |
---|
59 | addflags('--target-glib=%s'%self.vala_target_glib) |
---|
60 | addflags(['--define=%s'%x for x in getattr(self,'vala_defines',[])]) |
---|
61 | packages_private=Utils.to_list(getattr(self,'packages_private',[])) |
---|
62 | addflags(['--pkg=%s'%x for x in packages_private]) |
---|
63 | def _get_api_version(): |
---|
64 | api_version='1.0' |
---|
65 | if hasattr(Context.g_module,'API_VERSION'): |
---|
66 | version=Context.g_module.API_VERSION.split(".") |
---|
67 | if version[0]=="0": |
---|
68 | api_version="0."+version[1] |
---|
69 | else: |
---|
70 | api_version=version[0]+".0" |
---|
71 | return api_version |
---|
72 | self.includes=Utils.to_list(getattr(self,'includes',[])) |
---|
73 | self.uselib=self.to_list(getattr(self,'uselib',[])) |
---|
74 | valatask.install_path=getattr(self,'install_path','') |
---|
75 | valatask.vapi_path=getattr(self,'vapi_path','${DATAROOTDIR}/vala/vapi') |
---|
76 | valatask.pkg_name=getattr(self,'pkg_name',self.env['PACKAGE']) |
---|
77 | valatask.header_path=getattr(self,'header_path','${INCLUDEDIR}/%s-%s'%(valatask.pkg_name,_get_api_version())) |
---|
78 | valatask.install_binding=getattr(self,'install_binding',True) |
---|
79 | self.packages=packages=Utils.to_list(getattr(self,'packages',[])) |
---|
80 | self.vapi_dirs=vapi_dirs=Utils.to_list(getattr(self,'vapi_dirs',[])) |
---|
81 | includes=[] |
---|
82 | if hasattr(self,'use'): |
---|
83 | local_packages=Utils.to_list(self.use)[:] |
---|
84 | seen=[] |
---|
85 | while len(local_packages)>0: |
---|
86 | package=local_packages.pop() |
---|
87 | if package in seen: |
---|
88 | continue |
---|
89 | seen.append(package) |
---|
90 | try: |
---|
91 | package_obj=self.bld.get_tgen_by_name(package) |
---|
92 | except Errors.WafError: |
---|
93 | continue |
---|
94 | package_name=package_obj.target |
---|
95 | package_node=package_obj.path |
---|
96 | package_dir=package_node.path_from(self.path) |
---|
97 | for task in package_obj.tasks: |
---|
98 | for output in task.outputs: |
---|
99 | if output.name==package_name+".vapi": |
---|
100 | valatask.set_run_after(task) |
---|
101 | if package_name not in packages: |
---|
102 | packages.append(package_name) |
---|
103 | if package_dir not in vapi_dirs: |
---|
104 | vapi_dirs.append(package_dir) |
---|
105 | if package_dir not in includes: |
---|
106 | includes.append(package_dir) |
---|
107 | if hasattr(package_obj,'use'): |
---|
108 | lst=self.to_list(package_obj.use) |
---|
109 | lst.reverse() |
---|
110 | local_packages=[pkg for pkg in lst if pkg not in seen]+local_packages |
---|
111 | addflags(['--pkg=%s'%p for p in packages]) |
---|
112 | for vapi_dir in vapi_dirs: |
---|
113 | v_node=self.path.find_dir(vapi_dir) |
---|
114 | if not v_node: |
---|
115 | Logs.warn('Unable to locate Vala API directory: %r'%vapi_dir) |
---|
116 | else: |
---|
117 | addflags('--vapidir=%s'%v_node.abspath()) |
---|
118 | addflags('--vapidir=%s'%v_node.get_bld().abspath()) |
---|
119 | self.dump_deps_node=None |
---|
120 | if self.is_lib and self.packages: |
---|
121 | self.dump_deps_node=self.path.find_or_declare('%s.deps'%self.target) |
---|
122 | valatask.outputs.append(self.dump_deps_node) |
---|
123 | self.includes.append(self.bld.srcnode.abspath()) |
---|
124 | self.includes.append(self.bld.bldnode.abspath()) |
---|
125 | for include in includes: |
---|
126 | try: |
---|
127 | self.includes.append(self.path.find_dir(include).abspath()) |
---|
128 | self.includes.append(self.path.find_dir(include).get_bld().abspath()) |
---|
129 | except AttributeError: |
---|
130 | Logs.warn("Unable to locate include directory: '%s'"%include) |
---|
131 | if self.is_lib and valatask.install_binding: |
---|
132 | headers_list=[o for o in valatask.outputs if o.suffix()==".h"] |
---|
133 | try: |
---|
134 | self.install_vheader.source=headers_list |
---|
135 | except AttributeError: |
---|
136 | self.install_vheader=self.bld.install_files(valatask.header_path,headers_list,self.env) |
---|
137 | vapi_list=[o for o in valatask.outputs if(o.suffix()in(".vapi",".deps"))] |
---|
138 | try: |
---|
139 | self.install_vapi.source=vapi_list |
---|
140 | except AttributeError: |
---|
141 | self.install_vapi=self.bld.install_files(valatask.vapi_path,vapi_list,self.env) |
---|
142 | gir_list=[o for o in valatask.outputs if o.suffix()=='.gir'] |
---|
143 | try: |
---|
144 | self.install_gir.source=gir_list |
---|
145 | except AttributeError: |
---|
146 | self.install_gir=self.bld.install_files(getattr(self,'gir_path','${DATAROOTDIR}/gir-1.0'),gir_list,self.env) |
---|
147 | @extension('.vala','.gs') |
---|
148 | def vala_file(self,node): |
---|
149 | try: |
---|
150 | valatask=self.valatask |
---|
151 | except AttributeError: |
---|
152 | valatask=self.valatask=self.create_task('valac') |
---|
153 | self.init_vala_task() |
---|
154 | valatask.inputs.append(node) |
---|
155 | c_node=node.change_ext('.c') |
---|
156 | valatask.outputs.append(c_node) |
---|
157 | self.source.append(c_node) |
---|
158 | @conf |
---|
159 | def find_valac(self,valac_name,min_version): |
---|
160 | valac=self.find_program(valac_name,var='VALAC') |
---|
161 | try: |
---|
162 | output=self.cmd_and_log(valac+' --version') |
---|
163 | except Exception: |
---|
164 | valac_version=None |
---|
165 | else: |
---|
166 | ver=re.search(r'\d+.\d+.\d+',output).group(0).split('.') |
---|
167 | valac_version=tuple([int(x)for x in ver]) |
---|
168 | self.msg('Checking for %s version >= %r'%(valac_name,min_version),valac_version,valac_version and valac_version>=min_version) |
---|
169 | if valac and valac_version<min_version: |
---|
170 | self.fatal("%s version %r is too old, need >= %r"%(valac_name,valac_version,min_version)) |
---|
171 | self.env['VALAC_VERSION']=valac_version |
---|
172 | return valac |
---|
173 | @conf |
---|
174 | def check_vala(self,min_version=(0,8,0),branch=None): |
---|
175 | if not branch: |
---|
176 | branch=min_version[:2] |
---|
177 | try: |
---|
178 | find_valac(self,'valac-%d.%d'%(branch[0],branch[1]),min_version) |
---|
179 | except self.errors.ConfigurationError: |
---|
180 | find_valac(self,'valac',min_version) |
---|
181 | @conf |
---|
182 | def check_vala_deps(self): |
---|
183 | if not self.env['HAVE_GOBJECT']: |
---|
184 | pkg_args={'package':'gobject-2.0','uselib_store':'GOBJECT','args':'--cflags --libs'} |
---|
185 | if getattr(Options.options,'vala_target_glib',None): |
---|
186 | pkg_args['atleast_version']=Options.options.vala_target_glib |
---|
187 | self.check_cfg(**pkg_args) |
---|
188 | if not self.env['HAVE_GTHREAD']: |
---|
189 | pkg_args={'package':'gthread-2.0','uselib_store':'GTHREAD','args':'--cflags --libs'} |
---|
190 | if getattr(Options.options,'vala_target_glib',None): |
---|
191 | pkg_args['atleast_version']=Options.options.vala_target_glib |
---|
192 | self.check_cfg(**pkg_args) |
---|
193 | def configure(self): |
---|
194 | self.load('gnu_dirs') |
---|
195 | self.check_vala_deps() |
---|
196 | self.check_vala() |
---|
197 | self.env.VALAFLAGS=['-C','--quiet'] |
---|
198 | def options(opt): |
---|
199 | opt.load('gnu_dirs') |
---|
200 | valaopts=opt.add_option_group('Vala Compiler Options') |
---|
201 | valaopts.add_option('--vala-target-glib',default=None,dest='vala_target_glib',metavar='MAJOR.MINOR',help='Target version of glib for Vala GObject code generation') |
---|