]>
Commit | Line | Data |
---|---|---|
c719e02c A |
1 | #!/usr/bin/env python |
2 | # | |
40d841f6 | 3 | # Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> |
c719e02c | 4 | # |
40d841f6 | 5 | # This program and the accompanying materials |
c719e02c A |
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 | import sys | |
27 | import os | |
a709adfa LG |
28 | import subprocess |
29 | import pipes | |
c719e02c A |
30 | |
31 | # | |
32 | # Convert using cygpath command line tool | |
33 | # Currently not used, but just in case we need it in the future | |
34 | # | |
35 | def ConvertCygPathToDosViacygpath(CygPath): | |
a709adfa | 36 | p = subprocess.Popen("cygpath -m " + pipes.quote(CygPath), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
c719e02c A |
37 | return p.stdout.read().strip() |
38 | ||
39 | # | |
40 | # | |
41 | # | |
42 | def ConvertCygPathToDos(CygPath): | |
43 | if CygPath.find("/cygdrive/") == 0: | |
44 | # convert /cygdrive/c/Xyz to c:/Xyz | |
45 | DosPath = CygPath[10] + ':' + CygPath[11:] | |
46 | else: | |
47 | DosPath = CygPath | |
48 | ||
a709adfa LG |
49 | # pipes.quote will add the extra \\ for us. |
50 | return DosPath.replace('/','\\') | |
c719e02c A |
51 | |
52 | ||
a709adfa LG |
53 | # we receive our options as a list, but we will be passing them to the shell as a line |
54 | # this means we have to requote things as they will get one round of unquoting. | |
55 | # we can't set "shell=False" because we are running commands from the PATH and | |
56 | # if you don't use the shell you don't get a PATH search. | |
c719e02c A |
57 | def main(argv): |
58 | ||
59 | # use 1st argument as name of tool to call | |
a709adfa | 60 | Command = pipes.quote(sys.argv[1]); |
c719e02c A |
61 | |
62 | ExceptionList = ["/interwork"] | |
63 | ||
64 | for arg in argv: | |
65 | if arg.find('/') == -1: | |
66 | # if we don't need to convert just add to the command line | |
a709adfa | 67 | Command = Command + ' ' + pipes.quote(arg) |
c719e02c A |
68 | elif arg in ExceptionList: |
69 | # if it is in the list, then don't do a cygpath | |
70 | # assembler stuff after --apcs has the /. | |
a709adfa | 71 | Command = Command + ' ' + pipes.quote(arg) |
c719e02c A |
72 | else: |
73 | if ((arg[0] == '-') and (arg[1] == 'I' or arg[1] == 'i')): | |
74 | CygPath = arg[0] + arg[1] + ConvertCygPathToDos(arg[2:]) | |
75 | else: | |
76 | CygPath = ConvertCygPathToDos(arg) | |
a709adfa LG |
77 | |
78 | Command = Command + ' ' + pipes.quote(CygPath) | |
c719e02c A |
79 | |
80 | # call the real tool with the converted paths | |
81 | return subprocess.call(Command, shell=True) | |
82 | ||
83 | ||
84 | if __name__ == "__main__": | |
85 | try: | |
86 | ret = main(sys.argv[2:]) | |
87 | ||
88 | except: | |
89 | print "exiting: exception from " + sys.argv[0] | |
90 | ret = 2 | |
91 | ||
92 | sys.exit(ret) | |
93 |