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