Debian Codegraph @

test/CXX/CXX-fixture/myc++.py

raw
1 # SPDX-License-Identifier: MIT
2 #
3 # Copyright The SCons Foundation
4
5 """
6 Phony c++ command for testing SCons.
7
8 Copies its source file to the target file, dropping lines that match
9 a pattern, so we can recognize the tool has made a modification.
10 Intended for use as the $CXX construction variable.
11
12 Note: mycxx.py differs from the general fixture file mycompile.py
13 in arg handling: that one is intended for use as a *COM consvar,
14 where no compiler consvars will be passed on, this one is intended
15 for use as $CXX, where arguments like -o come into play.
16 """
17 import getopt
18 import sys
19
20 def fake_win32_cxx():
21 args = sys.argv[1:]
22 inf = None
23 while args:
24 arg = args[0]
25 if arg == '-o':
26 out = args[1]
27 args = args[2:]
28 continue
29 args = args[1:]
30 if arg[0] not in '/-':
31 if not inf:
32 inf = arg
33 continue
34 if arg.startswith('/Fo'):
35 out = arg[3:]
36
37 with open(inf, 'rb') as infile, open(out, 'wb') as outfile:
38 for line in infile:
39 if not line.startswith(b'/*c++*/'):
40 outfile.write(line)
41
42 def fake_cxx():
43 opts, args = getopt.getopt(sys.argv[1:], 'co:')
44 for opt, arg in opts:
45 if opt == '-o':
46 out = arg
47
48 with open(args[0], 'rb') as infile, open(out, 'wb') as outfile:
49 for line in infile:
50 if not line.startswith(b'/*c++*/'):
51 outfile.write(line)
52
53 if __name__ == '__main__':
54 print(f"DEBUG: {sys.argv[0]}: {sys.argv[1:]}")
55 if sys.platform == 'win32':
56 fake_win32_cxx()
57 else:
58 fake_cxx()
59 sys.exit(0)