Add Variables.defualted attribute
[scons.git] / test / fixture / mygcc.py
blob0e65bac07b019e9b2defd7eec789bd7b7331907d
1 # SPDX-License-Identifier: MIT
3 # Copyright The SCons Foundation
5 """
6 Phony compiler 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.
11 The first argument is the language (cc, c__, g77, etc.).
13 Recognizes a -x option to append the language to 'mygcc.out'
14 for tracing purposes.
16 Intended for use as $CC, $CXX, etc.
17 """
19 import getopt
20 import sys
22 def fake_gcc():
24 # The gcc tool has this comment:
25 #> is executable, and is a GNU compiler (or accepts '--version' at least)
26 # So to pretend to be gcc, we need to recognize. Parrot what
27 # test/CC/CCVERSION-fixture/versioned.py does.
28 if '-dumpversion' in sys.argv:
29 print('3.9.9')
30 sys.exit(0)
31 if '--version' in sys.argv:
32 print('this is version 2.9.9 with extra text')
33 sys.exit(0)
35 compiler = sys.argv[1].encode('utf-8')
36 opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:')
37 for opt, arg in opts:
38 if opt == '-o':
39 out = arg
40 elif opt == '-x':
41 with open('mygcc.out', 'ab') as logfile:
42 logfile.write(compiler + b"\n")
44 with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp:
45 for line in ifp:
46 if not line.startswith(b'#' + compiler):
47 ofp.write(line)
49 if __name__ == '__main__':
50 fake_gcc()
51 sys.exit(0)