Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / fixture / mygcc.py
blob146e596beb4e8b65ff07482e9455c62c032d6644
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():
23 compiler = sys.argv[1].encode('utf-8')
24 opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:')
25 for opt, arg in opts:
26 if opt == '-o':
27 out = arg
28 elif opt == '-x':
29 with open('mygcc.out', 'ab') as logfile:
30 logfile.write(compiler + b"\n")
32 with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp:
33 for line in ifp:
34 if not line.startswith(b'#' + compiler):
35 ofp.write(line)
37 if __name__ == '__main__':
38 fake_gcc()
39 sys.exit(0)