4 def writeSwigI(block, ommit_list, swigI, function_ommit=[]):
5 # create a new block with the updated info
9 function_ommitting = False
12 if function_ommitting:
18 function_ommitting = False
20 for ommit in function_ommit:
22 # we found the function. We'll not be too smart and we'll
23 # assume that if there is a beginning it'll be in the line
26 new_block = new_block[:len(new_block)-1]
27 function_ommitting = True;
34 for ommit in ommit_list:
35 if line.startswith(ommit):
40 new_block.append(line)
42 for line in new_block:
43 # remove __user flag, since swig can't understand
46 if "#define __user" in newline:
47 newline = line.replace('__user', '__lutf_user')
48 elif "#ifndef __user" in newline:
49 newline = line.replace('__user', '__lutf_user')
51 newline = line.replace('__user', '')
54 # set up the paths to all the files that need to be swigified
55 netconfig_path = sys.argv[1] + '/lnet/utils/lnetconfig/liblnetconfig.h'
56 cyaml_path = sys.argv[1] + '/lnet/utils/lnetconfig/cyaml.h'
57 lib_dlc_path = sys.argv[1] + '/lnet/include/uapi/linux/lnet/lnet-dlc.h'
58 string_path = sys.argv[1] + '/libcfs/include/libcfs/util/string.h'
59 nidstr_path = sys.argv[1] + '/lnet/include/uapi/linux/lnet/nidstr.h'
60 limits_path = '/usr/include/limits.h'
61 typemap_path = sys.argv[1] + '/lustre/tests/lutf/swig_templates/typemap.template'
62 lutf_missing_def = sys.argv[1] + '/lustre/tests/lutf/swig_templates/lutf_missing_definitions.h'
63 lutf_extra_defs = sys.argv[1] + '/lustre/tests/lutf/swig_templates/liblnetconfig.template'
64 swig_intf_path = sys.argv[1] + '/lustre/tests/lutf/src/liblnetconfig.i'
67 i_netconfig = open(netconfig_path)
68 i_cyaml = open(cyaml_path)
69 i_lib_dlc = open(lib_dlc_path)
70 i_string = open(string_path)
71 i_nidstr = open(nidstr_path)
72 i_limits = open(limits_path)
73 i_typemap = open(typemap_path)
74 i_lutf_missing_def = open(lutf_missing_def)
76 # open the swig interface output file
77 o_swig_intf = open(swig_intf_path, 'w')
80 l_netconfig = i_netconfig.readlines()
81 l_cyaml = i_cyaml.readlines()
82 l_lib_dlc = i_lib_dlc.readlines()
83 l_string = i_string.readlines()
84 l_nidstr = i_nidstr.readlines()
85 l_limits = i_limits.readlines()
86 l_typemap = i_typemap.readlines()
87 l_lutf_missing_def = i_lutf_missing_def.readlines()
89 # identify all the lines that I'd like to remove from the swig interface
91 netconfig_ommit_list = ['/*', ' *', '#ifndef LIB_LNET_CONFIG_API_H', '#define LIB_LNET_CONFIG_API_H',
92 'struct cYAML;', '#endif']
93 cyaml_ommit_list = ['/*', ' *', '#ifndef CYAML_H', '#define CYAML_H', '#endif']
94 generic_ommit_list = ['/*', ' *', '__printf(3, 4)']
96 # write the swig interface file
97 o_swig_intf.write('%module lnetconfig\n')
98 o_swig_intf.write('%{\n')
100 o_swig_intf.write("#include \"libcfs/util/ioctl.h\"\n")
101 o_swig_intf.write("#include \"libcfs/util/string.h\"\n")
103 writeSwigI(l_lutf_missing_def, [], o_swig_intf)
104 writeSwigI(l_cyaml, cyaml_ommit_list, o_swig_intf)
105 writeSwigI(l_netconfig, netconfig_ommit_list, o_swig_intf)
106 writeSwigI(l_lib_dlc, generic_ommit_list, o_swig_intf)
107 o_swig_intf.write('PyObject *lutf_parse_nidlist(char *str, int len, int max_nids);\n')
108 o_swig_intf.write('char *lutf_nid2str(unsigned long nid);\n')
110 o_swig_intf.write('%}\n')
112 for line in l_typemap:
113 o_swig_intf.write(line)
115 # handle the typdefs that are declared in
116 # /usr/include/asm-generic/int-ll64.h
117 # It appears that SWIG has a problem with __signed__ keyword
118 o_swig_intf.write("typedef char __s8;\n")
119 o_swig_intf.write("typedef unsigned char __u8;\n")
121 o_swig_intf.write("typedef short __s16;\n")
122 o_swig_intf.write("typedef unsigned short __u16;\n")
124 o_swig_intf.write("typedef int __s32;\n")
125 o_swig_intf.write("typedef unsigned int __u32;\n")
127 o_swig_intf.write("typedef long long __s64;\n")
128 o_swig_intf.write("typedef unsigned long long __u64;\n")
131 o_swig_intf.write('PyObject *lutf_parse_nidlist(char *str, int len, int max_nids);\n')
132 o_swig_intf.write('char *lutf_nid2str(unsigned long nid);\n')
133 writeSwigI(l_limits, [], o_swig_intf)
134 writeSwigI(l_cyaml, cyaml_ommit_list, o_swig_intf)
135 writeSwigI(l_netconfig, netconfig_ommit_list, o_swig_intf)
136 writeSwigI(l_lib_dlc, generic_ommit_list, o_swig_intf)
137 function_ommit = ['int vscnprintf(char *buf, size_t bufsz, const char *format, va_list args)',
138 'static inline int scnprintf(char *buf, size_t bufsz, const char *format, ...)']
139 writeSwigI(l_string, generic_ommit_list, o_swig_intf, function_ommit=function_ommit)
140 writeSwigI(l_nidstr, generic_ommit_list, o_swig_intf)
142 with open(lutf_extra_defs, 'r') as f:
144 o_swig_intf.write(line)