[PATCH master 2/4] waf: Add a config report

chrisj at rtems.org chrisj at rtems.org
Tue Sep 15 02:32:33 UTC 2020


From: Chris Johns <chrisj at rtems.org>

---
 builder.py          | 81 +++++++++++++++++++++++++++++++++------------
 freebsd-to-rtems.py | 40 ++++++++++++++--------
 2 files changed, 85 insertions(+), 36 deletions(-)

diff --git a/builder.py b/builder.py
index 83672935..79cb6c17 100755
--- a/builder.py
+++ b/builder.py
@@ -537,6 +537,16 @@ class BuildSystemFragmentComposer(object):
         else:
             self.includes = includes
 
+    def __str__(self):
+        return ''
+
+    def get_includes(self):
+        if None in self.includes:
+            incs = []
+        else:
+            incs = self.includes
+        return incs
+
     def compose(self, path):
         return ''
 
@@ -545,11 +555,14 @@ class SourceFileFragmentComposer(BuildSystemFragmentComposer):
     def __init__(self, cflags="default", includes=None):
         self.cflags, self.includes = _cflagsIncludes(cflags, includes)
 
+    def _get_flags(self):
+        return self.cflags + self.get_includes()
+
+    def __str__(self):
+        return 'SF: ' + ' '.join(self._get_flags())
+
     def compose(self, path):
-        if None in self.includes:
-            flags = self.cflags
-        else:
-            flags = self.cflags + self.includes
+        flags = self._get_flags()
         return ['sources', flags,
                 ('default', None)], [path], self.cflags, self.includes
 
@@ -561,6 +574,12 @@ class SourceFileIfHeaderComposer(SourceFileFragmentComposer):
         self.headers = headers
         super(SourceFileIfHeaderComposer, self).__init__(cflags=cflags,
                                                          includes=includes)
+    def __str__(self):
+        incs = self.headers + self.get_includes
+        if len(incs) > 0:
+            return 'SFIH:' + ' '.join(incs)
+        else:
+            return ''
 
     def compose(self, path):
         r = SourceFileFragmentComposer.compose(self, path)
@@ -589,6 +608,9 @@ class TestFragementComposer(BuildSystemFragmentComposer):
         self.netTest = netTest
         self.extraLibs = extraLibs
 
+    def __str__(self):
+        return 'TEST: ' + self.testName
+
     def compose(self, path):
         return ['tests', self.testName, ('default', None)], {
             'configTest': self.configTest,
@@ -717,10 +739,9 @@ class YaccFragmentComposer(BuildSystemFragmentComposer):
         return ['yacc', path, ('default', None)], d
 
 
-#
-# File - a file in the source we move backwards and forwards.
-#
 class File(object):
+    '''A file of source we move backwards and forwards and build.'''
+
     def __init__(self, path, pathComposer, forwardConverter, reverseConverter,
                  buildSystemComposer):
         if verbose(verboseMoreDetail):
@@ -737,6 +758,13 @@ class File(object):
         self.reverseConverter = reverseConverter
         self.buildSystemComposer = buildSystemComposer
 
+    def __str__(self):
+        out = self.path
+        bsc = str(self.buildSystemComposer)
+        if len(bsc) > 0:
+            out += ' (' + bsc + ')'
+        return out
+
     def processSource(self, forward):
         if forward:
             if verbose(verboseDetail):
@@ -754,10 +782,9 @@ class File(object):
             self.pathComposer.composeLibBSDPath(self.path, ''))
 
 
-#
-# Module - logical group of related files we can perform actions on
-#
 class Module(object):
+    '''Logical group of related files we can perform actions on'''
+
     def __init__(self, manager, name, enabled=True):
         self.manager = manager
         self.name = name
@@ -766,6 +793,20 @@ class Module(object):
         self.cpuDependentSourceFiles = {}
         self.dependencies = []
 
+    def __str__(self):
+        out = [self.name + ': ' + self.conditionalOn]
+        if len(self.dependencies) > 0:
+            out += [' Deps: ' + str(len(self.dependencies))]
+            out += ['  ' + type(d).__name__ for d in self.dependencies]
+        if len(self.files) > 0:
+            out += [' Files: ' + str(len(self.files))]
+            out += ['  ' + str(f) for f in self.files]
+        if len(self.cpuDependentSourceFiles) > 0:
+            out += [' CPU Dep: ' + str(len(self.cpuDependentSourceFiles))]
+            for cpu in self.cpuDependentSourceFiles:
+                out += ['  ' + cpu + ':' + str(f) for f in self.cpuDependentSourceFiles[cpu]]
+        return os.linesep.join(out)
+
     def initCPUDependencies(self, cpu):
         if cpu not in self.cpuDependentSourceFiles:
             self.cpuDependentSourceFiles[cpu] = []
@@ -779,15 +820,6 @@ class Module(object):
             for f in files:
                 f.processSource(direction)
 
-    def addFiles(self,
-                 newFiles,
-                 buildSystemComposer=BuildSystemFragmentComposer()):
-        files = []
-        for newFile in newFiles:
-            assertFile(newFile)
-            files += [File(newFile, composers, buildSystemComposer)]
-        return files
-
     def addFile(self, f):
         self.files += [f]
 
@@ -920,10 +952,9 @@ class Module(object):
         self.dependencies += [dep]
 
 
-#
-# Manager - a collection of modules.
-#
 class ModuleManager(object):
+    '''A manager for a collection of modules.'''
+
     def __init__(self):
         self.modules = {}
         self.generator = {}
@@ -935,6 +966,12 @@ class ModuleManager(object):
             raise KeyError('module %s not found' % (key))
         return self.modules[key]
 
+    def __str__(self):
+        out = ['Modules: ' + str(len(self.modules)), '']
+        for m in sorted(self.modules):
+            out += [str(self.modules[m]), '']
+        return os.linesep.join(out)
+
     def getAllModules(self):
         if 'modules' in self.configuration:
             return self.configuration['modules']
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py
index 3f06bdf9..5710b902 100755
--- a/freebsd-to-rtems.py
+++ b/freebsd-to-rtems.py
@@ -47,6 +47,7 @@ import libbsd
 isForward = True
 isEarlyExit = False
 statsReport = False
+isConfig = False
 
 def usage():
     print("freebsd-to-rtems.py [args]")
@@ -59,14 +60,15 @@ def usage():
     print("  -R|--reverse      default origin -> LibBSD, reverse that")
     print("  -r|--rtems        LibBSD directory (default: '.')")
     print("  -f|--freebsd      FreeBSD origin directory (default: 'freebsd-org')")
+    print("  -c|--config       Output the configuration then exit")
     print("  -v|--verbose      enable verbose output mode")
 
 # Parse the arguments
 def parseArguments():
-    global isForward, isEarlyExit, statsReport
+    global isForward, isEarlyExit, statsReport, isConfig
     try:
         opts, args = getopt.getopt(sys.argv[1:],
-                                   "?hdDembSRr:f:v",
+                                   "?hdDembSRr:f:cv",
                                    [ "help",
                                      "help",
                                      "dry-run"
@@ -78,6 +80,7 @@ def parseArguments():
                                      "stats"
                                      "rtems="
                                      "freebsd="
+                                     "config"
                                      "verbose" ])
     except getopt.GetoptError as err:
         # print help information and exit:
@@ -104,6 +107,8 @@ def parseArguments():
             builder.LIBBSD_DIR = a
         elif o in ("-f", "--freebsd"):
             builder.FreeBSD_DIR = a
+        elif o in ("-c", "--config"):
+            isConfig = True
         else:
             assert False, "unhandled option"
 
@@ -127,24 +132,31 @@ def wasDirectorySet(desc, path):
         print("error:" + desc + " Directory (" + path + ") does not exist")
         sys.exit(2)
 
-# Were directories specified?
-wasDirectorySet( "LibBSD", builder.LIBBSD_DIR )
-wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
+try:
+    if not isConfig:
+        # Were directories specified?
+        wasDirectorySet( "LibBSD", builder.LIBBSD_DIR )
+        wasDirectorySet( "FreeBSD", builder.FreeBSD_DIR )
 
-# Are we generating or reverting?
-if isForward == True:
-    print("Forward from", builder.FreeBSD_DIR, "into", builder.LIBBSD_DIR)
-else:
-    print("Reverting from", builder.LIBBSD_DIR)
+        # Are we generating or reverting?
+        if isForward == True:
+            print("Forward from", builder.FreeBSD_DIR, "into", builder.LIBBSD_DIR)
+        else:
+            print("Reverting from", builder.LIBBSD_DIR)
 
-if isEarlyExit == True:
-    print("Early exit at user request")
-    sys.exit(0)
+        if isEarlyExit == True:
+            print("Early exit at user request")
+            sys.exit(0)
 
-try:
     build = builder.ModuleManager()
     libbsd.load(build)
     build.generateBuild(only_enabled=False)
+
+    if isConfig:
+        print()
+        print(build)
+        sys.exit(0)
+
     build.processSource(isForward)
     builder.changedFileSummary(statsReport)
 except IOError as ioe:
-- 
2.24.1



More information about the devel mailing list