devtool: add sync command
PATCH 1/1 devtool: add sync command
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
--- scripts/lib/devtool/standard.py | 73 +++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 17 deletions(-)
scripts/lib/devtool/standard.py +56 -17
@@ -234,7 +234,29 @@ def extract(args, config, basepath, workspace): return 1 srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1 + +def sync(args, config, basepath, workspace): + """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shown + return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, True, rd) logger.info('Source tree extracted to %s' % srctree) if initial_rev:
@@ -289,7 +311,7 @@ def _prep_extract_operation(config, basepath, recipename): return tinfoil -def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d): """Extract sources of a recipe""" import bb.event import oe.recipeutils
@@ -308,21 +330,26 @@ def _extract_source(srctree, keep_temp, devbranch, d): _check_compatible_recipe(pn, d) - if os.path.exists(srctree): - if not os.path.isdir(srctree): - raise DevtoolError("output path %s exists and is not a directory" % - srctree) - elif os.listdir(srctree): - raise DevtoolError("output path %s already exists and is " - "non-empty" % srctree) + if sync: + if not os.path.exists(srctree): + raise DevtoolError("output path %s does not exist" % srctree) + else: + if os.path.exists(srctree): + if not os.path.isdir(srctree): + raise DevtoolError("output path %s exists and is not a directory" % + srctree) + elif os.listdir(srctree): + raise DevtoolError("output path %s already exists and is " + "non-empty" % srctree) - if 'noexec' in (d.getVarFlags('do_unpack', False) or []): - raise DevtoolError("The %s recipe has do_unpack disabled, unable to " - "extract source" % pn) + if 'noexec' in (d.getVarFlags('do_unpack', False) or []): + raise DevtoolError("The %s recipe has do_unpack disabled, unable to " + "extract source" % pn) - # Prepare for shutil.move later on - bb.utils.mkdirhier(srctree) - os.rmdir(srctree) + if not sync: + # Prepare for shutil.move later on + bb.utils.mkdirhier(srctree) + os.rmdir(srctree) # We don't want notes to be printed, they are too verbose origlevel = bb.logger.getEffectiveLevel()
@@ -431,8 +458,11 @@ def _extract_source(srctree, keep_temp, devbranch, d): logger.info('Adding local source files to srctree...') shutil.move(os.path.join(tempdir, 'oe-local-files'), srcsubdir) + if sync: + bb.process.run('git fetch file://' + srcsubdir + ' ' + devbranch + ':' + devbranch, cwd=srctree) + else: + shutil.move(srcsubdir, srctree) - shutil.move(srcsubdir, srctree) finally: bb.logger.setLevel(origlevel)
@@ -532,7 +562,7 @@ def modify(args, config, basepath, workspace): commits = [] srctree = os.path.abspath(args.srctree) if args.extract: - initial_rev = _extract_source(args.srctree, False, args.branch, rd) + initial_rev = _extract_source(args.srctree, False, args.branch, False, rd) if not initial_rev: return 1 logger.info('Source tree extracted to %s' % srctree)
@@ -1107,6 +1137,15 @@ def register_commands(subparsers, context): parser_extract.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') parser_extract.set_defaults(func=extract) + parser_sync = subparsers.add_parser('sync', help='Synchronize the source for an existing recipe', + description='Synchronize the source for an existing recipe', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_sync.add_argument('recipename', help='Name for recipe to sync the source for') + parser_sync.add_argument('srctree', help='Path to where to sync the source tree') + parser_sync.add_argument('--branch', '-b', default="devtool", help='Name for development branch to checkout') + parser_sync.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') + parser_sync.set_defaults(func=sync) + parser_update_recipe = subparsers.add_parser('update-recipe', help='Apply changes from external source tree to recipe', description='Applies changes from external source tree to a recipe (updating/adding/removing patches as necessary, or by updating SRCREV)') parser_update_recipe.add_argument('recipename', help='Name of recipe to update')
Signature · 1 line
2.6.2
Hi Tzu-Jung,
Thanks for the patch.
Quoted 19 lines · On Wednesday 21 October 2015 23:06:45 Tzu-Jung Lee wrote:
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
Signed-off-by Tzu-Jung Lee <[email protected]>--- scripts/lib/devtool/standard.py | 73+++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 17 deletions(-)
(quoted diff) +0
-0
b/scripts/lib/devtool/standard.pyindex 5d7e903..2c6b7b3 100644scripts/lib/devtool/standard.py +0
-0@@ -234,7 +234,29 @@ def extract(args, config, basepath, workspace): return 1
scripts/lib/devtool/standard.py def extract(args, config, basepath, workspace): · line 244
Quoted 10 lines
scripts/lib/devtool/standard.py +7
-1srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1
Hmm, so your patch shows this check being added but it's there in master. Are you patching an older version?
Quoted 99 lines
scripts/lib/devtool/standard.py +15
-0+def sync(args, config, basepath, workspace): + """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shown + return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, True, rd) logger.info('Source tree extracted to %s' % srctree) if initial_rev:@@ -289,7 +311,7 @@ def _prep_extract_operation(config, basepath,recipename): return tinfoil
scripts/lib/devtool/standard.py +4
-7-def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d): """Extract sources of a recipe""" import bb.event import oe.recipeutils@@ -308,21 +330,26 @@ def _extract_source(srctree, keep_temp, devbranch, d): _check_compatible_recipe(pn, d) - if os.path.exists(srctree): - if not os.path.isdir(srctree): - raise DevtoolError("output path %s exists and is not a directory" % - srctree) - elif os.listdir(srctree): - raise DevtoolError("output path %s already exists and is " - "non-empty" % srctree) + if sync: + if not os.path.exists(srctree): + raise DevtoolError("output path %s does not exist" %srctree) + else:
scripts/lib/devtool/standard.py +3
-0+ if os.path.exists(srctree): + if not os.path.isdir(srctree): + raise DevtoolError("output path %s exists and is not adirectory" % + srctree)
scripts/lib/devtool/standard.py +3
-2+ elif os.listdir(srctree): + raise DevtoolError("output path %s already exists and is " + "non-empty" % srctree) - if 'noexec' in (d.getVarFlags('do_unpack', False) or []): - raise DevtoolError("The %s recipe has do_unpack disabled, unable to" - "extract source" % pn)
scripts/lib/devtool/standard.py +2
-0+ if 'noexec' in (d.getVarFlags('do_unpack', False) or []): + raise DevtoolError("The %s recipe has do_unpack disabled,unable to " + "extract source" % pn)
scripts/lib/devtool/standard.py +9
-5- # Prepare for shutil.move later on - bb.utils.mkdirhier(srctree) - os.rmdir(srctree) + if not sync: + # Prepare for shutil.move later on + bb.utils.mkdirhier(srctree) + os.rmdir(srctree) # We don't want notes to be printed, they are too verbose origlevel = bb.logger.getEffectiveLevel()@@ -431,8 +458,11 @@ def _extract_source(srctree, keep_temp, devbranch, d): logger.info('Adding local source files to srctree...') shutil.move(os.path.join(tempdir, 'oe-local-files'), srcsubdir) + if sync: + bb.process.run('git fetch file://' + srcsubdir + ' ' + devbranch + ':' + devbranch, cwd=srctree) + else: + shutil.move(srcsubdir, srctree) - shutil.move(srcsubdir, srctree) finally: bb.logger.setLevel(origlevel)@@ -532,7 +562,7 @@ def modify(args, config, basepath, workspace): commits = [] srctree = os.path.abspath(args.srctree) if args.extract: - initial_rev = _extract_source(args.srctree, False, args.branch, rd) + initial_rev = _extract_source(args.srctree, False, args.branch,False, rd) if not
initial_rev:
return 1
logger.info('Source tree extracted to %s' % srctree)scripts/lib/devtool/standard.py +1
-0@@ -1107,6 +1137,15 @@ def register_commands(subparsers, context): parser_extract.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') parser_extract.set_defaults(func=extract) + parser_sync = subparsers.add_parser('sync', help='Synchronize thesource for an existing recipe', + description='Synchronize the source for an existing recipe', +
Quoted 15 lines
formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_sync.add_argument('recipename', help='Name for recipe to sync the
source for') + parser_sync.add_argument('srctree', help='Path to where
to sync the source tree') + parser_sync.add_argument('--branch', '-b',
default="devtool", help='Name for development branch to checkout') +parser_sync.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)')+parser_sync.set_defaults(func=sync)
+
parser_update_recipe= subparsers.add_parser('update-recipe',
help='Apply changes from external source tree to recipe', description='Applies changes from external source tree to a recipe (updating/adding/removing patches as necessary, or by updating SRCREV)')parser_update_recipe.add_argument('recipename', help='Name of recipe to update')
Exploring the use case a bit more, do you anticipate using this sync command in conjunction with a recipe that's in the workspace, or standalone?
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
A message that is not in the archive (sent off-list or not yet received): CAHZ5O5wJAsNPv52=_YDFUebC5H3H1N9Z3zsPN7QRakpox14B1A@mail.gmail.com
Paul Eggleton
Acked-byQuoted 220 lines · On Monday 26 October 2015 10:29:24 Tzu-Jung Lee wrote:
Hi Paul
On Mon, Oct 26, 2015 at 2:20 AM, Paul Eggleton <
Quoted 45 lines · [email protected]> wrote:
Hi Tzu-Jung,
Thanks for the patch.
Quoted 6 lines · On Wednesday 21 October 2015 23:06:45 Tzu-Jung Lee wrote:
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
Quoted 6 lines
Signed-off-by Tzu-Jung Lee <[email protected]>---
scripts/lib/devtool/standard.py | 73+++++++++++++++++++++++++++++++---------- 1 file changed, 56
insertions(+),
scripts/lib/devtool/standard.py def extract(args, config, basepath, workspace): · line 238
Quoted 13 lines
17 deletions(-)
(quoted diff) +0
-0
b/scripts/lib/devtool/standard.pyindex 5d7e903..2c6b7b3 100644scripts/lib/devtool/standard.py +0
-1@@ -234,7 +234,29 @@ def extract(args, config, basepath, workspace): return 1 srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp, args.branch,rd)
scripts/lib/devtool/standard.py def extract(args, config, basepath, workspace): · line 243
Quoted 8 lines
scripts/lib/devtool/standard.py +7
-0+ initial_rev = _extract_source(srctree, args.keep_temp, args.branch, False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1Quoted 3 lines
Hmm, so your patch shows this check being added but it's there in master. Are
you patching an older version?Not really, it was patched against the tip of master.
But git is sometimes confused by the boundary of back-to-back similar functions.
So that checks are actually belongs to "def sync", which was copied from "def extract"def extract ...--------------------
| [checks] | | def sync | | ...--------------------
[checks]Quoted 137 lines
+def
sync(args, config, basepath, workspace):scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp, devbranch,
Quoted 30 lines
scripts/lib/devtool/standard.py +14
-0+ """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shown + return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch,True, rd)
logger.info('Source tree extracted to %s' % srctree)if
initial_rev:scripts/lib/devtool/standard.py +0
-0@@ -289,7 +311,7 @@ def _prep_extract_operation(config, basepath,recipename): return tinfoil
scripts/lib/devtool/standard.py +1
-1-def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d): """Extract sources of a recipe""" import bb.event import oe.recipeutils@@ -308,21 +330,26 @@ def _extract_source(srctree, keep_temp, devbranch,d):
Quoted 17 lines
scripts/lib/devtool/standard.py +3
-6_check_compatible_recipe(pn, d) - if os.path.exists(srctree): - if not os.path.isdir(srctree): - raise DevtoolError("output path %s exists and is not a directory" % - srctree) - elif os.listdir(srctree): - raise DevtoolError("output path %s already exists and is " - "non-empty" % srctree) + if sync: + if not os.path.exists(srctree): + raise DevtoolError("output path %s does not exist" %srctree) + else:
scripts/lib/devtool/standard.py +3
-0+ if os.path.exists(srctree): + if not os.path.isdir(srctree): + raise DevtoolError("output path %s exists and is not adirectory" % + srctree)
scripts/lib/devtool/standard.py
Quoted 2 lines
scripts/lib/devtool/standard.py +2
-0+ elif os.listdir(srctree): + raise DevtoolError("output path %s already exists andis "
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp, devbranch, d):
Quoted 4 lines
scripts/lib/devtool/standard.py +1
-2+ "non-empty" % srctree) - if 'noexec' in (d.getVarFlags('do_unpack', False) or []): - raise DevtoolError("The %s recipe has do_unpack disabled,unable to
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp, devbranch,
Quoted 17 lines
" - "extract source" % pn)
scripts/lib/devtool/standard.py +2
-0+ if 'noexec' in (d.getVarFlags('do_unpack', False) or []): + raise DevtoolError("The %s recipe has do_unpack disabled,unable to " + "extract source" % pn)
scripts/lib/devtool/standard.py +4
-3- # Prepare for shutil.move later on - bb.utils.mkdirhier(srctree) - os.rmdir(srctree) + if not sync: + # Prepare for shutil.move later on + bb.utils.mkdirhier(srctree) + os.rmdir(srctree) # We don't want notes to be printed, they are too verbose origlevel = bb.logger.getEffectiveLevel()@@ -431,8 +458,11 @@ def _extract_source(srctree, keep_temp, devbranch,d):
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp, devbranch, · line 459
Quoted 2 lines
scripts/lib/devtool/standard.py +0
-0logger.info('Adding local source files to srctree...') shutil.move(os.path.join(tempdir, 'oe-local-files'),srcsubdir)
Quoted 12 lines
scripts/lib/devtool/standard.py +4
-1+ if sync: + bb.process.run('git fetch file://' + srcsubdir + ' ' + devbranch + ':' + devbranch, cwd=srctree) + else: + shutil.move(srcsubdir, srctree) - shutil.move(srcsubdir, srctree) finally: bb.logger.setLevel(origlevel)scripts/lib/devtool/standard.py def modify(args, config, basepath, workspace): · line 536
Quoted 5 lines
scripts/lib/devtool/standard.py +0
-1@@ -532,7 +562,7 @@ def modify(args, config, basepath, workspace): commits = [] srctree = os.path.abspath(args.srctree) if args.extract: - initial_rev = _extract_source(args.srctree, False, args.branch,rd)
Quoted 31 lines
scripts/lib/devtool/standard.py +1
-0+ initial_rev = _extract_source(args.srctree, False, args.branch,False, rd) if not
initial_rev:
return 1
logger.info('Source tree extracted to %s' % srctree)scripts/lib/devtool/standard.py +1
-0@@ -1107,6 +1137,15 @@ def register_commands(subparsers, context): parser_extract.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') parser_extract.set_defaults(func=extract) + parser_sync = subparsers.add_parser('sync', help='Synchronize thesource for an existing recipe', + description='Synchronize the source for an existing recipe', +
formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_sync.add_argument('recipename', help='Name for recipe to sync the
source for') + parser_sync.add_argument('srctree', help='Path to
where
to sync the source tree') + parser_sync.add_argument('--branch',
'-b',
default="devtool", help='Name for development branch to checkout') +parser_sync.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)')+parser_sync.set_defaults(func=sync)
+
parser_update_recipe= subparsers.add_parser('update-recipe',Quoted 9 lines
Quoted 5 lines
help='Apply changes from external source tree to recipe', description='Applies changes from external source tree to a recipe (updating/adding/removing patches as necessary, or by updating SRCREV)')
parser_update_recipe.add_argument('recipename', help='Name of recipe to update')Exploring the use case a bit more, do you anticipate using this sync command
in conjunction with a recipe that's in the workspace, or standalone?
Quoted 5 lines
The use case is for workspace to keep git repos up-to-date. (Kind of rebasing) So the assumption is that the recipes have a corresponding git repository already, which could be an existing internal one, or a freshly constructed by an earlier devtool modify/extract. For standalone recipes, they can still go through the workspace :-)
I guess what I was wondering was is there a way we can better fit this in with devtool's workflow for when the recipe is in the workspace. However, other than perhaps not expecting the path to the source tree when the recipe is in the workspace I can't think of anything though. I guess we can always improve it later.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
On Wed, Nov 4, 2015 at 7:48 AM, Paul Eggleton <[email protected]
Quoted 246 lines
wrote:
Quoted 32 lines · On Monday 26 October 2015 10:29:24 Tzu-Jung Lee wrote:
Hi Paul
On Mon, Oct 26, 2015 at 2:20 AM, Paul Eggleton <
Quoted 27 lines · [email protected]> wrote:
Hi Tzu-Jung,
Thanks for the patch.
Quoted 6 lines · On Wednesday 21 October 2015 23:06:45 Tzu-Jung Lee wrote:
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
Quoted 6 lines
Signed-off-by Tzu-Jung Lee <[email protected]>---
scripts/lib/devtool/standard.py | 73+++++++++++++++++++++++++++++++---------- 1 file changed, 56
insertions(+),
Quoted 7 lines
17 deletions(-)
(quoted diff) +0
-0
b/scripts/lib/devtool/standard.pyindex 5d7e903..2c6b7b3 100644scripts/lib/devtool/standard.py +0
-0Quoted 6 lines
Quoted 6 lines
scripts/lib/devtool/standard.py def extract(args, config, basepath, workspace): · line 238
Quoted 6 lines
scripts/lib/devtool/standard.py +0
-1@@ -234,7 +234,29 @@ def extract(args, config, basepath, workspace): return 1 srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp,args.branch,
Quoted 4 lines
Quoted 4 lines
rd)
Quoted 1 line
scripts/lib/devtool/standard.py +1
-0+ initial_rev = _extract_source(srctree, args.keep_temp,args.branch,
Quoted 9 lines
Quoted 9 lines
scripts/lib/devtool/standard.py def extract(args, config, basepath, workspace): · line 243
Quoted 7 lines
scripts/lib/devtool/standard.py +6
-0False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1Hmm, so your patch shows this check being added but it's there in
master.
Quoted 23 lines
Quoted 2 lines
Are
you patching an older version?Not really, it was patched against the tip of master.
But git is sometimes confused by the boundary of back-to-back similar functions.
So that checks are actually belongs to "def sync", which was copied from "def extract"def extract ...--------------------
| [checks] | | def sync | | ...--------------------
[checks]Quoted 1 line
+def
sync(args, config, basepath, workspace):Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
scripts/lib/devtool/standard.py +6
-0+ """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shownQuoted 8 lines
scripts/lib/devtool/standard.py def extract(args, config, basepath, workspace):
Quoted 8 lines
scripts/lib/devtool/standard.py +8
-0+ return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp,args.branch,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
True, rd)
logger.info('Source tree extracted to %s' % srctree)if
initial_rev:scripts/lib/devtool/standard.py +0
-0@@ -289,7 +311,7 @@ def _prep_extract_operation(config, basepath,recipename): return tinfoil
Quoted 8 lines
Quoted 8 lines
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp,
Quoted 8 lines
scripts/lib/devtool/standard.py +1
-1-def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d): """Extract sources of a recipe""" import bb.event import oe.recipeutils@@ -308,21 +330,26 @@ def _extract_source(srctree, keep_temp,devbranch,
Quoted 10 lines
Quoted 10 lines
d):
Quoted 8 lines
scripts/lib/devtool/standard.py +0
-5_check_compatible_recipe(pn, d) - if os.path.exists(srctree): - if not os.path.isdir(srctree): - raise DevtoolError("output path %s exists and is not a directory" % - srctree) - elif os.listdir(srctree): - raise DevtoolError("output path %s already exists andis "
Quoted 8 lines
Quoted 8 lines
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp, devbranch, d):
Quoted 8 lines
scripts/lib/devtool/standard.py +3
-1- "non-empty" % srctree) + if sync: + if not os.path.exists(srctree): + raise DevtoolError("output path %s does not exist" %srctree) + else:
scripts/lib/devtool/standard.py +3
-0+ if os.path.exists(srctree): + if not os.path.isdir(srctree): + raise DevtoolError("output path %s exists and isnot a
Quoted 3 lines
Quoted 3 lines
scripts/lib/devtool/standard.py
Quoted 3 lines
directory" % + srctree)
scripts/lib/devtool/standard.py +2
-0+ elif os.listdir(srctree): + raise DevtoolError("output path %s already existsand
Quoted 5 lines
Quoted 5 lines
is "
Quoted 2 lines
+ "non-empty" % srctree)
Quoted 8 lines
Quoted 8 lines
scripts/lib/devtool/standard.py
Quoted 2 lines
scripts/lib/devtool/standard.py +0
-2- if 'noexec' in (d.getVarFlags('do_unpack', False) or []): - raise DevtoolError("The %s recipe has do_unpack disabled,unable to
Quoted 3 lines
" - "extract source" % pn)
scripts/lib/devtool/standard.py +2
-0+ if 'noexec' in (d.getVarFlags('do_unpack', False) or []): + raise DevtoolError("The %s recipe has do_unpackdisabled,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
unable to " + "extract source" % pn)
scripts/lib/devtool/standard.py +4
-3- # Prepare for shutil.move later on - bb.utils.mkdirhier(srctree) - os.rmdir(srctree) + if not sync: + # Prepare for shutil.move later on + bb.utils.mkdirhier(srctree) + os.rmdir(srctree)Quoted 4 lines
Quoted 4 lines
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp,
Quoted 4 lines
# We don't want notes to be printed, they are too verbose origlevel =
bb.logger.getEffectiveLevel()scripts/lib/devtool/standard.py +0
-0@@ -431,8 +458,11 @@ def _extract_source(srctree, keep_temp,devbranch,
Quoted 18 lines
Quoted 18 lines
d):
scripts/lib/devtool/standard.py def _extract_source(srctree, keep_temp, · line 459
Quoted 2 lines
scripts/lib/devtool/standard.py +0
-0logger.info('Adding local source files to srctree...') shutil.move(os.path.join(tempdir, 'oe-local-files'),srcsubdir)
Quoted 11 lines
scripts/lib/devtool/standard.py +4
-1+ if sync: + bb.process.run('git fetch file://' + srcsubdir + ' ' + devbranch + ':' + devbranch, cwd=srctree) + else: + shutil.move(srcsubdir, srctree) - shutil.move(srcsubdir, srctree) finally: bb.logger.setLevel(origlevel)Quoted 6 lines
Quoted 6 lines
scripts/lib/devtool/standard.py def modify(args, config, basepath, workspace): · line 536
Quoted 6 lines
scripts/lib/devtool/standard.py +0
-1@@ -532,7 +562,7 @@ def modify(args, config, basepath, workspace): commits = [] srctree = os.path.abspath(args.srctree) if args.extract: - initial_rev = _extract_source(args.srctree, False,args.branch,
Quoted 4 lines
Quoted 4 lines
rd)
Quoted 1 line
scripts/lib/devtool/standard.py +1
-0+ initial_rev = _extract_source(args.srctree, False,args.branch,
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
False, rd) if not
initial_rev:
return 1
logger.info('Source tree extracted to %s' % srctree)Quoted 7 lines
Quoted 7 lines
scripts/lib/devtool/standard.py def register_commands(subparsers, context): · line 1142
Quoted 7 lines
scripts/lib/devtool/standard.py +1
-0@@ -1107,6 +1137,15 @@ def register_commands(subparsers, context): parser_extract.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') parser_extract.set_defaults(func=extract) + parser_sync = subparsers.add_parser('sync', help='Synchronizethe
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
source for an existing recipe', + description='Synchronize the source for an existing recipe', +
formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_sync.add_argument('recipename', help='Name for recipe to sync
the
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
source for') + parser_sync.add_argument('srctree', help='Path to
where
to sync the source tree') + parser_sync.add_argument('--branch',
'-b',
default="devtool", help='Name for development branch to checkout') + parser_sync.add_argument('--keep-temp', action="store_true",help='Keep
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
temporary directory (for debugging)') +
parser_sync.set_defaults(func=sync)
+
parser_update_recipe= subparsers.add_parser('update-recipe',help='Apply changes from external source tree to recipe', description='Applies changes from external source tree to a recipe (updating/adding/removing patches as necessary, or by updating
SRCREV)')
Quoted 1 line
Quoted 1 line
Quoted 1 line
parser_update_recipe.add_argument('recipename', help='Name of recipe
to
Quoted 11 lines
Quoted 5 lines
Quoted 1 line
update')
Exploring the use case a bit more, do you anticipate using this sync command
in conjunction with a recipe that's in the workspace, or standalone?The use case is for workspace to keep git repos up-to-date. (Kind of rebasing) So the assumption is that the recipes have a corresponding git repository already, which could be an existing internal one, or a freshly constructed by an earlier devtool modify/extract. For standalone recipes, they can still go through the workspace :-)
Quoted 9 lines
I guess what I was wondering was is there a way we can better fit this in with
devtool's workflow for when the recipe is in the workspace. However, other than
perhaps not expecting the path to the source tree when the recipe is in the workspace I can't think of anything though. I guess we can always improve it
later.
Maybe we can fit it like the following:
1. Start to modify a recipe by either:
a. reusing an existing <srctree>
$ devtool modify <recipename> <srctree>
b. or creating a new one with the -x option
$ devtool modify <recipename> -x <srctree>
2. Work on the <srctree>
3. After a while, the upstream of <recipename> moves forward before we contribute our changes back.
4. Sync up the upstream changes into <srctree> with a new branch <branchname>
$ devtool sync <recipename> <srctree> --branch <branchname>
5. Rebase our working branch onto the tip of the upstream <branchname>
$ git rebase <branchname> devtool
[ Repeat 2 - 5 ]
6. Apply the changes back to the recipe.
$ devtool update-recipe <branchname>
- Roy
Quoted 10 lines
Acked-by Paul Eggleton <[email protected]>Cheers,
Paul--
Paul Eggleton
Intel Open Source Technology Centre
PATCH v2 1/1 devtool: add sync command
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
scripts/lib/devtool/standard.py +79 -21
@@ -238,7 +238,29 @@ def extract(args, config, basepath, workspace): return 1 srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1 + +def sync(args, config, basepath, workspace): + """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shown + return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, True, rd) logger.info('Source tree extracted to %s' % srctree) if initial_rev:
@@ -293,7 +315,7 @@ def _prep_extract_operation(config, basepath, recipename): return tinfoil -def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d): """Extract sources of a recipe""" import bb.event import oe.recipeutils
@@ -312,21 +334,26 @@ def _extract_source(srctree, keep_temp, devbranch, d): _check_compatible_recipe(pn, d) - if os.path.exists(srctree): - if not os.path.isdir(srctree): - raise DevtoolError("output path %s exists and is not a directory" % - srctree) - elif os.listdir(srctree): - raise DevtoolError("output path %s already exists and is " - "non-empty" % srctree) + if sync: + if not os.path.exists(srctree): + raise DevtoolError("output path %s does not exist" % srctree) + else: + if os.path.exists(srctree): + if not os.path.isdir(srctree): + raise DevtoolError("output path %s exists and is not a directory" % + srctree) + elif os.listdir(srctree): + raise DevtoolError("output path %s already exists and is " + "non-empty" % srctree) - if 'noexec' in (d.getVarFlags('do_unpack', False) or []): - raise DevtoolError("The %s recipe has do_unpack disabled, unable to " - "extract source" % pn) + if 'noexec' in (d.getVarFlags('do_unpack', False) or []): + raise DevtoolError("The %s recipe has do_unpack disabled, unable to " + "extract source" % pn) - # Prepare for shutil.move later on - bb.utils.mkdirhier(srctree) - os.rmdir(srctree) + if not sync: + # Prepare for shutil.move later on + bb.utils.mkdirhier(srctree) + os.rmdir(srctree) # We don't want notes to be printed, they are too verbose origlevel = bb.logger.getEffectiveLevel()
@@ -430,13 +457,35 @@ def _extract_source(srctree, keep_temp, devbranch, d): if haspatches: bb.process.run('git checkout patches', cwd=srcsubdir) - # Move oe-local-files directory to srctree - if os.path.exists(os.path.join(tempdir, 'oe-local-files')): - logger.info('Adding local source files to srctree...') - shutil.move(os.path.join(tempdir, 'oe-local-files'), srcsubdir) + tempdir_localdir = os.path.join(tempdir, 'oe-local-files') + srctree_localdir = os.path.join(srctree, 'oe-local-files') + if sync: + bb.process.run('git fetch file://' + srcsubdir + ' ' + devbranch + ':' + devbranch, cwd=srctree) + + # Move oe-local-files directory to srctree + # As the oe-local-files is not part of the constructed git tree, + # remove them directly during the synchrounizating might surprise + # the users. Instead, we move it to oe-local-files.bak and remind + # user in the log message. + if os.path.exists(srctree_localdir + '.bak'): + shutil.rmtree(srctree_localdir, srctree_localdir + '.bak') + + if os.path.exists(srctree_localdir): + logger.info('Backing up current local file directory %s' % srctree_localdir) + shutil.move(srctree_localdir, srctree_localdir + '.bak') + + if os.path.exists(tempdir_localdir): + logger.info('Syncing local source files to srctree...') + shutil.copytree(tempdir_localdir, srctree_localdir) + else: + # Move oe-local-files directory to srctree + if os.path.exists(tempdir_localdir): + logger.info('Adding local source files to srctree...') + shutil.move(tempdir_localdir, srcsubdir) + + shutil.move(srcsubdir, srctree) - shutil.move(srcsubdir, srctree) finally: bb.logger.setLevel(origlevel)
@@ -544,7 +593,7 @@ def modify(args, config, basepath, workspace): commits = [] srctree = os.path.abspath(args.srctree) if args.extract: - initial_rev = _extract_source(args.srctree, False, args.branch, rd) + initial_rev = _extract_source(args.srctree, False, args.branch, False, rd) if not initial_rev: return 1 logger.info('Source tree extracted to %s' % srctree)
@@ -1119,6 +1168,15 @@ def register_commands(subparsers, context): parser_extract.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') parser_extract.set_defaults(func=extract) + parser_sync = subparsers.add_parser('sync', help='Synchronize the source for an existing recipe', + description='Synchronize the source for an existing recipe', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_sync.add_argument('recipename', help='Name for recipe to sync the source for') + parser_sync.add_argument('srctree', help='Path to where to sync the source tree') + parser_sync.add_argument('--branch', '-b', default="devtool", help='Name for development branch to checkout') + parser_sync.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') + parser_sync.set_defaults(func=sync) + parser_update_recipe = subparsers.add_parser('update-recipe', help='Apply changes from external source tree to recipe', description='Applies changes from external source tree to a recipe (updating/adding/removing patches as necessary, or by updating SRCREV)') parser_update_recipe.add_argument('recipename', help='Name of recipe to update')
Signature · 1 line
2.6.3
Quoted 47 lines · On Friday 06 November 2015 21:10:10 Tzu-Jung Lee wrote:
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
Signed-off-by Tzu-Jung Lee <[email protected]>(quoted diff) +0
-0
b/scripts/lib/devtool/standard.pyindex c5c647b..8efd262 100644scripts/lib/devtool/standard.py +22
-1@@ -238,7 +238,29 @@ def extract(args, config, basepath, workspace): return 1 srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1 + +def sync(args, config, basepath, workspace): + """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shown + return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, True, rd) logger.info('Source tree extracted to %s' % srctree) if initial_rev:@@ -293,7 +315,7 @@ def _prep_extract_operation(config, basepath,recipename): return tinfoil
scripts/lib/devtool/standard.py def _prep_extract_operation(config, basepath, recipename): · line 318
Quoted 2 lines
scripts/lib/devtool/standard.py +1
-1-def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d):
You're changing this function but you missed updating one call in scripts/lib/devtool/upgrade.py. (I know, the name starting with _ implies it's internal, but we're also using it there as well).
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH v3 1/1 devtool: add sync command
The sync command is similar to the extract command, except it fetches the sync'ed and patched branch to an existing git repository.
This enables users to keep track the upstream development while maintaining their own local git repository at the same time.
---
Thanks for the reminder :-)
scripts/lib/devtool/standard.py +79 -21
@@ -238,7 +238,29 @@ def extract(args, config, basepath, workspace): return 1 srctree = os.path.abspath(args.srctree) - initial_rev = _extract_source(srctree, args.keep_temp, args.branch, rd) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, False, rd) + logger.info('Source tree extracted to %s' % srctree) + + if initial_rev: + return 0 + else: + return 1 + +def sync(args, config, basepath, workspace): + """Entry point for the devtool 'sync' subcommand""" + import bb + + tinfoil = _prep_extract_operation(config, basepath, args.recipename) + if not tinfoil: + # Error already shown + return 1 + + rd = parse_recipe(config, tinfoil, args.recipename, True) + if not rd: + return 1 + + srctree = os.path.abspath(args.srctree) + initial_rev = _extract_source(srctree, args.keep_temp, args.branch, True, rd) logger.info('Source tree extracted to %s' % srctree) if initial_rev:
@@ -293,7 +315,7 @@ def _prep_extract_operation(config, basepath, recipename): return tinfoil -def _extract_source(srctree, keep_temp, devbranch, d): +def _extract_source(srctree, keep_temp, devbranch, sync, d): """Extract sources of a recipe""" import bb.event import oe.recipeutils
@@ -312,21 +334,26 @@ def _extract_source(srctree, keep_temp, devbranch, d): _check_compatible_recipe(pn, d) - if os.path.exists(srctree): - if not os.path.isdir(srctree): - raise DevtoolError("output path %s exists and is not a directory" % - srctree) - elif os.listdir(srctree): - raise DevtoolError("output path %s already exists and is " - "non-empty" % srctree) + if sync: + if not os.path.exists(srctree): + raise DevtoolError("output path %s does not exist" % srctree) + else: + if os.path.exists(srctree): + if not os.path.isdir(srctree): + raise DevtoolError("output path %s exists and is not a directory" % + srctree) + elif os.listdir(srctree): + raise DevtoolError("output path %s already exists and is " + "non-empty" % srctree) - if 'noexec' in (d.getVarFlags('do_unpack', False) or []): - raise DevtoolError("The %s recipe has do_unpack disabled, unable to " - "extract source" % pn) + if 'noexec' in (d.getVarFlags('do_unpack', False) or []): + raise DevtoolError("The %s recipe has do_unpack disabled, unable to " + "extract source" % pn) - # Prepare for shutil.move later on - bb.utils.mkdirhier(srctree) - os.rmdir(srctree) + if not sync: + # Prepare for shutil.move later on + bb.utils.mkdirhier(srctree) + os.rmdir(srctree) # We don't want notes to be printed, they are too verbose origlevel = bb.logger.getEffectiveLevel()
@@ -430,13 +457,35 @@ def _extract_source(srctree, keep_temp, devbranch, d): if haspatches: bb.process.run('git checkout patches', cwd=srcsubdir) - # Move oe-local-files directory to srctree - if os.path.exists(os.path.join(tempdir, 'oe-local-files')): - logger.info('Adding local source files to srctree...') - shutil.move(os.path.join(tempdir, 'oe-local-files'), srcsubdir) + tempdir_localdir = os.path.join(tempdir, 'oe-local-files') + srctree_localdir = os.path.join(srctree, 'oe-local-files') + if sync: + bb.process.run('git fetch file://' + srcsubdir + ' ' + devbranch + ':' + devbranch, cwd=srctree) + + # Move oe-local-files directory to srctree + # As the oe-local-files is not part of the constructed git tree, + # remove them directly during the synchrounizating might surprise + # the users. Instead, we move it to oe-local-files.bak and remind + # user in the log message. + if os.path.exists(srctree_localdir + '.bak'): + shutil.rmtree(srctree_localdir, srctree_localdir + '.bak') + + if os.path.exists(srctree_localdir): + logger.info('Backing up current local file directory %s' % srctree_localdir) + shutil.move(srctree_localdir, srctree_localdir + '.bak') + + if os.path.exists(tempdir_localdir): + logger.info('Syncing local source files to srctree...') + shutil.copytree(tempdir_localdir, srctree_localdir) + else: + # Move oe-local-files directory to srctree + if os.path.exists(tempdir_localdir): + logger.info('Adding local source files to srctree...') + shutil.move(tempdir_localdir, srcsubdir) + + shutil.move(srcsubdir, srctree) - shutil.move(srcsubdir, srctree) finally: bb.logger.setLevel(origlevel)
@@ -544,7 +593,7 @@ def modify(args, config, basepath, workspace): commits = [] srctree = os.path.abspath(args.srctree) if args.extract: - initial_rev = _extract_source(args.srctree, False, args.branch, rd) + initial_rev = _extract_source(args.srctree, False, args.branch, False, rd) if not initial_rev: return 1 logger.info('Source tree extracted to %s' % srctree)
@@ -1119,6 +1168,15 @@ def register_commands(subparsers, context): parser_extract.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') parser_extract.set_defaults(func=extract) + parser_sync = subparsers.add_parser('sync', help='Synchronize the source for an existing recipe', + description='Synchronize the source for an existing recipe', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser_sync.add_argument('recipename', help='Name for recipe to sync the source for') + parser_sync.add_argument('srctree', help='Path to where to sync the source tree') + parser_sync.add_argument('--branch', '-b', default="devtool", help='Name for development branch to checkout') + parser_sync.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') + parser_sync.set_defaults(func=sync) + parser_update_recipe = subparsers.add_parser('update-recipe', help='Apply changes from external source tree to recipe', description='Applies changes from external source tree to a recipe (updating/adding/removing patches as necessary, or by updating SRCREV)') parser_update_recipe.add_argument('recipename', help='Name of recipe to update')
scripts/lib/devtool/upgrade.py +1 -1
@@ -312,7 +312,7 @@ def upgrade(args, config, basepath, workspace): rf = None try: - rev1 = standard._extract_source(args.srctree, False, 'devtool-orig', rd) + rev1 = standard._extract_source(args.srctree, False, 'devtool-orig', False, rd) rev2, md5, sha256 = _extract_new_source(args.version, args.srctree, args.no_patch, args.srcrev, args.branch, args.keep_temp, tinfoil, rd)
Signature · 1 line
2.6.3