apply patch from Murray Jensen to fix lost CVS_RSH when doing incremental update
[vuplus_bitbake] / bin / oeimage
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 import sys, os, oe
6 from oe import *
7
8 __version__ = 1.0
9 type = "jffs2"
10 cfg_oe = data.init()
11 cfg_oespawn = data.init()
12
13
14 def usage():
15     print "Usage: oeimage [options ...]"
16     print "Creates an image for a target device from a root filesystem,"
17     print "obeying configuration parameters from the OpenEmbedded"
18     print "configuration files, thereby easing handling of deviceisms."
19     print ""
20     print "  %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})")
21     print "  %s\t\t%s" % ("-t [arg], --type [arg]", "image type (jffs2[default], cramfs)")
22     print "  %s\t\t%s" % ("-n [arg], --name [arg]", "image name (override IMAGE_NAME variable)")
23     print "  %s\t\t%s" % ("-v, --version", "output version information and exit")
24     sys.exit(0)
25
26 def version():
27     print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
28     print "OEImage version %s" % __version__
29
30 def emit_oe(d, base_d = {}):
31     for v in d.keys():
32         if d[v] != base_d[v]:
33             data.emit_var(v, d)
34
35 def getopthash(l):
36     h = {}
37     for (opt, val) in l:
38         h[opt] = val
39     return h
40
41 import getopt
42 try:
43     (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'oefile=', 'name=' ])
44 except getopt.GetoptError:
45     usage()
46
47 # handle opts
48 opthash = getopthash(opts)
49
50 if '--version' in opthash or '-v' in opthash:
51     version()
52     sys.exit(0)
53
54 try:
55     cfg_oe = parse.handle("conf/oe.conf", cfg_oe)
56 except IOError:
57     fatal("Unable to open oe.conf")
58
59 # sanity check
60 if cfg_oe is None:
61     fatal("Unable to open/parse conf/oe.conf")
62     usage(1)
63
64 rootfs = None
65 extra_files = []
66
67 if '--root' in opthash:
68     rootfs = opthash['--root']
69 if '-r' in opthash:
70     rootfs = opthash['-r']
71
72 if '--type' in opthash:
73     type = opthash['--type']
74 if '-t' in opthash:
75     type = opthash['-t']
76
77 if '--oefile' in opthash:
78     extra_files.append(opthash['--oefile'])
79 if '-e' in opthash:
80     extra_files.append(opthash['-e'])
81
82 for f in extra_files:
83     try:
84         cfg_oe = parse.handle(f, cfg_oe)
85     except IOError:
86         print "unable to open %s" % f
87
88 if not rootfs:
89     rootfs = data.getVar('IMAGE_ROOTFS', cfg_oe, 1)
90
91 if not rootfs:
92     oe.fatal("IMAGE_ROOTFS not defined")
93
94 data.setVar('IMAGE_ROOTFS', rootfs, cfg_oe)
95
96 from copy import copy, deepcopy
97 localdata = deepcopy(cfg_oe)
98
99 overrides = data.getVar('OVERRIDES', localdata)
100 if not overrides:
101     oe.fatal("OVERRIDES not defined.")
102 data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata)
103 data.update_data(localdata)
104 data.setVar('OVERRIDES', overrides, localdata)
105
106 if '-n' in opthash:
107     data.setVar('IMAGE_NAME', opthash['-n'], localdata)
108 if '--name' in opthash:
109     data.setVar('IMAGE_NAME', opthash['--name'], localdata)
110
111 topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()
112
113 cmd = data.getVar('IMAGE_CMD', localdata, 1)
114 if not cmd:
115     oe.fatal("IMAGE_CMD not defined")
116
117 outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
118 if not outdir:
119     oe.fatal('DEPLOY_DIR_IMAGE not defined')
120 mkdirhier(outdir)
121
122 #depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or ""
123 #if depends:
124 #       oe.note("Spawning oemake to satisfy dependencies: %s" % depends)
125 #       ret = os.system('oemake %s' % depends)
126 #       if ret != 0:
127 #           oe.error("executing oemake to satisfy dependencies")
128
129 oe.note("Executing %s" % cmd)
130 data.setVar('T', '${TMPDIR}', localdata)
131 data.setVar('image_cmd', cmd, localdata)
132 data.setVarFlag('image_cmd', 'func', 1, localdata)
133 try:
134     oe.build.exec_func('image_cmd', localdata)
135 except oe.build.FuncFailed:
136     sys.exit(1)
137 #ret = os.system(cmd)
138 #sys.exit(ret)