forked from kupferlauncher/kupfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwscript
92 lines (72 loc) · 3.06 KB
/
wscript
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
#!/usr/bin/env python
# Mallard waf adaptor written by Ulrik Sverdrup
# may be distributed, changed, used, etc freely for any purpose
## Mallard functionality definitions ##
import os
from waflib import Task, TaskGen, Utils
# FIXME: Support for figures
def _read_makefile_am(filename):
"read a Makefile.am file for DOC_* variable definitions, return a dict"
varstring = open(filename).read()
varstring = varstring.replace("\\\n", " ")
varlines = [L for L in varstring.splitlines() if L.startswith("DOC")]
return dict(tuple(map(str.strip, var.split("=", 1))) for var in varlines)
def init_mallard(self):
mf_am = self.path.find_resource(self.variable_definitions)
DOC_VAR = _read_makefile_am(mf_am.abspath())
require_vars = "DOC_ID DOC_LINGUAS DOC_PAGES".split()
have_vars = set(var for var in DOC_VAR if DOC_VAR[var])
missing_vars = set(require_vars).difference(have_vars)
if missing_vars:
print("Missing DOC variable declarations in %s:" % (mf_am.abspath()))
print("\n".join(missing_vars))
self.bld.env.update(DOC_VAR)
self.help_install_prefix='${PREFIX}/share/help/'
def apply_mallard(self):
bld = self.bld
lst = self.to_list(bld.env["DOC_LINGUAS"])
cnode = self.path.find_dir("C")
pages = cnode.ant_glob("*.page")
legal_xml = cnode.ant_glob("legal.xml")
self.install_path = Utils.subst_vars(self.help_install_prefix, self.env)
# Check if the declared page list is consistent
declared_pages = self.to_list(bld.env["DOC_PAGES"])
missing_pages = set([str(p) for p in pages]).difference(declared_pages)
if missing_pages:
print("Warning: Some pages not declared:")
print("\n".join([str(p) for p in missing_pages]))
for lang in lst:
lang_install_path = os.path.join(self.install_path, lang, bld.env["DOC_ID"])
node = self.path.find_resource("%s/%s.po" % (lang, lang))
for page in pages:
tsk = self.create_task('xml2po')
out = self.path.find_or_declare('%s/%s' % (lang, page))
src = self.path.find_resource('C/%s' % page)
tsk.set_inputs([node,src])
tsk.set_outputs(out)
bld.install_files(lang_install_path, tsk.outputs)
bld.install_files(lang_install_path, legal_xml)
c_install_path = os.path.join(self.install_path, "C", bld.env["DOC_ID"])
for page in pages:
bld.install_files(c_install_path, page)
bld.install_files(c_install_path, legal_xml)
Task.task_factory('xml2po', '${XML2PO} ${XML2POFLAGS} ${SRC} > ${TGT}',
color='BLUE')
TaskGen.feature("mallard")(init_mallard)
TaskGen.feature("mallard")(apply_mallard)
TaskGen.after('init_mallard')(apply_mallard)
## End Mallard functionality ##
# Build Configuration
def options(opt):
pass
def configure(ctx):
try:
ctx.find_program('xml2po', var='XML2PO')
ctx.env['XML2POFLAGS'] = '-mmallard -p'
except ctx.errors.ConfigurationError:
pass
def build(bld):
if bld.env["XML2PO"]:
task = bld(features="mallard",
variable_definitions="Makefile.am",
)