ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[samba4-gss.git] / buildtools / wafsamba / samba_pidl.py
blobe1010869cdd1ab7ba385b655705616f3ec982755
1 # waf build tool for building IDL files with pidl
3 import os
4 from waflib import Build, Utils
5 from waflib.TaskGen import feature, before
6 from samba_utils import SET_TARGET_TYPE, TO_LIST, LOCAL_CACHE
8 def SAMBA_PIDL(bld, pname, source,
9 options='',
10 output_dir='.',
11 generate_tables=True):
12 '''Build a IDL file using pidl.
13 This will produce up to 17 output files depending on the options used'''
15 bname = source[0:-4] # strip off the .idl suffix
16 bname = os.path.basename(bname)
17 name = "%s_%s" % (pname, bname.upper())
19 if not SET_TARGET_TYPE(bld, name, 'PIDL'):
20 return
22 bld.SET_BUILD_GROUP('build_source')
24 # the output files depend on the options used. Use this dictionary
25 # to map between the options and the resulting file names
26 options_map = { '--header' : '%s.h',
27 '--ndr-parser' : 'ndr_%s.c ndr_%s.h',
28 '--samba3-ndr-server' : 'srv_%s.c srv_%s.h',
29 '--samba3-ndr-client' : 'cli_%s.c cli_%s.h',
30 '--server' : 'ndr_%s_s.c',
31 '--server-compat' : 'ndr_%s_scompat.c ndr_%s_scompat.h',
32 '--client' : 'ndr_%s_c.c ndr_%s_c.h',
33 '--python' : 'py_%s.c',
34 '--tdr-parser' : 'tdr_%s.c tdr_%s.h',
35 '--dcom-proxy' : '%s_p.c',
36 '--com-header' : 'com_%s.h'
39 table_header_idx = None
40 out_files = []
41 options_list = TO_LIST(options)
43 for o in options_list:
44 if o in options_map:
45 ofiles = TO_LIST(options_map[o])
46 for f in ofiles:
47 out_files.append(os.path.join(output_dir, f % bname))
48 if f == 'ndr_%s.h':
49 # remember this one for the tables generation
50 table_header_idx = len(out_files) - 1
52 # depend on the full pidl sources
53 source = TO_LIST(source)
54 try:
55 pidl_src_nodes = bld.pidl_files_cache
56 except AttributeError:
57 bld.pidl_files_cache = bld.srcnode.ant_glob('pidl/lib/Parse/**/*.pm', flat=False)
58 bld.pidl_files_cache.extend(bld.srcnode.ant_glob('pidl', flat=False))
59 pidl_src_nodes = bld.pidl_files_cache
61 # the cd .. is needed because pidl currently is sensitive to the directory it is run in
62 cpp = ""
63 cc = ""
64 if bld.CONFIG_SET("CPP") and bld.CONFIG_GET("CPP") != "":
65 if isinstance(bld.CONFIG_GET("CPP"), list):
66 cpp = 'CPP="%s"' % " ".join(bld.CONFIG_GET("CPP"))
67 else:
68 cpp = 'CPP="%s"' % bld.CONFIG_GET("CPP")
70 if cpp == "CPP=xlc_r":
71 cpp = ""
73 if bld.env['PIDL_DEVELOPER_MODE']:
74 pidl_dev = 'PIDL_DEVELOPER=1 '
75 else:
76 pidl_dev = ''
78 if bld.CONFIG_SET("CC"):
79 if isinstance(bld.CONFIG_GET("CC"), list):
80 cc = 'CC="%s"' % " ".join(bld.CONFIG_GET("CC"))
81 else:
82 cc = 'CC="%s"' % bld.CONFIG_GET("CC")
84 t = bld(rule=('cd ${PIDL_LAUNCH_DIR} && PERL_HASH_SEED=0 %s%s %s ${PERL} '
85 '${PIDL} --quiet ${OPTIONS} --outputdir ${OUTPUTDIR} -- "${IDLSRC}"' %
86 (pidl_dev, cpp, cc)),
87 ext_out = '.c',
88 before = 'c',
89 update_outputs = True,
90 shell = True,
91 source = source,
92 target = out_files,
93 name = name,
94 samba_type = 'PIDL')
97 t.env.PIDL_LAUNCH_DIR = bld.srcnode.path_from(bld.bldnode)
98 pnode = bld.srcnode.find_resource('pidl/pidl')
99 t.env.PIDL = pnode.path_from(bld.srcnode)
100 t.env.OPTIONS = TO_LIST(options)
101 snode = t.path.find_resource(source[0])
102 t.env.IDLSRC = snode.path_from(bld.srcnode)
103 t.env.OUTPUTDIR = bld.bldnode.path_from(bld.srcnode) + '/' + bld.path.find_dir(output_dir).path_from(bld.srcnode)
105 bld.add_manual_dependency(snode, pidl_src_nodes)
107 if generate_tables and table_header_idx is not None:
108 pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
109 pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])]
111 t.more_includes = '#' + bld.path.path_from(bld.srcnode)
112 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
114 def SAMBA_PIDL_LIST(bld, name, source,
115 options='',
116 output_dir='.',
117 generate_tables=True,
118 generate_fuzzers=True):
119 '''A wrapper for building a set of IDL files'''
120 for p in TO_LIST(source):
121 bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, generate_tables=generate_tables)
123 # Some IDL files don't exactly match between name and
124 # "interface" so we need a way to skip those, while other IDL
125 # files have the table generation skipped entirely, on which
126 # the fuzzers rely
127 if generate_tables and generate_fuzzers:
128 interface = p[0:-4] # strip off the .idl suffix
129 bld.SAMBA_NDR_FUZZ(interface,
130 auto_deps=True,
131 fuzz_type="TYPE_STRUCT")
133 # Only generate the TYPE_STRUCT fuzzer if this isn't
134 # really DCE/RPC
135 if '--client' in options:
136 bld.SAMBA_NDR_FUZZ(interface,
137 auto_deps=True,
138 fuzz_type="TYPE_IN")
139 bld.SAMBA_NDR_FUZZ(interface,
140 auto_deps=True,
141 fuzz_type="TYPE_OUT")
142 Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
145 #################################################################
146 # the rule for generating the NDR tables
147 @feature('collect')
148 @before('exec_rule')
149 def collect(self):
150 pidl_headers = LOCAL_CACHE(self.bld, 'PIDL_HEADERS')
151 # The first source is tables.pl itself
152 self.source = Utils.to_list(self.source)
153 for (name, hd) in pidl_headers.items():
154 y = self.bld.get_tgen_by_name(name)
155 self.bld.ASSERT(y is not None, 'Failed to find PIDL header %s' % name)
156 y.post()
157 for node in hd:
158 self.bld.ASSERT(node is not None, 'Got None as build node generating PIDL table for %s' % name)
159 self.source.append(node)
162 def SAMBA_PIDL_TABLES(bld, name, target):
163 '''generate the pidl NDR tables file'''
164 bld.SET_BUILD_GROUP('main')
165 t = bld(
166 features = 'collect',
167 rule = '${PERL} ${SRC} > ${TGT}',
168 ext_out = '.c',
169 before = 'c',
170 update_outputs = True,
171 shell = True,
172 source = '../../librpc/tables.pl',
173 target = target,
174 name = name)
175 t.env.LIBRPC = os.path.join(bld.srcnode.abspath(), 'librpc')
176 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES