3 # Copyright 2008, Google Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
16 # * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 """Tools for exporting NativeClient ABI header files.
35 This module is used to export NativeClient ABI header files -- which are in
36 the native_client/service_runtime/include directory -- for use for NativeClient
37 applications compilation.
44 def ProcessStreams(instr
, outstr
):
45 """Read internal version of header file from instr, write exported version
49 pat
= r
'\b(?:nacl_abi_|NaClAbi|NACL_ABI_)([A-Za-z0-9_]*)'
50 cpat
= re
.compile(pat
)
52 inc
= r
'^#\s*include\s+"native_client(?:/service_runtime)?/include/([^"]*)"'
53 incpat
= re
.compile(inc
)
56 if incpat
.search(str):
57 print >>outstr
, incpat
.sub(r
'#include <\1>', str)
59 print >>outstr
, cpat
.sub(r
'\1', str),
64 def ProcessFileList(flist
):
66 ProcessStreams(open(f
), sys
.stdout
);
70 def ProcessDir(srcdir
, dstdir
):
71 if not os
.path
.isdir(srcdir
):
74 if not os
.path
.isdir(dstdir
):
77 for fn
in os
.listdir(srcdir
):
78 srcpath
= os
.path
.join(srcdir
, fn
)
79 dstpath
= os
.path
.join(dstdir
, fn
)
80 if os
.path
.isfile(srcpath
) and fn
.endswith('.h'):
81 ProcessStreams(open(srcpath
),
83 elif os
.path
.isdir(srcpath
):
84 ProcessDir(srcpath
, dstpath
)
91 print >>sys
.stderr
, ('Usage: ./export_header source/include/path'
95 ProcessDir(argv
[1], argv
[2]);
99 if __name__
== '__main__':
100 sys
.exit(main(sys
.argv
))