2010-02-28 17:34:43 +11:00
# waf build tool for building IDL files with pidl
2010-03-17 20:12:16 +11:00
from TaskGen import before
2011-01-05 12:16:15 +01:00
import Build , os , sys , Logs
2010-02-28 17:34:43 +11:00
from samba_utils import *
2010-03-17 22:15:46 +11:00
def SAMBA_PIDL ( bld , pname , source ,
options = ' ' ,
output_dir = ' . ' ,
2010-05-05 12:40:20 +10:00
symlink = False ,
generate_tables = True ) :
2010-02-28 17:34:43 +11:00
''' Build a IDL file using pidl.
2010-03-17 21:48:26 +11:00
This will produce up to 13 output files depending on the options used '''
2010-02-28 17:34:43 +11:00
2010-03-17 21:48:26 +11:00
bname = source [ 0 : - 4 ] ; # strip off the .idl suffix
2010-05-05 12:40:20 +10:00
bname = os . path . basename ( bname )
2010-03-17 21:48:26 +11:00
name = " %s _ %s " % ( pname , bname . upper ( ) )
2010-02-28 17:34:43 +11:00
if not SET_TARGET_TYPE ( bld , name , ' PIDL ' ) :
return
bld . SET_BUILD_GROUP ( ' build_source ' )
2010-03-17 21:46:38 +11:00
2010-03-17 21:48:26 +11:00
# the output files depend on the options used. Use this dictionary
# to map between the options and the resulting file names
options_map = { ' --header ' : ' %s .h ' ,
' --ndr-parser ' : ' ndr_ %s .c ndr_ %s .h ' ,
' --samba3-ndr-server ' : ' srv_ %s .c srv_ %s .h ' ,
' --samba3-ndr-client ' : ' cli_ %s .c cli_ %s .h ' ,
' --server ' : ' ndr_ %s _s.c ' ,
' --client ' : ' ndr_ %s _c.c ndr_ %s _c.h ' ,
' --python ' : ' py_ %s .c ' ,
' --tdr-parser ' : ' tdr_ %s .c tdr_ %s .h ' ,
2010-03-17 22:17:15 +11:00
' --dcom-proxy ' : ' %s _p.c ' ,
' --com-header ' : ' com_ %s .h '
2010-03-17 21:48:26 +11:00
}
table_header_idx = None
2010-03-17 21:46:38 +11:00
out_files = [ ]
2010-03-20 16:27:48 +11:00
options_list = TO_LIST ( options )
2010-03-17 21:46:38 +11:00
2010-03-17 21:48:26 +11:00
for o in options_list :
if o in options_map :
2010-03-20 16:27:48 +11:00
ofiles = TO_LIST ( options_map [ o ] )
2010-03-17 21:48:26 +11:00
for f in ofiles :
out_files . append ( os . path . join ( output_dir , f % bname ) )
if f == ' ndr_ %s .h ' :
# remember this one for the tables generation
table_header_idx = len ( out_files ) - 1
2010-03-17 21:46:38 +11:00
2010-03-17 20:12:16 +11:00
# depend on the full pidl sources
source = TO_LIST ( source )
2010-03-17 09:55:41 +11:00
try :
pidl_src_nodes = bld . pidl_files_cache
except AttributeError :
2010-04-02 19:57:32 +11:00
bld . pidl_files_cache = bld . srcnode . ant_glob ( ' pidl/lib/Parse/**/*.pm ' , flat = False )
2010-03-27 16:46:33 +11:00
bld . pidl_files_cache . extend ( bld . srcnode . ant_glob ( ' pidl ' , flat = False ) )
pidl_src_nodes = bld . pidl_files_cache
2010-03-17 21:53:29 +11:00
2010-03-17 21:48:26 +11:00
# the cd .. is needed because pidl currently is sensitive to the directory it is run in
2010-12-10 02:36:24 +03:00
cpp = " "
cc = " "
if bld . CONFIG_SET ( " CPP " ) :
2010-12-10 10:06:44 +03:00
if isinstance ( bld . CONFIG_GET ( " CPP " ) , list ) :
cpp = " CPP= %s " % bld . CONFIG_GET ( " CPP " ) [ 0 ]
else :
cpp = " CPP= %s " % bld . CONFIG_GET ( " CPP " )
2010-12-10 23:47:54 +03:00
if cpp == " CPP=xlc_r " :
2010-12-10 14:37:00 +03:00
cpp = " "
2010-12-10 02:36:24 +03:00
if bld . CONFIG_SET ( " CC " ) :
if isinstance ( bld . CONFIG_GET ( " CC " ) , list ) :
cc = " CC= %s " % bld . CONFIG_GET ( " CC " ) [ 0 ]
else :
cc = " CC= %s " % bld . CONFIG_GET ( " CC " )
2010-12-10 10:06:44 +03:00
2010-12-10 02:36:24 +03:00
t = bld ( rule = ' cd .. && %s %s $ {PERL} " $ {PIDL} " --quiet $ {OPTIONS} --outputdir $ {OUTPUTDIR} -- " $ { SRC[0].abspath(env)} " ' % ( cpp , cc ) ,
2010-03-17 22:17:15 +11:00
ext_out = ' .c ' ,
before = ' cc ' ,
2010-03-24 10:54:31 +01:00
on_results = True ,
2010-03-17 22:17:15 +11:00
shell = True ,
source = source ,
target = out_files ,
name = name ,
samba_type = ' PIDL ' )
2010-03-17 21:53:29 +11:00
2010-03-17 09:55:41 +11:00
# prime the list of nodes we are dependent on with the cached pidl sources
t . allnodes = pidl_src_nodes
2010-04-08 21:46:20 +10:00
t . env . PIDL = os . path . join ( bld . srcnode . abspath ( ) , ' pidl/pidl ' )
2010-03-20 16:27:48 +11:00
t . env . OPTIONS = TO_LIST ( options )
2010-03-17 22:15:46 +11:00
# this rather convoluted set of path calculations is to cope with the possibility
# that gen_ndr is a symlink into the source tree. By doing this for the source3
# gen_ndr directory we end up generating identical output in gen_ndr for the old
# build system and the new one. That makes keeping things in sync much easier.
# eventually we should drop the gen_ndr files in git, but in the meanwhile this works
2010-07-19 14:26:20 +10:00
found_dir = bld . path . find_dir ( output_dir )
if not ' abspath ' in dir ( found_dir ) :
Logs . error ( ' Unable to find pidl output directory %s ' %
os . path . normpath ( os . path . join ( bld . curdir , output_dir ) ) )
sys . exit ( 1 )
2010-04-08 21:46:20 +10:00
outdir = bld . path . find_dir ( output_dir ) . abspath ( t . env )
2010-03-17 22:15:46 +11:00
2010-04-08 21:46:20 +10:00
if symlink and not os . path . lexists ( outdir ) :
2010-03-17 22:15:46 +11:00
link_source = os . path . normpath ( os . path . join ( bld . curdir , output_dir ) )
os . symlink ( link_source , outdir )
real_outputdir = os . path . realpath ( outdir )
2010-04-08 21:46:20 +10:00
t . env . OUTPUTDIR = os_path_relpath ( real_outputdir , os . path . dirname ( bld . env . BUILD_DIRECTORY ) )
2010-03-17 21:53:29 +11:00
2010-05-05 12:40:20 +10:00
if generate_tables and table_header_idx is not None :
2010-03-17 21:48:26 +11:00
pidl_headers = LOCAL_CACHE ( bld , ' PIDL_HEADERS ' )
pidl_headers [ name ] = [ bld . path . find_or_declare ( out_files [ table_header_idx ] ) ]
2010-03-17 21:53:29 +11:00
2010-03-17 21:48:26 +11:00
t . more_includes = ' # ' + bld . path . relpath_gen ( bld . srcnode )
Build . BuildContext . SAMBA_PIDL = SAMBA_PIDL
2010-02-28 17:34:43 +11:00
2010-03-17 22:15:46 +11:00
def SAMBA_PIDL_LIST ( bld , name , source ,
options = ' ' ,
output_dir = ' . ' ,
2010-05-05 12:40:20 +10:00
symlink = False ,
generate_tables = True ) :
2010-03-17 21:48:26 +11:00
''' A wrapper for building a set of IDL files '''
2010-03-20 16:27:48 +11:00
for p in TO_LIST ( source ) :
2010-05-05 12:40:20 +10:00
bld . SAMBA_PIDL ( name , p , options = options , output_dir = output_dir , symlink = symlink , generate_tables = generate_tables )
2010-03-17 21:46:38 +11:00
Build . BuildContext . SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
#################################################################
# the rule for generating the NDR tables
from TaskGen import feature , before
@feature ( ' collect ' )
@before ( ' exec_rule ' )
def collect ( self ) :
2010-03-17 21:48:26 +11:00
pidl_headers = LOCAL_CACHE ( self . bld , ' PIDL_HEADERS ' )
for ( name , hd ) in pidl_headers . items ( ) :
2010-03-17 21:46:38 +11:00
y = self . bld . name_to_obj ( name , self . env )
2010-03-17 21:48:26 +11:00
self . bld . ASSERT ( y is not None , ' Failed to find PIDL header %s ' % name )
2010-03-17 21:46:38 +11:00
y . post ( )
for node in hd :
2010-05-05 12:40:20 +10:00
self . bld . ASSERT ( node is not None , ' Got None as build node generating PIDL table for %s ' % name )
2010-03-17 21:46:38 +11:00
self . source + = " " + node . relpath_gen ( self . path )
2010-03-17 21:48:26 +11:00
2010-03-17 21:46:38 +11:00
def SAMBA_PIDL_TABLES ( bld , name , target ) :
2010-03-28 22:01:04 +11:00
''' generate the pidl NDR tables file '''
2010-03-17 21:46:38 +11:00
headers = bld . env . PIDL_HEADERS
2010-03-28 10:00:53 +11:00
bld . SET_BUILD_GROUP ( ' main ' )
2010-03-17 21:46:38 +11:00
t = bld (
features = ' collect ' ,
2010-04-18 22:57:59 +10:00
rule = ' $ {PERL} $ {SRC} --output $ {TGT} | sed " s|default/|| " > $ {TGT} ' ,
2010-03-17 21:48:26 +11:00
ext_out = ' .c ' ,
before = ' cc ' ,
2010-03-24 10:54:31 +01:00
on_results = True ,
2010-03-17 21:48:26 +11:00
shell = True ,
source = ' ../../librpc/tables.pl ' ,
target = target ,
name = name )
2010-04-08 21:46:20 +10:00
t . env . LIBRPC = os . path . join ( bld . srcnode . abspath ( ) , ' librpc ' )
2010-03-17 21:46:38 +11:00
Build . BuildContext . SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES