]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Bin/CYGWIN_NT-5.1-i686/armcc_wrapper.py
3035732d5c81587eedc11634f4d59b0ea8f88aa0
[mirror_edk2.git] / BaseTools / Bin / CYGWIN_NT-5.1-i686 / armcc_wrapper.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 #
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
6 #
7
8 #
9 # ARMCC tools do not support cygwin paths. Ths script converts cygwin paths to DOS paths
10 # in any arguments.
11 #
12 # armcc_wrapper.py ToolToExec [command line to convert]
13 #
14 # anything with the / will be converted via cygpath cygwin call or manually.
15 # -I/cygpath/c/example is a special case as you can not pass -I to cygpath
16 #
17 # ExceptionList if a tool takes an argument with a / add it to the exception list
18 #
19 from __future__ import print_function
20 import sys
21 import os
22 import subprocess
23 import pipes
24
25 #
26 # Convert using cygpath command line tool
27 # Currently not used, but just in case we need it in the future
28 #
29 def ConvertCygPathToDosViacygpath(CygPath):
30 p = subprocess.Popen("cygpath -m " + pipes.quote(CygPath), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
31 return p.stdout.read().strip()
32
33 #
34 #
35 #
36 def ConvertCygPathToDos(CygPath):
37 if CygPath.find("/cygdrive/") == 0:
38 # convert /cygdrive/c/Xyz to c:/Xyz
39 DosPath = CygPath[10] + ':' + CygPath[11:]
40 else:
41 DosPath = CygPath
42
43 # pipes.quote will add the extra \\ for us.
44 return DosPath.replace('/', '\\')
45
46
47 # we receive our options as a list, but we will be passing them to the shell as a line
48 # this means we have to requote things as they will get one round of unquoting.
49 # we can't set "shell=False" because we are running commands from the PATH and
50 # if you don't use the shell you don't get a PATH search.
51 def main(argv):
52
53 # use 1st argument as name of tool to call
54 Command = pipes.quote(sys.argv[1]);
55
56 ExceptionList = ["/interwork"]
57
58 for arg in argv:
59 if arg.find('/') == -1:
60 # if we don't need to convert just add to the command line
61 Command = Command + ' ' + pipes.quote(arg)
62 elif arg in ExceptionList:
63 # if it is in the list, then don't do a cygpath
64 # assembler stuff after --apcs has the /.
65 Command = Command + ' ' + pipes.quote(arg)
66 else:
67 if ((arg[0] == '-') and (arg[1] == 'I' or arg[1] == 'i')):
68 CygPath = arg[0] + arg[1] + ConvertCygPathToDos(arg[2:])
69 else:
70 CygPath = ConvertCygPathToDos(arg)
71
72 Command = Command + ' ' + pipes.quote(CygPath)
73
74 # call the real tool with the converted paths
75 return subprocess.call(Command, shell=True)
76
77
78 if __name__ == "__main__":
79 try:
80 ret = main(sys.argv[2:])
81
82 except:
83 print("exiting: exception from " + sys.argv[0])
84 ret = 2
85
86 sys.exit(ret)
87