bitbake/bin/bitbake: Add code to handle RDEPENDS
[vuplus_bitbake] / bin / bitbake
index 24405d0..36263cb 100755 (executable)
@@ -31,7 +31,7 @@ import itertools, optparse
 parsespin = itertools.cycle( r'|/-\\' )
 bbdebug = 0
 
-__version__ = "1.3.9"
+__version__ = "1.5.0"
 
 #============================================================================#
 # BBParsingStatus
@@ -189,7 +189,6 @@ class BBConfiguration( object ):
     def __init__( self, options ):
         for key, val in options.__dict__.items():
             setattr( self, key, val )
-        self.data = data.init()
 
 #============================================================================#
 # BBCooker
@@ -262,7 +261,7 @@ class BBCooker:
             return False
 
         # See if this is a runtime dependency we've already built
-       # Or a build dependency being handled in a different build chain
+        # Or a build dependency being handled in a different build chain
         if fn in self.building_list:
             return self.addRunDeps(fn, virtual , buildAllDeps)
 
@@ -426,7 +425,7 @@ class BBCooker:
 
             print "%-30s %20s %20s" % (p, latest[0][0] + "-" + latest[0][1],
                                         prefstr)
-        
+
 
     def showEnvironment( self ):
         """Show the outer or per-package environment"""
@@ -450,6 +449,175 @@ class BBCooker:
             if data.getVarFlag( e, 'python', self.configuration.data ):
                 sys.__stdout__.write("\npython %s () {\n%s}\n" % (e, data.getVar(e, self.configuration.data, 1)))
 
+    def generateDotGraph( self, pkgs_to_build, ignore_deps ):
+        """
+        Generate two graphs one for the DEPENDS and RDEPENDS. The current
+        implementation creates crappy graphs ;)
+
+        pkgs_to_build A list of packages that needs to be built
+        ignore_deps   A list of names where processing of dependencies
+                      should be stopped. e.g. dependencies that get
+        """
+
+        def myFilterProvider( providers, item):
+            """
+            Take a list of providers and filter according to environment
+            variables. In contrast to filterProviders we do not discriminate
+            and take PREFERRED_PROVIDER into account.
+            """
+            eligible = []
+            preferred_versions = {}
+
+            # Collate providers by PN
+            pkg_pn = {}
+            for p in providers:
+                pn = self.status.pkg_fn[p]
+                if pn not in pkg_pn:
+                    pkg_pn[pn] = []
+                pkg_pn[pn].append(p)
+
+            bb.debug(1, "providers for %s are: %s" % (item, pkg_pn.keys()))
+
+            for pn in pkg_pn.keys():
+                preferred_versions[pn] = self.findBestProvider(pn, pkg_pn)[2:4]
+                eligible.append(preferred_versions[pn][1])
+
+            for p in eligible:
+                if p in self.build_cache_fail:
+                    bb.debug(1, "rejecting already-failed %s" % p)
+                    eligible.remove(p)
+
+            if len(eligible) == 0:
+                bb.error("no eligible providers for %s" % item)
+                return 0
+
+            prefervar = bb.data.getVar('PREFERRED_PROVIDER_%s' % package, self.configuration.data, 1)
+
+            # try the preferred provider first
+            if prefervar:
+                for p in elligible:
+                    if prefervar == self.status.pkg_fn[p]:
+                        bb.note("Selecting PREFERRED_PROVIDER %s" % prefervar)
+                        elligible.remove(p)
+                        elligible = [p] + elligible
+
+            return eligible
+
+
+
+
+        # try to avoid adding the same rdepends over an over again
+        seen_depends  = []
+        seen_rdepends = []
+
+
+        def add_depends(package_list):
+            """
+            Add all depends of all packages from this list
+            """
+            for package in package_list:
+                if package in seen_depends or package in ignore_deps:
+                    continue
+
+                seen_depends.append( package )
+                if not package in self.status.providers:
+                    """
+                    We have not seen this name -> error in
+                    dependency handling
+                    """
+                    bb.note( "ERROR with provider: %(package)s" % vars() )
+                    print >> depends_file, '"%(package)s" -> ERROR' % vars()
+                    continue
+
+                # get all providers for this package
+                providers = self.status.providers[package]
+
+                # now let us find the bestProvider for it
+                fn = self.filterProviders(providers, package)[0]
+
+                depends  = bb.utils.explode_deps(self.bb_cache.getVar('DEPENDS', fn, True) or "")
+                version  = self.bb_cache.getVar('PV', fn, True ) + '-' + self.bb_cache.getVar('PR', fn, True)
+                add_depends ( depends )
+
+                # now create the node
+                print >> depends_file, '"%(package)s" [label="%(package)s\\n%(version)s"]' % vars()
+
+                depends = filter( (lambda x: x not in ignore_deps), depends )
+                for depend in depends:
+                    print >> depends_file, '"%(package)s" -> "%(depend)s"' % vars()
+
+
+        def add_all_depends( the_depends, the_rdepends ):
+            """
+            Add both DEPENDS and RDEPENDS. RDEPENDS will get dashed
+            lines
+            """
+            package_list = the_depends + the_rdepends
+            for package in package_list:
+                if package in seen_rdepends or package in ignore_deps:
+                    continue
+
+                seen_rdepends.append( package )
+
+                # let us see if this is a runtime or
+                if package in the_depends:
+                    if not package in self.status.providers:
+                        bb.note( "ERROR with provider: %(package)s" % vars() )
+                        print >> alldepends_file, '"%(package)s" -> ERROR' % vars()
+                        continue
+
+                    providers = self.status.providers[package]
+                elif package in the_rdepends:
+                    if len(self.getProvidersRun(package)) == 0:
+                        bb.note( "ERROR with rprovider: %(package)s" % vars() )
+                        print >> alldepends_file, '"%(package)s" -> ERROR [style="dashed"]' % vars()
+                        continue
+
+                    providers = self.getProvidersRun(package)
+                else:
+                    print "Complete ERROR! %s" % package
+                    continue
+
+                # now let us find the bestProvider for it
+                fn = self.filterProviders(providers, package)[0]
+
+                depends  = bb.utils.explode_deps(self.bb_cache.getVar('DEPENDS', fn, True) or "")
+                if fn in self.status.rundeps and package in self.status.rundeps[fn]:
+                    rdepends= self.status.rundeps[fn][package].keys()
+                else:
+                    rdepends = []
+                version  = self.bb_cache.getVar('PV', fn, True ) + '-' + self.bb_cache.getVar('PR', fn, True)
+                if package == "task-opie-applets":
+                    print fn
+                    print depends
+                    print depends
+                    print version
+
+                add_all_depends ( depends, rdepends )
+
+                # now create the node
+                print >> alldepends_file, '"%(package)s" [label="%(package)s\\n%(version)s"]' % vars()
+
+                depends = filter( (lambda x: x not in ignore_deps), depends )
+                rdepends = filter( (lambda x: x not in ignore_deps), rdepends )
+                for depend in depends:
+                    print >> alldepends_file, '"%(package)s" -> "%(depend)s"' % vars()
+                for depend in rdepends:
+                    print >> alldepends_file, '"%(package)s" -> "%(depend)s" [style=dashed]' % vars()
+
+
+        # Add depends now
+        depends_file = file('depends.dot', 'w' )
+        print >> depends_file, "digraph depends {"
+        add_depends( pkgs_to_build )
+        print >> depends_file,  "}"
+
+        # Add all depends now
+        alldepends_file = file('alldepends.dot', 'w' )
+        print >> alldepends_file, "digraph alldepends {"
+        add_all_depends( pkgs_to_build, [] )
+        print >> alldepends_file, "}"
+
     def filterProviders(self, providers, item):
         """
         Take a list of providers and filter/reorder according to the 
@@ -701,6 +869,9 @@ class BBCooker:
         all_depends = self.status.all_depends
         pn_provides = self.status.pn_provides
 
+        localdata = data.createCopy(self.configuration.data)
+        bb.data.update_data(localdata)
+
         def calc_bbfile_priority(filename):
             for (regex, pri) in self.status.bbfile_config_priorities:
                 if regex.match(filename):
@@ -708,7 +879,7 @@ class BBCooker:
             return 0
 
         # Handle PREFERRED_PROVIDERS
-        for p in (bb.data.getVar('PREFERRED_PROVIDERS', self.configuration.data, 1) or "").split():
+        for p in (bb.data.getVar('PREFERRED_PROVIDERS', localdata, 1) or "").split():
             (providee, provider) = p.split(':')
             if providee in self.preferred and self.preferred[providee] != provider:
                 bb.error("conflicting preferences for %s: both %s and %s specified" % (providee, provider, self.preferred[providee]))
@@ -778,6 +949,21 @@ class BBCooker:
     def parseConfigurationFile( self, afile ):
         try:
             self.configuration.data = bb.parse.handle( afile, self.configuration.data )
+
+            # Add the handlers we inherited by INHERIT
+            # we need to do this manually as it is not guranteed
+            # we will pick up these classes... as we only INHERIT
+            # on .inc and .bb files but not on .conf
+            data = bb.data.createCopy( self.configuration.data )
+            inherits  = ["base"] + (bb.data.getVar('INHERIT', data, True ) or "").split()
+            for inherit in inherits:
+                data = bb.parse.handle( os.path.join('classes', '%s.bbclass' % inherit ), data, True )
+
+            # FIXME: This assumes that we included at least one .inc file
+            for var in bb.data.keys(data):
+                if bb.data.getVarFlag(var, 'handler', data):
+                    bb.event.register(var,bb.data.getVar(var, data))
+
         except IOError:
             bb.fatal( "Unable to open %s" % afile )
         except bb.parse.ParseError, details:
@@ -809,6 +995,12 @@ class BBCooker:
 
 
     def cook( self, configuration, args ):
+        """
+        We are building stuff here. We do the building
+        from here. By default we try to execute task
+        build.
+        """
+
         self.configuration = configuration
 
         if not self.configuration.cmd:
@@ -824,6 +1016,13 @@ class BBCooker:
 
         self.parseConfigurationFile( os.path.join( "conf", "bitbake.conf" ) )
 
+
+        #
+        # Special updated configuration we use for firing events
+        #
+        self.configuration.event_data = bb.data.createCopy(self.configuration.data)
+        bb.data.update_data(self.configuration.event_data)
+
         if self.configuration.show_environment:
             self.showEnvironment()
             sys.exit( 0 )
@@ -899,7 +1098,7 @@ class BBCooker:
                 print "Requested parsing .bb files only.  Exiting."
                 return
 
-            bb.data.update_data( self.configuration.data )
+
             self.buildDepgraph()
 
             if self.configuration.show_versions:
@@ -911,7 +1110,12 @@ class BBCooker:
                 for t in self.status.world_target:
                     pkgs_to_build.append(t)
 
-            bb.event.fire(bb.event.BuildStarted(buildname, pkgs_to_build, self.configuration.data))
+            if self.configuration.dot_graph:
+                self.generateDotGraph( pkgs_to_build, self.configuration.ignored_dot_deps )
+                sys.exit( 0 )
+
+
+            bb.event.fire(bb.event.BuildStarted(buildname, pkgs_to_build, self.configuration.event_data))
 
             failures = 0
             for k in pkgs_to_build:
@@ -929,7 +1133,7 @@ class BBCooker:
                     if self.configuration.abort:
                         sys.exit(1)
 
-            bb.event.fire(bb.event.BuildCompleted(buildname, pkgs_to_build, self.configuration.data, failures))
+            bb.event.fire(bb.event.BuildCompleted(buildname, pkgs_to_build, self.configuration.event_data, failures))
 
             sys.exit( self.stats.show() )
 
@@ -1061,10 +1265,10 @@ Default BBFILES are the .bb files in the current directory.""" )
     parser.add_option( "-f", "--force", help = "force run of specified cmd, regardless of stamp status",
                action = "store_true", dest = "force", default = False )
 
-    parser.add_option( "-i", "--interactive", help = "drop into the interactive mode.",
+    parser.add_option( "-i", "--interactive", help = "drop into the interactive mode also called the BitBake shell.",
                action = "store_true", dest = "interactive", default = False )
 
-    parser.add_option( "-c", "--cmd", help = "Specify task to execute. Note that this only executes the specified task for the providee and the packages it depends on, i.e. 'compile' does not implicitly call stage for the dependencies (IOW: use only if you know what you are doing)",
+    parser.add_option( "-c", "--cmd", help = "Specify task to execute. Note that this only executes the specified task for the providee and the packages it depends on, i.e. 'compile' does not implicitly call stage for the dependencies (IOW: use only if you know what you are doing). Depending on the base.bbclass a listtaks tasks is defined and will show available tasks",
                action = "store", dest = "cmd", default = "build" )
 
     parser.add_option( "-r", "--read", help = "read the specified file before bitbake.conf",
@@ -1073,7 +1277,7 @@ Default BBFILES are the .bb files in the current directory.""" )
     parser.add_option( "-v", "--verbose", help = "output more chit-chat to the terminal",
                action = "store_true", dest = "verbose", default = False )
 
-    parser.add_option( "-D", "--debug", help = "Increase the debug level",
+    parser.add_option( "-D", "--debug", help = "Increase the debug level. You can specify this more than once.",
                action = "count", dest="debug", default = 0)
 
     parser.add_option( "-n", "--dry-run", help = "don't execute, just go through the motions",
@@ -1091,6 +1295,12 @@ Default BBFILES are the .bb files in the current directory.""" )
     parser.add_option( "-e", "--environment", help = "show the global or per-package environment (this is what used to be bbread)",
                action = "store_true", dest = "show_environment", default = False )
 
+    parser.add_option( "-g", "--graphviz", help = "emit the dependency trees of the specified packages in the dot syntax",
+                action = "store_true", dest = "dot_graph", default = False )
+    parser.add_option( "-I", "--ignore-deps", help = """Stop processing at the given list of dependencies when generating dependency graphs. This can help to make the graph more appealing""",
+                action = "append", dest = "ignored_dot_deps", default = [] )
+
+
     options, args = parser.parse_args( sys.argv )
 
     cooker = BBCooker()
@@ -1099,4 +1309,9 @@ Default BBFILES are the .bb files in the current directory.""" )
 
 
 if __name__ == "__main__":
+    print """WARNING, WARNING, WARNING
+This is a Bitbake from the Unstable/Development Branch.
+You might want to use the bitbake-1.4 stable branch (if you are not a BitBake developer or tester). I'm going to sleep 5 seconds now to make sure you see that."""
+    import time
+    time.sleep(5)
     main()