build/buildutils/generateOdcFile.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 #! /usr/bin/python
       
    17 
       
    18 import sys
       
    19 import traceback
       
    20 import os
       
    21 
       
    22 
       
    23 
       
    24 def main():
       
    25     tmpExtension = ".cpp"
       
    26     try:
       
    27         odcFileName  = sys.argv[1]
       
    28         javaPeerDll  = sys.argv[2]
       
    29         classesDir   = sys.argv[3]
       
    30         sysPropsFile = sys.argv[4]
       
    31 
       
    32         genOdcFile(odcFileName, 
       
    33                    javaPeerDll,
       
    34                    getClasses(classesDir),
       
    35                    getProperties(sysPropsFile))
       
    36 
       
    37     except:
       
    38         print "Error during ODC generation!"
       
    39         traceback.print_exc()
       
    40         sys.exit(-1)
       
    41 
       
    42 def getProperties(sysPropsFile):
       
    43 
       
    44     contents = []
       
    45     try:
       
    46         f = open(sysPropsFile, 'r')
       
    47         contents = f.readlines()
       
    48         f.close()
       
    49     except IOError:
       
    50         pass                           
       
    51     return contents
       
    52 
       
    53 
       
    54 def getClasses(classesDir):
       
    55     startDir = os.path.abspath(classesDir)
       
    56 
       
    57     files = []
       
    58     suffix = ".class"
       
    59 
       
    60     def callBack(arg, dirname, files):
       
    61         # Remove startDir-part from dirname
       
    62         dirname = dirname[len(startDir) + 1:]
       
    63         for file in files:
       
    64             if file.endswith(suffix):
       
    65                 # replace '\' with '/' and strip the class name.
       
    66                 res = os.path.join(dirname, file).replace("\\","/").rsplit("/",1)[0]
       
    67                 arg.append(res)
       
    68             
       
    69     os.path.walk(startDir, callBack, files)
       
    70     
       
    71     return files
       
    72 
       
    73 def genOdcFile( odcFileName,
       
    74                 javaPeerDll, 
       
    75                 classes, 
       
    76                 properties = []):
       
    77 
       
    78     # If a list of classes was given instead of packages, strip class names and
       
    79     # remove duplicates
       
    80     classes = list(set([c for c in classes]))
       
    81 
       
    82     lines = [    
       
    83         "[container]",
       
    84         "name=" + javaPeerDll,
       
    85         "type=JXESL",
       
    86         "",
       
    87         "[packages]"]
       
    88     lines.extend([p.replace(".", "/") for p in sorted(classes)])    
       
    89     lines.append("")
       
    90     lines.append("[properties]")
       
    91     
       
    92     # Append system properties, but only if there are classes
       
    93     # (classes may be missing if component sources has been excluded
       
    94     # from release, which means that properties should not be written
       
    95     # either)
       
    96     if classes:
       
    97         for property in properties:
       
    98             property = property.strip()
       
    99             if not property:
       
   100                 continue
       
   101             lines.append("-D" + property)
       
   102     lines.append("")
       
   103 
       
   104     f = open(odcFileName, 'w')
       
   105     f.write("\n".join(lines))
       
   106     f.close()
       
   107 
       
   108         
       
   109 if __name__ == "__main__":
       
   110     main()