buildframework/helium/sf/python/pythoncore/lib/archive/builders.py
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424
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        : builders.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
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
This modules contains the archive builders.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
An archive builder is a class that is able to use data from a configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
and generate a set of shell commands.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import archive.tools
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import archive.selectors
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
import archive.mappers
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import archive.scanners
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
import pathaddition.relative
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
import buildtools
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
import codecs
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
import fileutils
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
_logger = logging.getLogger('archive')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
_logger.setLevel(logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
class ArchivePreBuilder(buildtools.PreBuilder):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
    """ Processes an archive build specification. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
    def __init__(self, config_set, config_name, writerType='ant', index = None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        buildtools.PreBuilder.__init__(self, config_set)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        self.configs = config_set.getConfigurations()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        self.spec_name = config_name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        self.index = index
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        self.writerType = writerType
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        self.listToFindPrefix = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    def build_manifest(self, config):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        """ Generate a manifest file from the a configuration. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        _logger.info('Processing archive config: ' + config['name'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        _scanners = archive.scanners.get_scanners(config.get_list('scanners', ['default']), config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        content_list = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        if not os.path.exists(config['temp.build.dir']):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
            os.makedirs(config['temp.build.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        manifest_file_path = os.path.abspath(os.path.join(config['temp.build.dir'], config['name'] + '_includefile.txt'))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        out = codecs.open(manifest_file_path, 'w+', 'utf-8')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
        # zip.root.dir can be set to root.dir so that when zipping from another dir,
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        # the manifest is relative to that dir
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        (_, root_dir) = os.path.splitdrive(os.path.normpath(config.get('zip.root.dir', config['root.dir'])))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        _logger.info("   * Scanning")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        for scanner in _scanners:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
            _logger.debug("Scanner %s" % scanner)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
            for subpath in scanner.scan():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
                (_, subpath) = os.path.splitdrive(subpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
                if pathaddition.relative.abs2rel(subpath, root_dir):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
                    _logger.debug(subpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
                    subpath = subpath[len(root_dir):]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
                    if subpath.startswith(os.sep):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
                        subpath = subpath[1:]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
                # normpath is to remove any occurances of "..\.." before checking for duplicates
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
                subpath = os.path.normpath(subpath)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
                if subpath not in content_list:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
                    out.write(u"".join([subpath, u'\n']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
                    content_list[subpath] = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
        out.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        return manifest_file_path
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
    def manifest_to_commands(self, config, manifest):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        """ Generate return a command list. Commands are stored in a two dimension array."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        _logger.info("   * Generating commands")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        tool = archive.tools.get_tool(config['archive.tool'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        mapper_name = 'default'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        if config.has_key('mapper'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
            mapper_name = config['mapper']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        mapper = archive.mappers.get_mapper(mapper_name, config, tool)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        return mapper.create_commands(manifest)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
    def create_command_list(self, commands):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        """ Convert a two dimensions array of command to a CommandList object. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        stages = buildtools.CommandList()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        newstage = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        for cmds_stage in commands:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
            _logger.debug("Stage: %s" % cmds_stage)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
            for cmd in cmds_stage:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
                stages.addCommand(cmd, newstage)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
                newstage = False
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
            newstage = True
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
        return stages
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    def writeTopLevel(self, build_file_path, output_path, xml_file):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        """Creates a build tool config makefile that executes archieve build."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        config_name_list = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
            config_name_list.append(config['name'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
            if not os.path.exists(config['archives.dir']):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
                os.makedirs(config['archives.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
        writer = buildtools.get_writer(self.writerType, build_file_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        writer.writeTopLevel(config_name_list, self.spec_name, output_path, xml_file)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        writer.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
    def getCommonUncRoots(self, uncPaths):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        """get common UNC roots"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        commonRoots = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        for p_path in uncPaths:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
            commonRoots["\\\\" + os.sep.join(p_path[2:].split(os.sep)[0:2]) + os.sep] = 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
        return commonRoots.keys()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
    def getPrefix(self, dir, commonUncRoots):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        """get prefix"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
        for root in commonUncRoots:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
            if dir.startswith(root):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
                return root
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
        raise Exception("Could not find root for %s." % dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
    def checkRootDirValue(self, builder, parse_xml_file, build_drive, config_type):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
        """Checks UNC path in root.dir and adds the substituted drive into EMAKEROOT."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
        substDrives = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
        if build_drive:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
            substDrives.append(build_drive + os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
        # Read all the config's root.dir to get UNC Path if any
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        # Of course this is only on windows platform
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
        if os.sep == '\\':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
            for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
                (drive, root_dir) = os.path.splitdrive(os.path.normpath(config['root.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
                _logger.debug("drive=%s, root_dir=%s" % (drive, root_dir))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
                if drive == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
                    self.listToFindPrefix.append(root_dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
            commonUncRoots = self.getCommonUncRoots(self.listToFindPrefix)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
            _logger.debug("Common roots %s" % (commonUncRoots))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
            driveMapping = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
            for root in commonUncRoots:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
                _logger.info("Substing %s" % (root))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
                driveMapping[root] = self.substUncPath(root)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
                _logger.debug("%s subst as %s" % (root, driveMapping[root]))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
                substDrives.append(driveMapping[root] + os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   154
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
            for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
                (drive, root_dir) = os.path.splitdrive(os.path.normpath(config['root.dir']) + os.sep) 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
                if drive == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
                    for root in driveMapping:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
                        if root_dir.startswith(root):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
                            config['root.dir'] = os.path.normpath(driveMapping[root] + os.sep + root_dir[len(root):len(root_dir)])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
                            _logger.info("Updated %s in %s" % (root_dir, config['root.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
                            config['unsubst.dir'] = driveMapping[root]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
                            break                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
                elif drive != build_drive:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
                    if config['root.dir'] not in substDrives:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
                        substDrives.append(config['root.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
            for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   169
                if config['root.dir'].startswith('\\\\'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
                    _logger.error("UNC path are not supported under this platform: %s" % (config['root.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
        builder.writeToXML(parse_xml_file, self.configs, config_type)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
        return os.path.pathsep.join(substDrives)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
       
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   174
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
    def substUncPath(self, path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   176
        """substitute UNC path"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   177
        freedrive = fileutils.get_next_free_drive()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   178
        fileutils.subst(freedrive, path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
        return freedrive
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
    def cleanupSubstDrives(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
        """ Read all the config's root.dir to get UNC Path if any"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
        drives = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
        for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
            _logger.debug("Checking configuration...")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
            _logger.debug("unsubst.dir: %s" % 'unsubst.dir' in config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
            _logger.debug("drives: %s" % drives)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
            if 'unsubst.dir' in config and not config['unsubst.dir'] in drives:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
                _logger.debug("Found drive to unsubst %s" % (config['unsubst.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
                self.unSubStituteDrives(config['unsubst.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
                drives[config['unsubst.dir']] = config['unsubst.dir']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
    def unSubStituteDrives(self, drive):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
        """un-substitute Drives"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
        _logger.info("Unsubsting %s" % (drive))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
        fileutils.unsubst(drive)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
    def write(self, outputname):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        """Creates a build tool configuration file that executes archive build operations.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
        The input to each archive build operation is an includefile that lists
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
        all the files to be included in the archive. These text files are
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
        generated before the build file by scanning the filesystem.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
        stages = buildtools.CommandList()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
        commands = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
        if self.index > len(self.configs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
            raise Exception("index not found in configuration")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        config = self.configs[self.index]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
        stages = self.manifest_to_commands(config, self.build_manifest(config))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
        # merging the commands            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
        while len(commands) < len(stages):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
            commands.append([])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
        for i in range(len(stages)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
            commands[i].extend(stages[i])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        writer = buildtools.get_writer(self.writerType, outputname)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        writer.write(self.create_command_list(commands))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
        writer.close()