2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 # Copyright (C) 2003, 2004 Chris Larson
6 # Copyright (C) 2003, 2004 Phil Blundell
7 # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer
8 # Copyright (C) 2005 Holger Hans Peter Freyther
9 # Copyright (C) 2005 ROAD GmbH
11 # This program is free software; you can redistribute it and/or modify it under
12 # the terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # This program is distributed in the hope that it will be useful, but WITHOUT
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 # Place, Suite 330, Boston, MA 02111-1307 USA.
24 import sys, os, getopt, glob, copy, os.path, re, time
25 sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
27 from bb import utils, data, parse, debug, event, fatal
29 import itertools, optparse
31 parsespin = itertools.cycle( r'|/-\\' )
34 __version__ = "1.3.3.2"
36 #============================================================================#
38 #============================================================================#
39 class BBParsingStatus:
41 The initial idea for this status class is to use the data when it is
42 already loaded instead of loading it from various place over and over
47 self.cache_dirty = False
51 self.packages_dynamic = {}
52 self.bbfile_priority = {}
53 self.bbfile_config_priorities = []
54 self.ignored_dependencies = None
55 self.possible_world = []
56 self.world_target = Set()
62 self.all_depends = Set()
64 def handle_bb_data(self, file_name, bb_data, cached):
66 We will fill the dictionaries with the stuff we
67 need for building the tree more fast
73 self.cache_dirty = True
75 pn = bb.data.getVar('PN', bb_data, True)
76 pv = bb.data.getVar('PV', bb_data, True)
77 pr = bb.data.getVar('PR', bb_data, True)
78 dp = int(bb.data.getVar('DEFAULT_PREFERENCE', bb_data, True) or "0")
79 provides = Set([pn] + (bb.data.getVar("PROVIDES", bb_data, 1) or "").split())
80 rprovides = (bb.data.getVar("RPROVIDES", bb_data, 1) or "").split()
81 depends = (bb.data.getVar("DEPENDS", bb_data, True) or "").split()
82 packages = (bb.data.getVar('PACKAGES', bb_data, True) or "").split()
83 packages_dynamic = (bb.data.getVar('PACKAGES_DYNAMIC', bb_data, True) or "").split()
86 # build PackageName to FileName lookup table
87 if pn not in self.pkg_pn:
89 self.pkg_pn[pn].append(file_name)
91 # build FileName to PackageName lookup table
92 self.pkg_fn[file_name] = pn
93 self.pkg_pvpr[file_name] = (pv,pr)
94 self.pkg_dp[file_name] = dp
96 # Build forward and reverse provider hashes
97 # Forward: virtual -> [filenames]
98 # Reverse: PN -> [virtuals]
99 if pn not in self.pn_provides:
100 self.pn_provides[pn] = Set()
101 self.pn_provides[pn] |= provides
103 for provide in provides:
104 if provide not in self.providers:
105 self.providers[provide] = []
106 self.providers[provide].append(file_name)
109 self.all_depends.add(dep)
111 # Build reverse hash for PACKAGES, so runtime dependencies
112 # can be be resolved (RDEPENDS, RRECOMMENDS etc.)
114 for package in packages:
115 if not package in self.packages:
116 self.packages[package] = []
117 self.packages[package].append(file_name)
119 for package in packages_dynamic:
120 if not package in self.packages_dynamic:
121 self.packages_dynamic[package] = []
122 self.packages_dynamic[package].append(file_name)
124 for rprovide in rprovides:
125 if not rprovide in self.rproviders:
126 self.rproviders[rprovide] = []
127 self.rproviders[rprovide].append(file_name)
129 # Collect files we may need for possible world-dep
131 if not bb.data.getVar('BROKEN', bb_data, True) and not bb.data.getVar('EXCLUDE_FROM_WORLD', bb_data, True):
132 self.possible_world.append(file_name)
135 #============================================================================#
137 #============================================================================#
140 Manage build statistics for one run
149 print "Build statistics:"
150 print " Attempted builds: %d" % self.attempt
152 print " Failed builds: %d" % self.fail
154 print " Dependencies not satisfied: %d" % self.deps
155 if self.fail or self.deps: return 1
159 #============================================================================#
161 #============================================================================#
162 class BBConfiguration( object ):
164 Manages build options and configurations for one run
166 def __init__( self, options ):
167 for key, val in options.__dict__.items():
168 setattr( self, key, val )
169 self.data = data.init()
171 #============================================================================#
173 #============================================================================#
176 Manages one bitbake build run
179 ParsingStatus = BBParsingStatus # make it visible from the shell
180 Statistics = BBStatistics # make it visible from the shell
182 def __init__( self ):
183 self.build_cache_fail = []
184 self.build_cache = []
185 self.rbuild_cache = []
186 self.building_list = []
188 self.consider_msgs_cache = []
190 self.stats = BBStatistics()
196 def tryBuildPackage( self, fn, item, the_data ):
197 """Build one package"""
198 bb.event.fire(bb.event.PkgStarted(item, the_data))
200 self.stats.attempt += 1
201 if self.configuration.force:
202 bb.data.setVarFlag('do_%s' % self.configuration.cmd, 'force', 1, the_data)
203 if not self.configuration.dry_run:
204 bb.build.exec_task('do_%s' % self.configuration.cmd, the_data)
205 bb.event.fire(bb.event.PkgSucceeded(item, the_data))
206 self.build_cache.append(fn)
208 except bb.build.FuncFailed:
210 bb.error("task stack execution failed")
211 bb.event.fire(bb.event.PkgFailed(item, the_data))
212 self.build_cache_fail.append(fn)
214 except bb.build.EventException, e:
217 bb.error("%s event exception, aborting" % bb.event.getName(event))
218 bb.event.fire(bb.event.PkgFailed(item, the_data))
219 self.build_cache_fail.append(fn)
222 def tryBuild( self, fn, virtual , buildAllDeps , build_depends = []):
224 Build a provider and its dependencies.
225 build_depends is a list of previous build dependencies (not runtime)
226 If build_depends is empty, we're dealing with a runtime depends
229 the_data = self.pkgdata[fn]
232 buildAllDeps = bb.data.getVar('BUILD_ALL_DEPS', the_data, True) or False
234 # Error on build time dependency loops
235 if build_depends and build_depends.count(fn) > 1:
236 bb.error("%s depends on itself (eventually)" % fn)
237 bb.error("upwards chain is: %s" % (" -> ".join(self.build_path)))
240 # See if this is a runtime dependency we've already built
241 # Or a build dependency being handled in a different build chain
242 if fn in self.building_list:
243 return self.addRunDeps(fn, virtual , buildAllDeps)
245 item = self.status.pkg_fn[fn]
247 self.building_list.append(fn)
249 pathstr = "%s (%s)" % (item, virtual)
250 self.build_path.append(pathstr)
252 depends_list = (bb.data.getVar('DEPENDS', the_data, True) or "").split()
254 if self.configuration.verbose:
255 bb.note("current path: %s" % (" -> ".join(self.build_path)))
256 bb.note("dependencies for %s are: %s" % (item, " ".join(depends_list)))
261 depcmd = self.configuration.cmd
262 bbdepcmd = bb.data.getVarFlag('do_%s' % self.configuration.cmd, 'bbdepcmd', the_data)
263 if bbdepcmd is not None:
270 oldcmd = self.configuration.cmd
271 self.configuration.cmd = depcmd
273 for dependency in depends_list:
274 if dependency in self.status.ignored_dependencies:
278 if self.buildProvider( dependency , buildAllDeps , build_depends ) == 0:
279 bb.error("dependency %s (for %s) not satisfied" % (dependency,item))
281 if self.configuration.abort:
285 self.configuration.cmd = oldcmd
291 if not self.addRunDeps(fn, virtual , buildAllDeps):
294 if bb.build.stamp_is_current('do_%s' % self.configuration.cmd, the_data):
295 self.build_cache.append(fn)
298 return self.tryBuildPackage( fn, item, the_data )
301 self.building_list.remove(fn)
302 self.build_path.remove(pathstr)
304 def findBestProvider( self, pn, pkg_pn = None):
306 If there is a PREFERRED_VERSION, find the highest-priority bbfile
307 providing that version. If not, find the latest version provided by
308 an bbfile in the highest-priority set.
311 pkg_pn = self.status.pkg_pn
316 priority = self.status.bbfile_priority[f]
317 if priority not in priorities:
318 priorities[priority] = []
319 priorities[priority].append(f)
320 p_list = priorities.keys()
321 p_list.sort(lambda a, b: a - b)
324 tmp_pn = [priorities[p]] + tmp_pn
326 preferred_file = None
328 localdata = data.createCopy(self.configuration.data)
329 bb.data.setVar('OVERRIDES', "%s:%s" % (pn, data.getVar('OVERRIDES', localdata)), localdata)
330 bb.data.update_data(localdata)
332 preferred_v = bb.data.getVar('PREFERRED_VERSION_%s' % pn, localdata, True)
334 m = re.match('(.*)_(.*)', preferred_v)
336 preferred_v = m.group(1)
337 preferred_r = m.group(2)
341 for file_set in tmp_pn:
343 pv,pr = self.status.pkg_pvpr[f]
344 if preferred_v == pv and (preferred_r == pr or preferred_r == None):
346 preferred_ver = (pv, pr)
351 pv_str = '%s-%s' % (preferred_v, preferred_r)
354 if preferred_file is None:
355 bb.note("preferred version %s of %s not available" % (pv_str, pn))
357 bb.debug(1, "selecting %s as PREFERRED_VERSION %s of package %s" % (preferred_file, pv_str, pn))
361 # get highest priority file set
366 for file_name in files:
367 pv,pr = self.status.pkg_pvpr[file_name]
368 dp = self.status.pkg_dp[file_name]
370 if (latest is None) or ((latest_p == dp) and (utils.vercmp(latest, (pv, pr)) < 0)) or (dp > latest_p):
374 if preferred_file is None:
375 preferred_file = latest_f
376 preferred_ver = latest
378 return (latest,latest_f,preferred_ver, preferred_file)
380 def showVersions( self ):
381 pkg_pn = self.status.pkg_pn
382 preferred_versions = {}
386 for pn in pkg_pn.keys():
387 (last_ver,last_file,pref_ver,pref_file) = self.findBestProvider(pn)
388 preferred_versions[pn] = (pref_ver, pref_file)
389 latest_versions[pn] = (last_ver, last_file)
391 pkg_list = pkg_pn.keys()
395 pref = preferred_versions[p]
396 latest = latest_versions[p]
399 prefstr = pref[0][0] + "-" + pref[0][1]
403 print "%-30s %20s %20s" % (p, latest[0][0] + "-" + latest[0][1],
406 def showEnvironment( self ):
407 """Show the outer or per-package environment"""
408 if self.configuration.buildfile:
410 self.configuration.data, fromCache = self.load_bbfile( self.configuration.buildfile )
412 fatal("Unable to read %s: %s" % ( self.configuration.buildfile, e ))
415 # emit variables and shell functions
417 data.update_data( self.configuration.data )
418 data.emit_env(sys.__stdout__, self.configuration.data, True)
421 # emit the metadata which isnt valid shell
422 for e in self.configuration.data.keys():
423 if data.getVarFlag( e, 'python', self.configuration.data ):
424 sys.__stdout__.write("\npython %s () {\n%s}\n" % (e, data.getVar(e, self.configuration.data, 1)))
426 def filterProviders(self, providers, item):
428 Take a list of providers and filter/reorder according to the
429 environment variables and previous build results
432 preferred_versions = {}
434 # Collate providers by PN
437 pn = self.status.pkg_fn[p]
442 bb.debug(1, "providers for %s are: %s" % (item, pkg_pn.keys()))
444 for pn in pkg_pn.keys():
445 preferred_versions[pn] = self.findBestProvider(pn, pkg_pn)[2:4]
446 eligible.append(preferred_versions[pn][1])
449 if p in self.build_cache_fail:
450 bb.debug(1, "rejecting already-failed %s" % p)
453 if len(eligible) == 0:
454 bb.error("no eligible providers for %s" % item)
457 # look to see if one of them is already staged, or marked as preferred.
458 # if so, bump it to the head of the queue
460 the_data = self.pkgdata[p]
461 pn = bb.data.getVar('PN', the_data, 1)
462 pv = bb.data.getVar('PV', the_data, 1)
463 pr = bb.data.getVar('PR', the_data, 1)
464 stamp = '%s.do_populate_staging' % bb.data.getVar('STAMP', the_data, 1)
465 if os.path.exists(stamp):
466 (newvers, fn) = preferred_versions[pn]
467 if not fn in eligible:
468 # package was made ineligible by already-failed check
470 oldver = "%s-%s" % (pv, pr)
471 newver = '-'.join(newvers)
472 if (newver != oldver):
473 extra_chat = "; upgrading from %s to %s" % (oldver, newver)
476 if self.configuration.verbose:
477 bb.note("selecting already-staged %s to satisfy %s%s" % (pn, item, extra_chat))
479 eligible = [fn] + eligible
485 def buildProvider( self, item , buildAllDeps , build_depends = [] ):
487 Build something to provide a named build requirement
488 (takes item names from DEPENDS namespace)
492 discriminated = False
494 if not item in self.status.providers:
495 bb.error("Nothing provides dependency %s" % item)
498 all_p = self.status.providers[item]
501 if p in self.build_cache:
502 bb.debug(1, "already built %s in this run\n" % p)
505 eligible = self.filterProviders(all_p, item)
510 prefervar = bb.data.getVar('PREFERRED_PROVIDER_%s' % item, self.configuration.data, 1)
512 self.preferred[item] = prefervar
514 if item in self.preferred:
516 pn = self.status.pkg_fn[p]
517 if self.preferred[item] == pn:
518 if self.configuration.verbose:
519 bb.note("selecting %s to satisfy %s due to PREFERRED_PROVIDERS" % (pn, item))
521 eligible = [p] + eligible
525 if len(eligible) > 1 and discriminated == False:
526 if item not in self.consider_msgs_cache:
529 providers_list.append(self.status.pkg_fn[fn])
530 bb.note("multiple providers are available (%s);" % ", ".join(providers_list))
531 bb.note("consider defining PREFERRED_PROVIDER_%s" % item)
532 bb.event.fire(bb.event.MultipleProviders(item,providers_list,self.configuration.data))
533 self.consider_msgs_cache.append(item)
536 # run through the list until we find one that we can build
538 bb.debug(2, "selecting %s to satisfy %s" % (fn, item))
539 if self.tryBuild(fn, item, buildAllDeps, build_depends + [fn]):
542 bb.note("no buildable providers for %s" % item)
545 def buildRProvider( self, item , buildAllDeps ):
547 Build something to provide a named runtime requirement
548 (takes item names from RDEPENDS/PACKAGES namespace)
553 discriminated = False
558 all_p = self.getProvidersRun(item)
561 bb.error("Nothing provides runtime dependency %s" % (item))
565 if p in self.rbuild_cache:
566 bb.debug(2, "Already built %s providing runtime %s\n" % (p,item))
568 if p in self.build_cache:
569 bb.debug(2, "Already built %s but adding any further RDEPENDS for %s\n" % (p, item))
570 return self.addRunDeps(p, item , buildAllDeps)
572 eligible = self.filterProviders(all_p, item)
578 pn = self.status.pkg_fn[p]
579 provides = self.status.pn_provides[pn]
580 for provide in provides:
581 prefervar = bb.data.getVar('PREFERRED_PROVIDER_%s' % provide, self.configuration.data, 1)
583 if self.configuration.verbose:
584 bb.note("selecting %s to satisfy runtime %s due to PREFERRED_PROVIDERS" % (pn, item))
586 eligible = [p] + eligible
589 if len(eligible) > 1 and len(preferred) == 0:
590 if item not in self.consider_msgs_cache:
593 providers_list.append(self.status.pkg_fn[fn])
594 bb.note("multiple providers are available (%s);" % ", ".join(providers_list))
595 bb.note("consider defining a PREFERRED_PROVIDER to match runtime %s" % item)
596 bb.event.fire(bb.event.MultipleProviders(item,providers_list,self.configuration.data,runtime=True))
597 self.consider_msgs_cache.append(item)
599 if len(preferred) > 1:
600 if item not in self.consider_msgs_cache:
603 providers_list.append(self.status.pkg_fn[fn])
604 bb.note("multiple preferred providers are available (%s);" % ", ".join(providers_list))
605 bb.note("consider defining only one PREFERRED_PROVIDER to match runtime %s" % item)
606 bb.event.fire(bb.event.MultipleProviders(item,providers_list,self.configuration.data,runtime=True))
607 self.consider_msgs_cache.append(item)
609 # run through the list until we find one that we can build
611 bb.debug(2, "selecting %s to satisfy runtime %s" % (fn, item))
612 if self.tryBuild(fn, item, buildAllDeps):
615 bb.error("No buildable providers for runtime %s" % item)
618 def getProvidersRun(self, rdepend):
620 Return any potential providers of runtime rdepend
624 if rdepend in self.status.rproviders:
625 rproviders += self.status.rproviders[rdepend]
627 if rdepend in self.status.packages:
628 rproviders += self.status.packages[rdepend]
633 # Only search dynamic packages if we can't find anything in other variables
634 for pattern in self.status.packages_dynamic:
635 regexp = re.compile(pattern)
636 if regexp.match(rdepend):
637 rproviders += self.status.packages_dynamic[pattern]
641 def addRunDeps(self , fn, item , buildAllDeps):
643 Add any runtime dependencies of runtime item provided by fn
644 as long as item has't previously been processed by this function.
647 if item in self.rbuild_cache:
654 self.rbuild_cache.append(item)
655 the_data = self.pkgdata[fn]
656 pn = self.status.pkg_fn[fn]
659 rdepends += bb.utils.explode_deps(bb.data.getVar('RDEPENDS', the_data, True) or "")
660 rdepends += bb.utils.explode_deps(bb.data.getVar('RRECOMMENDS', the_data, True) or "")
661 rdepends += bb.utils.explode_deps(bb.data.getVar("RDEPENDS_%s" % pn, the_data, True) or "")
663 packages = (bb.data.getVar('PACKAGES', the_data, 1).split() or "")
664 for package in packages:
666 rdepends += bb.utils.explode_deps(bb.data.getVar("RDEPENDS_%s" % package, the_data, True) or "")
667 rdepends += bb.utils.explode_deps(bb.data.getVar("RRECOMMENDS_%s" % package, the_data, True) or "")
669 bb.debug(2, "Additional runtime dependencies for %s are: %s" % (item, " ".join(rdepends)))
671 for rdepend in rdepends:
672 if rdepend in self.status.ignored_dependencies:
674 if not self.buildRProvider(rdepend, buildAllDeps):
678 def buildDepgraph( self ):
679 all_depends = self.status.all_depends
680 pn_provides = self.status.pn_provides
682 def calc_bbfile_priority(filename):
683 for (regex, pri) in self.status.bbfile_config_priorities:
684 if regex.match(filename):
688 # Handle PREFERRED_PROVIDERS
689 for p in (bb.data.getVar('PREFERRED_PROVIDERS', self.configuration.data, 1) or "").split():
690 (providee, provider) = p.split(':')
691 if providee in self.preferred and self.preferred[providee] != provider:
692 bb.error("conflicting preferences for %s: both %s and %s specified" % (providee, provider, self.preferred[providee]))
693 self.preferred[providee] = provider
695 # Calculate priorities for each file
696 for p in self.pkgdata.keys():
697 self.status.bbfile_priority[p] = calc_bbfile_priority(p)
699 # Build package list for "bitbake world"
700 bb.debug(1, "collating packages for \"world\"")
701 for f in self.status.possible_world:
703 pn = self.status.pkg_fn[f]
705 for p in pn_provides[pn]:
706 if p.startswith('virtual/'):
707 bb.debug(2, "skipping %s due to %s provider starting with virtual/" % (f, p))
710 for pf in self.status.providers[p]:
711 if self.status.pkg_fn[pf] != pn:
712 bb.debug(2, "skipping %s due to both us and %s providing %s" % (f, pf, p))
716 self.status.world_target.add(pn)
718 # drop reference count now
719 self.status.possible_world = None
720 self.status.all_depends = None
722 def myProgressCallback( self, x, y, f, file_data, from_cache ):
723 # feed the status with new input
724 self.status.handle_bb_data(f, file_data, from_cache)
728 if os.isatty(sys.stdout.fileno()):
729 sys.stdout.write("\rNOTE: Handling BitBake files: %s (%04d/%04d) [%2d %%]" % ( parsespin.next(), x, y, x*100/y ) )
733 sys.stdout.write("Parsing .bb files, please wait...")
736 sys.stdout.write("done.")
739 def interactiveMode( self ):
740 """Drop off into a shell"""
743 except ImportError, details:
744 bb.fatal("Sorry, shell not available (%s)" % details )
746 bb.data.update_data( self.configuration.data )
750 def parseConfigurationFile( self, afile ):
752 self.configuration.data = bb.parse.handle( afile, self.configuration.data )
754 bb.fatal( "Unable to open %s" % afile )
755 except bb.parse.ParseError, details:
756 bb.fatal( "Unable to parse %s (%s)" % (afile, details) )
758 def handleCollections( self, collections ):
759 """Handle collections"""
761 collection_list = collections.split()
762 for c in collection_list:
763 regex = bb.data.getVar("BBFILE_PATTERN_%s" % c, self.configuration.data, 1)
765 bb.error("BBFILE_PATTERN_%s not defined" % c)
767 priority = bb.data.getVar("BBFILE_PRIORITY_%s" % c, self.configuration.data, 1)
769 bb.error("BBFILE_PRIORITY_%s not defined" % c)
772 cre = re.compile(regex)
774 bb.error("BBFILE_PATTERN_%s \"%s\" is not a valid regular expression" % (c, regex))
778 self.status.bbfile_config_priorities.append((cre, pri))
780 bb.error("invalid value for BBFILE_PRIORITY_%s: \"%s\"" % (c, priority))
783 def cook( self, configuration, args ):
784 self.configuration = configuration
786 if not self.configuration.cmd:
787 self.configuration.cmd = "build"
789 if self.configuration.debug:
790 bb.debug_level = self.configuration.debug
792 self.configuration.data = bb.data.init()
794 for f in self.configuration.file:
795 self.parseConfigurationFile( f )
797 self.parseConfigurationFile( os.path.join( "conf", "bitbake.conf" ) )
799 if self.configuration.show_environment:
800 self.showEnvironment()
803 # inject custom variables
804 if not bb.data.getVar("BUILDNAME", self.configuration.data):
805 bb.data.setVar("BUILDNAME", os.popen('date +%Y%m%d%H%M').readline().strip(), self.configuration.data)
806 bb.data.setVar("BUILDSTART", time.strftime('%m/%d/%Y %H:%M:%S',time.gmtime()),self.configuration.data)
808 buildname = bb.data.getVar("BUILDNAME", self.configuration.data)
810 if self.configuration.interactive:
811 self.interactiveMode()
813 if self.configuration.buildfile is not None:
814 bf = os.path.abspath( self.configuration.buildfile )
816 bbfile_data = bb.parse.handle(bf, self.configuration.data)
818 bb.fatal("Unable to open %s" % bf)
820 item = bb.data.getVar('PN', bbfile_data, 1)
822 self.tryBuildPackage( bf, item, bbfile_data )
823 except bb.build.EventException:
824 bb.error( "Build of '%s' failed" % item )
826 sys.exit( self.stats.show() )
828 # initialise the parsing status now we know we will need deps
829 self.status = BBParsingStatus()
831 ignore = bb.data.getVar("ASSUME_PROVIDED", self.configuration.data, 1) or ""
832 self.status.ignored_dependencies = Set( ignore.split() )
834 self.handleCollections( bb.data.getVar("BBFILE_COLLECTIONS", self.configuration.data, 1) )
838 if not pkgs_to_build:
840 pkgs_to_build.extend(args)
841 if not pkgs_to_build:
842 bbpkgs = bb.data.getVar('BBPKGS', self.configuration.data, 1)
844 pkgs_to_build = bbpkgs.split()
845 if not pkgs_to_build and not self.configuration.show_versions \
846 and not self.configuration.interactive \
847 and not self.configuration.show_environment:
848 print "Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help'"
849 print "for usage information."
852 # Import Psyco if available and not disabled
853 if not self.configuration.disable_psyco:
858 bb.note("Psyco JIT Compiler (http://psyco.sf.net) not available. Install it to increase performance.")
860 psyco.bind( self.collect_bbfiles )
862 bb.note("You have disabled Psyco. This decreases performance.")
865 bb.debug(1, "collecting .bb files")
866 self.collect_bbfiles( self.myProgressCallback )
867 bb.debug(1, "parsing complete")
870 if self.configuration.parse_only:
871 print "Requested parsing .bb files only. Exiting."
874 bb.data.update_data( self.configuration.data )
877 if self.configuration.show_versions:
880 if 'world' in pkgs_to_build:
881 pkgs_to_build.remove('world')
882 for t in self.status.world_target:
883 pkgs_to_build.append(t)
885 bb.event.fire(bb.event.BuildStarted(buildname, pkgs_to_build, self.configuration.data))
888 for k in pkgs_to_build:
891 if self.buildProvider( k , False ) == 0:
894 except bb.build.EventException:
895 bb.error("Build of " + k + " failed")
900 if self.configuration.abort:
903 bb.event.fire(bb.event.BuildCompleted(buildname, pkgs_to_build, self.configuration.data, failures))
905 sys.exit( self.stats.show() )
907 except KeyboardInterrupt:
908 print "\nNOTE: KeyboardInterrupt - Build not completed."
911 def get_bbfiles( self, path = os.getcwd() ):
912 """Get list of default .bb files by reading out the current directory"""
913 contents = os.listdir(path)
916 (root, ext) = os.path.splitext(f)
918 bbfiles.append(os.path.abspath(os.path.join(os.getcwd(),f)))
921 def find_bbfiles( self, path ):
922 """Find all the .bb files in a directory (uses find)"""
923 findcmd = 'find ' + path + ' -name *.bb | grep -v SCCS/'
925 finddata = os.popen(findcmd)
928 return finddata.readlines()
930 def deps_clean(self, d):
931 depstr = data.getVar('__depends', d)
933 deps = depstr.split(" ")
935 (f,old_mtime_s) = dep.split("@")
936 old_mtime = int(old_mtime_s)
937 new_mtime = parse.cached_mtime(f)
938 if (new_mtime > old_mtime):
942 def load_bbfile( self, bbfile ):
943 """Load and parse one .bb build file"""
945 if not self.cache in [None, '']:
947 cache_mtime = data.init_db_mtime(self.cache, bbfile)
948 file_mtime = parse.cached_mtime(bbfile)
950 if file_mtime > cache_mtime:
951 #print " : '%s' dirty. reparsing..." % bbfile
954 #print " : '%s' clean. loading from cache..." % bbfile
955 cache_data = data.init_db( self.cache, bbfile, False )
956 if self.deps_clean(cache_data):
957 return cache_data, True
959 topdir = data.getVar('TOPDIR', self.configuration.data)
961 topdir = os.path.abspath(os.getcwd())
963 data.setVar('TOPDIR', topdir, self.configuration)
964 bbfile = os.path.abspath(bbfile)
965 bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
966 # expand tmpdir to include this topdir
967 data.setVar('TMPDIR', data.getVar('TMPDIR', self.configuration.data, 1) or "", self.configuration.data)
968 # set topdir to location of .bb file
970 #data.setVar('TOPDIR', topdir, cfg)
972 oldpath = os.path.abspath(os.getcwd())
974 bb = data.init_db(self.cache,bbfile, True, self.configuration.data)
976 parse.handle(bbfile, bb) # read .bb data
977 if not self.cache in [None, '']:
978 bb.commit(parse.cached_mtime(bbfile)) # write cache
984 def collect_bbfiles( self, progressCallback ):
985 """Collect all available .bb build files"""
986 self.cb = progressCallback
987 parsed, cached, skipped, masked = 0, 0, 0, 0
988 self.cache = bb.data.getVar( "CACHE", self.configuration.data, 1 )
989 self.pkgdata = data.pkgdata( not self.cache in [None, ''], self.cache, self.configuration.data )
991 if not self.cache in [None, '']:
992 if self.cb is not None:
993 print "NOTE: Using cache in '%s'" % self.cache
995 os.stat( self.cache )
997 bb.mkdirhier( self.cache )
999 if self.cb is not None:
1000 print "NOTE: Not using a cache. Set CACHE = <directory> to enable."
1001 files = (data.getVar( "BBFILES", self.configuration.data, 1 ) or "").split()
1002 data.setVar("BBFILES", " ".join(files), self.configuration.data)
1005 files = self.get_bbfiles()
1008 bb.error("no files to build.")
1012 if os.path.isdir(f):
1013 dirfiles = self.find_bbfiles(f)
1015 newfiles += dirfiles
1017 newfiles += glob.glob(f) or [ f ]
1019 bbmask = bb.data.getVar('BBMASK', self.configuration.data, 1) or ""
1021 bbmask_compiled = re.compile(bbmask)
1022 except sre_constants.error:
1023 bb.fatal("BBMASK is not a valid regular expression.")
1025 for i in xrange( len( newfiles ) ):
1027 if bbmask and bbmask_compiled.search(f):
1028 bb.debug(1, "bbmake: skipping %s" % f)
1031 debug(1, "bbmake: parsing %s" % f)
1033 # read a file's metadata
1035 bb_data, fromCache = self.load_bbfile(f)
1036 if fromCache: cached += 1
1039 if bb_data is not None:
1040 # allow metadata files to add items to BBFILES
1041 #data.update_data(self.pkgdata[f])
1042 addbbfiles = data.getVar('BBFILES', bb_data) or None
1044 for aof in addbbfiles.split():
1045 if not files.count(aof):
1046 if not os.path.isabs(aof):
1047 aof = os.path.join(os.path.dirname(f),aof)
1049 for var in bb_data.keys():
1050 if data.getVarFlag(var, "handler", bb_data) and data.getVar(var, bb_data):
1051 event.register(data.getVar(var, bb_data))
1052 self.pkgdata[f] = bb_data
1054 # now inform the caller
1055 if self.cb is not None:
1056 self.cb( i + 1, len( newfiles ), f, bb_data, fromCache )
1059 bb.error("opening %s: %s" % (f, e))
1061 except bb.parse.SkipPackage:
1064 except KeyboardInterrupt:
1066 except Exception, e:
1067 bb.error("%s while parsing %s" % (e, f))
1069 if self.cb is not None:
1070 print "\rNOTE: Parsing finished. %d cached, %d parsed, %d skipped, %d masked." % ( cached, parsed, skipped, masked ),
1072 #============================================================================#
1074 #============================================================================#
1076 if __name__ == "__main__":
1078 parser = optparse.OptionParser( version = "BitBake Build Tool Core version %s, %%prog version %s" % ( bb.__version__, __version__ ),
1079 usage = """%prog [options] [package ...]
1081 Executes the specified task (default is 'build') for a given set of BitBake files.
1082 It expects that BBFILES is defined, which is a space seperated list of files to
1083 be executed. BBFILES does support wildcards.
1084 Default BBFILES are the .bb files in the current directory.""" )
1086 parser.add_option( "-b", "--buildfile", help = "execute the task against this .bb file, rather than a package from BBFILES.",
1087 action = "store", dest = "buildfile", default = None )
1089 parser.add_option( "-k", "--continue", help = "continue as much as possible after an error. While the target that failed, and those that depend on it, cannot be remade, the other dependencies of these targets can be processed all the same.",
1090 action = "store_false", dest = "abort", default = True )
1092 parser.add_option( "-f", "--force", help = "force run of specified cmd, regardless of stamp status",
1093 action = "store_true", dest = "force", default = False )
1095 parser.add_option( "-i", "--interactive", help = "drop into the interactive mode.",
1096 action = "store_true", dest = "interactive", default = False )
1098 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)",
1099 action = "store", dest = "cmd", default = "build" )
1101 parser.add_option( "-r", "--read", help = "read the specified file before bitbake.conf",
1102 action = "append", dest = "file", default = [] )
1104 parser.add_option( "-v", "--verbose", help = "output more chit-chat to the terminal",
1105 action = "store_true", dest = "verbose", default = False )
1107 parser.add_option( "-D", "--debug", help = "Increase the debug level",
1108 action = "count", dest="debug", default = 0)
1110 parser.add_option( "-n", "--dry-run", help = "don't execute, just go through the motions",
1111 action = "store_true", dest = "dry_run", default = False )
1113 parser.add_option( "-p", "--parse-only", help = "quit after parsing the BB files (developers only)",
1114 action = "store_true", dest = "parse_only", default = False )
1116 parser.add_option( "-d", "--disable-psyco", help = "disable using the psyco just-in-time compiler (not recommended)",
1117 action = "store_true", dest = "disable_psyco", default = False )
1119 parser.add_option( "-s", "--show-versions", help = "show current and preferred versions of all packages",
1120 action = "store_true", dest = "show_versions", default = False )
1122 parser.add_option( "-e", "--environment", help = "show the global or per-package environment (this is what used to be bbread)",
1123 action = "store_true", dest = "show_environment", default = False )
1125 options, args = parser.parse_args( sys.argv )
1128 cooker.cook( BBConfiguration( options ), args[1:] )