build/buildutils/fixmmp.py
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 #
       
     2 # Copyright (c) 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 "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 #
       
    16 
       
    17 import sys, os, re
       
    18 import traceback
       
    19 from optparse import OptionParser
       
    20 
       
    21 TMP_RE = re.compile(r"^SYSTEMINCLUDE\s+(.+[\\/])?tmp$\n", re.MULTILINE)
       
    22 DRIVE_RE = re.compile("(SYSTEMINCLUDE\s+|SOURCEPATH\s+)[a-zA-Z]:")
       
    23 RESOURCE_RE = re.compile(r"\nSTART RESOURCE.*?\nEND\n", re.DOTALL)
       
    24 TIME_RE = re.compile(r"(// Generated by qmake .*? on): .*")
       
    25 
       
    26 def main():
       
    27     parser = OptionParser(
       
    28         usage = "Usage: %prog [args] <input mmp> <output mmp>")
       
    29 
       
    30     parser.add_option(
       
    31         "--driveletter", dest = "driveletter", action = "store_true", default = False)
       
    32     parser.add_option(
       
    33         "--tmp-dirs", dest = "tmpDirs", action = "store_true", default = False)
       
    34     parser.add_option(
       
    35         "--resource", dest = "resource", action = "store_true", default = False)
       
    36     parser.add_option(
       
    37         "--datetime", dest = "datetime", action = "store_true", default = False)
       
    38     parser.add_option(
       
    39         "--mocpath", dest = "mocpath", action = "store_true", default = False)
       
    40     parser.add_option(
       
    41         "--header", dest = "header")
       
    42 
       
    43     (opts, args) = parser.parse_args()
       
    44 
       
    45     try:
       
    46         inputFile = args[0]
       
    47         outputFile = args[1]
       
    48         
       
    49         # Read mmp file
       
    50         fin = open(inputFile)
       
    51         mmp = fin.read()
       
    52         fin.close()
       
    53 
       
    54         # Remove /tmp directories from system includes
       
    55         if opts.tmpDirs:
       
    56             mmp = TMP_RE.sub("", mmp)
       
    57 
       
    58         # Remove driveletter from systeminclude and sourcepath
       
    59         if opts.driveletter:
       
    60             mmp = DRIVE_RE.sub("\\1", mmp)
       
    61 
       
    62         # Remove resource block
       
    63         if opts.resource:
       
    64             mmp = RESOURCE_RE.sub("", mmp)
       
    65 
       
    66         # Remove changing time
       
    67         if opts.datetime:
       
    68             mmp = TIME_RE.sub("\\1: (date)", mmp)
       
    69 
       
    70         # Fix MOC path (in bld.inf)
       
    71         if opts.mocpath:
       
    72             mmp = mmp.replace(r"/epoc32/tools/qt/moc.exe", 
       
    73                               r"$(EPOCROOT)epoc32/tools/qt/moc.exe")
       
    74 
       
    75         # Add header
       
    76         if opts.header:
       
    77             headerText = open(opts.header).read()
       
    78             mmp = headerText + mmp
       
    79 
       
    80         # Write mmp file
       
    81         open(outputFile, "w").write(mmp)
       
    82         
       
    83     except:
       
    84         print "Usage: %s inputFile outputFile" % sys.argv[0]
       
    85         traceback.print_exc()
       
    86         sys.exit(1)
       
    87 
       
    88         
       
    89 if __name__ == "__main__":
       
    90     main()