def _write_append(rc, srctree, same_dir, no_same_dir, rev, copied, workspace, d): """Writes an append file""" if not os.path.exists(rc): raise DevtoolError("bbappend not created because %s does not exist" % rc) appendpath = os.path.join(workspace, 'appends') if not os.path.exists(appendpath): bb.utils.mkdirhier(appendpath) brf = os.path.basename(os.path.splitext(rc)[0]) # rc basename srctree = os.path.abspath(srctree) pn = d.getVar('PN') af = os.path.join(appendpath, '%s.bbappend' % brf) with open(af, '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' % (pn, srctree)) b_is_s = use_external_build(same_dir, no_same_dir, d) if b_is_s: f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (pn, srctree)) f.write('\n') if rev: f.write('# initial_rev: %s\n' % rev) if copied: f.write('# original_path: %s\n' % os.path.dirname(d.getVar('FILE'))) f.write('# original_files: %s\n' % ' '.join(copied)) return af
def _write_append(rc, srctree, same_dir, no_same_dir, rev, workspace, d): """Writes an append file""" if not os.path.exists(rc): raise DevtoolError("bbappend not created because %s does not exist" % rc) appendpath = os.path.join(workspace, 'appends') if not os.path.exists(appendpath): bb.utils.mkdirhier(appendpath) brf = os.path.basename(os.path.splitext(rc)[0]) # rc basename srctree = os.path.abspath(srctree) pn = d.getVar('PN',True) af = os.path.join(appendpath, '%s.bbappend' % brf) with open(af, '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' % (pn, srctree)) b_is_s = use_external_build(same_dir, no_same_dir, d) if b_is_s: f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (pn, srctree)) if rev: f.write('\n# initial_rev: %s\n' % rev) return af
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) if args.extract: tinfoil = _prep_extract_operation(config, basepath, args.recipename) else: tinfoil = setup_tinfoil(basepath=basepath) 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 logger.info('Source tree extracted to %s' % srctree) # 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') # Local files can be modified/tracked in separate subdir under srctree # Mostly useful for packages with S != WORKDIR f.write('FILESPATH_prepend := "%s:"\n' % os.path.join(srctree, 'oe-local-files')) f.write('\ninherit 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 = use_external_build(args.same_dir, args.no_same_dir, rd) if b_is_s: f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (args.recipename, srctree)) if bb.data.inherits_class('kernel', rd): f.write('SRCTREECOVEREDTASKS = "do_validate_branches do_kernel_checkout do_fetch do_unpack"\n') 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 args.color == 'auto' and 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 if args.binary: extracmdopts += ' -b' try: stdout, _ = exec_build_env_command(config.init_path, basepath, 'recipetool --color=%s create -o %s "%s" %s' % (color, recipefile, source, extracmdopts)) except bb.process.ExecutionError as e: raise DevtoolError('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) _add_md5(config, args.recipename, recipefile) if args.fetch and not args.no_git: setup_git_repo(srctree, args.version, 'devtool') 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() tinfoil = setup_tinfoil(config_only=True, basepath=basepath) rd = oe.recipeutils.parse_recipe(recipefile, None, tinfoil.config_data) if not rd: return 1 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) b_is_s = use_external_build(args.same_dir, args.no_same_dir, rd) if b_is_s: f.write('EXTERNALSRC_BUILD = "%s"\n' % srctree) if initial_rev: f.write('\n# initial_rev: %s\n' % initial_rev) if args.binary: f.write('do_install_append() {\n') f.write(' rm -rf ${D}/.git\n') f.write(' rm -f ${D}/singletask.lock\n') f.write('}\n') _add_md5(config, args.recipename, appendfile) logger.info('Recipe %s has been automatically created; further editing may be required to make it fully functional' % recipefile) tinfoil.shutdown() return 0