buildframework/helium/sf/python/pythoncore/lib/archive/builders.py
author wbernard
Thu, 22 Jul 2010 17:08:43 +0300
branchhelium-9.0
changeset 618 df88fead2976
parent 587 85df38eb4012
child 628 7c4a911dc066
permissions -rw-r--r--
helium_9.0.5-4399343f4f50
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):
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   118
        """ Get common UNC roots.
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   119
            The following [r'\\server1\foo\bar', r'\\server2\foo', r'\\server1\foo'] input
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   120
            will return [r'\\server1\foo\', r'\\server2\foo'].
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   121
        """
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
        commonRoots = {}
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   123
        uncPaths = [os.path.normpath(p_path) for p_path in uncPaths]
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   124
        # sorting the input by alphabetical order, so smaller roots 
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   125
        # are coming first.
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   126
        uncPaths.sort()
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
        for p_path in uncPaths:
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   128
            common_path = "\\\\"
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   129
            for p_comp in p_path[2:].split(os.sep):
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   130
                common_path = common_path + p_comp + os.sep
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   131
                if common_path in commonRoots:
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   132
                    break
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   133
            else:
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   134
                commonRoots[common_path] = 1
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        return commonRoots.keys()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
    def getPrefix(self, dir, commonUncRoots):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
        """get prefix"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
        for root in commonUncRoots:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
            if dir.startswith(root):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
                return root
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
        raise Exception("Could not find root for %s." % dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
    def checkRootDirValue(self, builder, parse_xml_file, build_drive, config_type):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        """Checks UNC path in root.dir and adds the substituted drive into EMAKEROOT."""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        substDrives = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
        if build_drive:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
            substDrives.append(build_drive + os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
        # Read all the config's root.dir to get UNC Path if any
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151
        # Of course this is only on windows platform
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   152
        if os.sep == '\\':
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   153
            for config in self.configs:
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   154
                (drive, root_dir) = os.path.splitdrive(os.path.abspath(os.path.normpath(config['root.dir'])))
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   155
                _logger.debug("drive=%s, root_dir=%s" % (drive, root_dir))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   156
                if drive == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   157
                    self.listToFindPrefix.append(root_dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   158
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   159
            commonUncRoots = self.getCommonUncRoots(self.listToFindPrefix)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   160
            _logger.debug("Common roots %s" % (commonUncRoots))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   161
            driveMapping = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   162
            for root in commonUncRoots:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   163
                _logger.info("Substing %s" % (root))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   164
                driveMapping[root] = self.substUncPath(root)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   165
                _logger.debug("%s subst as %s" % (root, driveMapping[root]))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   166
                substDrives.append(driveMapping[root] + os.sep)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   167
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   168
            for config in self.configs:
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   169
                (drive, root_dir) = os.path.splitdrive(os.path.abspath(os.path.normpath(config['root.dir'])) + os.sep) 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   170
                if drive == "":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   171
                    for root in driveMapping:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   172
                        if root_dir.startswith(root):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   173
                            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
   174
                            _logger.info("Updated %s in %s" % (root_dir, config['root.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   175
                            config['unsubst.dir'] = driveMapping[root]
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   176
                            break
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   177
                    else:
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   178
                        _logger.error("Could not find root for %s." % root_dir)
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   179
                elif drive != build_drive:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   180
                    if config['root.dir'] not in substDrives:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   181
                        substDrives.append(config['root.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   182
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   183
            for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   184
                if config['root.dir'].startswith('\\\\'):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   185
                    _logger.error("UNC path are not supported under this platform: %s" % (config['root.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   186
        builder.writeToXML(parse_xml_file, self.configs, config_type)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   187
        return os.path.pathsep.join(substDrives)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   188
       
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   189
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   190
    def substUncPath(self, path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   191
        """substitute UNC path"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   192
        freedrive = fileutils.get_next_free_drive()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   193
        fileutils.subst(freedrive, path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   194
        return freedrive
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   195
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   196
    def cleanupSubstDrives(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   197
        """ Read all the config's root.dir to get UNC Path if any"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   198
        drives = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   199
        for config in self.configs:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   200
            _logger.debug("Checking configuration...")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   201
            _logger.debug("unsubst.dir: %s" % 'unsubst.dir' in config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   202
            _logger.debug("drives: %s" % drives)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   203
            if 'unsubst.dir' in config and not config['unsubst.dir'] in drives:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   204
                _logger.debug("Found drive to unsubst %s" % (config['unsubst.dir']))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   205
                self.unSubStituteDrives(config['unsubst.dir'])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   206
                drives[config['unsubst.dir']] = config['unsubst.dir']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   207
                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   208
    def unSubStituteDrives(self, drive):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   209
        """un-substitute Drives"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   210
        _logger.info("Unsubsting %s" % (drive))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   211
        fileutils.unsubst(drive)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   212
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   213
    def write(self, outputname):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   214
        """Creates a build tool configuration file that executes archive build operations.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   215
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   216
        The input to each archive build operation is an includefile that lists
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   217
        all the files to be included in the archive. These text files are
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   218
        generated before the build file by scanning the filesystem.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   219
        """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   220
        stages = buildtools.CommandList()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   221
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   222
        commands = []
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   223
        if self.index > len(self.configs):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   224
            raise Exception("index not found in configuration")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   225
        config = self.configs[self.index]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   226
        stages = self.manifest_to_commands(config, self.build_manifest(config))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   227
                
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   228
        # merging the commands            
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   229
        while len(commands) < len(stages):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   230
            commands.append([])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   231
        for i in range(len(stages)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   232
            commands[i].extend(stages[i])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   233
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   234
        writer = buildtools.get_writer(self.writerType, outputname)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   235
        writer.write(self.create_command_list(commands))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   236
        writer.close()