os/mm/mmtestenv/mmtesttools/Build/buildutils/mmbuild2.py
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmtestenv/mmtesttools/Build/buildutils/mmbuild2.py	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,295 @@
     1.4 +
     1.5 +# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +# All rights reserved.
     1.7 +# This component and the accompanying materials are made available
     1.8 +# under the terms of "Eclipse Public License v1.0"
     1.9 +# which accompanies this distribution, and is available
    1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +#
    1.12 +# Initial Contributors:
    1.13 +# Nokia Corporation - initial contribution.
    1.14 +#
    1.15 +# Contributors:
    1.16 +#
    1.17 +# Description:
    1.18 +# mmbuild2 - python script intended to replace mmbuild.pl
    1.19 +#
    1.20 +
    1.21 +from optparse import (make_option,OptionParser)
    1.22 +import sys
    1.23 +import os
    1.24 +import subprocess
    1.25 +import MbcUtils
    1.26 +
    1.27 +# some literals. TODO - use explicit type?
    1.28 +_KAll = "all"
    1.29 +_KMmf = "mmf"
    1.30 +_KMisc = "misc"
    1.31 +_KIcl = "icl"
    1.32 +
    1.33 +_KMainTempConfig = ".config.xml"
    1.34 +_KTestTempConfig = ".testconfig.xml"
    1.35 +_KTestBuildTempConfig = ".testbuildconfig.xml"
    1.36 +
    1.37 +class Unimplemented(Exception):
    1.38 +    """Raised for invalid commands"""
    1.39 +
    1.40 +    def __init__(self, msg):
    1.41 +        self.__msg = msg
    1.42 +
    1.43 +    def __str__(self):
    1.44 +        return self.__msg
    1.45 +
    1.46 +class Script(object):
    1.47 +
    1.48 +
    1.49 +    # TODO this option_list should be replaced by add_option calls to parameter
    1.50 +    # option_list parameter to OptionParser is down as deprecated
    1.51 +    option_table = [
    1.52 +        make_option ("-t", "--test",
    1.53 +                     action="store_true", dest="buildTest", default=False,
    1.54 +                     help="""build test code rather than main code (without -b, that built by "abld build" or equiv)"""),
    1.55 +        make_option ("-b", "--testBuild",
    1.56 +                     action="store_true", dest="buildTestBuild", default=False,
    1.57 +                     help="""when given with -t, build that code that requires "abld test build" """),
    1.58 +         make_option ("-x", "--additional", "--opt", "--extra",
    1.59 +                     action="store_true", dest="extra", default=False,
    1.60 +                     help="build additional modules (from Xopt.mbc files)"),
    1.61 +        make_option ("-i", "--icl",
    1.62 +                     action="store_const", const=_KIcl, dest="toBuild", default=_KAll,
    1.63 +                     help="build icl modules only"),
    1.64 +        make_option ("-m", "--mmf",
    1.65 +                     action="store_const", const=_KMmf, dest="toBuild", default=_KAll,
    1.66 +                     help="build mmf modules only"),
    1.67 +        make_option ("-c", "--misc",
    1.68 +                     action="store_const", const=_KMisc, dest="toBuild", default=_KAll,
    1.69 +                     help="build misc modules only"),
    1.70 +        make_option ("-f", "--full", "--all",
    1.71 +                     action="store_const", const=_KAll, dest="toBuild", default=_KAll,
    1.72 +                     help="build all modules (which depends on if -x is given too)"),
    1.73 +        make_option ("-k", "--keepgoing",
    1.74 +                     action="store_true", dest="keepgoing", default=False,
    1.75 +                     help="keep going if errors are found"),
    1.76 +        make_option ("-g", "--gccxml",
    1.77 +                     action="store_true", dest="gccxml", default=False,
    1.78 +                     help="build for gccxml"),
    1.79 +        make_option ("-s", "--skipmake",
    1.80 +                     action="store_true", dest="skipmake", default=False,
    1.81 +                     help="skip building makefile (ignored)"),
    1.82 +        make_option ("--iclTestdata",
    1.83 +                     action="store_true", dest="icl_tests", default=False,
    1.84 +                     help="build ICL Tests"),
    1.85 +        ]
    1.86 +
    1.87 +    description = \
    1.88 +"""Script for selection appropriate set of multimedia
    1.89 +components and build them together, so build order does not matter.
    1.90 +One, and only one of "setup", "build" or "clean" must be given.
    1.91 +"""
    1.92 +
    1.93 +    def __init__(self):
    1.94 +        # need to implement commands as property and not class constant or
    1.95 +        # we get a forward declaration problem
    1.96 +        self.iCommands = {"setup": self.doSetup, "build": self.doBuild, "clean": self.doClean}
    1.97 +        self.iOptions = None
    1.98 +        self.iProdCodeList = []
    1.99 +        self.iTestCodeList = []
   1.100 +        self.iTestBuildCodeList = []
   1.101 +        self.iOptionParser = None
   1.102 +        self.iDebug = False
   1.103 +
   1.104 +    def main(self):
   1.105 +        "main function of script"
   1.106 +        self.iOptionParser = OptionParser(
   1.107 +            option_list = Script.option_table,
   1.108 +            usage="%prog [-t [-b]] [-i|-m|-c|-f] (setup|build [winscw]|clean)",
   1.109 +            description = Script.description
   1.110 +            )
   1.111 +        (self.iOptions, args) = self.iOptionParser.parse_args()
   1.112 +
   1.113 +        self.DebugPrint (str(self.iOptions))
   1.114 +        self.DebugPrint (str(args))
   1.115 +
   1.116 +        if (len(args)==0 or not args[0] in self.iCommands or
   1.117 +                not self.CheckOptions()):
   1.118 +            self.iOptionParser.print_usage()
   1.119 +            return -1
   1.120 +
   1.121 +        remainingArgs = args[1:len(args)]
   1.122 +
   1.123 +        return self.iCommands[args[0]](remainingArgs) # effective switch to doBuild, doSetup or doClean
   1.124 +
   1.125 +    def CheckOptions(self):
   1.126 +        "Check for any invalid option combinations. Warn about ignored ones etc"
   1.127 +        if self.iOptions.skipmake:
   1.128 +            print ("Warning ignoring -s - option is no longer valid in raptor version")
   1.129 +        if not self.iOptions.buildTest and self.iOptions.buildTestBuild:
   1.130 +            return False # can't do -b without -t
   1.131 +        return True # all other combinations OK
   1.132 +
   1.133 +    def doBuild(self, remainingArgs):
   1.134 +        # if we have a remainingArg, only "winscw" is allowed
   1.135 +        if not (len(remainingArgs)==0 or len(remainingArgs)==1 and remainingArgs[0]=="winscw"):
   1.136 +            self.iOptionParser.print_usage()
   1.137 +            return -1
   1.138 +
   1.139 +        # for normal build need to run "sbs -s .config.xml build"
   1.140 +        # for test build need to run "sbs -s .testconfig.xml build"
   1.141 +        # use --logfile=- to send output to stdout instead of log file
   1.142 +        configFile = _KMainTempConfig
   1.143 +        testBuild = False
   1.144 +        if self.iOptions.buildTest:
   1.145 +            if not self.iOptions.buildTestBuild:
   1.146 +                # build test config instead when -t etc given
   1.147 +                configFile = _KTestTempConfig
   1.148 +            else:
   1.149 +                # build test config instead when -t -b etc given
   1.150 +                configFile = _KTestBuildTempConfig
   1.151 +                testBuild = True
   1.152 +        sbs_command = self.sbsCommand()
   1.153 +        commands = [sbs_command, "-s", configFile]
   1.154 +        commands += ["--logfile=-"] # send output to stdout
   1.155 +        if self.iOptions.keepgoing:
   1.156 +            commands += ["--keepgoing"]
   1.157 +        if testBuild:
   1.158 +            commands += ["--config=winscw.test"]
   1.159 +        else:
   1.160 +            commands += ["--config=winscw"]
   1.161 +        if not(len(remainingArgs)>0 and remainingArgs[0]=="winscw"):
   1.162 +            # not the winscw scenario - we want both winscw and armv5
   1.163 +            if testBuild:
   1.164 +                commands += ["--config=armv5.test"]
   1.165 +            else:
   1.166 +                commands += ["--config=armv5"]
   1.167 +        commands += ["--filters=FilterSquashLog"] # reduce log size
   1.168 +        commands += ["--tries=2"] # retry on failure - e.g. for license fails
   1.169 +        commands += ["build"]
   1.170 +        self.DebugPrint("""command="%s" """ % str(commands))
   1.171 +        print "------------------ sbs start : %s" % str(commands)
   1.172 +        sys.stdout.flush() # flush any output here so appears correct in log
   1.173 +        subprocess.check_call(commands) # raises exception on error
   1.174 +        print "------------------ sbs end"
   1.175 +        return 0
   1.176 +
   1.177 +    def sbsCommand(self):
   1.178 +        "sbs command - that can be used by subprocess"
   1.179 +        # For some reason, have to work out batch file to run by longhand
   1.180 +        # rather than just saying "sbs" and letting command work it out.
   1.181 +        # Could use sys.command() instead, but that is deprecated
   1.182 +        sbs_home = os.getenv("SBS_HOME")
   1.183 +        assert sbs_home, "SBS_HOME must be defined to use this script"
   1.184 +        sbs_command = os.path.join(sbs_home, "bin", "sbs.bat")
   1.185 +        return sbs_command
   1.186 +
   1.187 +    def doSetup(self, remainingArgs):
   1.188 +        if len(remainingArgs)!=0:
   1.189 +            self.iOptionParser.print_usage()
   1.190 +            return -1
   1.191 +
   1.192 +        self.buildMbcLists()
   1.193 +
   1.194 +        self.DebugPrint ("prodCodeList=%s" % str(self.iProdCodeList))
   1.195 +        self.DebugPrint ("testCodeList=%s" % str(self.iTestCodeList))
   1.196 +        self.DebugPrint ("testBuildCodeList=%s" % str(self.iTestBuildCodeList))
   1.197 +
   1.198 +        mbcParser = MbcUtils.MbcParser(self.iProdCodeList)
   1.199 +        folders = mbcParser()
   1.200 +        self.DebugPrint ("folders=%s" % str (folders))
   1.201 +        getFolderList = MbcUtils.GetFolderList(folders)
   1.202 +        groupFolders = getFolderList()
   1.203 +        self.DebugPrint ("prodCodeFolderList=%s" % str(groupFolders))
   1.204 +
   1.205 +        generator = MbcUtils.ConfigFileGenerator(groupFolders, _KMainTempConfig)
   1.206 +        generator.write()
   1.207 +
   1.208 +        mbcParser = MbcUtils.MbcParser(self.iTestCodeList)
   1.209 +        folders = mbcParser()
   1.210 +        self.DebugPrint ("testfolders=%s" % str (folders))
   1.211 +        getFolderList = MbcUtils.GetFolderList(folders)
   1.212 +        groupFolders = getFolderList()
   1.213 +        self.DebugPrint ("testCodeFolderList=%s" % str(groupFolders))
   1.214 +
   1.215 +        generator = MbcUtils.ConfigFileGenerator(groupFolders, _KTestTempConfig)
   1.216 +        generator.write()
   1.217 +
   1.218 +        mbcParser = MbcUtils.MbcParser(self.iTestBuildCodeList)
   1.219 +        folders = mbcParser()
   1.220 +        self.DebugPrint ("testBuildfolders=%s" % str (folders))
   1.221 +        getFolderList = MbcUtils.GetFolderList(folders)
   1.222 +        groupFolders = getFolderList()
   1.223 +        self.DebugPrint ("testBuildCodeFolderList=%s" % str(groupFolders))
   1.224 +
   1.225 +        generator = MbcUtils.ConfigFileGenerator(groupFolders, _KTestBuildTempConfig)
   1.226 +        generator.write()
   1.227 +        return 0
   1.228 +
   1.229 +    def buildMbcLists(self):
   1.230 +        # some boolean values
   1.231 +        want_mmf = self.iOptions.toBuild in [_KAll, _KMmf];
   1.232 +        want_icl = self.iOptions.toBuild in [_KAll, _KIcl];
   1.233 +        want_misc = self.iOptions.toBuild in [_KAll, _KMisc];
   1.234 +        want_extra = self.iOptions.extra
   1.235 +        want_icl_tests = self.iOptions.icl_tests
   1.236 +
   1.237 +        # now build up the lists depending on which "component" we want
   1.238 +        # perhaps this should be reworked as a table, but not obvious as to how
   1.239 +        self.iTestCodeList += ["AllTests.mbc", "TestFrameworkTest.mbc",
   1.240 +                               "targettools.mbc"]
   1.241 +        if want_mmf:
   1.242 +            self.iProdCodeList += ["mmf.mbc"]
   1.243 +            self.iTestCodeList += ["mmfTest.mbc"]
   1.244 +            self.iTestBuildCodeList += ["mmfTestBuild.mbc"]
   1.245 +            # assume mmfPhys and mmfOptPhys can currently be ignored
   1.246 +            # they should generate another list and be built as special cases
   1.247 +            # self.iProdCodeList += ["mmfPhys.mbc"]
   1.248 +            if want_extra:
   1.249 +                self.iProdCodeList += ["mmfOpt.mbc"]
   1.250 +                self.iTestCodeList += ["mmfOptTest.mbc"]
   1.251 +                self.iTestBuildCodeList += ["mmfOptTestBuild.mbc"]
   1.252 +                # self.iProdCodeList += ["mmfOptPhys.mbc"]
   1.253 +            else:
   1.254 +                self.iTestCodeList += ["mmfNotOptTest.mbc"]
   1.255 +        if want_icl:
   1.256 +            self.iProdCodeList += ["icl.mbc"]
   1.257 +            if want_icl_tests:
   1.258 +            	self.iTestCodeList += ["iclTest.mbc"]
   1.259 +            	self.iTestBuildCodeList += ["iclTestBuild.mbc"]
   1.260 +            	if want_extra:
   1.261 +            		self.iTestCodeList += ["iclOptTest.mbc"]
   1.262 +            		self.iTestBuildCodeList += ["iclOptTestBuild.mbc"]
   1.263 +            if want_extra:
   1.264 +                self.iProdCodeList += ["iclOpt.mbc"]   
   1.265 +        if want_misc:
   1.266 +            self.iProdCodeList += ["misc.mbc"]
   1.267 +            self.iTestCodeList += ["miscTest.mbc"]
   1.268 +            self.iTestBuildCodeList += ["miscTestBuild.mbc"]
   1.269 +            if want_extra:
   1.270 +                self.iProdCodeList += ["miscOpt.mbc"]
   1.271 +                self.iTestCodeList += ["miscOptTest.mbc"]
   1.272 +                self.iTestBuildCodeList += ["miscOptTestBuild.mbc"]
   1.273 +
   1.274 +    def doClean(self, remainingArgs):
   1.275 +        "clean is called. Note -t clean means clean test code too, not instead"
   1.276 +        # for normal clean need to run "sbs -s .config.xml clean"
   1.277 +        # for test clean need to run "sbs -s .testconfig.xml clean"
   1.278 +        # use --logfile=- to send output to stdout instead of log file
   1.279 +        whatToClean = [_KMainTempConfig]
   1.280 +        if self.iOptions.buildTest:
   1.281 +            whatToClean += [_KTestTempConfig]
   1.282 +        for configFile in whatToClean:
   1.283 +            sbs_command = self.sbsCommand()
   1.284 +            commands = [sbs_command, "-s", configFile]
   1.285 +            commands += ["--logfile=-"] # send output to stdout
   1.286 +            commands += ["reallyclean"]
   1.287 +            self.DebugPrint ("""command="%s" """ % str(commands))
   1.288 +            subprocess.check_call(commands) # raises exception on error
   1.289 +        return 0
   1.290 +
   1.291 +    def DebugPrint(self, str):
   1.292 +        "print a string if self.iDebug is set - would be turned on manually"
   1.293 +        if self.iDebug:
   1.294 +            print(str)
   1.295 +
   1.296 +if __name__ == "__main__":
   1.297 +    script = Script()
   1.298 +    sys.exit(script.main())