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