fixmeta.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
  3. # All rights reserved.
  4. # This component and the accompanying materials are made available
  5. # under the terms of the License "Eclipse Public License v1.0"
  6. # which accompanies this distribution, and is available
  7. # at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. #
  9. # Initial Contributors:
  10. # Nokia Corporation - initial contribution.
  11. #
  12. # Contributors:
  13. #
  14. # Description:
  15. # fixmeta
  16. #
  17. """
  18. Correct bld.infs, mmps etc to the point where it can be read by the build system
  19. Currently it:
  20. Corrects '\' in include statements to '/'
  21. Author: Tim Murphy, with a nod to Peter Harper's fixslashes.pl
  22. """
  23. import sys
  24. import os
  25. import re
  26. from optparse import OptionParser
  27. includeslash_re = re.compile('#include.*\\\\')
  28. mmpfile_re = re.compile(".*\.mm[hp]$", re.I)
  29. bldinf_re = re.compile(".*bld\.inf$", re.I)
  30. def fixincludeslash(m):
  31. return m.group(0).replace('\\','/')
  32. def checkconvert(dirname, filename):
  33. tofilename=dirname + "/" + filename+".converted"
  34. fromfilename = dirname + "/" + filename
  35. fromfile = open(fromfilename,"r")
  36. conversions = False
  37. fromtext = fromfile.read()
  38. (totext, subcount) = re.subn(includeslash_re, fixincludeslash, fromtext)
  39. if subcount != 0:
  40. print '"%s", %d backslash includes\n' % (fromfilename, subcount)
  41. tofile = open( tofilename,"w")
  42. tofile.write(totext)
  43. tofile.close()
  44. fromfile.close()
  45. if subcount != 0:
  46. os.rename(fromfilename,fromfilename+".wrongslash")
  47. os.rename(tofilename,fromfilename)
  48. def visit(arg, dirname, names):
  49. #print "dir: %s\n" % (dirname)
  50. for f in names:
  51. m = mmpfile_re.match(f)
  52. b = bldinf_re.match(f)
  53. if m != None or b != None:
  54. #print "\t"+f
  55. checkconvert(dirname, f)
  56. parser = OptionParser(prog = "fixmeta",
  57. usage = "%prog [-h | options] sourcepath containing files to be fixed.")
  58. (options, args) = parser.parse_args()
  59. if len(args) == 0:
  60. print "Need at least one argument: a path to the source which is to be fixed."
  61. sys.exit(-1)
  62. print "Walking\n"
  63. os.path.walk(args[0],visit,None)