armcc_wrapper.py 2.6 KB

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