s3: Remove a use of smbd_server_fd
[Samba/gbeck.git] / buildtools / wafsamba / samba_pidl.py
blob521222dc5cc34aa4e59a51397a7301b7ca40c4da
1 # waf build tool for building IDL files with pidl
3 from TaskGen import before
4 import Build, os
5 from samba_utils import *
7 def SAMBA_PIDL(bld, pname, source,
8 options='',
9 output_dir='.',
10 symlink=False,
11 generate_tables=True):
12 '''Build a IDL file using pidl.
13 This will produce up to 13 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 '--client' : 'ndr_%s_c.c ndr_%s_c.h',
32 '--python' : 'py_%s.c',
33 '--tdr-parser' : 'tdr_%s.c tdr_%s.h',
34 '--dcom-proxy' : '%s_p.c',
35 '--com-header' : 'com_%s.h'
38 table_header_idx = None
39 out_files = []
40 options_list = TO_LIST(options)
42 for o in options_list:
43 if o in options_map:
44 ofiles = TO_LIST(options_map[o])
45 for f in ofiles:
46 out_files.append(os.path.join(output_dir, f % bname))
47 if f == 'ndr_%s.h':
48 # remember this one for the tables generation
49 table_header_idx = len(out_files) - 1
51 # depend on the full pidl sources
52 source = TO_LIST(source)
53 try:
54 pidl_src_nodes = bld.pidl_files_cache
55 except AttributeError:
56 bld.pidl_files_cache = bld.srcnode.ant_glob('pidl/lib/Parse/**/*.pm', flat=False)
57 bld.pidl_files_cache.extend(bld.srcnode.ant_glob('pidl', flat=False))
58 pidl_src_nodes = bld.pidl_files_cache
60 # the cd .. is needed because pidl currently is sensitive to the directory it is run in
61 t = bld(rule='cd .. && ${PERL} ${PIDL} --quiet ${OPTIONS} --outputdir ${OUTPUTDIR} -- ${SRC[0].abspath(env)}',
62 ext_out = '.c',
63 before = 'cc',
64 on_results = True,
65 shell = True,
66 source = source,
67 target = out_files,
68 name = name,
69 samba_type = 'PIDL')
71 # prime the list of nodes we are dependent on with the cached pidl sources
72 t.allnodes = pidl_src_nodes
74 t.env.PIDL = os.path.join(bld.srcnode.abspath(), 'pidl/pidl')
75 t.env.OPTIONS = TO_LIST(options)
77 # this rather convoluted set of path calculations is to cope with the possibility
78 # that gen_ndr is a symlink into the source tree. By doing this for the source3
79 # gen_ndr directory we end up generating identical output in gen_ndr for the old
80 # build system and the new one. That makes keeping things in sync much easier.
81 # eventually we should drop the gen_ndr files in git, but in the meanwhile this works
83 found_dir = bld.path.find_dir(output_dir)
84 if not 'abspath' in dir(found_dir):
85 Logs.error('Unable to find pidl output directory %s' %
86 os.path.normpath(os.path.join(bld.curdir, output_dir)))
87 sys.exit(1)
89 outdir = bld.path.find_dir(output_dir).abspath(t.env)
91 if symlink and not os.path.lexists(outdir):
92 link_source = os.path.normpath(os.path.join(bld.curdir,output_dir))
93 os.symlink(link_source, outdir)
95 real_outputdir = os.path.realpath(outdir)
96 t.env.OUTPUTDIR = os_path_relpath(real_outputdir, os.path.dirname(bld.env.BUILD_DIRECTORY))
98 if generate_tables and table_header_idx is not None:
99 pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
100 pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])]
102 t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
103 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
106 def SAMBA_PIDL_LIST(bld, name, source,
107 options='',
108 output_dir='.',
109 symlink=False,
110 generate_tables=True):
111 '''A wrapper for building a set of IDL files'''
112 for p in TO_LIST(source):
113 bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir, symlink=symlink, generate_tables=generate_tables)
114 Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
117 #################################################################
118 # the rule for generating the NDR tables
119 from TaskGen import feature, before
120 @feature('collect')
121 @before('exec_rule')
122 def collect(self):
123 pidl_headers = LOCAL_CACHE(self.bld, 'PIDL_HEADERS')
124 for (name, hd) in pidl_headers.items():
125 y = self.bld.name_to_obj(name, self.env)
126 self.bld.ASSERT(y is not None, 'Failed to find PIDL header %s' % name)
127 y.post()
128 for node in hd:
129 self.bld.ASSERT(node is not None, 'Got None as build node generating PIDL table for %s' % name)
130 self.source += " " + node.relpath_gen(self.path)
133 def SAMBA_PIDL_TABLES(bld, name, target):
134 '''generate the pidl NDR tables file'''
135 headers = bld.env.PIDL_HEADERS
136 bld.SET_BUILD_GROUP('main')
137 t = bld(
138 features = 'collect',
139 rule = '${PERL} ${SRC} --output ${TGT} | sed "s|default/||" > ${TGT}',
140 ext_out = '.c',
141 before = 'cc',
142 on_results = True,
143 shell = True,
144 source = '../../librpc/tables.pl',
145 target = target,
146 name = name)
147 t.env.LIBRPC = os.path.join(bld.srcnode.abspath(), 'librpc')
148 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES