def postoptparse(self, options): abspath = lambda pth: os.path.abspath(os.path.expanduser(pth)) if options.verbose: msger.set_loglevel('verbose') if options.debug: msger.set_loglevel('debug') if options.logfile: logfile_abs_path = abspath(options.logfile) if os.path.isdir(logfile_abs_path): raise errors.Usage("logfile's path %s should be file" % options.logfile) if not os.path.exists(os.path.dirname(logfile_abs_path)): os.makedirs(os.path.dirname(logfile_abs_path)) msger.set_interactive(False) msger.set_logfile(logfile_abs_path) configmgr.create['logfile'] = options.logfile if options.config: configmgr.reset() configmgr._siteconf = options.config if options.outdir is not None: configmgr.create['outdir'] = abspath(options.outdir) cdir = 'outdir' if os.path.exists(configmgr.create[cdir]) \ and not os.path.isdir(configmgr.create[cdir]): msger.error('Invalid directory specified: %s' \ % configmgr.create[cdir]) if options.enabletmpfs: configmgr.create['enabletmpfs'] = options.enabletmpfs
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, scripts_path, options): """ Create image wks_file - user-defined OE kickstart file rootfs_dir - absolute path to the build's /rootfs dir bootimg_dir - absolute path to the build's boot artifacts directory kernel_dir - absolute path to the build's kernel directory native_sysroot - absolute path to the build's native sysroots dir scripts_path - absolute path to /scripts dir image_output_dir - dirname to create for image options - wic command line options (debug, bmap, etc) Normally, the values for the build artifacts values are determined by 'wic -e' from the output of the 'bitbake -e' command given an image name e.g. 'core-image-minimal' and a given machine set in local.conf. If that's the case, the variables get the following values from the output of 'bitbake -e': rootfs_dir: IMAGE_ROOTFS kernel_dir: DEPLOY_DIR_IMAGE native_sysroot: STAGING_DIR_NATIVE In the above case, bootimg_dir remains unset and the plugin-specific image creation code is responsible for finding the bootimg artifacts. In the case where the values are passed in explicitly i.e 'wic -e' is not used but rather the individual 'wic' options are used to explicitly specify these values. """ try: oe_builddir = os.environ["BUILDDIR"] except KeyError: print( "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)" ) sys.exit(1) if options.debug: msger.set_loglevel('debug') if not os.path.exists(options.outdir): os.makedirs(options.outdir) pname = 'direct' plugin_class = pluginmgr.get_plugins('imager').get(pname) if not plugin_class: msger.error('Unknown plugin: %s' % pname) plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, scripts_path, oe_builddir, options) plugin.do_create() print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)
def wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, scripts_path, image_output_dir, debug, properties_file, properties=None): """Create image wks_file - user-defined OE kickstart file rootfs_dir - absolute path to the build's /rootfs dir bootimg_dir - absolute path to the build's boot artifacts directory kernel_dir - absolute path to the build's kernel directory native_sysroot - absolute path to the build's native sysroots dir scripts_path - absolute path to /scripts dir image_output_dir - dirname to create for image properties_file - use values from this file if nonempty i.e no prompting properties - use values from this string if nonempty i.e no prompting Normally, the values for the build artifacts values are determined by 'wic -e' from the output of the 'bitbake -e' command given an image name e.g. 'core-image-minimal' and a given machine set in local.conf. If that's the case, the variables get the following values from the output of 'bitbake -e': rootfs_dir: IMAGE_ROOTFS kernel_dir: DEPLOY_DIR_IMAGE native_sysroot: STAGING_DIR_NATIVE In the above case, bootimg_dir remains unset and the plugin-specific image creation code is responsible for finding the bootimg artifacts. In the case where the values are passed in explicitly i.e 'wic -e' is not used but rather the individual 'wic' options are used to explicitly specify these values. """ try: oe_builddir = os.environ["BUILDDIR"] except KeyError: print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)" sys.exit(1) direct_args = list() direct_args.insert(0, oe_builddir) direct_args.insert(0, image_output_dir) direct_args.insert(0, wks_file) direct_args.insert(0, rootfs_dir) direct_args.insert(0, bootimg_dir) direct_args.insert(0, kernel_dir) direct_args.insert(0, native_sysroot) direct_args.insert(0, "direct") if debug: msger.set_loglevel('debug') cr = creator.Creator() cr.main(direct_args) print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, scripts_path, image_output_dir, compressor, bmap, debug): """Create image wks_file - user-defined OE kickstart file rootfs_dir - absolute path to the build's /rootfs dir bootimg_dir - absolute path to the build's boot artifacts directory kernel_dir - absolute path to the build's kernel directory native_sysroot - absolute path to the build's native sysroots dir scripts_path - absolute path to /scripts dir image_output_dir - dirname to create for image compressor - compressor utility to compress the image bmap - enable generation of .bmap Normally, the values for the build artifacts values are determined by 'wic -e' from the output of the 'bitbake -e' command given an image name e.g. 'core-image-minimal' and a given machine set in local.conf. If that's the case, the variables get the following values from the output of 'bitbake -e': rootfs_dir: IMAGE_ROOTFS kernel_dir: DEPLOY_DIR_IMAGE native_sysroot: STAGING_DIR_NATIVE In the above case, bootimg_dir remains unset and the plugin-specific image creation code is responsible for finding the bootimg artifacts. In the case where the values are passed in explicitly i.e 'wic -e' is not used but rather the individual 'wic' options are used to explicitly specify these values. """ try: oe_builddir = os.environ["BUILDDIR"] except KeyError: print( "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)" ) sys.exit(1) if debug: msger.set_loglevel('debug') crobj = creator.Creator() cmdline = [ "direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir, wks_file, image_output_dir, oe_builddir, compressor or "" ] if bmap: cmdline.append('--bmap') crobj.main(cmdline) print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)
def get_var(self, var, image=None, cache=True): """ Get bitbake variable from 'bitbake -e' output or from .env file. This is a lazy method, i.e. it runs bitbake or parses file only when only when variable is requested. It also caches results. """ if not image: image = self.default_image if image not in self: if image and self.vars_dir: fname = os.path.join(self.vars_dir, image + '.env') if os.path.isfile(fname): # parse .env file with open(fname) as varsfile: for line in varsfile: self._parse_line(line, image) else: print("Couldn't get bitbake variable from %s." % fname) print("File %s doesn't exist." % fname) return else: # Get bitbake -e output cmd = "bitbake -e" if image: cmd += " %s" % image log_level = msger.get_loglevel() msger.set_loglevel('normal') ret, lines = _exec_cmd(cmd) msger.set_loglevel(log_level) if ret: print("Couldn't get '%s' output." % cmd) print("Bitbake failed with error:\n%s\n" % lines) return # Parse bitbake -e output for line in lines.split('\n'): self._parse_line(line, image) # Make first image a default set of variables if cache: images = [key for key in self if key] if len(images) == 1: self[None] = self[image] result = self[image].get(var) if not cache: self.pop(image, None) return result
def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, scripts_path, image_output_dir, compressor, bmap, debug): """Create image wks_file - user-defined OE kickstart file rootfs_dir - absolute path to the build's /rootfs dir bootimg_dir - absolute path to the build's boot artifacts directory kernel_dir - absolute path to the build's kernel directory native_sysroot - absolute path to the build's native sysroots dir scripts_path - absolute path to /scripts dir image_output_dir - dirname to create for image compressor - compressor utility to compress the image bmap - enable generation of .bmap Normally, the values for the build artifacts values are determined by 'wic -e' from the output of the 'bitbake -e' command given an image name e.g. 'core-image-minimal' and a given machine set in local.conf. If that's the case, the variables get the following values from the output of 'bitbake -e': rootfs_dir: IMAGE_ROOTFS kernel_dir: DEPLOY_DIR_IMAGE native_sysroot: STAGING_DIR_NATIVE In the above case, bootimg_dir remains unset and the plugin-specific image creation code is responsible for finding the bootimg artifacts. In the case where the values are passed in explicitly i.e 'wic -e' is not used but rather the individual 'wic' options are used to explicitly specify these values. """ try: oe_builddir = os.environ["BUILDDIR"] except KeyError: print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)") sys.exit(1) if debug: msger.set_loglevel('debug') crobj = creator.Creator() cmdline = ["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir, wks_file, image_output_dir, oe_builddir, compressor or ""] if bmap: cmdline.append('--bmap') crobj.main(cmdline) print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file)
def get_bitbake_var(var, image=None): """ Get bitbake variable value lazy way, i.e. run 'bitbake -e' only when variable is requested. """ if image not in _BITBAKE_VARS: # Get bitbake -e output cmd = "bitbake -e" if image: cmd += " %s" % image log_level = msger.get_loglevel() msger.set_loglevel('normal') rc, lines = __exec_cmd(cmd) msger.set_loglevel(log_level) if rc: print "Couldn't get '%s' output." % cmd print "Bitbake failed with error:\n%s\n" % lines return # Parse bitbake -e output for line in lines.split('\n'): if "=" not in line: continue try: key, val = line.split("=") except ValueError: continue key = key.strip() val = val.strip() if key.replace('_', '').isalnum(): _BITBAKE_VARS[image][key] = val.strip('"') # Make first image a default set of variables images = [key for key in _BITBAKE_VARS if key] if len(images) == 1: _BITBAKE_VARS[None] = _BITBAKE_VARS[image] return _BITBAKE_VARS[image].get(var)
def get_bitbake_var(var, image=None): """ Get bitbake variable value lazy way, i.e. run 'bitbake -e' only when variable is requested. """ if image not in _BITBAKE_VARS: # Get bitbake -e output cmd = "bitbake -e" if image: cmd += " %s" % image log_level = msger.get_loglevel() msger.set_loglevel('normal') ret, lines = __exec_cmd(cmd) msger.set_loglevel(log_level) if ret: print "Couldn't get '%s' output." % cmd print "Bitbake failed with error:\n%s\n" % lines return # Parse bitbake -e output for line in lines.split('\n'): if "=" not in line: continue try: key, val = line.split("=") except ValueError: continue key = key.strip() val = val.strip() if key.replace('_', '').isalnum(): _BITBAKE_VARS[image][key] = val.strip('"') # Make first image a default set of variables images = [key for key in _BITBAKE_VARS if key] if len(images) == 1: _BITBAKE_VARS[None] = _BITBAKE_VARS[image] return _BITBAKE_VARS[image].get(var)