[ci skip] update generated files
[scons.git] / test / fixture / mylink.py
blobabe22aec615767a0dc330c97561041741680fdd3
1 # SPDX-License-Identifier: MIT
3 # Copyright The SCons Foundation
5 """
6 Phony linker for testing SCons.
8 Copies its source files 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 $LINK construction variable.
11 """
12 import fileinput
13 import getopt
14 import sys
16 def fake_link():
17 opts, args = getopt.getopt(sys.argv[1:], 'o:s:')
18 for opt, arg in opts:
19 if opt == '-o':
20 out = arg
22 with open(out, 'wb') as ofp, fileinput.input(files=args, mode='rb') as ifp:
23 for line in ifp:
24 if not line.startswith(b'#link'):
25 ofp.write(line)
27 def fake_win32_link():
28 args = sys.argv[1:]
29 while args:
30 arg = args[0]
31 if arg == '-o':
32 out = args[1]
33 args = args[2:]
34 continue
35 if arg[0] not in '/-':
36 break
37 args = args[1:]
38 if arg.lower().startswith('/out:'):
39 out = arg[5:]
40 with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp:
41 for line in ifp:
42 if not line.startswith(b'#link'):
43 ofp.write(line)
45 if __name__ == '__main__':
46 if sys.platform == 'win32':
47 fake_win32_link()
48 else:
49 fake_link()
50 sys.exit(0)