1
- #!/usr/bin/env python2
1
+ # waf script called from the root wscript, by
2
+ # conf.recurse("help")
2
3
3
4
# Mallard waf adaptor written by Ulrik Sverdrup
4
5
# may be distributed, changed, used, etc freely for any purpose
5
6
6
7
## Mallard functionality definitions ##
7
8
import os
8
- import Task
9
- import TaskGen
9
+ from waflib import Logs , TaskGen
10
10
11
11
def _read_makefile_am (filename ):
12
12
"read a Makefile.am file for DOC_* variable definitions, return a dict"
@@ -23,8 +23,8 @@ def init_mallard(self):
23
23
have_vars = set (var for var in DOC_VAR if DOC_VAR [var ])
24
24
missing_vars = set (require_vars ).difference (have_vars )
25
25
if missing_vars :
26
- print "Missing DOC variable declarations in %s:" % (mf_am .abspath ())
27
- print "\n " .join (missing_vars )
26
+ print ( "Missing DOC variable declarations in {}:" . format (mf_am .abspath () ))
27
+ print ( "\n " .join (missing_vars ) )
28
28
29
29
self .bld .env .update (DOC_VAR )
30
30
self .default_install_path = '${PREFIX}/share/help'
@@ -33,35 +33,35 @@ def apply_mallard(self):
33
33
bld = self .bld
34
34
lst = self .to_list (bld .env ["DOC_LINGUAS" ])
35
35
cnode = self .path .find_dir ("C" )
36
- self .bld .rescan (cnode )
37
36
38
- pages = [p for p in self .bld .cache_dir_contents [cnode .id ]
39
- if (os .path .splitext (p )[- 1 ].lower ()) == ".page" ]
37
+ pages = [p .name for p in cnode .ant_glob ("*.page" )]
40
38
41
39
# Check if the declared page list is consistent
42
40
declared_pages = self .to_list (bld .env ["DOC_PAGES" ])
43
41
missing_pages = set (pages ).difference (declared_pages )
44
42
if missing_pages :
45
- print "Warning: Some pages not declared:"
46
- print "\n " .join (missing_pages )
43
+ print ("Warning: Some pages not declared:" )
44
+ print ("\n " .join (missing_pages ))
45
+
46
+ install_path = lambda lang : os .path .join (bld .env .DATADIR , "help" , lang , "${DOC_ID}" )
47
47
48
48
for lang in lst :
49
49
node = self .path .find_resource ("%s/%s.po" % (lang , lang ))
50
50
for page in pages :
51
- tsk = self .create_task ('xml2po' )
52
51
out = self .path .find_or_declare ('%s/%s' % (lang , page ))
53
52
src = self .path .find_resource ('C/%s' % page )
54
- tsk .set_inputs ([node ,src ])
55
- tsk .set_outputs (out )
56
- tsk .install_path = os .path .join (self .install_path , lang , "${DOC_ID}" )
53
+ bld (name = 'xml2po' , color = 'BLUE' ,
54
+ rule = '${XML2PO} ${XML2POFLAGS} ${SRC} > ${TGT}' ,
55
+ source = [node , src ],
56
+ target = out ,
57
+ install_path = install_path (lang )
58
+ )
59
+
57
60
if bld .is_install :
58
- for page in pages :
59
- out = "%s/%s" % (cnode .abspath (), page )
60
- instdir = os .path .join (self .install_path , "C" , "${DOC_ID}" )
61
- bld .install_files (instdir , out )
61
+ page_nodes = [cnode .find_resource (page ) for page in pages ]
62
+ instdir = install_path ("C" )
63
+ bld .install_files (instdir , page_nodes )
62
64
63
- Task .simple_task_type ('xml2po' , '${XML2PO} ${XML2POFLAGS} ${SRC} > ${TGT}' ,
64
- color = 'BLUE' )
65
65
66
66
TaskGen .feature ("mallard" )(init_mallard )
67
67
TaskGen .feature ("mallard" )(apply_mallard )
@@ -72,16 +72,20 @@ TaskGen.after('init_mallard')(apply_mallard)
72
72
73
73
# Build Configuration
74
74
75
- def set_options (opt ):
76
- pass
77
75
78
- def configure (conf ):
79
- xml2po = conf .find_program ('xml2po' , var = 'XML2PO' )
80
- conf .env ['XML2POFLAGS' ] = '-mmallard -p'
76
+ def configure (ctx ):
77
+ lookfor = "xml2po"
78
+ try :
79
+ ctx .find_program (lookfor , var = 'XML2PO' )
80
+ ctx .env .docs = True
81
+ ctx .env .XML2POFLAGS = '-mmallard -p'
82
+ except ctx .errors .ConfigurationError :
83
+ Logs .warn ("'{}' not found; documentation build disabled" .format (lookfor ))
84
+ ctx .env .docs = False
81
85
82
- def build (bld ):
83
- if bld .env [ "XML2PO" ] :
84
- task = bld . new_task_gen (
86
+ def build (ctx ):
87
+ if ctx .env . docs :
88
+ task = ctx (
85
89
features = "mallard" ,
86
90
variable_definitions = "Makefile.am" ,
87
91
)
0 commit comments