buildframework/helium/tools/common/python/lib/sis.py
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
--- a/buildframework/helium/tools/common/python/lib/sis.py	Wed Oct 28 14:39:48 2009 +0000
+++ b/buildframework/helium/tools/common/python/lib/sis.py	Wed Dec 23 19:29:07 2009 +0200
@@ -24,39 +24,90 @@
 
 
 class SisPreBuilder(buildtools.PreBuilder):
-    """"""
-    def __init__(self, config):
-        buildtools.PreBuilder.__init__(self, config)
+    """ Generates a set of build commands for processing a SIS/X build
+    configuration file. """
+    def __init__(self, config_set, config_name=None):
+        """ Initialisation. """
+        buildtools.PreBuilder.__init__(self, config_set)
+        self._config_name = config_name
 
     def write(self, buildFilePath):
-        sisConfigs = self.configSet.getConfigurations()
+        """ Generate the build file that will run the actual commands. """
+        sisConfigs = self.configSet.getConfigurations(self._config_name)
         commandList = buildtools.CommandList()
         for config in sisConfigs:
-            sis_filename = config['name'] + '.sis'
-            if config.get('sis.name', None) != None:
-                sis_filename = config['sis.name'] + '.sis'
-            makeSisArgs = ['-v', config['name'] + '.pkg', sis_filename]
-            makeSisCommand = buildtools.Command(config['makesis.tool'], config['path'], makeSisArgs)
-            commandList.addCommand(makeSisCommand)
-            
-            if config.get_boolean('publish.unsigned', False):
-                # This is hardcoded xcopy operation that should be replaced by a more generic
-                # definition of tasks that can be created in build files
-                srcFile = os.path.join(config['path'], sis_filename)
-                todir = config['build.sisfiles.dir']
-                copyCommand = buildtools.Copy(srcFile, todir)
-                commandList.addCommand(copyCommand, newstage=True)
-
-            sisx_filename = sis_filename + 'x'
-            signSisArgs = ['-v', sis_filename, sisx_filename, config['cert'], config['key']]
-            signSisCommand = buildtools.Command(config['signsis.tool'], config['path'], signSisArgs)
-            commandList.addCommand(signSisCommand, newstage=True)
-
-            # This is hardcoded xcopy operation that should be replaced by a more generic
-            # definition of tasks that can be created in build files
-            srcFile = os.path.join(config['path'], sisx_filename)
+            if 'input' in config:
+                SisPreBuilder._write_v2(config, commandList)
+            else:
+                SisPreBuilder._write_v1(config, commandList)
+                
+        self.writeBuildFile(commandList, buildFilePath)
+                
+    @staticmethod
+    def _write_v1(config, commandList):
+        """ v1 config that uses name and path properties. """
+        sis_filename = config['name'] + '.sis'
+        if config.get('sis.name', None) != None:
+            sis_filename = config['sis.name'] + '.sis'
+        makeSisArgs = ['-v', config['name'] + '.pkg', sis_filename]
+        makeSisCommand = buildtools.Command(config['makesis.tool'], config['path'], makeSisArgs)
+        commandList.addCommand(makeSisCommand)
+        
+        if config.get_boolean('publish.unsigned', False):
+            srcFile = os.path.join(config['path'], sis_filename)
             todir = config['build.sisfiles.dir']
             copyCommand = buildtools.Copy(srcFile, todir)
             commandList.addCommand(copyCommand, newstage=True)
 
-        self.writeBuildFile(commandList, buildFilePath)
+        sisx_filename = sis_filename + 'x'
+        signSisArgs = ['-v', sis_filename, sisx_filename, config['cert'], config['key']]
+        signSisCommand = buildtools.Command(config['signsis.tool'], config['path'], signSisArgs)
+        commandList.addCommand(signSisCommand, newstage=True)
+
+        # Copy content to SIS files directory
+        srcFile = os.path.join(config['path'], sisx_filename)
+        todir = config['build.sisfiles.dir']
+        copyCommand = buildtools.Copy(srcFile, todir)
+        commandList.addCommand(copyCommand, newstage=True)
+
+    @staticmethod
+    def _write_v2(config, commandList):
+        """ v2 config that uses input and output properties. """ 
+        # Check for invalid old parameters
+        v1_properties = ['name', 'path', 'sis.name']
+        for property_ in v1_properties:
+            if property_ in config:
+                raise Exception("Invalid property %s if using new 'input' SIS configuration" % property_)
+        
+        input_ = config['input']
+        (input_path, input_name) = os.path.split(input_)
+        (input_root, input_ext) = os.path.splitext(input_)
+        valid_extensions = ['.pkg', '.sis', '.sisx']
+        if input_ext not in valid_extensions:
+            raise Exception('Invalid extension for SIS configuration.')
+        
+        # See if makesis needs to be run
+        if input_ext == '.pkg':
+            output = config.get('output', input_root + '.sis')
+            if output.endswith('.sisx'):
+                output = output[:-1]
+            # Set input for the next stage
+            makesis_args = ['-v', input_, output]
+            makesis_command = buildtools.Command(config['makesis.tool'], input_path, makesis_args)
+            commandList.addCommand(makesis_command)
+            input_ = output
+            
+        # See if signsis needs to be run
+        if 'key' in config:
+            output = config.get('output', input_root + '.sisx')
+            signsis_args = ['-v', input_, output, config['cert'], config['key']]
+            signsis_command = buildtools.Command(config['signsis.tool'], input_path, signsis_args)
+            commandList.addCommand(signsis_command, newstage=True)
+            
+        # Copy content to SIS files directory
+        copyCommand = buildtools.Copy(output, config['build.sisfiles.dir'])
+        commandList.addCommand(copyCommand, newstage=True)
+        
+
+
+