def build_image(args, config, basepath, workspace): """Entry point for the devtool 'build-image' subcommand.""" image = args.recipe appendfile = os.path.join(config.workspace_path, 'appends', '%s.bbappend' % image) with open(appendfile, 'w') as afile: afile.write('IMAGE_INSTALL_append = " %s"\n' % \ ' '.join(workspace.keys())) add_md5(config, image, appendfile) try: exec_build_env_command(config.init_path, basepath, 'bitbake %s' % image, watch=True) except ExecutionError as err: return err.exitcode LOG.info('Successfully built %s', image)
def modify(args, config, basepath, workspace): """Entry point for the devtool 'modify' subcommand""" import bb import oe.recipeutils if args.recipename in workspace: raise DevtoolError("recipe %s is already in your workspace" % args.recipename) if not args.extract and not os.path.isdir(args.srctree): raise DevtoolError("directory %s does not exist or not a directory " "(specify -x to extract source from recipe)" % args.srctree) tinfoil = setup_tinfoil() rd = _parse_recipe(config, tinfoil, args.recipename, True) if not rd: return 1 recipefile = rd.getVar('FILE', True) appendname = os.path.splitext(os.path.basename(recipefile))[0] if args.wildcard: appendname = re.sub(r'_.*', '_%', appendname) appendpath = os.path.join(config.workspace_path, 'appends') appendfile = os.path.join(appendpath, appendname + '.bbappend') if os.path.exists(appendfile): raise DevtoolError("Another variant of recipe %s is already in your " "workspace (only one variant of a recipe can " "currently be worked on at once)" % args.recipename) _check_compatible_recipe(args.recipename, rd) initial_rev = None commits = [] srctree = os.path.abspath(args.srctree) if args.extract: initial_rev = _extract_source(args.srctree, False, args.branch, rd) if not initial_rev: return 1 # Get list of commits since this revision (stdout, _) = bb.process.run('git rev-list --reverse %s..HEAD' % initial_rev, cwd=args.srctree) commits = stdout.split() else: if os.path.exists(os.path.join(args.srctree, '.git')): # Check if it's a tree previously extracted by us try: (stdout, _) = bb.process.run('git branch --contains devtool-base', cwd=args.srctree) except bb.process.ExecutionError: stdout = '' for line in stdout.splitlines(): if line.startswith('*'): (stdout, _) = bb.process.run('git rev-parse devtool-base', cwd=args.srctree) initial_rev = stdout.rstrip() if not initial_rev: # Otherwise, just grab the head revision (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=args.srctree) initial_rev = stdout.rstrip() # Check that recipe isn't using a shared workdir s = os.path.abspath(rd.getVar('S', True)) workdir = os.path.abspath(rd.getVar('WORKDIR', True)) if s.startswith(workdir) and s != workdir and os.path.dirname(s) != workdir: # Handle if S is set to a subdirectory of the source srcsubdir = os.path.relpath(s, workdir).split(os.sep, 1)[1] srctree = os.path.join(srctree, srcsubdir) if not os.path.exists(appendpath): os.makedirs(appendpath) with open(appendfile, 'w') as f: f.write('FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n\n') f.write('inherit externalsrc\n') f.write('# NOTE: We use pn- overrides here to avoid affecting multiple variants in the case where the recipe uses BBCLASSEXTEND\n') f.write('EXTERNALSRC_pn-%s = "%s"\n' % (args.recipename, srctree)) b_is_s = True if args.no_same_dir: logger.info('using separate build directory since --no-same-dir specified') b_is_s = False elif args.same_dir: logger.info('using source tree as build directory since --same-dir specified') elif bb.data.inherits_class('autotools-brokensep', rd): logger.info('using source tree as build directory since original recipe inherits autotools-brokensep') elif rd.getVar('B', True) == s: logger.info('using source tree as build directory since that is the default for this recipe') else: b_is_s = False if b_is_s: f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (args.recipename, srctree)) if initial_rev: f.write('\n# initial_rev: %s\n' % initial_rev) for commit in commits: f.write('# commit: %s\n' % commit) add_md5(config, args.recipename, appendfile) logger.info('Recipe %s now set up to build from %s' % (args.recipename, srctree)) return 0
def modify(args, config, basepath, workspace): """Entry point for the devtool 'modify' subcommand""" import bb import oe.recipeutils if args.recipename in workspace: raise DevtoolError("recipe %s is already in your workspace" % args.recipename) if not args.extract and not os.path.isdir(args.srctree): raise DevtoolError("directory %s does not exist or not a directory " "(specify -x to extract source from recipe)" % args.srctree) tinfoil = setup_tinfoil() rd = _parse_recipe(config, tinfoil, args.recipename, True) if not rd: return 1 recipefile = rd.getVar('FILE', True) appendname = os.path.splitext(os.path.basename(recipefile))[0] if args.wildcard: appendname = re.sub(r'_.*', '_%', appendname) appendpath = os.path.join(config.workspace_path, 'appends') appendfile = os.path.join(appendpath, appendname + '.bbappend') if os.path.exists(appendfile): raise DevtoolError("Another variant of recipe %s is already in your " "workspace (only one variant of a recipe can " "currently be worked on at once)" % args.recipename) _check_compatible_recipe(args.recipename, rd) initial_rev = None commits = [] srctree = os.path.abspath(args.srctree) if args.extract: initial_rev = _extract_source(args.srctree, False, args.branch, rd) if not initial_rev: return 1 # Get list of commits since this revision (stdout, _) = bb.process.run('git rev-list --reverse %s..HEAD' % initial_rev, cwd=args.srctree) commits = stdout.split() else: if os.path.exists(os.path.join(args.srctree, '.git')): # Check if it's a tree previously extracted by us try: (stdout, _) = bb.process.run('git branch --contains devtool-base', cwd=args.srctree) except bb.process.ExecutionError: stdout = '' for line in stdout.splitlines(): if line.startswith('*'): (stdout, _) = bb.process.run('git rev-parse devtool-base', cwd=args.srctree) initial_rev = stdout.rstrip() if not initial_rev: # Otherwise, just grab the head revision (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=args.srctree) initial_rev = stdout.rstrip() # Check that recipe isn't using a shared workdir s = os.path.abspath(rd.getVar('S', True)) workdir = os.path.abspath(rd.getVar('WORKDIR', True)) if s.startswith( workdir) and s != workdir and os.path.dirname(s) != workdir: # Handle if S is set to a subdirectory of the source srcsubdir = os.path.relpath(s, workdir).split(os.sep, 1)[1] srctree = os.path.join(srctree, srcsubdir) if not os.path.exists(appendpath): os.makedirs(appendpath) with open(appendfile, 'w') as f: f.write('FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n\n') f.write('inherit externalsrc\n') f.write( '# NOTE: We use pn- overrides here to avoid affecting multiple variants in the case where the recipe uses BBCLASSEXTEND\n' ) f.write('EXTERNALSRC_pn-%s = "%s"\n' % (args.recipename, srctree)) b_is_s = True if args.no_same_dir: logger.info( 'using separate build directory since --no-same-dir specified') b_is_s = False elif args.same_dir: logger.info( 'using source tree as build directory since --same-dir specified' ) elif bb.data.inherits_class('autotools-brokensep', rd): logger.info( 'using source tree as build directory since original recipe inherits autotools-brokensep' ) elif rd.getVar('B', True) == s: logger.info( 'using source tree as build directory since that is the default for this recipe' ) else: b_is_s = False if b_is_s: f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (args.recipename, srctree)) if initial_rev: f.write('\n# initial_rev: %s\n' % initial_rev) for commit in commits: f.write('# commit: %s\n' % commit) add_md5(config, args.recipename, appendfile) logger.info('Recipe %s now set up to build from %s' % (args.recipename, srctree)) return 0
def add(args, config, basepath, workspace): """Entry point for the devtool 'add' subcommand""" import bb import oe.recipeutils if args.recipename in workspace: raise DevtoolError("recipe %s is already in your workspace" % args.recipename) reason = oe.recipeutils.validate_pn(args.recipename) if reason: raise DevtoolError(reason) srctree = os.path.abspath(args.srctree) if os.path.exists(srctree): if args.fetch: if not os.path.isdir(srctree): raise DevtoolError("Cannot fetch into source tree path %s as " "it exists and is not a directory" % srctree) elif os.listdir(srctree): raise DevtoolError("Cannot fetch into source tree path %s as " "it already exists and is non-empty" % srctree) elif not args.fetch: raise DevtoolError("Specified source tree %s could not be found" % srctree) appendpath = os.path.join(config.workspace_path, 'appends') if not os.path.exists(appendpath): os.makedirs(appendpath) recipedir = os.path.join(config.workspace_path, 'recipes', args.recipename) bb.utils.mkdirhier(recipedir) rfv = None if args.version: if '_' in args.version or ' ' in args.version: raise DevtoolError('Invalid version string "%s"' % args.version) rfv = args.version if args.fetch: if args.fetch.startswith('git://'): rfv = 'git' elif args.fetch.startswith('svn://'): rfv = 'svn' elif args.fetch.startswith('hg://'): rfv = 'hg' if rfv: bp = "%s_%s" % (args.recipename, rfv) else: bp = args.recipename recipefile = os.path.join(recipedir, "%s.bb" % bp) if sys.stdout.isatty(): color = 'always' else: color = args.color extracmdopts = '' if args.fetch: source = args.fetch extracmdopts = '-x %s' % srctree else: source = srctree if args.version: extracmdopts += ' -V %s' % args.version try: stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts)) logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) except bb.process.ExecutionError as e: raise DevtoolError('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) add_md5(config, args.recipename, recipefile) initial_rev = None if os.path.exists(os.path.join(srctree, '.git')): (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=srctree) initial_rev = stdout.rstrip() appendfile = os.path.join(appendpath, '%s.bbappend' % bp) with open(appendfile, 'w') as f: f.write('inherit externalsrc\n') f.write('EXTERNALSRC = "%s"\n' % srctree) if args.same_dir: f.write('EXTERNALSRC_BUILD = "%s"\n' % srctree) if initial_rev: f.write('\n# initial_rev: %s\n' % initial_rev) add_md5(config, args.recipename, appendfile) return 0
def add(args, config, basepath, workspace): """Entry point for the devtool 'add' subcommand""" import bb import oe.recipeutils if args.recipename in workspace: raise DevtoolError("recipe %s is already in your workspace" % args.recipename) reason = oe.recipeutils.validate_pn(args.recipename) if reason: raise DevtoolError(reason) srctree = os.path.abspath(args.srctree) if os.path.exists(srctree): if args.fetch: if not os.path.isdir(srctree): raise DevtoolError("Cannot fetch into source tree path %s as " "it exists and is not a directory" % srctree) elif os.listdir(srctree): raise DevtoolError("Cannot fetch into source tree path %s as " "it already exists and is non-empty" % srctree) elif not args.fetch: raise DevtoolError("Specified source tree %s could not be found" % srctree) appendpath = os.path.join(config.workspace_path, 'appends') if not os.path.exists(appendpath): os.makedirs(appendpath) recipedir = os.path.join(config.workspace_path, 'recipes', args.recipename) bb.utils.mkdirhier(recipedir) rfv = None if args.version: if '_' in args.version or ' ' in args.version: raise DevtoolError('Invalid version string "%s"' % args.version) rfv = args.version if args.fetch: if args.fetch.startswith('git://'): rfv = 'git' elif args.fetch.startswith('svn://'): rfv = 'svn' elif args.fetch.startswith('hg://'): rfv = 'hg' if rfv: bp = "%s_%s" % (args.recipename, rfv) else: bp = args.recipename recipefile = os.path.join(recipedir, "%s.bb" % bp) if sys.stdout.isatty(): color = 'always' else: color = args.color extracmdopts = '' if args.fetch: source = args.fetch extracmdopts = '-x %s' % srctree else: source = srctree if args.version: extracmdopts += ' -V %s' % args.version try: stdout, _ = exec_build_env_command( config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts)) logger.info( 'Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) except bb.process.ExecutionError as e: raise DevtoolError('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) add_md5(config, args.recipename, recipefile) initial_rev = None if os.path.exists(os.path.join(srctree, '.git')): (stdout, _) = bb.process.run('git rev-parse HEAD', cwd=srctree) initial_rev = stdout.rstrip() appendfile = os.path.join(appendpath, '%s.bbappend' % bp) with open(appendfile, 'w') as f: f.write('inherit externalsrc\n') f.write('EXTERNALSRC = "%s"\n' % srctree) if args.same_dir: f.write('EXTERNALSRC_BUILD = "%s"\n' % srctree) if initial_rev: f.write('\n# initial_rev: %s\n' % initial_rev) add_md5(config, args.recipename, appendfile) return 0