Add Variables.defualted attribute
[scons.git] / test / CC / CC-fixture / mycc.py
blob0a0da59db5e4a5727103f3c2675a1df464630a30
1 # SPDX-License-Identifier: MIT
3 # Copyright The SCons Foundation
5 """
6 Phony cc command for testing SCons.
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.
12 Note: mycc.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 $CC, where arguments like -o come into play.
16 """
17 import getopt
18 import sys
20 def fake_win32_cc():
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:]
37 with open(inf, 'rb') as infile, open(out, 'wb') as outfile:
38 for line in infile:
39 if not line.startswith(b'/*cc*/'):
40 outfile.write(line)
42 def fake_cc():
43 opts, args = getopt.getopt(sys.argv[1:], 'co:')
44 for opt, arg in opts:
45 if opt == '-o':
46 out = arg
48 with open(args[0], 'rb') as infile, open(out, 'wb') as outfile:
49 for line in infile:
50 if not line.startswith(b'/*cc*/'):
51 outfile.write(line)
53 if __name__ == '__main__':
54 print(f"DEBUG: {sys.argv[0]}: {sys.argv[1:]}")
55 if sys.platform == 'win32':
56 fake_win32_cc()
57 else:
58 fake_cc()
59 sys.exit(0)