armcc_wrapper.py 2.9 KB

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