build: waf quicktest nearly works
[samba.git] / buildtools / wafsamba / samba_pidl.py
1 # waf build tool for building IDL files with pidl
2
3 from TaskGen import before
4 import Build, os
5 from samba_utils import *
6
7 def SAMBA_PIDL(bld, pname, source, options='', output_dir='.'):
8     '''Build a IDL file using pidl.
9        This will produce up to 13 output files depending on the options used'''
10
11     bname = source[0:-4]; # strip off the .idl suffix
12     name = "%s_%s" % (pname, bname.upper())
13
14     if not SET_TARGET_TYPE(bld, name, 'PIDL'):
15         return
16
17     bld.SET_BUILD_GROUP('build_source')
18
19     # the output files depend on the options used. Use this dictionary
20     # to map between the options and the resulting file names
21     options_map = { '--header'            : '%s.h',
22                     '--ndr-parser'        : 'ndr_%s.c ndr_%s.h',
23                     '--samba3-ndr-server' : 'srv_%s.c srv_%s.h',
24                     '--samba3-ndr-client' : 'cli_%s.c cli_%s.h',
25                     '--server'            : 'ndr_%s_s.c',
26                     '--client'            : 'ndr_%s_c.c ndr_%s_c.h',
27                     '--python'            : 'py_%s.c',
28                     '--tdr-parser'        : 'tdr_%s.c tdr_%s.h',
29                     }
30
31     table_header_idx = None
32     out_files = []
33     options_list = TO_LIST(options)
34
35     for o in options_list:
36         if o in options_map:
37             ofiles = TO_LIST(options_map[o])
38             for f in ofiles:
39                 out_files.append(os.path.join(output_dir, f % bname))
40                 if f == 'ndr_%s.h':
41                     # remember this one for the tables generation
42                     table_header_idx = len(out_files) - 1
43
44     # depend on the full pidl sources
45     source = TO_LIST(source)
46     pidl_src = [x.relpath_gen(bld.path) for x in
47                 bld.srcnode.ant_glob('pidl/**/*', flat=False)]
48     source.extend(pidl_src)
49
50     # the cd .. is needed because pidl currently is sensitive to the directory it is run in
51     t = bld(rule='cd .. && ${PIDL} ${OPTIONS} --outputdir ${OUTPUTDIR} -- ${SRC[0].abspath(env)}',
52             ext_out = '.c',
53             before  = 'cc',
54             shell   = True,
55             source  = source,
56             target  = out_files,
57             name    = name)
58
59     t.env.PIDL = "../pidl/pidl"
60     t.env.OPTIONS = TO_LIST(options)
61     t.env.OUTPUTDIR = bld.bldnode.name + '/' + bld.path.find_dir(output_dir).bldpath(t.env)
62
63     if table_header_idx is not None:
64         pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
65         pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])]
66
67     t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
68 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
69
70
71 def SAMBA_PIDL_LIST(bld, name, source, options='', output_dir='.'):
72     '''A wrapper for building a set of IDL files'''
73     for p in TO_LIST(source):
74         bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir)
75 Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
76
77
78 #################################################################
79 # the rule for generating the NDR tables
80 from TaskGen import feature, before
81 @feature('collect')
82 @before('exec_rule')
83 def collect(self):
84     pidl_headers = LOCAL_CACHE(self.bld, 'PIDL_HEADERS')
85     for (name, hd) in pidl_headers.items():
86         y = self.bld.name_to_obj(name, self.env)
87         self.bld.ASSERT(y is not None, 'Failed to find PIDL header %s' % name)
88         y.post()
89         for node in hd:
90             self.source += " " + node.relpath_gen(self.path)
91
92
93 def SAMBA_PIDL_TABLES(bld, name, target):
94     headers = bld.env.PIDL_HEADERS
95     t = bld(
96             features = 'collect',
97             rule     = '${SRC} --output ${TGT} | sed "s|default/||" > ${TGT}',
98             ext_out  = '.c',
99             before   = 'cc',
100             shell    = True,
101             source   = '../../librpc/tables.pl',
102             target   = target,
103             name     = name)
104 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES
105