QtCreator exporter: switch to jinja-based templates

this also makes so that the export directory setting is honored
pull/4278/head
Matteo Italia 2017-04-06 11:10:10 +02:00 committed by adbridge
parent e496a637c3
commit c2f5aa19a7
5 changed files with 42 additions and 25 deletions

View File

@ -30,32 +30,36 @@ class QtCreator(Exporter):
def generate(self):
self.resources.win_to_unix()
with open("%s.creator" % self.project_name, "w") as fd:
fd.write("[General]\n")
defines = [] # list of tuples ('D'/'U', [key, value]) (value is optional)
forced_includes = [] # list of strings
sources = [] # list of strings
include_paths = [] # list of strings
next_is_include = False
includes = []
with open("%s.config" % self.project_name, "w") as fd:
for f in self.flags['c_flags'] + self.flags['cxx_flags']:
f=f.strip()
if next_is_include:
includes.append(f)
next_is_include = False
continue
if f.startswith('-D'):
fd.write("#define %s\n" % (f[2:].replace('=', ' ')))
elif f.startswith('-U'):
fd.write("#undef %s\n" % f[2:])
elif f == "-include":
next_is_include = True
for i in includes:
fd.write("#include \"%s\"\n" % i)
for f in self.flags['c_flags'] + self.flags['cxx_flags']:
f=f.strip()
if next_is_include:
forced_includes.append(f)
next_is_include = False
continue
if f.startswith('-D'):
defines.append(('D', f[2:].split('=', 1)))
elif f.startswith('-U'):
defines.append(('U', [f[2:]]))
elif f == "-include":
next_is_include = True
with open("%s.files" % self.project_name, "w") as fd:
for r_type in ['headers', 'c_sources', 's_sources', 'cpp_sources']:
for f in getattr(self.resources, r_type):
fd.write(f + "\n")
for r_type in ['headers', 'c_sources', 's_sources', 'cpp_sources']:
sources.extend(getattr(self.resources, r_type))
with open("%s.includes" % self.project_name, "w") as fd:
for i in self.resources.inc_dirs:
fd.write(i + "\n")
include_paths = self.resources.inc_dirs
ctx = {
'defines': defines,
'forced_includes': forced_includes,
'sources': sources,
'include_paths': self.resources.inc_dirs
}
for ext in ['creator', 'files', 'includes', 'config']:
self.gen_file('qtcreator/%s.tmpl' % ext, ctx, "%s.%s" % (self.project_name, ext))

View File

@ -0,0 +1,6 @@
{% for d in defines -%}
{% if d[0] == 'D' %}#define {% else %}#undef{% endif %} {{ d[1]|join(' ')}}
{% endfor %}
{% for i in forced_includes -%}
#include "{{i}}"
{% endfor %}

View File

@ -0,0 +1 @@
[General]

View File

@ -0,0 +1,3 @@
{% for s in sources -%}
{{s}}
{% endfor %}

View File

@ -0,0 +1,3 @@
{% for i in include_paths -%}
{{i}}
{% endfor %}