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
|
#!/usr/bin/python3
# Mallard waf adaptor written by Ulrik Sverdrup
# may be distributed, changed, used, etc freely for any purpose
## Mallard functionality definitions ##
import os
from pathlib import Path
from waflib import Task, TaskGen, Utils
# FIXME: Support for figures
def _read_makefile_am(filename):
"""Read a Makefile.am file for HELP_* variable definitions, return tuples
(key, value)
"""
varstring = Path(filename).read_text(encoding="UTF-8")
varstring = varstring.replace("\\\n", " ")
for line in varstring.splitlines():
if line.startswith("HELP"):
key, _d, value = line.partition("=")
yield key.strip(), value.strip()
def init_mallard(self):
mf_am = self.path.find_resource(self.variable_definitions)
help_var = dict(_read_makefile_am(mf_am.abspath()))
require_vars = "HELP_ID HELP_LINGUAS HELP_FILES".split()
have_vars = set(var for var, val in help_var.items() if val)
if missing_vars := set(require_vars).difference(have_vars):
print(f"Missing HELP variable declarations in {mf_am.abspath()}:")
print("\n".join(missing_vars))
self.bld.env.update(help_var)
self.help_install_prefix = "${PREFIX}/share/help/"
def apply_mallard(self):
bld = self.bld
lst = self.to_list(bld.env["HELP_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["HELP_FILES"])
pages = [os.path.basename(str(p)) for p in pages]
if missing_pages := set(pages).difference(declared_pages):
print("Warning: Some pages not declared:")
print("\n".join(missing_pages))
for lang in lst:
lang_install_path = os.path.join(
self.install_path, lang, bld.env["HELP_ID"]
)
node = self.path.find_resource(f"{lang}/{lang}.po")
mo = self.path.find_or_declare(f"{lang}/{lang}.mo")
bld(
name="msgfmt",
color="BLUE",
rule="${MSGFMT} ${SRC} -o ${TGT}",
source=node,
target=mo,
)
for page in pages:
tsk = self.create_task("itstool")
out = self.path.find_or_declare(f"{lang}/{page}")
src = self.path.find_resource(f"C/{page}")
tsk.set_inputs([mo, 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["HELP_ID"])
for page in cnode.ant_glob("*.page"):
bld.install_files(c_install_path, page)
bld.install_files(c_install_path, legal_xml)
Task.task_factory(
"itstool", "${ITSTOOL} ${ITSTOOLFLAGS} ${SRC} -o ${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("msgfmt", var="MSGFMT")
ctx.find_program("itstool", var="ITSTOOL")
ctx.env["ITSTOOLFLAGS"] = "-m"
except ctx.errors.ConfigurationError:
pass
def build(bld):
if bld.env["ITSTOOL"]:
bld(
features="mallard",
variable_definitions="Makefile.am",
)
|