devtool improvements
cover devtool improvements
Adds "upgrade" and "package" subcommands to devtool, provides a way to disable parallel make, improves the default behaviour of update-recipe with git recipes, and fixes running devtool from a different directory.
This rolls up and fixes some previously posted patches; changes from the previously posted versions:
* devtool: add upgrade feature:
- Handle upgrading git recipes i.e. where version may not change, we need to be able to specify the SRCREV, md5sum/sha256sum aren't used and most importantly we don't want to munge the existing repository
- Fix rebasing logic - we want to be rebasing the old patched branch onto the new branch, not the other way around
- Fix branching/tagging
- Use branch name for the new version branch not the old one
- Ensure we delete/preserve copied in recipe files when resetting
- Use common fetch_uri function instead of duplicating
- Fix handling recipes that use BBCLASSEXTEND
- Tweak some messages and command line help
- Squash in test commits (we probably need additional tests - to be added later)
* devtool: Allow disabling make parallelism on build command:
- Add a short option (-s for "single")
- Use traditional spacing in created postfile
- Delete postfile after building, there's not much point keeping it
- Tweak log output
* devtool: add package plugin that lets you create package via devtool:
- Fix config file reading
- Make this available only within the extensible SDK (since it's not particularly useful outside of it)
* devtool: update-recipe: better 'auto' mode
- Fix oe-selftest tests for this behaviour change
The following changes since commit 8402958cd2cb87b8283c8ee4e2d08e1a6717d67a:
pseudo_1.7.3.bb: New version of pseudo (2015-09-06 15:24:28 +0100)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib paule/devtool7
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=paule/devtool7
Brendan Le Foll (1):
devtool: add package plugin that lets you create package via devtool
Leonardo Sandoval (3):
devtool: add upgrade feature
devtool: Create a single file for the build devtool feature
devtool: Allow disabling make parallelism on build command
Markus Lehtonen (1):
devtool: update-recipe: better 'auto' mode
Paul Eggleton (4):
scriptutils: split out simple fetching function from recipetool
devtool: improve modified file preservation to handle directory
structures
devtool: update-recipe: add a warning when recipe is inside the
workspace
devtool: fix running from a different directory
.../recipes-test/devtool/devtool-upgrade_0.1.bb | 25 ++ ...-exit-with-EXIT_SUCCESS-instead-of-a-magi.patch | 27 ++ .../devtool/files/devtool-upgrade-0.1.tar.gz | Bin 0 -> 411 bytes .../devtool/files/devtool-upgrade-0.2.tar.gz | Bin 0 -> 411 bytes meta/lib/oeqa/selftest/devtool.py | 68 +++- scripts/devtool | 3 + scripts/lib/devtool/build.py | 77 +++++ scripts/lib/devtool/package.py | 61 ++++ scripts/lib/devtool/standard.py | 94 +++--- scripts/lib/devtool/upgrade.py | 354 +++++++++++++++++++++ scripts/lib/recipetool/create.py | 30 +- scripts/lib/scriptutils.py | 27 ++ 12 files changed, 692 insertions(+), 74 deletions(-) create mode 100644 meta-selftest/recipes-test/devtool/devtool-upgrade_0.1.bb create mode 100644 meta-selftest/recipes-test/devtool/files/0001-helloword.c-exit-with-EXIT_SUCCESS-instead-of-a-magi.patch create mode 100644 meta-selftest/recipes-test/devtool/files/devtool-upgrade-0.1.tar.gz create mode 100644 meta-selftest/recipes-test/devtool/files/devtool-upgrade-0.2.tar.gz create mode 100644 scripts/lib/devtool/build.py create mode 100644 scripts/lib/devtool/package.py create mode 100644 scripts/lib/devtool/upgrade.py
Signature · 1 line
2.1.0
PATCH 1/9 scriptutils: split out simple fetching function from recipetool
This will now also be used by "devtool upgrade".
--- scripts/lib/recipetool/create.py | 30 +----------------------------- scripts/lib/scriptutils.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 29 deletions(-)
scripts/lib/recipetool/create.py +1 -29
@@ -58,34 +58,6 @@ class RecipeHandler(): -def fetch_source(uri, destdir, srcrev): - import bb.data - bb.utils.mkdirhier(destdir) - localdata = bb.data.createCopy(tinfoil.config_data) - bb.data.update_data(localdata) - localdata.setVar('BB_STRICT_CHECKSUM', '') - localdata.setVar('SRCREV', srcrev) - ret = (None, None) - olddir = os.getcwd() - try: - fetcher = bb.fetch2.Fetch([uri], localdata) - for u in fetcher.ud: - ud = fetcher.ud[u] - ud.ignore_checksums = True - fetcher.download() - fetcher.unpack(destdir) - for u in fetcher.ud: - ud = fetcher.ud[u] - if ud.method.recommends_checksum(ud): - md5value = bb.utils.md5_file(ud.localpath) - sha256value = bb.utils.sha256_file(ud.localpath) - ret = (md5value, sha256value) - except bb.fetch2.BBFetchException, e: - raise bb.build.FuncFailed(e) - finally: - os.chdir(olddir) - return ret - def supports_srcrev(uri): localdata = bb.data.createCopy(tinfoil.config_data) # This is a bit sad, but if you don't have this set there can be some
@@ -123,7 +95,7 @@ def create_recipe(args): tempsrc = tempfile.mkdtemp(prefix='recipetool-') srctree = tempsrc logger.info('Fetching %s...' % srcuri) - checksums = fetch_source(args.source, srctree, srcrev) + checksums = scriptutils.fetch_uri(tinfoil.config_data, args.source, srctree, srcrev) dirlist = os.listdir(srctree) if 'git.indirectionsymlink' in dirlist: dirlist.remove('git.indirectionsymlink')
scripts/lib/scriptutils.py +27 -0
@@ -69,3 +69,30 @@ def git_convert_standalone_clone(repodir): # of the contents is shared bb.process.run('git repack -a', cwd=repodir) os.remove(alternatesfile) + +def fetch_uri(d, uri, destdir, srcrev=None): + """Fetch a URI to a local directory""" + import bb.data + bb.utils.mkdirhier(destdir) + localdata = bb.data.createCopy(d) + localdata.setVar('BB_STRICT_CHECKSUM', '') + localdata.setVar('SRCREV', srcrev) + ret = (None, None) + olddir = os.getcwd() + try: + fetcher = bb.fetch2.Fetch([uri], localdata) + for u in fetcher.ud: + ud = fetcher.ud[u] + ud.ignore_checksums = True + fetcher.download() + fetcher.unpack(destdir) + for u in fetcher.ud: + ud = fetcher.ud[u] + if ud.method.recommends_checksum(ud): + md5value = bb.utils.md5_file(ud.localpath) + sha256value = bb.utils.sha256_file(ud.localpath) + ret = (md5value, sha256value) + finally: + os.chdir(olddir) + return ret +
Signature · 1 line
2.1.0
PATCH 2/9 devtool: improve modified file preservation to handle directory structures
In reply to Paul EggletonAllow the _add_md5() function to be called with a directory in order to recursively add the files under it. Additionally, we need to skip preserving empty directories (since directories aren't listed in the md5 file).
--- scripts/lib/devtool/standard.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
scripts/lib/devtool/standard.py +21 -9
@@ -362,14 +362,23 @@ def _extract_source(srctree, keep_temp, devbranch, d): return initial_rev def _add_md5(config, recipename, filename): - """Record checksum of a recipe to the md5-file of the workspace""" + """Record checksum of a file (or recursively for a directory) to the md5-file of the workspace""" import bb.utils - md5 = bb.utils.md5_file(filename) - with open(os.path.join(config.workspace_path, '.devtool_md5'), 'a') as f: - f.write('%s|%s|%s\n' % (recipename, os.path.relpath(filename, config.workspace_path), md5)) + + def addfile(fn): + md5 = bb.utils.md5_file(fn) + with open(os.path.join(config.workspace_path, '.devtool_md5'), 'a') as f: + f.write('%s|%s|%s\n' % (recipename, os.path.relpath(fn, config.workspace_path), md5)) + + if os.path.isdir(filename): + for root, _, files in os.walk(os.path.dirname(filename)): + for f in files: + addfile(os.path.join(root, f)) + else: + addfile(filename) def _check_preserve(config, recipename): - """Check if a recipe was manually changed and needs to be saved in 'attic' + """Check if a file was manually changed and needs to be saved in 'attic' directory""" import bb.utils origfile = os.path.join(config.workspace_path, '.devtool_md5')
@@ -830,10 +839,13 @@ def reset(args, config, basepath, workspace): preservepath = os.path.join(config.workspace_path, 'attic', pn) def preservedir(origdir): if os.path.exists(origdir): - for fn in os.listdir(origdir): - logger.warn('Preserving %s in %s' % (fn, preservepath)) - bb.utils.mkdirhier(preservepath) - shutil.move(os.path.join(origdir, fn), os.path.join(preservepath, fn)) + for root, dirs, files in os.walk(origdir): + for fn in files: + logger.warn('Preserving %s in %s' % (fn, preservepath)) + bb.utils.mkdirhier(preservepath) + shutil.move(os.path.join(origdir, fn), os.path.join(preservepath, fn)) + for dn in dirs: + os.rmdir(os.path.join(root, dn)) os.rmdir(origdir) preservedir(os.path.join(config.workspace_path, 'recipes', pn))
Signature · 1 line
2.1.0
PATCH 3/9 devtool: add upgrade feature
In reply to Paul EggletonFrom: Leonardo Sandoval <[email protected]>
Upgrades a recipe to a particular version and downloads the source code into a folder. User can avoid patching the source code.
These are the general steps of the upgrade function:
- Extract current recipe source code into srctree and create a branch
- Extract upgrade recipe source code into srctree and rebase with previous branch. In case the rebase is not correctly applied, source code will not be deleted, so user correct the patches
- Creates the new recipe under the workspace
[YOCTO #7642]
--- .../recipes-test/devtool/devtool-upgrade_0.1.bb | 25 ++ ...-exit-with-EXIT_SUCCESS-instead-of-a-magi.patch | 27 ++ .../devtool/files/devtool-upgrade-0.1.tar.gz | Bin 0 -> 411 bytes .../devtool/files/devtool-upgrade-0.2.tar.gz | Bin 0 -> 411 bytes meta/lib/oeqa/selftest/devtool.py | 36 +++ scripts/lib/devtool/standard.py | 4 +- scripts/lib/devtool/upgrade.py | 354 +++++++++++++++++++++ 7 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 meta-selftest/recipes-test/devtool/devtool-upgrade_0.1.bb create mode 100644 meta-selftest/recipes-test/devtool/files/0001-helloword.c-exit-with-EXIT_SUCCESS-instead-of-a-magi.patch create mode 100644 meta-selftest/recipes-test/devtool/files/devtool-upgrade-0.1.tar.gz create mode 100644 meta-selftest/recipes-test/devtool/files/devtool-upgrade-0.2.tar.gz create mode 100644 scripts/lib/devtool/upgrade.py
meta-selftest/recipes-test/devtool/devtool-upgrade_0.1.bb new file +25 -0
@@ -0,0 +1,25 @@ +# +# This file was derived from the 'Hello World!' example recipe in the +# Yocto Project Development Manual. +# + +DESCRIPTION = "Simple helloworld application used to test the devtool upgrade feature" +SECTION = "devtool" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" +PR = "r0" + +SRC_URI = "file://${THISDIR}/files/${P}.tar.gz \ + file://0001-helloword.c-exit-with-EXIT_SUCCESS-instead-of-a-magi.patch \ + " + +S = "${WORKDIR}/${P}" + +do_compile() { + ${CC} helloworld.c -o helloworld +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 helloworld ${D}${bindir} +}
meta-selftest/recipes-test/devtool/files/0001-helloword.c-exit-with-EXIT_SUCCESS-instead-of-a-magi.patch new file +27 -0
@@ -0,0 +1,27 @@ +From 0f37affbc6e6c71687301d99d7259f1968e57c48 Mon Sep 17 00:00:00 2001 +From: Leonardo Sandoval <[email protected]> +Date: Wed, 26 Aug 2015 12:42:23 +0000 +Subject: [PATCH] helloword.c: exit with EXIT_SUCCESS instead of a magic number + +--- + helloworld.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/helloworld.c b/helloworld.c +index 71f2e46..54bf50b 100644 +--- a/helloworld.c ++++ b/helloworld.c +@@ -1,8 +1,9 @@ + #include <stdio.h> ++#include <stdlib.h> + + int main(int argc, char **argv) + { + printf("Hello World!\n"); + +- return 0; ++ return EXIT_SUCCESS; + } +-- +1.8.4.5 +
meta-selftest/recipes-test/devtool/files/devtool-upgrade-0.1.tar.gz new file binary +0 -0
meta-selftest/recipes-test/devtool/files/devtool-upgrade-0.2.tar.gz new file binary +0 -0
meta/lib/oeqa/selftest/devtool.py +36 -0
@@ -913,3 +913,39 @@ class DevtoolTests(DevtoolBase): # NOTE: native recipe parted-native should not be in IMAGE_INSTALL_append self.assertTrue('IMAGE_INSTALL_append = " mdadm"\n' in open(bbappend).readlines(), 'IMAGE_INSTALL_append = " mdadm" not found in %s' % bbappend) + + def test_devtool_upgrade(self): + # Check preconditions + workspacedir = os.path.join(self.builddir, 'workspace') + self.assertTrue(not os.path.exists(workspacedir), 'This test cannot be run with a workspace directory under the build directory') + # Check parameters + result = runCmd('devtool upgrade -h') + for param in 'recipename srctree --version -V --branch -b --keep-temp --no-patch'.split(): + self.assertIn(param, result.output) + # For the moment, we are using a real recipe. + recipe='devtool-upgrade' + version='0.2' + tempdir = tempfile.mkdtemp(prefix='devtoolqa') + # Check that recipe is not already under devtool control + result = runCmd('devtool status') + self.assertNotIn(recipe, result.output) + # Check upgrade. Code does not check if new PV is older or newer that current PV, so, it may be that + # we are downgrading instead of upgrading. + result = runCmd('devtool upgrade %s %s -V %s' % (recipe, tempdir, version)) + # Check if srctree at least is populated + self.assertTrue(len(os.listdir(tempdir)) > 0, 'scrtree (%s) should be populated with new (%s) source code' % (tempdir, version)) + # Check new recipe folder is present + self.assertTrue(os.path.exists(os.path.join(workspacedir,'recipes',recipe)), 'Recipe folder should exist') + # Check new recipe file is present + self.assertTrue(os.path.exists(os.path.join(workspacedir,'recipes',recipe,"%s_%s.bb" % (recipe,version))), 'Recipe folder should exist') + # Check devtool status and make sure recipe is present + result = runCmd('devtool status') + self.assertIn(recipe, result.output) + self.assertIn(tempdir, result.output) + # Check devtool reset recipe + result = runCmd('devtool reset %s -n' % recipe) + result = runCmd('devtool status') + self.assertNotIn(recipe, result.output) + self.track_for_cleanup(tempdir) + self.track_for_cleanup(workspacedir) + self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
scripts/lib/devtool/standard.py +3 -1
@@ -178,6 +178,8 @@ def extract(args, config, basepath, workspace): srctree = os.path.abspath(args.srctree) initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) + logger.info('Source tree extracted to %s' % srctree) + if initial_rev: return 0 else:
@@ -351,7 +353,6 @@ def _extract_source(srctree, keep_temp, devbranch, d): bb.process.run('git checkout patches', cwd=srcsubdir) shutil.move(srcsubdir, srctree) - logger.info('Source tree extracted to %s' % srctree) finally: bb.logger.setLevel(origlevel)
@@ -451,6 +452,7 @@ def modify(args, config, basepath, workspace): 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()
scripts/lib/devtool/upgrade.py new file +354 -0
354 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 4/9 devtool: Create a single file for the build devtool feature
In reply to Paul EggletonFrom: Leonardo Sandoval <[email protected]>
The intention is to have a single file for each devtool feature so devtool can grow in a modular way. In this direction, this patch creates build.py, moving all related build features from standard.py to build.py.
--- scripts/lib/devtool/build.py | 50 +++++++++++++++++++++++++++++++++++++++++ scripts/lib/devtool/standard.py | 22 ------------------ 2 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 scripts/lib/devtool/build.py
scripts/lib/devtool/build.py new file +50 -0
@@ -0,0 +1,50 @@ +# Development tool - build command plugin +# +# Copyright (C) 2014-2015 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +"""Devtool build plugin""" + +import logging +import argparse +from devtool import exec_build_env_command + +logger = logging.getLogger('devtool') + +def plugin_init(pluginlist): + """Plugin initialization""" + pass + +def build(args, config, basepath, workspace): + """Entry point for the devtool 'build' subcommand""" + import bb + if not args.recipename in workspace: + raise DevtoolError("no recipe named %s in your workspace" % + args.recipename) + build_task = config.get('Build', 'build_task', 'populate_sysroot') + try: + exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) + except bb.process.ExecutionError as e: + # We've already seen the output since watch=True, so just ensure we return something to the user + return e.exitcode + + return 0 + +def register_commands(subparsers, context): + """Register devtool subcommands from this plugin""" + parser_build = subparsers.add_parser('build', help='Build a recipe', + description='Builds the specified recipe using bitbake', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_build.add_argument('recipename', help='Recipe to build') + parser_build.set_defaults(func=build)
scripts/lib/devtool/standard.py +0 -22
@@ -857,22 +857,6 @@ def reset(args, config, basepath, workspace): return 0 -def build(args, config, basepath, workspace): - """Entry point for the devtool 'build' subcommand""" - import bb - if not args.recipename in workspace: - raise DevtoolError("no recipe named %s in your workspace" % - args.recipename) - build_task = config.get('Build', 'build_task', 'populate_sysroot') - try: - exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) - except bb.process.ExecutionError as e: - # We've already seen the output since watch=True, so just ensure we return something to the user - return e.exitcode - - return 0 - - def register_commands(subparsers, context): """Register devtool subcommands from this plugin""" parser_add = subparsers.add_parser('add', help='Add a new recipe',
@@ -921,12 +905,6 @@ def register_commands(subparsers, context): formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser_status.set_defaults(func=status) - parser_build = subparsers.add_parser('build', help='Build a recipe', - description='Builds the specified recipe using bitbake', - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser_build.add_argument('recipename', help='Recipe to build') - parser_build.set_defaults(func=build) - parser_reset = subparsers.add_parser('reset', help='Remove a recipe from your workspace', description='Removes the specified recipe from your workspace (resetting its state)', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
Signature · 1 line
2.1.0
PATCH 5/9 devtool: Allow disabling make parallelism on build command
In reply to Paul EggletonFrom: Leonardo Sandoval <[email protected]>
Through -s/--disable-parallel-make, the user can turn off parallelism on the make tool. This can be useful when debuging race condition issues. In order to set PARALLEL_MAKE = "" a post-config file created and then passed into the build.
[YOCTO #7589]
--- scripts/lib/devtool/build.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
scripts/lib/devtool/build.py +30 -3
@@ -16,9 +16,12 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """Devtool build plugin""" +import os +import bb import logging import argparse -from devtool import exec_build_env_command +import tempfile +from devtool import exec_build_env_command, DevtoolError logger = logging.getLogger('devtool')
@@ -26,18 +29,41 @@ def plugin_init(pluginlist): """Plugin initialization""" pass +def _create_conf_file(values, conf_file=None): + if not conf_file: + fd, conf_file = tempfile.mkstemp(suffix='.conf') + elif not os.path.exists(os.path.dirname(conf_file)): + logger.debug("Creating folder %s" % os.path.dirname(conf_file)) + bb.utils.mkdirhier(os.path.dirname(conf_file)) + with open(conf_file, 'w') as f: + for key, value in values.iteritems(): + f.write('%s = "%s"\n' % (key, value)) + return conf_file + def build(args, config, basepath, workspace): """Entry point for the devtool 'build' subcommand""" - import bb if not args.recipename in workspace: raise DevtoolError("no recipe named %s in your workspace" % args.recipename) + build_task = config.get('Build', 'build_task', 'populate_sysroot') + + postfile_param = "" + postfile = "" + if args.disable_parallel_make: + logger.info("Disabling 'make' parallelism") + postfile = os.path.join(basepath, 'conf', 'disable_parallelism.conf') + _create_conf_file({'PARALLEL_MAKE':''}, postfile) + postfile_param = "-R %s" % postfile try: - exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (build_task, args.recipename), watch=True) + exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s %s' % (build_task, postfile_param, args.recipename), watch=True) except bb.process.ExecutionError as e: # We've already seen the output since watch=True, so just ensure we return something to the user return e.exitcode + finally: + if postfile: + logger.debug('Removing postfile') + os.remove(postfile) return 0
@@ -47,4 +73,5 @@ def register_commands(subparsers, context): description='Builds the specified recipe using bitbake', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser_build.add_argument('recipename', help='Recipe to build') + parser_build.add_argument('-s', '--disable-parallel-make', action="store_true", help='Disable make parallelism') parser_build.set_defaults(func=build)
Signature · 1 line
2.1.0
PATCH 6/9 devtool: update-recipe: better 'auto' mode
In reply to Paul EggletonFrom: Markus Lehtonen <[email protected]>
Enhance the logic behind the 'auto' mode a bit by only updating the SRCREV if the changes are already found upstream. The logic is simple:
update SRCREV only if the current local HEAD commit is found in the remote branch (i.e. 'origin/<branch_name>'). Otherwise resort to patching.
This affects a couple of the oe-selftest tests so update those as well.
[YOCTO #7907]
--- meta/lib/oeqa/selftest/devtool.py | 32 ++++++++++++++++++++++++++------ scripts/lib/devtool/standard.py | 34 +++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 13 deletions(-)
meta/lib/oeqa/selftest/devtool.py +26 -6
@@ -547,8 +547,8 @@ class DevtoolTests(DevtoolBase): result = runCmd('echo "A new file" > devtool-new-file', cwd=tempdir) result = runCmd('git add devtool-new-file', cwd=tempdir) result = runCmd('git commit -m "Add a new file"', cwd=tempdir) - self.add_command_to_tearDown('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile))) - result = runCmd('devtool update-recipe %s' % testrecipe) + self.add_command_to_tearDown('cd %s; rm -rf %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, testrecipe, os.path.basename(recipefile))) + result = runCmd('devtool update-recipe -m srcrev %s' % testrecipe) result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) self.assertNotEqual(result.output.strip(), "", '%s recipe should be modified' % testrecipe) status = result.output.splitlines()
@@ -585,6 +585,26 @@ class DevtoolTests(DevtoolBase): matched = True break self.assertTrue(matched, 'Unexpected diff remove line: %s' % line) + # Now try with auto mode + runCmd('cd %s; git checkout %s %s' % (os.path.dirname(recipefile), testrecipe, os.path.basename(recipefile))) + result = runCmd('devtool update-recipe %s' % testrecipe) + result = runCmd('git rev-parse --show-toplevel') + topleveldir = result.output.strip() + result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile)) + status = result.output.splitlines() + relpatchpath = os.path.join(os.path.relpath(os.path.dirname(recipefile), topleveldir), testrecipe) + expectedstatus = [('M', os.path.relpath(recipefile, topleveldir)), + ('??', '%s/0001-Change-the-Makefile.patch' % relpatchpath), + ('??', '%s/0002-Add-a-new-file.patch' % relpatchpath)] + for line in status: + statusline = line.split(None, 1) + for fstatus, fn in expectedstatus: + if fn == statusline[1]: + if fstatus != statusline[0]: + self.fail('Unexpected status in line: %s' % line) + break + else: + self.fail('Unexpected modified file in line: %s' % line) @testcase(1170) def test_devtool_update_recipe_append(self):
@@ -708,7 +728,7 @@ class DevtoolTests(DevtoolBase): self.add_command_to_tearDown('bitbake-layers remove-layer %s || true' % templayerdir) result = runCmd('bitbake-layers add-layer %s' % templayerdir, cwd=self.builddir) # Create the bbappend - result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) + result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir)) self.assertNotIn('WARNING:', result.output) # Check recipe is still clean result = runCmd('git status . --porcelain', cwd=os.path.dirname(recipefile))
@@ -729,12 +749,12 @@ class DevtoolTests(DevtoolBase): self.assertEqual(expectedlines, f.readlines()) # Check we can run it again and bbappend isn't modified - result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) + result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir)) with open(bbappendfile, 'r') as f: self.assertEqual(expectedlines, f.readlines()) # Drop new commit and check SRCREV changes result = runCmd('git reset HEAD^', cwd=tempsrcdir) - result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) + result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir)) self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') result = runCmd('git rev-parse HEAD', cwd=tempsrcdir) expectedlines = ['SRCREV = "%s"\n' % result.output,
@@ -747,7 +767,7 @@ class DevtoolTests(DevtoolBase): os.remove(bbappendfile) result = runCmd('git commit -a -m "Change the Makefile"', cwd=tempsrcdir) result = runCmd('bitbake-layers remove-layer %s' % templayerdir, cwd=self.builddir) - result = runCmd('devtool update-recipe %s -a %s' % (testrecipe, templayerdir)) + result = runCmd('devtool update-recipe -m srcrev %s -a %s' % (testrecipe, templayerdir)) self.assertIn('WARNING: Specified layer is not currently enabled in bblayers.conf', result.output) self.assertFalse(os.path.exists(os.path.join(appenddir, testrecipe)), 'Patch directory should not be created') result = runCmd('git rev-parse HEAD', cwd=tempsrcdir)
scripts/lib/devtool/standard.py +27 -7
@@ -757,6 +757,31 @@ def _update_recipe_patch(args, config, srctree, rd, config_data): _remove_patch_files(args, removepatches, destpath) +def _guess_recipe_update_mode(srctree, rdata): + """Guess the recipe update mode to use""" + src_uri = (rdata.getVar('SRC_URI', False) or '').split() + git_uris = [uri for uri in src_uri if uri.startswith('git://')] + if not git_uris: + return 'patch' + # Just use the first URI for now + uri = git_uris[0] + # Check remote branch + upstr_branch = 'master' + for paramdef in uri.split(';')[1:]: + name, value = paramdef.split('=', 1) + if name == 'branch': + upstr_branch = value + # Check if current branch HEAD is found in upstream branch + stdout, _ = bb.process.run('git rev-parse HEAD', cwd=srctree) + head_rev = stdout.rstrip() + stdout, _ = bb.process.run('git branch -r --contains %s' % head_rev, + cwd=srctree) + remote_brs = [branch.strip() for branch in stdout.splitlines()] + if 'origin/' + upstr_branch in remote_brs: + return 'srcrev' + + return 'patch' + def update_recipe(args, config, basepath, workspace): """Entry point for the devtool 'update-recipe' subcommand""" if not args.recipename in workspace:
@@ -777,17 +802,12 @@ def update_recipe(args, config, basepath, workspace): if not rd: return 1 - orig_src_uri = rd.getVar('SRC_URI', False) or '' + srctree = workspace[args.recipename]['srctree'] if args.mode == 'auto': - if 'git://' in orig_src_uri: - mode = 'srcrev' - else: - mode = 'patch' + mode = _guess_recipe_update_mode(srctree, rd) else: mode = args.mode - srctree = workspace[args.recipename]['srctree'] - if mode == 'srcrev': _update_recipe_srcrev(args, srctree, rd, tinfoil.config_data) elif mode == 'patch':
Signature · 1 line
2.1.0
PATCH 7/9 devtool: update-recipe: add a warning when recipe is inside the workspace
In reply to Paul EggletonIf a recipe has been added to the workspace via "devtool add" or "devtool upgrade" then the recipe file itself will be in the workspace layer; if you run "devtool update-recipe" particularly in the upgrade case you might think it would apply the upgrade to the original recipe, but it will not - in order to remain consistent it has to update the recipe that's in use which is the one in the workspace. Warn the user in this situation so that they know what they need to do when they are finished.
--- scripts/lib/devtool/standard.py | 4 ++++ 1 file changed, 4 insertions(+)
scripts/lib/devtool/standard.py +4 -0
@@ -815,6 +815,10 @@ def update_recipe(args, config, basepath, workspace): else: raise DevtoolError('update_recipe: invalid mode %s' % mode) + rf = rd.getVar('FILE', True) + if rf.startswith(config.workspace_path): + logger.warn('Recipe file %s has been updated but is inside the workspace - you will need to move it (and any associated files next to it) out to the desired layer before using "devtool reset" in order to keep any changes' % rf) + return 0
Signature · 1 line
2.1.0
PATCH 8/9 devtool: add package plugin that lets you create package via devtool
In reply to Paul EggletonFrom: Brendan Le Foll <[email protected]>
Enables creating packages using devtool within the extensible SDK. (This is only enabled within the extensible SDK because it provides no advantage over just running bitbake directly there).
--- scripts/lib/devtool/package.py | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 scripts/lib/devtool/package.py
scripts/lib/devtool/package.py new file +61 -0
@@ -0,0 +1,61 @@ +# Development tool - package command plugin +# +# Copyright (C) 2014-2015 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +"""Devtool plugin containing the package subcommands""" + +import os +import subprocess +import logging +from bb.process import ExecutionError +from devtool import exec_build_env_command, setup_tinfoil, DevtoolError + +logger = logging.getLogger('devtool') + +def plugin_init(pluginlist): + """Plugin initialization""" + pass + +def package(args, config, basepath, workspace): + """Entry point for the devtool 'package' subcommand""" + if not args.recipename in workspace: + raise DevtoolError("no recipe named %s in your workspace" % + args.recipename) + + image_pkgtype = config.get('Package', 'image_pkgtype', '') + if not image_pkgtype: + tinfoil = setup_tinfoil() + try: + tinfoil.prepare(config_only=True) + image_pkgtype = tinfoil.config_data.getVar('IMAGE_PKGTYPE', True) + finally: + tinfoil.shutdown() + + package_task = config.get('Package', 'package_task', 'package_write_%s' % image_pkgtype) + try: + exec_build_env_command(config.init_path, basepath, 'bitbake -c %s %s' % (package_task, args.recipename), watch=True) + except bb.process.ExecutionError as e: + # We've already seen the output since watch=True, so just ensure we return something to the user + return e.exitcode + logger.info('Your packages are in %s/tmp/deploy/%s' % (basepath, image_pkgtype)) + + return 0 + +def register_commands(subparsers, context): + """Register devtool subcommands from the package plugin""" + if context.fixed_setup: + parser_package = subparsers.add_parser('package', help='Build packages for a recipe', description='Builds packages for a recipe\'s output files') + parser_package.add_argument('recipename', help='Recipe to package') + parser_package.set_defaults(func=package)
Signature · 1 line
2.1.0
PATCH 9/9 devtool: fix running from a different directory
In reply to Paul EggletonFixes the following error when running devtool from a directory other than the build directory (or the SDK base path when using within the extensible SDK):
The BBPATH variable is not set and bitbake did not find a conf/bblayers.conf file in the expected location. Maybe you accidentally invoked bitbake from the wrong directory?
--- scripts/devtool | 3 +++ 1 file changed, 3 insertions(+)
scripts/devtool +3 -0
@@ -221,6 +221,9 @@ def main(): if not config.read(): return -1 + # We need to be in this directory or we won't be able to initialise tinfoil + os.chdir(basepath) + bitbake_subdir = config.get('General', 'bitbake_subdir', '') if bitbake_subdir: # Normally set for use within the SDK
Signature · 1 line
2.1.0