]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Bin/CYGWIN_NT-5.1-i686/armcc_wrapper.py
b26b4e5b511224981cb96272ca45d6beb974f52c
[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 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 #
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 #
16 # ARMCC tools do not support cygwin paths. Ths script converts cygwin paths to DOS paths
17 # in any arguments.
18 #
19 # armcc_wrapper.py ToolToExec [command line to convert]
20 #
21 # anthing with the / will be converted via cygpath cygwin call or manually.
22 # -I/cygpath/c/example is a special case as you can not pass -I to cygpath
23 #
24 # ExceptionList if a tool takes an argument with a / add it to the exception list
25 #
26 from __future__ import print_function
27 import sys
28 import os
29 import subprocess
30 import pipes
31
32 #
33 # Convert using cygpath command line tool
34 # Currently not used, but just in case we need it in the future
35 #
36 def ConvertCygPathToDosViacygpath(CygPath):
37 p = subprocess.Popen("cygpath -m " + pipes.quote(CygPath), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
38 return p.stdout.read().strip()
39
40 #
41 #
42 #
43 def ConvertCygPathToDos(CygPath):
44 if CygPath.find("/cygdrive/") == 0:
45 # convert /cygdrive/c/Xyz to c:/Xyz
46 DosPath = CygPath[10] + ':' + CygPath[11:]
47 else:
48 DosPath = CygPath
49
50 # pipes.quote will add the extra \\ for us.
51 return DosPath.replace('/', '\\')
52
53
54 # we receive our options as a list, but we will be passing them to the shell as a line
55 # this means we have to requote things as they will get one round of unquoting.
56 # we can't set "shell=False" because we are running commands from the PATH and
57 # if you don't use the shell you don't get a PATH search.
58 def main(argv):
59
60 # use 1st argument as name of tool to call
61 Command = pipes.quote(sys.argv[1]);
62
63 ExceptionList = ["/interwork"]
64
65 for arg in argv:
66 if arg.find('/') == -1:
67 # if we don't need to convert just add to the command line
68 Command = Command + ' ' + pipes.quote(arg)
69 elif arg in ExceptionList:
70 # if it is in the list, then don't do a cygpath
71 # assembler stuff after --apcs has the /.
72 Command = Command + ' ' + pipes.quote(arg)
73 else:
74 if ((arg[0] == '-') and (arg[1] == 'I' or arg[1] == 'i')):
75 CygPath = arg[0] + arg[1] + ConvertCygPathToDos(arg[2:])
76 else:
77 CygPath = ConvertCygPathToDos(arg)
78
79 Command = Command + ' ' + pipes.quote(CygPath)
80
81 # call the real tool with the converted paths
82 return subprocess.call(Command, shell=True)
83
84
85 if __name__ == "__main__":
86 try:
87 ret = main(sys.argv[2:])
88
89 except:
90 print("exiting: exception from " + sys.argv[0])
91 ret = 2
92
93 sys.exit(ret)
94