3
|
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 |
"""
|
|
19 |
Correct bld.infs, mmps etc to the point where it can be read by the build system
|
|
20 |
Currently it:
|
|
21 |
Corrects '\' in include statements to '/'
|
|
22 |
|
|
23 |
Author: Tim Murphy, with a nod to Peter Harper's fixslashes.pl
|
|
24 |
"""
|
|
25 |
|
|
26 |
import sys
|
|
27 |
import os
|
|
28 |
import re
|
|
29 |
from optparse import OptionParser
|
|
30 |
|
|
31 |
|
|
32 |
includeslash_re = re.compile('#include.*\\\\')
|
|
33 |
mmpfile_re = re.compile(".*\.mm[hp]$", re.I)
|
|
34 |
bldinf_re = re.compile(".*bld\.inf$", re.I)
|
|
35 |
|
|
36 |
def fixincludeslash(m):
|
|
37 |
return m.group(0).replace('\\','/')
|
|
38 |
|
|
39 |
|
|
40 |
def checkconvert(dirname, filename):
|
|
41 |
tofilename=dirname + "/" + filename+".converted"
|
|
42 |
fromfilename = dirname + "/" + filename
|
|
43 |
fromfile = open(fromfilename,"r")
|
|
44 |
|
|
45 |
conversions = False
|
|
46 |
fromtext = fromfile.read()
|
|
47 |
(totext, subcount) = re.subn(includeslash_re, fixincludeslash, fromtext)
|
|
48 |
|
|
49 |
if subcount != 0:
|
|
50 |
print '"%s", %d backslash includes\n' % (fromfilename, subcount)
|
|
51 |
tofile = open( tofilename,"w")
|
|
52 |
tofile.write(totext)
|
|
53 |
tofile.close()
|
|
54 |
|
|
55 |
fromfile.close()
|
|
56 |
if subcount != 0:
|
|
57 |
os.rename(fromfilename,fromfilename+".wrongslash")
|
|
58 |
os.rename(tofilename,fromfilename)
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
def visit(arg, dirname, names):
|
|
63 |
#print "dir: %s\n" % (dirname)
|
|
64 |
for f in names:
|
|
65 |
m = mmpfile_re.match(f)
|
|
66 |
b = bldinf_re.match(f)
|
|
67 |
if m != None or b != None:
|
|
68 |
#print "\t"+f
|
|
69 |
checkconvert(dirname, f)
|
|
70 |
|
|
71 |
parser = OptionParser(prog = "fixmeta",
|
|
72 |
usage = "%prog [-h | options] sourcepath containing files to be fixed.")
|
|
73 |
|
|
74 |
(options, args) = parser.parse_args()
|
|
75 |
|
|
76 |
if len(args) == 0:
|
|
77 |
print "Need at least one argument: a path to the source which is to be fixed."
|
|
78 |
sys.exit(-1)
|
|
79 |
|
|
80 |
print "Walking\n"
|
|
81 |
os.path.walk(args[0],visit,None)
|