buildframework/helium/sf/python/pythoncore/lib/sis.py
author lorewang
Wed, 01 Dec 2010 16:05:36 +0800
changeset 715 e0739b8406dd
parent 588 c7c26511138f
permissions -rw-r--r--
Specify extenal tool with path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : sis.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    19
""" SIS """
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import buildtools
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
class SisPreBuilder(buildtools.PreBuilder):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
    """ Generates a set of build commands for processing a SIS/X build
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
    configuration file. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
    def __init__(self, config_set, config_name=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
        """ Initialisation. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
        buildtools.PreBuilder.__init__(self, config_set)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
        self._config_name = config_name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    def write(self, buildFilePath):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
        """ Generate the build file that will run the actual commands. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
        sisConfigs = self.configSet.getConfigurations(self._config_name)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        commandList = buildtools.CommandList()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        for config in sisConfigs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
            if 'input' in config:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
                SisPreBuilder._write_v2(config, commandList)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
            else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
                SisPreBuilder._write_v1(config, commandList)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        self.writeBuildFile(commandList, buildFilePath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    @staticmethod
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    def _write_v1(config, commandList):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        """ v1 config that uses name and path properties. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        sis_filename = config['name'] + '.sis'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        if config.get('sis.name', None) != None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
            sis_filename = config['sis.name'] + '.sis'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        makeSisArgs = ['-v', config['name'] + '.pkg', sis_filename]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        makeSisCommand = buildtools.Command(config['makesis.tool'], config['path'], makeSisArgs)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        commandList.addCommand(makeSisCommand)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        if config.get_boolean('publish.unsigned', False):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
            srcFile = os.path.join(config['path'], sis_filename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
            todir = config['build.sisfiles.dir']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
            copyCommand = buildtools.Copy(srcFile, todir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
            commandList.addCommand(copyCommand, newstage=True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        sisx_filename = sis_filename + 'x'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        signSisArgs = ['-v', sis_filename, sisx_filename, config['cert'], config['key']]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        signSisCommand = buildtools.Command(config['signsis.tool'], config['path'], signSisArgs)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        commandList.addCommand(signSisCommand, newstage=True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        # Copy content to SIS files directory
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        srcFile = os.path.join(config['path'], sisx_filename)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
        todir = config['build.sisfiles.dir']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        copyCommand = buildtools.Copy(srcFile, todir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        commandList.addCommand(copyCommand, newstage=True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    @staticmethod
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    def _write_v2(config, commandList):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        """ v2 config that uses input and output properties. """ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        # Check for invalid old parameters
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        v1_properties = ['name', 'path', 'sis.name']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        for property_ in v1_properties:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
            if property_ in config:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
                raise Exception("Invalid property %s if using new 'input' SIS configuration" % property_)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        input_ = config['input']
588
c7c26511138f helium-10.0.0-bc45d50958fe
wbernard
parents: 587
diff changeset
    82
        (input_path, _) = os.path.split(input_)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        (input_root, input_ext) = os.path.splitext(input_)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        valid_extensions = ['.pkg', '.sis', '.sisx']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        if input_ext not in valid_extensions:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
            raise Exception('Invalid extension for SIS configuration.')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        # See if makesis needs to be run
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        if input_ext == '.pkg':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
            output = config.get('output', input_root + '.sis')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
            if output.endswith('.sisx'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
                output = output[:-1]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
            # Set input for the next stage
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
            makesis_args = ['-v', input_, output]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
            makesis_command = buildtools.Command(config['makesis.tool'], input_path, makesis_args)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
            commandList.addCommand(makesis_command)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
            input_ = output
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        # See if signsis needs to be run
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        if 'key' in config:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
            output = config.get('output', input_root + '.sisx')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
            signsis_args = ['-v', input_, output, config['cert'], config['key']]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
            signsis_command = buildtools.Command(config['signsis.tool'], input_path, signsis_args)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
            commandList.addCommand(signsis_command, newstage=True)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        # Copy content to SIS files directory
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        copyCommand = buildtools.Copy(output, config['build.sisfiles.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        commandList.addCommand(copyCommand, newstage=True)