]> git.proxmox.com Git - ovs.git/blob - build-aux/soexpand.py
Require Python 3 and remove support for Python 2.
[ovs.git] / build-aux / soexpand.py
1 #! /usr/bin/env python3
2
3 # Copyright (c) 2008, 2017 Nicira, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 from build import soutil
18 import sys
19
20
21 def soexpand(include_dirs, src, dst):
22 ok = True
23 while True:
24 line = src.readline()
25 if not line:
26 break
27
28 name = soutil.extract_include_directive(line)
29 if name:
30 fn = soutil.find_file(include_dirs, name)
31 if fn:
32 try:
33 f = open(fn)
34 while True:
35 inner = f.readline()
36 if not inner:
37 break
38 dst.write(inner)
39 except IOError as e:
40 sys.stderr.write("%s: open: %s\n" % (fn, e.strerror))
41 ok = False
42 continue
43 else:
44 ok = False
45
46 dst.write(line)
47 return ok
48
49
50 if __name__ == '__main__':
51 include_dirs, args = soutil.parse_include_dirs()
52 if args:
53 error = False
54 for arg in args:
55 if not soexpand(include_dirs, open(arg), sys.stdout):
56 error = True
57 else:
58 error = not soexpand(include_dirs, sys.stdin, sys.stdout)
59 sys.exit(1 if error else 0)