summaryrefslogtreecommitdiffstats
path: root/bitbake/bin
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2005-08-31 10:47:56 +0000
committerRichard Purdie <richard@openedhand.com>2005-08-31 10:47:56 +0000
commitf54da734eb7b69e8e34de505bd89a13479e230e0 (patch)
treef796bea6f5683dfe3d591ca5390d12fd78e59c96 /bitbake/bin
parent4b46c1f6e891b1ddd5968536440b888661fade3e (diff)
downloadpoky-f54da734eb7b69e8e34de505bd89a13479e230e0.tar.gz
Initial population
git-svn-id: https://svn.o-hand.com/repos/poky@2 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/bin')
-rwxr-xr-xbitbake/bin/bbimage154
-rwxr-xr-xbitbake/bin/bitbake927
-rw-r--r--bitbake/bin/bitbakecbin0 -> 27715 bytes
-rwxr-xr-xbitbake/bin/bitdoc529
4 files changed, 1610 insertions, 0 deletions
diff --git a/bitbake/bin/bbimage b/bitbake/bin/bbimage
new file mode 100755
index 0000000000..df6caa28ed
--- /dev/null
+++ b/bitbake/bin/bbimage
@@ -0,0 +1,154 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# Copyright (C) 2003 Chris Larson
6#
7# This program is free software; you can redistribute it and/or modify it under
8# the terms of the GNU General Public License as published by the Free Software
9# Foundation; either version 2 of the License, or (at your option) any later
10# version.
11#
12# This program is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18# Place, Suite 330, Boston, MA 02111-1307 USA.
19
20import sys, os
21sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
22import bb
23from bb import *
24
25__version__ = 1.0
26type = "jffs2"
27cfg_bb = data.init()
28cfg_oespawn = data.init()
29
30
31def usage():
32 print "Usage: bbimage [options ...]"
33 print "Creates an image for a target device from a root filesystem,"
34 print "obeying configuration parameters from the BitBake"
35 print "configuration files, thereby easing handling of deviceisms."
36 print ""
37 print " %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})")
38 print " %s\t\t%s" % ("-t [arg], --type [arg]", "image type (jffs2[default], cramfs)")
39 print " %s\t\t%s" % ("-n [arg], --name [arg]", "image name (override IMAGE_NAME variable)")
40 print " %s\t\t%s" % ("-v, --version", "output version information and exit")
41 sys.exit(0)
42
43def version():
44 print "BitBake Build Tool Core version %s" % bb.__version__
45 print "BBImage version %s" % __version__
46
47def emit_bb(d, base_d = {}):
48 for v in d.keys():
49 if d[v] != base_d[v]:
50 data.emit_var(v, d)
51
52def getopthash(l):
53 h = {}
54 for (opt, val) in l:
55 h[opt] = val
56 return h
57
58import getopt
59try:
60 (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'bbfile=', 'name=' ])
61except getopt.GetoptError:
62 usage()
63
64# handle opts
65opthash = getopthash(opts)
66
67if '--version' in opthash or '-v' in opthash:
68 version()
69 sys.exit(0)
70
71try:
72 cfg_bb = parse.handle(os.path.join('conf', 'bitbake.conf'), cfg_bb)
73except IOError:
74 fatal("Unable to open bitbake.conf")
75
76# sanity check
77if cfg_bb is None:
78 fatal("Unable to open/parse %s" % os.path.join('conf', 'bitbake.conf'))
79 usage(1)
80
81rootfs = None
82extra_files = []
83
84if '--root' in opthash:
85 rootfs = opthash['--root']
86if '-r' in opthash:
87 rootfs = opthash['-r']
88
89if '--type' in opthash:
90 type = opthash['--type']
91if '-t' in opthash:
92 type = opthash['-t']
93
94if '--bbfile' in opthash:
95 extra_files.append(opthash['--bbfile'])
96if '-e' in opthash:
97 extra_files.append(opthash['-e'])
98
99for f in extra_files:
100 try:
101 cfg_bb = parse.handle(f, cfg_bb)
102 except IOError:
103 print "unable to open %s" % f
104
105if not rootfs:
106 rootfs = data.getVar('IMAGE_ROOTFS', cfg_bb, 1)
107
108if not rootfs:
109 bb.fatal("IMAGE_ROOTFS not defined")
110
111data.setVar('IMAGE_ROOTFS', rootfs, cfg_bb)
112
113from copy import copy, deepcopy
114localdata = data.createCopy(cfg_bb)
115
116overrides = data.getVar('OVERRIDES', localdata)
117if not overrides:
118 bb.fatal("OVERRIDES not defined.")
119data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata)
120data.update_data(localdata)
121data.setVar('OVERRIDES', overrides, localdata)
122
123if '-n' in opthash:
124 data.setVar('IMAGE_NAME', opthash['-n'], localdata)
125if '--name' in opthash:
126 data.setVar('IMAGE_NAME', opthash['--name'], localdata)
127
128topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()
129
130cmd = data.getVar('IMAGE_CMD', localdata, 1)
131if not cmd:
132 bb.fatal("IMAGE_CMD not defined")
133
134outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
135if not outdir:
136 bb.fatal('DEPLOY_DIR_IMAGE not defined')
137mkdirhier(outdir)
138
139#depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or ""
140#if depends:
141# bb.note("Spawning bbmake to satisfy dependencies: %s" % depends)
142# ret = os.system('bbmake %s' % depends)
143# if ret != 0:
144# bb.error("executing bbmake to satisfy dependencies")
145
146bb.note("Executing %s" % cmd)
147data.setVar('image_cmd', cmd, localdata)
148data.setVarFlag('image_cmd', 'func', 1, localdata)
149try:
150 bb.build.exec_func('image_cmd', localdata)
151except bb.build.FuncFailed:
152 sys.exit(1)
153#ret = os.system(cmd)
154#sys.exit(ret)
diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake
new file mode 100755
index 0000000000..d327a69ab8
--- /dev/null
+++ b/bitbake/bin/bitbake
@@ -0,0 +1,927 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
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
10#
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
14# version.
15#
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.
19#
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.
23
24import sys, os, getopt, glob, copy, os.path, re, time
25sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
26import bb
27from bb import utils, data, parse, debug, event, fatal
28from sets import Set
29import itertools, optparse
30
31parsespin = itertools.cycle( r'|/-\\' )
32bbdebug = 0
33
34__version__ = "1.3.2"
35
36#============================================================================#
37# BBParsingStatus
38#============================================================================#
39class BBParsingStatus:
40 """
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
43 again.
44 """
45
46 def __init__(self):
47 self.cache_dirty = False
48 self.providers = {}
49 self.bbfile_priority = {}
50 self.bbfile_config_priorities = []
51 self.ignored_depedencies = None
52 self.possible_world = []
53 self.world_target = Set()
54 self.pkg_pn = {}
55 self.pkg_fn = {}
56 self.pkg_pvpr = {}
57 self.pkg_dp = {}
58 self.pn_provides = {}
59 self.all_depends = Set()
60
61 def handle_bb_data(self, file_name, bb_data, cached):
62 """
63 We will fill the dictionaries with the stuff we
64 need for building the tree more fast
65 """
66 if bb_data == None:
67 return
68
69 if not cached:
70 self.cache_dirty = True
71
72 pn = bb.data.getVar('PN', bb_data, True)
73 pv = bb.data.getVar('PV', bb_data, True)
74 pr = bb.data.getVar('PR', bb_data, True)
75 dp = int(bb.data.getVar('DEFAULT_PREFERENCE', bb_data, True) or "0")
76 provides = Set([pn] + (bb.data.getVar("PROVIDES", bb_data, 1) or "").split())
77 depends = (bb.data.getVar("DEPENDS", bb_data, True) or "").split()
78
79
80 # build PackageName to FileName lookup table
81 if pn not in self.pkg_pn:
82 self.pkg_pn[pn] = []
83 self.pkg_pn[pn].append(file_name)
84
85 # build FileName to PackageName lookup table
86 self.pkg_fn[file_name] = pn
87 self.pkg_pvpr[file_name] = (pv,pr)
88 self.pkg_dp[file_name] = dp
89
90 # Build forward and reverse provider hashes
91 # Forward: virtual -> [filenames]
92 # Reverse: PN -> [virtuals]
93 if pn not in self.pn_provides:
94 self.pn_provides[pn] = Set()
95 self.pn_provides[pn] |= provides
96
97 for provide in provides:
98 if provide not in self.providers:
99 self.providers[provide] = []
100 self.providers[provide].append(file_name)
101
102 for dep in depends:
103 self.all_depends.add(dep)
104
105 # Collect files we may need for possible world-dep
106 # calculations
107 if not bb.data.getVar('BROKEN', bb_data, True) and not bb.data.getVar('EXCLUDE_FROM_WORLD', bb_data, True):
108 self.possible_world.append(file_name)
109
110
111#============================================================================#
112# BBStatistics
113#============================================================================#
114class BBStatistics:
115 """
116 Manage build statistics for one run
117 """
118 def __init__(self ):
119 self.attempt = 0
120 self.success = 0
121 self.fail = 0
122 self.deps = 0
123
124 def show( self ):
125 print "Build statistics:"
126 print " Attempted builds: %d" % self.attempt
127 if self.fail:
128 print " Failed builds: %d" % self.fail
129 if self.deps:
130 print " Dependencies not satisfied: %d" % self.deps
131 if self.fail or self.deps: return 1
132 else: return 0
133
134
135#============================================================================#
136# BBOptions
137#============================================================================#
138class BBConfiguration( object ):
139 """
140 Manages build options and configurations for one run
141 """
142 def __init__( self, options ):
143 for key, val in options.__dict__.items():
144 setattr( self, key, val )
145 self.data = data.init()
146
147#============================================================================#
148# BBCooker
149#============================================================================#
150class BBCooker:
151 """
152 Manages one bitbake build run
153 """
154
155 ParsingStatus = BBParsingStatus # make it visible from the shell
156 Statistics = BBStatistics # make it visible from the shell
157
158 def __init__( self ):
159 self.build_cache_fail = []
160 self.build_cache = []
161 self.building_list = []
162 self.build_path = []
163 self.consider_msgs_cache = []
164 self.preferred = {}
165 self.stats = BBStatistics()
166 self.status = None
167
168 self.pkgdata = None
169 self.cache = None
170
171 def tryBuildPackage( self, fn, item, the_data ):
172 """Build one package"""
173 bb.event.fire(bb.event.PkgStarted(item, the_data))
174 try:
175 self.stats.attempt += 1
176 if self.configuration.force:
177 bb.data.setVarFlag('do_%s' % self.configuration.cmd, 'force', 1, the_data)
178 if not self.configuration.dry_run:
179 bb.build.exec_task('do_%s' % self.configuration.cmd, the_data)
180 bb.event.fire(bb.event.PkgSucceeded(item, the_data))
181 self.build_cache.append(fn)
182 return True
183 except bb.build.FuncFailed:
184 self.stats.fail += 1
185 bb.error("task stack execution failed")
186 bb.event.fire(bb.event.PkgFailed(item, the_data))
187 self.build_cache_fail.append(fn)
188 raise
189 except bb.build.EventException, e:
190 self.stats.fail += 1
191 event = e.args[1]
192 bb.error("%s event exception, aborting" % bb.event.getName(event))
193 bb.event.fire(bb.event.PkgFailed(item, the_data))
194 self.build_cache_fail.append(fn)
195 raise
196
197 def tryBuild( self, fn, virtual ):
198 """Build a provider and its dependencies"""
199 if fn in self.building_list:
200 bb.error("%s depends on itself (eventually)" % fn)
201 bb.error("upwards chain is: %s" % (" -> ".join(self.build_path)))
202 return False
203
204 the_data = self.pkgdata[fn]
205 item = self.status.pkg_fn[fn]
206
207 self.building_list.append(fn)
208
209 pathstr = "%s (%s)" % (item, virtual)
210 self.build_path.append(pathstr)
211
212 depends_list = (bb.data.getVar('DEPENDS', the_data, 1) or "").split()
213 if self.configuration.verbose:
214 bb.note("current path: %s" % (" -> ".join(self.build_path)))
215 bb.note("dependencies for %s are: %s" % (item, " ".join(depends_list)))
216
217 try:
218 failed = False
219
220 depcmd = self.configuration.cmd
221 bbdepcmd = bb.data.getVarFlag('do_%s' % self.configuration.cmd, 'bbdepcmd', the_data)
222 if bbdepcmd is not None:
223 if bbdepcmd == "":
224 depcmd = None
225 else:
226 depcmd = bbdepcmd
227
228 if depcmd:
229 oldcmd = self.configuration.cmd
230 self.configuration.cmd = depcmd
231
232 for dependency in depends_list:
233 if dependency in self.status.ignored_dependencies:
234 continue
235 if not depcmd:
236 continue
237 if self.buildProvider( dependency ) == 0:
238 bb.error("dependency %s (for %s) not satisfied" % (dependency,item))
239 failed = True
240 if self.configuration.abort:
241 break
242
243 if depcmd:
244 self.configuration.cmd = oldcmd
245
246 if failed:
247 self.stats.deps += 1
248 return False
249
250 if bb.build.stamp_is_current('do_%s' % self.configuration.cmd, the_data):
251 self.build_cache.append(fn)
252 return True
253
254 return self.tryBuildPackage( fn, item, the_data )
255
256 finally:
257 self.building_list.remove(fn)
258 self.build_path.remove(pathstr)
259
260 def findBestProvider( self, pn, pkg_pn = None):
261 """
262 If there is a PREFERRED_VERSION, find the highest-priority bbfile
263 providing that version. If not, find the latest version provided by
264 an bbfile in the highest-priority set.
265 """
266 if not pkg_pn:
267 pkg_pn = self.status.pkg_pn
268
269 files = pkg_pn[pn]
270 priorities = {}
271 for f in files:
272 priority = self.status.bbfile_priority[f]
273 if priority not in priorities:
274 priorities[priority] = []
275 priorities[priority].append(f)
276 p_list = priorities.keys()
277 p_list.sort(lambda a, b: a - b)
278 tmp_pn = []
279 for p in p_list:
280 tmp_pn = [priorities[p]] + tmp_pn
281
282 preferred_file = None
283
284 preferred_v = bb.data.getVar('PREFERRED_VERSION_%s' % pn, self.configuration.data, 1)
285 if preferred_v:
286 m = re.match('(.*)_(.*)', preferred_v)
287 if m:
288 preferred_v = m.group(1)
289 preferred_r = m.group(2)
290 else:
291 preferred_r = None
292
293 for file_set in tmp_pn:
294 for f in file_set:
295 pv,pr = self.status.pkg_pvpr[f]
296 if preferred_v == pv and (preferred_r == pr or preferred_r == None):
297 preferred_file = f
298 preferred_ver = (pv, pr)
299 break
300 if preferred_file:
301 break;
302 if preferred_r:
303 pv_str = '%s-%s' % (preferred_v, preferred_r)
304 else:
305 pv_str = preferred_v
306 if preferred_file is None:
307 bb.note("preferred version %s of %s not available" % (pv_str, pn))
308 else:
309 bb.debug(1, "selecting %s as PREFERRED_VERSION %s of package %s" % (preferred_file, pv_str, pn))
310
311 # get highest priority file set
312 files = tmp_pn[0]
313 latest = None
314 latest_p = 0
315 latest_f = None
316 for file_name in files:
317 pv,pr = self.status.pkg_pvpr[file_name]
318 dp = self.status.pkg_dp[file_name]
319
320 if (latest is None) or ((latest_p == dp) and (utils.vercmp(latest, (pv, pr)) < 0)) or (dp > latest_p):
321 latest = (pv, pr)
322 latest_f = file_name
323 latest_p = dp
324 if preferred_file is None:
325 preferred_file = latest_f
326 preferred_ver = latest
327
328 return (latest,latest_f,preferred_ver, preferred_file)
329
330 def showVersions( self ):
331 pkg_pn = self.status.pkg_pn
332 preferred_versions = {}
333 latest_versions = {}
334
335 # Sort by priority
336 for pn in pkg_pn.keys():
337 (last_ver,last_file,pref_ver,pref_file) = self.findBestProvider(pn)
338 preferred_versions[pn] = (pref_ver, pref_file)
339 latest_versions[pn] = (last_ver, last_file)
340
341 pkg_list = pkg_pn.keys()
342 pkg_list.sort()
343
344 for p in pkg_list:
345 pref = preferred_versions[p]
346 latest = latest_versions[p]
347
348 if pref != latest:
349 prefstr = pref[0][0] + "-" + pref[0][1]
350 else:
351 prefstr = ""
352
353 print "%-30s %20s %20s" % (p, latest[0][0] + "-" + latest[0][1],
354 prefstr)
355
356 def showEnvironment( self ):
357 """Show the outer or per-package environment"""
358 if self.configuration.buildfile:
359 try:
360 self.configuration.data, fromCache = self.load_bbfile( self.configuration.buildfile )
361 except IOError, e:
362 fatal("Unable to read %s: %s" % ( self.configuration.buildfile, e ))
363 except Exception, e:
364 fatal("%s" % e)
365 # emit variables and shell functions
366 try:
367 data.update_data( self.configuration.data )
368 data.emit_env(sys.__stdout__, self.configuration.data, True)
369 except Exception, e:
370 fatal("%s" % e)
371 # emit the metadata which isnt valid shell
372 for e in self.configuration.data.keys():
373 if data.getVarFlag( e, 'python', self.configuration.data ):
374 sys.__stdout__.write("\npython %s () {\n%s}\n" % (e, data.getVar(e, self.configuration.data, 1)))
375
376 def buildProvider( self, item ):
377 fn = None
378
379 discriminated = False
380
381 if item not in self.status.providers:
382 bb.error("Nothing provides %s" % item)
383 return 0
384
385 all_p = self.status.providers[item]
386
387 for p in all_p:
388 if p in self.build_cache:
389 bb.debug(1, "already built %s in this run\n" % p)
390 return 1
391
392 eligible = []
393 preferred_versions = {}
394
395 # Collate providers by PN
396 pkg_pn = {}
397 for p in all_p:
398 pn = self.status.pkg_fn[p]
399 if pn not in pkg_pn:
400 pkg_pn[pn] = []
401 pkg_pn[pn].append(p)
402
403 bb.debug(1, "providers for %s are: %s" % (item, pkg_pn.keys()))
404
405 for pn in pkg_pn.keys():
406 preferred_versions[pn] = self.findBestProvider(pn, pkg_pn)[2:4]
407 eligible.append(preferred_versions[pn][1])
408
409 for p in eligible:
410 if p in self.build_cache_fail:
411 bb.debug(1, "rejecting already-failed %s" % p)
412 eligible.remove(p)
413
414 if len(eligible) == 0:
415 bb.error("no eligible providers for %s" % item)
416 return 0
417
418 # look to see if one of them is already staged, or marked as preferred.
419 # if so, bump it to the head of the queue
420 for p in all_p:
421 the_data = self.pkgdata[p]
422 pn = bb.data.getVar('PN', the_data, 1)
423 pv = bb.data.getVar('PV', the_data, 1)
424 pr = bb.data.getVar('PR', the_data, 1)
425 tmpdir = bb.data.getVar('TMPDIR', the_data, 1)
426 stamp = '%s/stamps/%s-%s-%s.do_populate_staging' % (tmpdir, pn, pv, pr)
427 if os.path.exists(stamp):
428 (newvers, fn) = preferred_versions[pn]
429 if not fn in eligible:
430 # package was made ineligible by already-failed check
431 continue
432 oldver = "%s-%s" % (pv, pr)
433 newver = '-'.join(newvers)
434 if (newver != oldver):
435 extra_chat = "; upgrading from %s to %s" % (oldver, newver)
436 else:
437 extra_chat = ""
438 if self.configuration.verbose:
439 bb.note("selecting already-staged %s to satisfy %s%s" % (pn, item, extra_chat))
440 eligible.remove(fn)
441 eligible = [fn] + eligible
442 discriminated = True
443 break
444
445 prefervar = bb.data.getVar('PREFERRED_PROVIDER_%s' % item, self.configuration.data, 1)
446 if prefervar:
447 self.preferred[item] = prefervar
448
449 if item in self.preferred:
450 for p in eligible:
451 pn = self.status.pkg_fn[p]
452 if self.preferred[item] == pn:
453 if self.configuration.verbose:
454 bb.note("selecting %s to satisfy %s due to PREFERRED_PROVIDERS" % (pn, item))
455 eligible.remove(p)
456 eligible = [p] + eligible
457 discriminated = True
458 break
459
460 if len(eligible) > 1 and discriminated == False:
461 if item not in self.consider_msgs_cache:
462 providers_list = []
463 for fn in eligible:
464 providers_list.append(self.status.pkg_fn[fn])
465 bb.note("multiple providers are available (%s);" % ", ".join(providers_list))
466 bb.note("consider defining PREFERRED_PROVIDER_%s" % item)
467 self.consider_msgs_cache.append(item)
468
469
470 # run through the list until we find one that we can build
471 for fn in eligible:
472 bb.debug(2, "selecting %s to satisfy %s" % (fn, item))
473 if self.tryBuild(fn, item):
474 return 1
475
476 bb.note("no buildable providers for %s" % item)
477 return 0
478
479 def buildDepgraph( self ):
480 all_depends = self.status.all_depends
481 pn_provides = self.status.pn_provides
482
483 def calc_bbfile_priority(filename):
484 for (regex, pri) in self.status.bbfile_config_priorities:
485 if regex.match(filename):
486 return pri
487 return 0
488
489 # Handle PREFERRED_PROVIDERS
490 for p in (bb.data.getVar('PREFERRED_PROVIDERS', self.configuration.data, 1) or "").split():
491 (providee, provider) = p.split(':')
492 if providee in self.preferred and self.preferred[providee] != provider:
493 bb.error("conflicting preferences for %s: both %s and %s specified" % (providee, provider, self.preferred[providee]))
494 self.preferred[providee] = provider
495
496 # Calculate priorities for each file
497 for p in self.pkgdata.keys():
498 self.status.bbfile_priority[p] = calc_bbfile_priority(p)
499
500 # Build package list for "bitbake world"
501 bb.debug(1, "collating packages for \"world\"")
502 for f in self.status.possible_world:
503 terminal = True
504 pn = self.status.pkg_fn[f]
505
506 for p in pn_provides[pn]:
507 if p.startswith('virtual/'):
508 bb.debug(2, "skipping %s due to %s provider starting with virtual/" % (f, p))
509 terminal = False
510 break
511 for pf in self.status.providers[p]:
512 if self.status.pkg_fn[pf] != pn:
513 bb.debug(2, "skipping %s due to both us and %s providing %s" % (f, pf, p))
514 terminal = False
515 break
516 if terminal:
517 self.status.world_target.add(pn)
518
519 # drop reference count now
520 self.status.possible_world = None
521 self.status.all_depends = None
522
523 def myProgressCallback( self, x, y, f, file_data, from_cache ):
524 # feed the status with new input
525 self.status.handle_bb_data(f, file_data, from_cache)
526
527 if bbdebug > 0:
528 return
529 if os.isatty(sys.stdout.fileno()):
530 sys.stdout.write("\rNOTE: Handling BitBake files: %s (%04d/%04d) [%2d %%]" % ( parsespin.next(), x, y, x*100/y ) )
531 sys.stdout.flush()
532 else:
533 if x == 1:
534 sys.stdout.write("Parsing .bb files, please wait...")
535 sys.stdout.flush()
536 if x == y:
537 sys.stdout.write("done.")
538 sys.stdout.flush()
539
540 def interactiveMode( self ):
541 """Drop off into a shell"""
542 try:
543 from bb import shell
544 except ImportError, details:
545 bb.fatal("Sorry, shell not available (%s)" % details )
546 else:
547 bb.data.update_data( self.configuration.data )
548 shell.start( self )
549 sys.exit( 0 )
550
551 def parseConfigurationFile( self, afile ):
552 try:
553 self.configuration.data = bb.parse.handle( afile, self.configuration.data )
554 except IOError:
555 bb.fatal( "Unable to open %s" % afile )
556 except bb.parse.ParseError, details:
557 bb.fatal( "Unable to parse %s (%s)" % (afile, details) )
558
559 def handleCollections( self, collections ):
560 """Handle collections"""
561 if collections:
562 collection_list = collections.split()
563 for c in collection_list:
564 regex = bb.data.getVar("BBFILE_PATTERN_%s" % c, self.configuration.data, 1)
565 if regex == None:
566 bb.error("BBFILE_PATTERN_%s not defined" % c)
567 continue
568 priority = bb.data.getVar("BBFILE_PRIORITY_%s" % c, self.configuration.data, 1)
569 if priority == None:
570 bb.error("BBFILE_PRIORITY_%s not defined" % c)
571 continue
572 try:
573 cre = re.compile(regex)
574 except re.error:
575 bb.error("BBFILE_PATTERN_%s \"%s\" is not a valid regular expression" % (c, regex))
576 continue
577 try:
578 pri = int(priority)
579 self.status.bbfile_config_priorities.append((cre, pri))
580 except ValueError:
581 bb.error("invalid value for BBFILE_PRIORITY_%s: \"%s\"" % (c, priority))
582
583
584 def cook( self, configuration, args ):
585 self.configuration = configuration
586
587 if not self.configuration.cmd:
588 self.configuration.cmd = "build"
589
590 if self.configuration.debug:
591 bb.debug_level = self.configuration.debug
592
593 self.configuration.data = bb.data.init()
594
595 for f in self.configuration.file:
596 self.parseConfigurationFile( f )
597
598 self.parseConfigurationFile( os.path.join( "conf", "bitbake.conf" ) )
599
600 if self.configuration.show_environment:
601 self.showEnvironment()
602 sys.exit( 0 )
603
604 # inject custom variables
605 if not bb.data.getVar("BUILDNAME", self.configuration.data):
606 bb.data.setVar("BUILDNAME", os.popen('date +%Y%m%d%H%M').readline().strip(), self.configuration.data)
607 bb.data.setVar("BUILDSTART", time.strftime('%m/%d/%Y %H:%M:%S',time.gmtime()),self.configuration.data)
608
609 buildname = bb.data.getVar("BUILDNAME", self.configuration.data)
610
611 if self.configuration.interactive:
612 self.interactiveMode()
613
614 if self.configuration.buildfile is not None:
615 bf = os.path.abspath( self.configuration.buildfile )
616 try:
617 bbfile_data = bb.parse.handle(bf, self.configuration.data)
618 except IOError:
619 bb.fatal("Unable to open %s" % bf)
620
621 item = bb.data.getVar('PN', bbfile_data, 1)
622 try:
623 self.tryBuildPackage( bf, item, bbfile_data )
624 except bb.build.EventException:
625 bb.error( "Build of '%s' failed" % item )
626
627 sys.exit( self.stats.show() )
628
629 # initialise the parsing status now we know we will need deps
630 self.status = BBParsingStatus()
631
632 ignore = bb.data.getVar("ASSUME_PROVIDED", self.configuration.data, 1) or ""
633 self.status.ignored_dependencies = Set( ignore.split() )
634
635 self.handleCollections( bb.data.getVar("BBFILE_COLLECTIONS", self.configuration.data, 1) )
636
637 pkgs_to_build = None
638 if args:
639 if not pkgs_to_build:
640 pkgs_to_build = []
641 pkgs_to_build.extend(args)
642 if not pkgs_to_build:
643 bbpkgs = bb.data.getVar('BBPKGS', self.configuration.data, 1)
644 if bbpkgs:
645 pkgs_to_build = bbpkgs.split()
646 if not pkgs_to_build and not self.configuration.show_versions \
647 and not self.configuration.interactive \
648 and not self.configuration.show_environment:
649 print "Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help'"
650 print "for usage information."
651 sys.exit(0)
652
653 # Import Psyco if available and not disabled
654 if not self.configuration.disable_psyco:
655 try:
656 import psyco
657 except ImportError:
658 if bbdebug == 0:
659 bb.note("Psyco JIT Compiler (http://psyco.sf.net) not available. Install it to increase performance.")
660 else:
661 psyco.bind( self.collect_bbfiles )
662 else:
663 bb.note("You have disabled Psyco. This decreases performance.")
664
665 try:
666 bb.debug(1, "collecting .bb files")
667 self.collect_bbfiles( self.myProgressCallback )
668 bb.debug(1, "parsing complete")
669 if bbdebug == 0:
670 print
671 if self.configuration.parse_only:
672 print "Requested parsing .bb files only. Exiting."
673 return
674
675 bb.data.update_data( self.configuration.data )
676 self.buildDepgraph()
677
678 if self.configuration.show_versions:
679 self.showVersions()
680 sys.exit( 0 )
681 if 'world' in pkgs_to_build:
682 pkgs_to_build.remove('world')
683 for t in self.status.world_target:
684 pkgs_to_build.append(t)
685
686 bb.event.fire(bb.event.BuildStarted(buildname, pkgs_to_build, self.configuration.data))
687
688 for k in pkgs_to_build:
689 failed = False
690 try:
691 if self.buildProvider( k ) == 0:
692 # already diagnosed
693 failed = True
694 except bb.build.EventException:
695 bb.error("Build of " + k + " failed")
696 failed = True
697
698 if failed:
699 if self.configuration.abort:
700 sys.exit(1)
701
702 bb.event.fire(bb.event.BuildCompleted(buildname, pkgs_to_build, self.configuration.data))
703
704 sys.exit( self.stats.show() )
705
706 except KeyboardInterrupt:
707 print "\nNOTE: KeyboardInterrupt - Build not completed."
708 sys.exit(1)
709
710 def get_bbfiles( self, path = os.getcwd() ):
711 """Get list of default .bb files by reading out the current directory"""
712 contents = os.listdir(path)
713 bbfiles = []
714 for f in contents:
715 (root, ext) = os.path.splitext(f)
716 if ext == ".bb":
717 bbfiles.append(os.path.abspath(os.path.join(os.getcwd(),f)))
718 return bbfiles
719
720 def find_bbfiles( self, path ):
721 """Find all the .bb files in a directory (uses find)"""
722 findcmd = 'find ' + path + ' -name *.bb | grep -v SCCS/'
723 try:
724 finddata = os.popen(findcmd)
725 except OSError:
726 return []
727 return finddata.readlines()
728
729 def deps_clean(self, d):
730 depstr = data.getVar('__depends', d)
731 if depstr:
732 deps = depstr.split(" ")
733 for dep in deps:
734 (f,old_mtime_s) = dep.split("@")
735 old_mtime = int(old_mtime_s)
736 new_mtime = parse.cached_mtime(f)
737 if (new_mtime > old_mtime):
738 return False
739 return True
740
741 def load_bbfile( self, bbfile ):
742 """Load and parse one .bb build file"""
743
744 if not self.cache in [None, '']:
745 # get the times
746 cache_mtime = data.init_db_mtime(self.cache, bbfile)
747 file_mtime = parse.cached_mtime(bbfile)
748
749 if file_mtime > cache_mtime:
750 #print " : '%s' dirty. reparsing..." % bbfile
751 pass
752 else:
753 #print " : '%s' clean. loading from cache..." % bbfile
754 cache_data = data.init_db( self.cache, bbfile, False )
755 if self.deps_clean(cache_data):
756 return cache_data, True
757
758 topdir = data.getVar('TOPDIR', self.configuration.data)
759 if not topdir:
760 topdir = os.path.abspath(os.getcwd())
761 # set topdir to here
762 data.setVar('TOPDIR', topdir, self.configuration)
763 bbfile = os.path.abspath(bbfile)
764 bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
765 # expand tmpdir to include this topdir
766 data.setVar('TMPDIR', data.getVar('TMPDIR', self.configuration.data, 1) or "", self.configuration.data)
767 # set topdir to location of .bb file
768 topdir = bbfile_loc
769 #data.setVar('TOPDIR', topdir, cfg)
770 # go there
771 oldpath = os.path.abspath(os.getcwd())
772 os.chdir(topdir)
773 bb = data.init_db(self.cache,bbfile, True, self.configuration.data)
774 try:
775 parse.handle(bbfile, bb) # read .bb data
776 if not self.cache in [None, '']:
777 bb.commit(parse.cached_mtime(bbfile)) # write cache
778 os.chdir(oldpath)
779 return bb, False
780 finally:
781 os.chdir(oldpath)
782
783 def collect_bbfiles( self, progressCallback ):
784 """Collect all available .bb build files"""
785 self.cb = progressCallback
786 parsed, cached, skipped, masked = 0, 0, 0, 0
787 self.cache = bb.data.getVar( "CACHE", self.configuration.data, 1 )
788 self.pkgdata = data.pkgdata( not self.cache in [None, ''], self.cache, self.configuration.data )
789
790 if not self.cache in [None, '']:
791 if self.cb is not None:
792 print "NOTE: Using cache in '%s'" % self.cache
793 try:
794 os.stat( self.cache )
795 except OSError:
796 bb.mkdirhier( self.cache )
797 else:
798 if self.cb is not None:
799 print "NOTE: Not using a cache. Set CACHE = <directory> to enable."
800 files = (data.getVar( "BBFILES", self.configuration.data, 1 ) or "").split()
801 data.setVar("BBFILES", " ".join(files), self.configuration.data)
802
803 if not len(files):
804 files = self.get_bbfiles()
805
806 if not len(files):
807 bb.error("no files to build.")
808
809 newfiles = []
810 for f in files:
811 if os.path.isdir(f):
812 dirfiles = self.find_bbfiles(f)
813 if dirfiles:
814 newfiles += dirfiles
815 continue
816 newfiles += glob.glob(f) or [ f ]
817
818 bbmask = bb.data.getVar('BBMASK', self.configuration.data, 1) or ""
819 try:
820 bbmask_compiled = re.compile(bbmask)
821 except sre_constants.error:
822 bb.fatal("BBMASK is not a valid regular expression.")
823
824 for i in xrange( len( newfiles ) ):
825 f = newfiles[i]
826 if bbmask and bbmask_compiled.search(f):
827 bb.debug(1, "bbmake: skipping %s" % f)
828 masked += 1
829 continue
830 debug(1, "bbmake: parsing %s" % f)
831
832 # read a file's metadata
833 try:
834 bb_data, fromCache = self.load_bbfile(f)
835 if fromCache: cached += 1
836 else: parsed += 1
837 deps = None
838 if bb_data is not None:
839 # allow metadata files to add items to BBFILES
840 #data.update_data(self.pkgdata[f])
841 addbbfiles = data.getVar('BBFILES', bb_data) or None
842 if addbbfiles:
843 for aof in addbbfiles.split():
844 if not files.count(aof):
845 if not os.path.isabs(aof):
846 aof = os.path.join(os.path.dirname(f),aof)
847 files.append(aof)
848 for var in bb_data.keys():
849 if data.getVarFlag(var, "handler", bb_data) and data.getVar(var, bb_data):
850 event.register(data.getVar(var, bb_data))
851 self.pkgdata[f] = bb_data
852
853 # now inform the caller
854 if self.cb is not None:
855 self.cb( i + 1, len( newfiles ), f, bb_data, fromCache )
856
857 except IOError, e:
858 bb.error("opening %s: %s" % (f, e))
859 pass
860 except bb.parse.SkipPackage:
861 skipped += 1
862 pass
863 except KeyboardInterrupt:
864 raise
865 except Exception, e:
866 bb.error("%s while parsing %s" % (e, f))
867
868 if self.cb is not None:
869 print "\rNOTE: Parsing finished. %d cached, %d parsed, %d skipped, %d masked." % ( cached, parsed, skipped, masked ),
870
871#============================================================================#
872# main
873#============================================================================#
874
875if __name__ == "__main__":
876
877 parser = optparse.OptionParser( version = "BitBake Build Tool Core version %s, %%prog version %s" % ( bb.__version__, __version__ ),
878 usage = """%prog [options] [package ...]
879
880Executes the specified task (default is 'build') for a given set of BitBake files.
881It expects that BBFILES is defined, which is a space seperated list of files to
882be executed. BBFILES does support wildcards.
883Default BBFILES are the .bb files in the current directory.""" )
884
885 parser.add_option( "-b", "--buildfile", help = "execute the task against this .bb file, rather than a package from BBFILES.",
886 action = "store", dest = "buildfile", default = None )
887
888 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.",
889 action = "store_false", dest = "abort", default = True )
890
891 parser.add_option( "-f", "--force", help = "force run of specified cmd, regardless of stamp status",
892 action = "store_true", dest = "force", default = False )
893
894 parser.add_option( "-i", "--interactive", help = "drop into the interactive mode.",
895 action = "store_true", dest = "interactive", default = False )
896
897 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)",
898 action = "store", dest = "cmd", default = "build" )
899
900 parser.add_option( "-r", "--read", help = "read the specified file before bitbake.conf",
901 action = "append", dest = "file", default = [] )
902
903 parser.add_option( "-v", "--verbose", help = "output more chit-chat to the terminal",
904 action = "store_true", dest = "verbose", default = False )
905
906 parser.add_option( "-D", "--debug", help = "Increase the debug level",
907 action = "count", dest="debug", default = 0)
908
909 parser.add_option( "-n", "--dry-run", help = "don't execute, just go through the motions",
910 action = "store_true", dest = "dry_run", default = False )
911
912 parser.add_option( "-p", "--parse-only", help = "quit after parsing the BB files (developers only)",
913 action = "store_true", dest = "parse_only", default = False )
914
915 parser.add_option( "-d", "--disable-psyco", help = "disable using the psyco just-in-time compiler (not recommended)",
916 action = "store_true", dest = "disable_psyco", default = False )
917
918 parser.add_option( "-s", "--show-versions", help = "show current and preferred versions of all packages",
919 action = "store_true", dest = "show_versions", default = False )
920
921 parser.add_option( "-e", "--environment", help = "show the global or per-package environment (this is what used to be bbread)",
922 action = "store_true", dest = "show_environment", default = False )
923
924 options, args = parser.parse_args( sys.argv )
925
926 cooker = BBCooker()
927 cooker.cook( BBConfiguration( options ), args[1:] )
diff --git a/bitbake/bin/bitbakec b/bitbake/bin/bitbakec
new file mode 100644
index 0000000000..dc2e0a9fa9
--- /dev/null
+++ b/bitbake/bin/bitbakec
Binary files differ
diff --git a/bitbake/bin/bitdoc b/bitbake/bin/bitdoc
new file mode 100755
index 0000000000..64d32945ba
--- /dev/null
+++ b/bitbake/bin/bitdoc
@@ -0,0 +1,529 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# Copyright (C) 2005 Holger Hans Peter Freyther
6#
7#
8# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and associated documentation files (the "Software"), to deal
10# in the Software without restriction, including without limitation the rights
11# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12# copies of the Software, and to permit persons to whom the Software is
13# furnished to do so, subject to the following conditions:
14#
15# The above copyright notice and this permission notice shall be included in all
16# copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
24# THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25#
26#
27
28import optparse, os, sys
29
30# bitbake
31sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
32import bb
33from bb import make
34from string import split, join
35
36__version__ = "0.0.2"
37
38class HTMLFormatter:
39 """
40 Simple class to help to generate some sort of HTML files. It is
41 quite inferior solution compared to docbook, gtkdoc, doxygen but it
42 should work for now.
43 We've a global introduction site (index.html) and then one site for
44 the list of keys (alphabetical sorted) and one for the list of groups,
45 one site for each key with links to the relations and groups.
46
47 index.html
48 keys.html
49 groups.html
50 groupNAME.html
51 keyNAME.html
52 """
53
54 def replace(self, text, *pairs):
55 """
56 From pydoc... almost identical at least
57 """
58 while pairs:
59 (a,b) = pairs[0]
60 text = join(split(text, a), b)
61 pairs = pairs[1:]
62 return text
63 def escape(self, text):
64 """
65 Escape string to be conform HTML
66 """
67 return self.replace(text,
68 ('&', '&amp;'),
69 ('<', '&lt;' ),
70 ('>', '&gt;' ) )
71 def createNavigator(self):
72 """
73 Create the navgiator
74 """
75 return """<table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
76<tr valign="middle">
77<td><a accesskey="g" href="index.html">Home</a></td>
78<td><a accesskey="n" href="groups.html">Groups</a></td>
79<td><a accesskey="u" href="keys.html">Keys</a></td>
80</tr></table>
81"""
82
83 def relatedKeys(self, item):
84 """
85 Create HTML to link to foreign keys
86 """
87
88 if len(item.related()) == 0:
89 return ""
90
91 txt = "<p><b>See also:</b><br>"
92 for it in item.related():
93 txt += """<a href="key%s.html">%s</a>, """ % (it, it)
94
95 return txt
96
97 def groups(self,item):
98 """
99 Create HTML to link to related groups
100 """
101
102 if len(item.groups()) == 0:
103 return ""
104
105
106 txt = "<p><b>Seel also:</b><br>"
107 for group in item.groups():
108 txt += """<a href="group%s.html">%s</a>, """ % (group,group)
109
110 return txt
111
112
113 def createKeySite(self,item):
114 """
115 Create a site for a key. It contains the header/navigator, a heading,
116 the description, links to related keys and to the groups.
117 """
118
119 return """<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
120<html><head><title>Key %s</title></head>
121<link rel="stylesheet" href="style.css" type="text/css">
122<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
123%s
124<h2><span class="refentrytitle">%s</span></h2>
125
126<div class="refsynopsisdiv">
127<h2>Synopsis</h2>
128<pre class="synopsis">
129%s
130</pre>
131</div>
132
133<div class="refsynopsisdiv">
134<h2>Related Keys</h2>
135<pre class="synopsis">
136%s
137</pre>
138</div>
139
140<div class="refsynopsisdiv">
141<h2>Groups</h2>
142<pre class="synopsis">
143%s
144</pre>
145</div>
146
147
148</body>
149""" % (item.name(), self.createNavigator(), item.name(),
150 self.escape(item.description()), self.relatedKeys(item), self.groups(item))
151
152 def createGroupsSite(self, doc):
153 """
154 Create the Group Overview site
155 """
156
157 groups = ""
158 sorted_groups = doc.groups()
159 sorted_groups.sort()
160 for group in sorted_groups:
161 groups += """<a href="group%s.html">%s</a><br>""" % (group, group)
162
163 return """<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
164<html><head><title>Group overview</title></head>
165<link rel="stylesheet" href="style.css" type="text/css">
166<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
167%s
168<h2>Available Groups</h2>
169%s
170</body>
171""" % (self.createNavigator(), groups)
172
173 def createIndex(self):
174 """
175 Create the index file
176 """
177
178 return """<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
179<html><head><title>Bitbake Documentation</title></head>
180<link rel="stylesheet" href="style.css" type="text/css">
181<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
182%s
183<h2>Documentation Entrance</h2>
184<a href="groups.html">All available groups</a><br>
185<a href="keys.html">All available keys</a><br>
186</body>
187""" % self.createNavigator()
188
189 def createKeysSite(self, doc):
190 """
191 Create Overview of all avilable keys
192 """
193 keys = ""
194 sorted_keys = doc.doc_keys()
195 sorted_keys.sort()
196 for key in sorted_keys:
197 keys += """<a href="key%s.html">%s</a><br>""" % (key, key)
198
199 return """<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
200<html><head><title>Key overview</title></head>
201<link rel="stylesheet" href="style.css" type="text/css">
202<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
203%s
204<h2>Available Keys</h2>
205%s
206</body>
207""" % (self.createNavigator(), keys)
208
209 def createGroupSite(self,gr, items):
210 """
211 Create a site for a group:
212 Group the name of the group, items contain the name of the keys
213 inside this group
214 """
215 groups = ""
216 for group in items:
217 groups += """<a href="key%s.html">%s</a><br>""" % (group.name(), group.name())
218
219 return """<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
220<html><head><title>Group %s</title></head>
221<link rel="stylesheet" href="style.css" type="text/css">
222<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
223%s
224<div class="refsynopsisdiv">
225<h2>Keys in Group %s</h2>
226<pre class="synopsis">
227%s
228</pre>
229</div>
230</body>
231""" % (gr, self.createNavigator(), gr, groups)
232
233
234
235 def createCSS(self):
236 """
237 Create the CSS file
238 """
239 return """.synopsis, .classsynopsis
240{
241 background: #eeeeee;
242 border: solid 1px #aaaaaa;
243 padding: 0.5em;
244}
245.programlisting
246{
247 background: #eeeeff;
248 border: solid 1px #aaaaff;
249 padding: 0.5em;
250}
251.variablelist
252{
253 padding: 4px;
254 margin-left: 3em;
255}
256.variablelist td:first-child
257{
258 vertical-align: top;
259}
260table.navigation
261{
262 background: #ffeeee;
263 border: solid 1px #ffaaaa;
264 margin-top: 0.5em;
265 margin-bottom: 0.5em;
266}
267.navigation a
268{
269 color: #770000;
270}
271.navigation a:visited
272{
273 color: #550000;
274}
275.navigation .title
276{
277 font-size: 200%;
278}
279div.refnamediv
280{
281 margin-top: 2em;
282}
283div.gallery-float
284{
285 float: left;
286 padding: 10px;
287}
288div.gallery-float img
289{
290 border-style: none;
291}
292div.gallery-spacer
293{
294 clear: both;
295}
296a
297{
298 text-decoration: none;
299}
300a:hover
301{
302 text-decoration: underline;
303 color: #FF0000;
304}
305"""
306
307
308
309class DocumentationItem:
310 """
311 A class to hold information about a configuration
312 item. It contains the key name, description, a list of related names,
313 and the group this item is contained in.
314 """
315
316 def __init__(self):
317 self._groups = []
318 self._related = []
319 self._name = ""
320 self._desc = ""
321
322 def groups(self):
323 return self._groups
324
325 def name(self):
326 return self._name
327
328 def description(self):
329 return self._desc
330
331 def related(self):
332 return self._related
333
334 def setName(self, name):
335 self._name = name
336
337 def setDescription(self, desc):
338 self._desc = desc
339
340 def addGroup(self, group):
341 self._groups.append(group)
342
343 def addRelation(self,relation):
344 self._related.append(relation)
345
346 def sort(self):
347 self._related.sort()
348 self._groups.sort()
349
350
351class Documentation:
352 """
353 Holds the documentation... with mappings from key to items...
354 """
355
356 def __init__(self):
357 self.__keys = {}
358 self.__groups = {}
359
360 def insert_doc_item(self, item):
361 """
362 Insert the Doc Item into the internal list
363 of representation
364 """
365 item.sort()
366 self.__keys[item.name()] = item
367
368 for group in item.groups():
369 if not group in self.__groups:
370 self.__groups[group] = []
371 self.__groups[group].append(item)
372 self.__groups[group].sort()
373
374
375 def doc_item(self, key):
376 """
377 Return the DocumentationInstance describing the key
378 """
379 try:
380 return self.__keys[key]
381 except KeyError:
382 return None
383
384 def doc_keys(self):
385 """
386 Return the documented KEYS (names)
387 """
388 return self.__keys.keys()
389
390 def groups(self):
391 """
392 Return the names of available groups
393 """
394 return self.__groups.keys()
395
396 def group_content(self,group_name):
397 """
398 Return a list of keys/names that are in a specefic
399 group or the empty list
400 """
401 try:
402 return self.__groups[group_name]
403 except KeyError:
404 return []
405
406
407def parse_cmdline(args):
408 """
409 Parse the CMD line and return the result as a n-tuple
410 """
411
412 parser = optparse.OptionParser( version = "Bitbake Documentation Tool Core version %s, %%prog version %s" % (bb.__version__,__version__))
413 usage = """%prog [options]
414
415Create a set of html pages (documentation) for a bitbake.conf....
416"""
417
418 # Add the needed options
419 parser.add_option( "-c", "--config", help = "Use the specified configuration file as source",
420 action = "store", dest = "config", default = os.path.join("conf", "documentation.conf") )
421
422 parser.add_option( "-o", "--output", help = "Output directory for html files",
423 action = "store", dest = "output", default = "html/" )
424
425 parser.add_option( "-D", "--debug", help = "Increase the debug level",
426 action = "count", dest = "debug", default = 0 )
427
428 parser.add_option( "-v","--verbose", help = "output more chit-char to the terminal",
429 action = "store_true", dest = "verbose", default = False )
430
431 options, args = parser.parse_args( sys.argv )
432
433 if options.debug:
434 bb.debug_level = options.debug
435
436 return options.config, options.output
437
438def main():
439 """
440 The main Method
441 """
442
443 (config_file,output_dir) = parse_cmdline( sys.argv )
444
445 # right to let us load the file now
446 try:
447 documentation = bb.parse.handle( config_file, bb.data.init() )
448 except IOError:
449 bb.fatal( "Unable to open %s" % config_file )
450 except bb.parse.ParseError:
451 bb.fatal( "Unable to parse %s" % config_file )
452
453
454 # Assuming we've the file loaded now, we will initialize the 'tree'
455 doc = Documentation()
456
457 # defined states
458 state_begin = 0
459 state_see = 1
460 state_group = 2
461
462 for key in bb.data.keys(documentation):
463 data = bb.data.getVarFlag(key, "doc", documentation)
464 if not data:
465 continue
466
467 # The Documentation now starts
468 doc_ins = DocumentationItem()
469 doc_ins.setName(key)
470
471
472 tokens = data.split(' ')
473 state = state_begin
474 string= ""
475 for token in tokens:
476 token = token.strip(',')
477
478 if not state == state_see and token == "@see":
479 state = state_see
480 continue
481 elif not state == state_group and token == "@group":
482 state = state_group
483 continue
484
485 if state == state_begin:
486 string += " %s" % token
487 elif state == state_see:
488 doc_ins.addRelation(token)
489 elif state == state_group:
490 doc_ins.addGroup(token)
491
492 # set the description
493 doc_ins.setDescription(string)
494 doc.insert_doc_item(doc_ins)
495
496 # let us create the HTML now
497 bb.mkdirhier(output_dir)
498 os.chdir(output_dir)
499
500 # Let us create the sites now. We do it in the following order
501 # Start with the index.html. It will point to sites explaining all
502 # keys and groups
503 html_slave = HTMLFormatter()
504
505 f = file('style.css', 'w')
506 print >> f, html_slave.createCSS()
507
508 f = file('index.html', 'w')
509 print >> f, html_slave.createIndex()
510
511 f = file('groups.html', 'w')
512 print >> f, html_slave.createGroupsSite(doc)
513
514 f = file('keys.html', 'w')
515 print >> f, html_slave.createKeysSite(doc)
516
517 # now for each group create the site
518 for group in doc.groups():
519 f = file('group%s.html' % group, 'w')
520 print >> f, html_slave.createGroupSite(group, doc.group_content(group))
521
522 # now for the keys
523 for key in doc.doc_keys():
524 f = file('key%s.html' % doc.doc_item(key).name(), 'w')
525 print >> f, html_slave.createKeySite(doc.doc_item(key))
526
527
528if __name__ == "__main__":
529 main()