source: rtems-libbsd/builder.py @ 95a12a2

5-freebsd-12freebsd-9.3
Last change on this file since 95a12a2 was 95a12a2, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 7, 2016 at 7:01:02 AM

Fix FreeBSD source file reverse conversion

  • Property mode set to 100755
File size: 24.6 KB
RevLine 
[314be23]1#
[97c5024a]2#  Copyright (c) 2015-2016 Chris Johns <chrisj@rtems.org>. All rights reserved.
[314be23]3#
4#  Copyright (c) 2009-2015 embedded brains GmbH.  All rights reserved.
5#
6#   embedded brains GmbH
7#   Dornierstr. 4
8#   82178 Puchheim
9#   Germany
10#   <info@embedded-brains.de>
11#
12#  Copyright (c) 2012 OAR Corporation. All rights reserved.
13#
14#  Redistribution and use in source and binary forms, with or without
15#  modification, are permitted provided that the following conditions
16#  are met:
17#  1. Redistributions of source code must retain the above copyright
18#     notice, this list of conditions and the following disclaimer.
19#  2. Redistributions in binary form must reproduce the above copyright
20#     notice, this list of conditions and the following disclaimer in the
21#     documentation and/or other materials provided with the distribution.
22#
23#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27#  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35# FreeBSD: http://svn.freebsd.org/base/releng/8.2/sys (revision 222485)
36
[97c5024a]37from __future__ import print_function
38
[314be23]39import shutil
40import os
41import re
42import sys
43import getopt
44import filecmp
45import difflib
[f1fcdba]46import codecs
[314be23]47
48#
49# Global controls.
50#
51RTEMS_DIR = "."
52FreeBSD_DIR = "freebsd-org"
[f1fcdba]53verboseLevel = 0
[314be23]54isDryRun = False
55isDiffMode = False
[97c5024a]56filesProcessedCount = 0
57filesProcessed = []
[f9798ad]58filesTotal = 0
59filesTotalLines = 0
60filesTotalInserts = 0
61filesTotalDeletes = 0
62diffDetails = { }
[97c5024a]63
[f1fcdba]64verboseInfo = 1
65verboseDetail = 2
66verboseMoreDetail = 3
67verboseDebug = 4
68
69def verbose(level = verboseInfo):
70    return verboseLevel >= level
71
[f9798ad]72def changedFileSummary(statsReport = False):
73
74    global filesTotal, filesTotalLines, filesTotalInserts, filesTotalDeletes
75
[97c5024a]76    if isDiffMode == False:
[f1fcdba]77        if verbose():
[f9798ad]78            print('%d file(s) were changed:' % (filesProcessedCount))
[f1fcdba]79            for f in sorted(filesProcessed):
80                print(' %s' % (f))
[f9798ad]81        else:
82            print('%d file(s) were changed.' % (filesProcessedCount))
83    if statsReport:
84        print('Stats Report:')
85        transparent = filesTotal - len(diffDetails)
86        changes = filesTotalInserts + filesTotalDeletes
87        opacity = (float(changes) / (filesTotalLines + changes)) * 100.0
88        print(' Total File(s):%d  Unchanged:%d (%.1f%%)  Changed:%d' \
89              '   Opacity:%5.1f%% Lines:%d Edits:%d (+):%d (-):%d'  % \
90              (filesTotal, transparent, (float(transparent) / filesTotal) * 100.0, len(diffDetails), \
91               opacity, filesTotalLines, changes, filesTotalInserts, filesTotalDeletes))
92        #
93        # Sort by opacity.
94        #
95        ordered_diffs = sorted(diffDetails.items(), key = lambda diff: diff[1].opacity, reverse = True)
96        for f in ordered_diffs:
97            print(%s' % (diffDetails[f[0]].status()))
[f1fcdba]98
[5338089]99def readFile(name):
[f1fcdba]100    try:
101        contents = codecs.open(name, mode = 'r', encoding = 'utf-8', errors = 'ignore').read()
102    except UnicodeDecodeError as ude:
103        print('error: reading: %s: %s' % (name, ude))
104        sys.exit(1)
105    return contents
106
[5338089]107def writeFile(name, contents):
[f1fcdba]108    path = os.path.dirname(name)
109    if not os.path.exists(path):
110        try:
111            os.makedirs(path)
112        except OSError as oe:
[5338089]113            print('error: cannot create directory: %s: %s' % (path, oe))
[f1fcdba]114            sys.exit(1)
115    try:
116        codecs.open(name, mode = 'w',  encoding = 'utf-8', errors = 'ignore').write(contents)
117    except UnicodeDecodeError as ude:
118        print('error: write: %s: %s' % (name, ude))
119        sys.exit(1)
[314be23]120
[f1fcdba]121#
122# A builder error.
123#
[5ba6949]124class error(Exception):
125    """Base class for exceptions."""
[f1fcdba]126    def __init__(self, msg):
[5ba6949]127        self.msg = 'error: %s' % (msg)
128    def set_output(self, msg):
129        self.msg = msg
130    def __str__(self):
131        return self.msg
132
[f9798ad]133#
134# Diff Record
135#
136class diffRecord:
137    def __init__(self, src, dst, orig, diff, inserts, deletes):
138        self.src = src
139        self.dst = dst
140        self.orig = orig
141        self.diff = diff
142        self.lines = len(orig)
143        self.inserts = inserts
144        self.deletes = deletes
145        self.changes = inserts + deletes
146        self.opacity = (float(self.changes) / (self.lines + self.changes)) * 100.0
147
148    def __repr__(self):
149        return self.src
150
151    def status(self):
152        return 'opacity:%5.1f%% edits:%4d (+):%-4d (-):%-4d %s' % \
153            (self.opacity, self.changes, self.inserts, self.deletes, self.src)
154
[f1fcdba]155#
156# This stuff needs to move to libbsd.py.
157#
[5338089]158def commonFlags():
[c689915]159    return ['-O2',
[5ba6949]160            '-g',
161            '-fno-strict-aliasing',
162            '-ffreestanding',
163            '-fno-common']
164
[5338089]165def commonWarnings():
[5ba6949]166    return ['-Wall',
167            '-Wno-format']
168
[5338089]169def commonNoWarnings():
[e9aa9537]170    return ['-w']
[5ba6949]171
172def includes():
173    return ['-Irtemsbsd/include',
174            '-Ifreebsd/sys',
175            '-Ifreebsd/sys/contrib/altq',
176            '-Ifreebsd/sys/contrib/pf',
177            '-Ifreebsd/include',
178            '-Ifreebsd/lib/libc/include',
179            '-Ifreebsd/lib/libc/isc/include',
180            '-Ifreebsd/lib/libc/resolv',
181            '-Ifreebsd/lib/libutil',
182            '-Ifreebsd/lib/libkvm',
183            '-Ifreebsd/lib/libmemstat',
184            '-Ifreebsd/lib/libipsec',
[8440506]185            '-Ifreebsd/contrib/libpcap',
[5ba6949]186            '-Irtemsbsd/sys',
187            '-ImDNSResponder/mDNSCore',
188            '-ImDNSResponder/mDNSShared',
189            '-ImDNSResponder/mDNSPosix',
190            '-Itestsuite/include']
191
[5338089]192def cpuIncludes():
[5ba6949]193    return ['-Irtemsbsd/@CPU@/include',
194            '-Ifreebsd/sys/@CPU@/include']
195
196def cflags():
197    return ['-std=gnu11']
198
199def cxxflags():
200    return ['-std=gnu++11']
201
[5338089]202def headerPaths():
[0768880]203    #         local path                      wildcard             dest path
204    return [('rtemsbsd/include',              '*.h',               ''),
205            ('rtemsbsd/mghttpd',              'mongoose.h',        'mghttpd'),
206            ('freebsd/include',               '*.h',               ''),
207            ('freebsd/sys/contrib/altq/altq', '*.h',               'altq'),
208            ('freebsd/sys/bsm',               '*.h',               'bsm'),
209            ('freebsd/sys/cam',               '*.h',               'cam'),
210            ('freebsd/sys/net',               '*.h',               'net'),
211            ('freebsd/sys/net80211',          '*.h',               'net80211'),
212            ('freebsd/sys/netinet',           '*.h',               'netinet'),
213            ('freebsd/sys/netinet6',          '*.h',               'netinet6'),
214            ('freebsd/sys/netipsec',          '*.h',               'netipsec'),
[f478e3c]215            ('freebsd/sys/rpc',               '*.h',               'rpc'),
[0768880]216            ('freebsd/sys/sys',               '*.h',               'sys'),
217            ('freebsd/sys/vm',                '*.h',               'vm'),
218            ('freebsd/sys/dev/mii',           '*.h',               'dev/mii'),
219            ('mDNSResponder/mDNSCore',        'mDNSDebug.h',       ''),
220            ('mDNSResponder/mDNSCore',        'mDNSEmbeddedAPI.h', ''),
221            ('mDNSResponder/mDNSShared',      'dns_sd.h',          ''),
222            ('mDNSResponder/mDNSPosix',       'mDNSPosix.h',       '')]
223
[314be23]224# Move target dependent files under a machine directory
225def mapCPUDependentPath(path):
226  return path.replace("include/", "include/machine/")
227
228def fixIncludes(data):
[f1fcdba]229    data = re.sub('#include <sys/lock.h>',     '#include <rtems/bsd/sys/lock.h>', data)
230    data = re.sub('#include <sys/cpuset.h>',   '#include <rtems/bsd/sys/cpuset.h>', data)
231    data = re.sub('#include <sys/errno.h>',    '#include <rtems/bsd/sys/errno.h>', data)
232    data = re.sub('#include <sys/param.h>',    '#include <rtems/bsd/sys/param.h>', data)
[314be23]233    data = re.sub('#include <sys/resource.h>', '#include <rtems/bsd/sys/resource.h>', data)
[f1fcdba]234    data = re.sub('#include <sys/unistd.h>',   '#include <rtems/bsd/sys/unistd.h>', data)
[314be23]235    return data
236
237# revert fixing the include paths inside a C or .h file
238def revertFixIncludes(data):
[f1fcdba]239    data = re.sub('#include <rtems/bsd/',  '#include <', data)
240    data = re.sub('#include <util.h>',     '#include <rtems/bsd/util.h>', data)
241    data = re.sub('#include <bsd.h>',      '#include <rtems/bsd/bsd.h>', data)
[314be23]242    data = re.sub('#include <zerocopy.h>', '#include <rtems/bsd/zerocopy.h>', data)
243    return data
244
245# fix include paths inside a C or .h file
246def fixLocalIncludes(data):
[f1fcdba]247    data = re.sub('#include "opt_([^"]*)"',    '#include <rtems/bsd/local/opt_\\1>', data)
248    data = re.sub('#include "([^"]*)_if.h"',   '#include <rtems/bsd/local/\\1_if.h>', data)
[314be23]249    data = re.sub('#include "miidevs([^"]*)"', '#include <rtems/bsd/local/miidevs\\1>', data)
250    data = re.sub('#include "usbdevs([^"]*)"', '#include <rtems/bsd/local/usbdevs\\1>', data)
251    return data
252
253# revert fixing the include paths inside a C or .h file
254def revertFixLocalIncludes(data):
255    data = re.sub('#include <rtems/bsd/local/([^>]*)>', '#include "\\1"', data)
256    return data
257
258def assertHeaderFile(path):
259    if path[-2] != '.' or path[-1] != 'h':
[97c5024a]260        print("*** " + path + " does not end in .h")
261        print("*** Move it to a C source file list")
[314be23]262        sys.exit(2)
263
264def assertSourceFile(path):
265    if path[-2] != '.' or (path[-1] != 'c' and path[-1] != 'S'):
[97c5024a]266        print("*** " + path + " does not end in .c")
267        print("*** Move it to a header file list")
[314be23]268        sys.exit(2)
269
[f9798ad]270def diffSource(dstLines, srcLines, src, dst):
271    global filesTotal, filesTotalLines, filesTotalInserts, filesTotalDeletes
272    #
273    # Diff, note there is no line termination on each string.  Expand the
274    # generator to list because the generator is not reusable.
275    #
276    diff = list(difflib.unified_diff(dstLines,
277                                     srcLines,
278                                     fromfile = src,
279                                     tofile = dst,
280                                     n = 5,
281                                     lineterm = ''))
282    inserts = 0
283    deletes = 0
284    if len(diff) > 0:
285        if src in diffDetails and \
286           diffDetails[src].dst != dst and diffDetails[src].diff != diff:
287            raise error('repeated diff of file different: src:%s dst:%s' % (src, dst))
288        for l in diff:
289            if l[0] == '-':
290                deletes += 1
291            elif l[0] == '+':
292                inserts += 1
293        diffDetails[src] = diffRecord(src, dst, srcLines, diff, inserts, deletes)
294
295    #
296    # Count the total files, lines and the level of changes.
297    #
298    filesTotal += 1
299    filesTotalLines += len(srcLines)
300    filesTotalInserts += inserts
301    filesTotalDeletes += deletes
302
303    return diff
304
[f1fcdba]305#
306# Converters provide a way to alter the various types of code. The conversion
307# process filters a file as it is copies from the source path to the
308# destination path. Specialised versions are provided for different types of
309# source.
310#
[314be23]311class Converter(object):
312
[5338089]313    def convert(self, src, dst, hasSource = True, sourceFilter = None, srcContents = None):
[f1fcdba]314
315        global filesProcessed, filesProcessedCount
316
317        if verbose(verboseDebug):
318            print("convert: filter:%s: %s -> %s" % \
[5338089]319                  (['yes', 'no'][sourceFilter is None], src, dst))
[f1fcdba]320
321        #
322        # If there is no source raise an error if we expect source else print a
323        # warning and do not try and convert.
324        #
[5338089]325        if srcContents is None:
[f1fcdba]326            if not os.path.exists(src):
[5338089]327                if hasSource:
[f1fcdba]328                    raise error('source not found: %s' % (src))
329                else:
330                    print('warning: no source: %s' % (src))
331                    return
332
333            #
334            # Files read as a single string if not passed in.
335            #
[5338089]336            srcContents = readFile(src)
[f1fcdba]337
338        if os.path.exists(dst):
[5338089]339            dstContents = readFile(dst)
[f1fcdba]340        else:
341            print('warning: no destination: %s' % (dst))
[5338089]342            dstContents = ''
[f1fcdba]343
344        #
345        # Filter the source.
346        #
[5338089]347        if sourceFilter is not None:
348            srcContents = sourceFilter(srcContents)
[f1fcdba]349
350        #
351        # Split into a list of lines.
352        #
[5338089]353        srcLines = srcContents.split(os.linesep)
354        dstLines = dstContents.split(os.linesep)
[f1fcdba]355
356        if verbose(verboseDebug):
[5338089]357            print('Unified diff: %s (lines:%d)' % (src, len(srcLines)))
[f1fcdba]358
359        #
[f9798ad]360        # Diff, note there is no line termination on each string.
[f1fcdba]361        #
[f9798ad]362        diff = diffSource(dstLines, srcLines, src, dst)
[f1fcdba]363
364        #
365        # The diff list is empty if the files are the same.
366        #
367        if len(diff) > 0:
368
369            if verbose(verboseDebug):
370                print('Unified diff length: %d' % len(diff))
371
372            filesProcessed += [dst]
373            filesProcessedCount += 1
374            if isDiffMode == False:
375                if verbose(verboseDetail):
376                    print("UPDATE: %s -> %s" % (src, dst))
377                if isDryRun == False:
[5338089]378                    writeFile(dst, srcContents)
[f1fcdba]379            else:
380                print("diff -u %s %s" % (src, dst))
381                for l in diff:
382                    print(l)
[314be23]383
384class NoConverter(Converter):
[5338089]385    def convert(self, src, dst, hasSource = True, sourceFilter = None):
[314be23]386        return '/* EMPTY */\n'
387
388class FromFreeBSDToRTEMSHeaderConverter(Converter):
[5338089]389    def sourceFilter(self, data):
[314be23]390        data = fixLocalIncludes(data)
391        data = fixIncludes(data)
392        return data
393
[f1fcdba]394    def convert(self, src, dst):
395        sconverter = super(FromFreeBSDToRTEMSHeaderConverter, self)
[5338089]396        sconverter.convert(src, dst, sourceFilter = self.sourceFilter)
[f1fcdba]397
[314be23]398class FromFreeBSDToRTEMSUserSpaceHeaderConverter(Converter):
[5338089]399    def sourceFilter(self, data):
[314be23]400        data = fixIncludes(data)
401        return data
402
[f1fcdba]403    def convert(self, src, dst):
404        sconverter = super(FromFreeBSDToRTEMSUserSpaceHeaderConverter, self)
[5338089]405        sconverter.convert(src, dst, sourceFilter = self.sourceFilter)
[f1fcdba]406
[314be23]407class FromFreeBSDToRTEMSSourceConverter(Converter):
[5338089]408    def sourceFilter(self, data):
[314be23]409        data = fixLocalIncludes(data)
410        data = fixIncludes(data)
411        data = '#include <machine/rtems-bsd-kernel-space.h>\n\n' + data
412        return data
413
[f1fcdba]414    def convert(self, src, dst):
415        sconverter = super(FromFreeBSDToRTEMSSourceConverter, self)
[5338089]416        sconverter.convert(src, dst, sourceFilter = self.sourceFilter)
[f1fcdba]417
[314be23]418class FromFreeBSDToRTEMSUserSpaceSourceConverter(Converter):
[5338089]419    def sourceFilter(self, data):
[314be23]420        data = fixIncludes(data)
421        data = '#include <machine/rtems-bsd-user-space.h>\n\n' + data
422        return data
423
[f1fcdba]424    def convert(self, src, dst):
425        sconverter = super(FromFreeBSDToRTEMSUserSpaceSourceConverter, self)
[5338089]426        sconverter.convert(src, dst, sourceFilter = self.sourceFilter)
[f1fcdba]427
[314be23]428class FromRTEMSToFreeBSDHeaderConverter(Converter):
[5338089]429    def sourceFilter(self, data):
[314be23]430        data = revertFixLocalIncludes(data)
431        data = revertFixIncludes(data)
432        return data
433
[f1fcdba]434    def convert(self, src, dst):
435        sconverter = super(FromRTEMSToFreeBSDHeaderConverter, self)
[5338089]436        sconverter.convert(src, dst, hasSource = False,  sourceFilter = self.sourceFilter)
[f1fcdba]437
[314be23]438class FromRTEMSToFreeBSDSourceConverter(Converter):
[5338089]439    def sourceFilter(self, data):
[314be23]440        data = re.sub('#include <machine/rtems-bsd-kernel-space.h>\n\n', '', data)
441        data = re.sub('#include <machine/rtems-bsd-user-space.h>\n\n', '', data)
[95a12a2]442        data = revertFixLocalIncludes(data)
443        data = revertFixIncludes(data)
[314be23]444        return data
445
[f1fcdba]446    def convert(self, src, dst):
447        sconverter = super(FromRTEMSToFreeBSDSourceConverter, self)
[5338089]448        sconverter.convert(src, dst, hasSource = False, sourceFilter = self.sourceFilter)
[f1fcdba]449
450#
451# Compose a path based for the various parts of the source tree.
452#
[314be23]453class PathComposer(object):
454    def composeFreeBSDPath(self, path):
455        return path
456
457    def composeRTEMSPath(self, path, prefix):
[f1fcdba]458        return os.path.join(prefix, path)
[314be23]459
460class FreeBSDPathComposer(PathComposer):
461    def composeFreeBSDPath(self, path):
[f1fcdba]462        return os.path.join(FreeBSD_DIR, path)
[314be23]463
464    def composeRTEMSPath(self, path, prefix):
[f1fcdba]465        return os.path.join(prefix, 'freebsd', path)
[314be23]466
467class RTEMSPathComposer(PathComposer):
468    def composeFreeBSDPath(self, path):
469        return path
470
471    def composeRTEMSPath(self, path, prefix):
[f1fcdba]472        return os.path.join(prefix, 'rtemsbsd', path)
[314be23]473
474class CPUDependentPathComposer(FreeBSDPathComposer):
475    def composeRTEMSPath(self, path, prefix):
476        path = super(CPUDependentPathComposer, self).composeRTEMSPath(path, prefix)
477        path = mapCPUDependentPath(path)
478        return path
479
480class TargetSourceCPUDependentPathComposer(CPUDependentPathComposer):
481    def __init__(self, targetCPU, sourceCPU):
482        self.targetCPU = targetCPU
483        self.sourceCPU = sourceCPU
484
485    def composeRTEMSPath(self, path, prefix):
486        path = super(TargetSourceCPUDependentPathComposer, self).composeRTEMSPath(path, prefix)
487        path = path.replace(self.sourceCPU, self.targetCPU)
488        return path
489
490class BuildSystemFragmentComposer(object):
[8440506]491    def __init__(self, includes = None):
492        if type(includes) is not list:
493            self.includes = [includes]
494        else:
495            self.includes = includes
496
[314be23]497    def compose(self, path):
498        return ''
499
[f1fcdba]500#
501# File - a file in the source we move backwards and forwards.
502#
[314be23]503class File(object):
504    def __init__(self, path, pathComposer,
[f1fcdba]505                 forwardConverter, reverseConverter, buildSystemComposer):
506        if verbose(verboseMoreDetail):
507            print("FILE: %-50s F:%-45s R:%-45s" % \
508                  (path,
509                   forwardConverter.__class__.__name__,
510                   reverseConverter.__class__.__name__))
[314be23]511        self.path = path
512        self.pathComposer = pathComposer
[f1fcdba]513        self.freebsdPath = self.pathComposer.composeFreeBSDPath(self.path)
514        self.rtemsPath = self.pathComposer.composeRTEMSPath(self.path, RTEMS_DIR)
515        self.forwardConverter = forwardConverter
516        self.reverseConverter = reverseConverter
[314be23]517        self.buildSystemComposer = buildSystemComposer
518
[f1fcdba]519    def processSource(self, forward):
520        if forward:
521            if verbose(verboseDetail):
522                print("process source: %s => %s" % (self.freebsdPath, self.rtemsPath))
523            self.forwardConverter.convert(self.freebsdPath, self.rtemsPath)
524        else:
525            if verbose(verboseDetail):
526                print("process source: %s => %s converter:%s" % \
527                      (self.rtemsPath, self.freebsdPath, self.reverseConverter.__class__.__name__))
528            self.reverseConverter.convert(self.rtemsPath, self.freebsdPath)
[314be23]529
530    def getFragment(self):
531        return self.buildSystemComposer.compose(self.pathComposer.composeRTEMSPath(self.path, ''))
532
[f1fcdba]533#
[314be23]534# Module - logical group of related files we can perform actions on
[f1fcdba]535#
[314be23]536class Module:
537    def __init__(self, name):
538        self.name = name
539        self.conditionalOn = "none"
540        self.files = []
541        self.cpuDependentSourceFiles = {}
542        self.dependencies = []
543
544    def initCPUDependencies(self, cpu):
545        if cpu not in self.cpuDependentSourceFiles:
546            self.cpuDependentSourceFiles[cpu] = []
547
[f1fcdba]548    def processSource(self, direction):
549        if verbose(verboseDetail):
550            print("process module: %s" % (self.name))
[314be23]551        for f in self.files:
[f1fcdba]552            f.processSource(direction)
[314be23]553        for cpu, files in self.cpuDependentSourceFiles.items():
554            for f in files:
[f1fcdba]555                f.processSource(direction)
[314be23]556
557    def addFiles(self, newFiles, buildSystemComposer = BuildSystemFragmentComposer()):
558        files = []
559        for newFile in newFiles:
560            assertFile(newFile)
561            files += [File(newFile, composers, buildSystemComposer)]
562        return files
563
564    def addFile(self, f):
565        self.files += [f]
566
567    def addFiles(self, newFiles,
568                 pathComposer, fromFreeBSDToRTEMSConverter, fromRTEMSToFreeBSDConverter,
569                 assertFile, buildSystemComposer = BuildSystemFragmentComposer()):
570        files = []
571        for newFile in newFiles:
572            assertFile(newFile)
573            files += [File(newFile, pathComposer, fromFreeBSDToRTEMSConverter,
574                           fromRTEMSToFreeBSDConverter, buildSystemComposer)]
575        return files
576
577    def addKernelSpaceHeaderFiles(self, files):
578        self.files += self.addFiles(files,
579                                    FreeBSDPathComposer(), FromFreeBSDToRTEMSHeaderConverter(),
580                                    FromRTEMSToFreeBSDHeaderConverter(), assertHeaderFile)
581
582    def addUserSpaceHeaderFiles(self, files):
583        self.files += self.addFiles(files,
584                                    FreeBSDPathComposer(), FromFreeBSDToRTEMSUserSpaceHeaderConverter(),
585                                    FromRTEMSToFreeBSDHeaderConverter(), assertHeaderFile)
586
587    def addRTEMSHeaderFiles(self, files):
588        self.files += self.addFiles(files, RTEMSPathComposer(),
589                                    NoConverter(), NoConverter(), assertHeaderFile)
590
591    def addCPUDependentHeaderFiles(self, files):
592        self.files += self.addFiles(files,
593                                    CPUDependentPathComposer(), FromFreeBSDToRTEMSHeaderConverter(),
594                                    FromRTEMSToFreeBSDHeaderConverter(), assertHeaderFile)
595
596    def addTargetSourceCPUDependentHeaderFiles(self, targetCPUs, sourceCPU, files):
597        for cpu in targetCPUs:
598            self.files += self.addFiles(files,
599                                        TargetSourceCPUDependentPathComposer(cpu, sourceCPU),
600                                        FromFreeBSDToRTEMSHeaderConverter(),
601                                        NoConverter(), assertHeaderFile)
602
603    def addSourceFiles(self, files, sourceFileFragmentComposer):
604        self.files += self.addFiles(files,
605                                    PathComposer(), NoConverter(), NoConverter(), assertSourceFile,
606                                    sourceFileFragmentComposer)
607
608    def addKernelSpaceSourceFiles(self, files, sourceFileFragmentComposer):
609        self.files += self.addFiles(files,
610                                    FreeBSDPathComposer(), FromFreeBSDToRTEMSSourceConverter(),
611                                    FromRTEMSToFreeBSDSourceConverter(), assertSourceFile,
612                                    sourceFileFragmentComposer)
613
614    def addUserSpaceSourceFiles(self, files, sourceFileFragmentComposer):
615        self.files += self.addFiles(files,
616                                    FreeBSDPathComposer(),
617                                    FromFreeBSDToRTEMSUserSpaceSourceConverter(),
618                                    FromRTEMSToFreeBSDSourceConverter(), assertSourceFile,
619                                    sourceFileFragmentComposer)
620
621    def addRTEMSSourceFiles(self, files, sourceFileFragmentComposer):
622        self.files += self.addFiles(files,
623                                    RTEMSPathComposer(), NoConverter(), NoConverter(),
624                                    assertSourceFile, sourceFileFragmentComposer)
625
[40f7d5c]626    def addCPUDependentSourceFiles(self, cpus, files, sourceFileFragmentComposer):
627        for cpu in cpus:
[314be23]628            self.initCPUDependencies(cpu)
629            self.cpuDependentSourceFiles[cpu] += \
630                self.addFiles(files,
[40f7d5c]631                              CPUDependentPathComposer(), FromFreeBSDToRTEMSSourceConverter(),
632                              FromRTEMSToFreeBSDSourceConverter(), assertSourceFile,
633                              sourceFileFragmentComposer)
[314be23]634
635    def addTest(self, testFragementComposer):
636        self.files += [File(testFragementComposer.testName,
637                            PathComposer(), NoConverter(), NoConverter(),
638                            testFragementComposer)]
639
640    def addDependency(self, dep):
641        self.dependencies += [dep]
642
[f1fcdba]643#
644# Manager - a collection of modules.
645#
[314be23]646class ModuleManager:
647    def __init__(self):
648        self.modules = {}
649        self.generator = {}
650        self.setGenerators()
651
652    def __getitem__(self, key):
653        if key not in self.modules:
654            raise KeyError('module %s not found' % (key))
655        return self.modules[key]
656
657    def getModules(self):
658        return sorted(self.modules.keys())
659
660    def addModule(self, module):
661        self.modules[module.name] = module
662
[f1fcdba]663    def processSource(self, direction):
664        if verbose(verboseDetail):
665            print("process modules:")
[314be23]666        for m in sorted(self.modules):
[f1fcdba]667            self.modules[m].processSource(direction)
Note: See TracBrowser for help on using the repository browser.