blob: 05fb9e5ed07af8da7979ba61ce4ca144b32f30f0 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Development tool - upgrade command plugin
2#
3# Copyright (C) 2014-2015 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17#
18"""Devtool upgrade plugin"""
19
20import os
21import sys
22import re
23import shutil
24import tempfile
25import logging
26import argparse
27import scriptutils
28import errno
29import bb
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030
31devtool_path = os.path.dirname(os.path.realpath(__file__)) + '/../../../meta/lib'
32sys.path = sys.path + [devtool_path]
33
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034import oe.recipeutils
35from devtool import standard
Patrick Williamsf1e5d692016-03-30 15:21:19 -050036from devtool import exec_build_env_command, setup_tinfoil, DevtoolError, parse_recipe, use_external_build
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38logger = logging.getLogger('devtool')
39
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040def _run(cmd, cwd=''):
41 logger.debug("Running command %s> %s" % (cwd,cmd))
42 return bb.process.run('%s' % cmd, cwd=cwd)
43
44def _get_srctree(tmpdir):
45 srctree = tmpdir
46 dirs = os.listdir(tmpdir)
47 if len(dirs) == 1:
48 srctree = os.path.join(tmpdir, dirs[0])
49 return srctree
50
51def _copy_source_code(orig, dest):
52 for path in standard._ls_tree(orig):
53 dest_dir = os.path.join(dest, os.path.dirname(path))
54 bb.utils.mkdirhier(dest_dir)
55 dest_path = os.path.join(dest, path)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050056 shutil.move(os.path.join(orig, path), dest_path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057
58def _get_checksums(rf):
59 import re
60 checksums = {}
61 with open(rf) as f:
62 for line in f:
63 for cs in ['md5sum', 'sha256sum']:
64 m = re.match("^SRC_URI\[%s\].*=.*\"(.*)\"" % cs, line)
65 if m:
66 checksums[cs] = m.group(1)
67 return checksums
68
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069def _remove_patch_dirs(recipefolder):
70 for root, dirs, files in os.walk(recipefolder):
71 for d in dirs:
72 shutil.rmtree(os.path.join(root,d))
73
Patrick Williamsf1e5d692016-03-30 15:21:19 -050074def _recipe_contains(rd, var):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050075 rf = rd.getVar('FILE')
Patrick Williamsf1e5d692016-03-30 15:21:19 -050076 varfiles = oe.recipeutils.get_var_files(rf, [var], rd)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077 for var, fn in varfiles.items():
Patrick Williamsf1e5d692016-03-30 15:21:19 -050078 if fn and fn.startswith(os.path.dirname(rf) + os.sep):
79 return True
80 return False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050081
82def _rename_recipe_dirs(oldpv, newpv, path):
83 for root, dirs, files in os.walk(path):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060084 # Rename directories with the version in their name
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085 for olddir in dirs:
86 if olddir.find(oldpv) != -1:
87 newdir = olddir.replace(oldpv, newpv)
88 if olddir != newdir:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050089 shutil.move(os.path.join(path, olddir), os.path.join(path, newdir))
Patrick Williamsc0f7c042017-02-23 20:41:17 -060090 # Rename any inc files with the version in their name (unusual, but possible)
91 for oldfile in files:
92 if oldfile.endswith('.inc'):
93 if oldfile.find(oldpv) != -1:
94 newfile = oldfile.replace(oldpv, newpv)
95 if oldfile != newfile:
96 os.rename(os.path.join(path, oldfile), os.path.join(path, newfile))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050098def _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path):
99 oldrecipe = os.path.basename(oldrecipe)
100 if oldrecipe.endswith('_%s.bb' % oldpv):
101 newrecipe = '%s_%s.bb' % (bpn, newpv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102 if oldrecipe != newrecipe:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500103 shutil.move(os.path.join(path, oldrecipe), os.path.join(path, newrecipe))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500105 newrecipe = oldrecipe
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500106 return os.path.join(path, newrecipe)
107
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500108def _rename_recipe_files(oldrecipe, bpn, oldpv, newpv, path):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 _rename_recipe_dirs(oldpv, newpv, path)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500110 return _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600112def _write_append(rc, srctree, same_dir, no_same_dir, rev, copied, workspace, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113 """Writes an append file"""
114 if not os.path.exists(rc):
115 raise DevtoolError("bbappend not created because %s does not exist" % rc)
116
117 appendpath = os.path.join(workspace, 'appends')
118 if not os.path.exists(appendpath):
119 bb.utils.mkdirhier(appendpath)
120
121 brf = os.path.basename(os.path.splitext(rc)[0]) # rc basename
122
123 srctree = os.path.abspath(srctree)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 pn = d.getVar('PN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 af = os.path.join(appendpath, '%s.bbappend' % brf)
126 with open(af, 'w') as f:
127 f.write('FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n\n')
128 f.write('inherit externalsrc\n')
129 f.write(('# NOTE: We use pn- overrides here to avoid affecting'
130 'multiple variants in the case where the recipe uses BBCLASSEXTEND\n'))
131 f.write('EXTERNALSRC_pn-%s = "%s"\n' % (pn, srctree))
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500132 b_is_s = use_external_build(same_dir, no_same_dir, d)
133 if b_is_s:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (pn, srctree))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600135 f.write('\n')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 if rev:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137 f.write('# initial_rev: %s\n' % rev)
138 if copied:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500139 f.write('# original_path: %s\n' % os.path.dirname(d.getVar('FILE')))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600140 f.write('# original_files: %s\n' % ' '.join(copied))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 return af
142
143def _cleanup_on_error(rf, srctree):
144 rfp = os.path.split(rf)[0] # recipe folder
145 rfpp = os.path.split(rfp)[0] # recipes folder
146 if os.path.exists(rfp):
147 shutil.rmtree(b)
148 if not len(os.listdir(rfpp)):
149 os.rmdir(rfpp)
150 srctree = os.path.abspath(srctree)
151 if os.path.exists(srctree):
152 shutil.rmtree(srctree)
153
154def _upgrade_error(e, rf, srctree):
155 if rf:
156 cleanup_on_error(rf, srctree)
157 logger.error(e)
158 raise DevtoolError(e)
159
160def _get_uri(rd):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500161 srcuris = rd.getVar('SRC_URI').split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 if not len(srcuris):
163 raise DevtoolError('SRC_URI not found on recipe')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500164 # Get first non-local entry in SRC_URI - usually by convention it's
165 # the first entry, but not always!
166 srcuri = None
167 for entry in srcuris:
168 if not entry.startswith('file://'):
169 srcuri = entry
170 break
171 if not srcuri:
172 raise DevtoolError('Unable to find non-local entry in SRC_URI')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173 srcrev = '${AUTOREV}'
174 if '://' in srcuri:
175 # Fetch a URL
176 rev_re = re.compile(';rev=([^;]+)')
177 res = rev_re.search(srcuri)
178 if res:
179 srcrev = res.group(1)
180 srcuri = rev_re.sub('', srcuri)
181 return srcuri, srcrev
182
183def _extract_new_source(newpv, srctree, no_patch, srcrev, branch, keep_temp, tinfoil, rd):
184 """Extract sources of a recipe with a new version"""
185
186 def __run(cmd):
187 """Simple wrapper which calls _run with srctree as cwd"""
188 return _run(cmd, srctree)
189
190 crd = rd.createCopy()
191
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192 pv = crd.getVar('PV')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193 crd.setVar('PV', newpv)
194
195 tmpsrctree = None
196 uri, rev = _get_uri(crd)
197 if srcrev:
198 rev = srcrev
199 if uri.startswith('git://'):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500200 __run('git fetch')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500201 __run('git checkout %s' % rev)
202 __run('git tag -f devtool-base-new')
203 md5 = None
204 sha256 = None
205 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500206 __run('git checkout devtool-base -b devtool-%s' % newpv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207
208 tmpdir = tempfile.mkdtemp(prefix='devtool')
209 try:
210 md5, sha256 = scriptutils.fetch_uri(tinfoil.config_data, uri, tmpdir, rev)
211 except bb.fetch2.FetchError as e:
212 raise DevtoolError(e)
213
214 tmpsrctree = _get_srctree(tmpdir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500215 srctree = os.path.abspath(srctree)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500217 # Delete all sources so we ensure no stray files are left over
218 for item in os.listdir(srctree):
219 if item in ['.git', 'oe-local-files']:
220 continue
221 itempath = os.path.join(srctree, item)
222 if os.path.isdir(itempath):
223 shutil.rmtree(itempath)
224 else:
225 os.remove(itempath)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500227 # Copy in new ones
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 _copy_source_code(tmpsrctree, srctree)
229
230 (stdout,_) = __run('git ls-files --modified --others --exclude-standard')
231 for f in stdout.splitlines():
232 __run('git add "%s"' % f)
233
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600234 useroptions = []
235 oe.patch.GitApplyTree.gitCommandUserOptions(useroptions, d=rd)
236 __run('git %s commit -q -m "Commit of upstream changes at version %s" --allow-empty' % (' '.join(useroptions), newpv))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237 __run('git tag -f devtool-base-%s' % newpv)
238
239 (stdout, _) = __run('git rev-parse HEAD')
240 rev = stdout.rstrip()
241
242 if no_patch:
243 patches = oe.recipeutils.get_recipe_patches(crd)
244 if len(patches):
245 logger.warn('By user choice, the following patches will NOT be applied')
246 for patch in patches:
247 logger.warn("%s" % os.path.basename(patch))
248 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600249 __run('git checkout devtool-patched -b %s' % branch)
250 skiptag = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251 try:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252 __run('git rebase %s' % rev)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600253 except bb.process.ExecutionError as e:
254 skiptag = True
255 if 'conflict' in e.stdout:
256 logger.warn('Command \'%s\' failed:\n%s\n\nYou will need to resolve conflicts in order to complete the upgrade.' % (e.command, e.stdout.rstrip()))
257 else:
258 logger.warn('Command \'%s\' failed:\n%s' % (e.command, e.stdout))
259 if not skiptag:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260 if uri.startswith('git://'):
261 suffix = 'new'
262 else:
263 suffix = newpv
264 __run('git tag -f devtool-patched-%s' % suffix)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
266 if tmpsrctree:
267 if keep_temp:
268 logger.info('Preserving temporary directory %s' % tmpsrctree)
269 else:
270 shutil.rmtree(tmpsrctree)
271
272 return (rev, md5, sha256)
273
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500274def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, workspace, tinfoil, rd):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275 """Creates the new recipe under workspace"""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500277 bpn = rd.getVar('BPN')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 path = os.path.join(workspace, 'recipes', bpn)
279 bb.utils.mkdirhier(path)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600280 copied, _ = oe.recipeutils.copy_recipe_files(rd, path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500282 oldpv = rd.getVar('PV')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500283 if not newpv:
284 newpv = oldpv
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500285 origpath = rd.getVar('FILE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500286 fullpath = _rename_recipe_files(origpath, bpn, oldpv, newpv, path)
287 logger.debug('Upgraded %s => %s' % (origpath, fullpath))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500289 newvalues = {}
290 if _recipe_contains(rd, 'PV') and newpv != oldpv:
291 newvalues['PV'] = newpv
292
293 if srcrev:
294 newvalues['SRCREV'] = srcrev
295
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500296 if srcbranch:
297 src_uri = oe.recipeutils.split_var_value(rd.getVar('SRC_URI', False) or '')
298 changed = False
299 replacing = True
300 new_src_uri = []
301 for entry in src_uri:
302 scheme, network, path, user, passwd, params = bb.fetch2.decodeurl(entry)
303 if replacing and scheme in ['git', 'gitsm']:
304 branch = params.get('branch', 'master')
305 if rd.expand(branch) != srcbranch:
306 # Handle case where branch is set through a variable
307 res = re.match(r'\$\{([^}@]+)\}', branch)
308 if res:
309 newvalues[res.group(1)] = srcbranch
310 # We know we won't change SRC_URI now, so break out
311 break
312 else:
313 params['branch'] = srcbranch
314 entry = bb.fetch2.encodeurl((scheme, network, path, user, passwd, params))
315 changed = True
316 replacing = False
317 new_src_uri.append(entry)
318 if changed:
319 newvalues['SRC_URI'] = ' '.join(new_src_uri)
320
321 newvalues['PR'] = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322
323 if md5 and sha256:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500324 newvalues['SRC_URI[md5sum]'] = md5
325 newvalues['SRC_URI[sha256sum]'] = sha256
326
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327 rd = tinfoil.parse_recipe_file(fullpath, False)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500328 oe.recipeutils.patch_recipe(rd, fullpath, newvalues)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500329
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600330 return fullpath, copied
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331
332def upgrade(args, config, basepath, workspace):
333 """Entry point for the devtool 'upgrade' subcommand"""
334
335 if args.recipename in workspace:
336 raise DevtoolError("recipe %s is already in your workspace" % args.recipename)
337 if not args.version and not args.srcrev:
338 raise DevtoolError("You must provide a version using the --version/-V option, or for recipes that fetch from an SCM such as git, the --srcrev/-S option")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500339 if args.srcbranch and not args.srcrev:
340 raise DevtoolError("If you specify --srcbranch/-B then you must use --srcrev/-S to specify the revision" % args.recipename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500342 tinfoil = setup_tinfoil(basepath=basepath, tracking=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600344 rd = parse_recipe(config, tinfoil, args.recipename, True)
345 if not rd:
346 return 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500348 pn = rd.getVar('PN')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600349 if pn != args.recipename:
350 logger.info('Mapping %s to %s' % (args.recipename, pn))
351 if pn in workspace:
352 raise DevtoolError("recipe %s is already in your workspace" % pn)
353
354 if args.srctree:
355 srctree = os.path.abspath(args.srctree)
356 else:
357 srctree = standard.get_default_srctree(config, pn)
358
359 standard._check_compatible_recipe(pn, rd)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500360 old_srcrev = rd.getVar('SRCREV')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600361 if old_srcrev == 'INVALID':
362 old_srcrev = None
363 if old_srcrev and not args.srcrev:
364 raise DevtoolError("Recipe specifies a SRCREV value; you must specify a new one when upgrading")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500365 if rd.getVar('PV') == args.version and old_srcrev == args.srcrev:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600366 raise DevtoolError("Current and upgrade versions are the same version")
367
368 rf = None
369 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500370 rev1 = standard._extract_source(srctree, False, 'devtool-orig', False, rd, tinfoil)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600371 rev2, md5, sha256 = _extract_new_source(args.version, srctree, args.no_patch,
372 args.srcrev, args.branch, args.keep_temp,
373 tinfoil, rd)
374 rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, args.srcbranch, config.workspace_path, tinfoil, rd)
375 except bb.process.CmdError as e:
376 _upgrade_error(e, rf, srctree)
377 except DevtoolError as e:
378 _upgrade_error(e, rf, srctree)
379 standard._add_md5(config, pn, os.path.dirname(rf))
380
381 af = _write_append(rf, srctree, args.same_dir, args.no_same_dir, rev2,
382 copied, config.workspace_path, rd)
383 standard._add_md5(config, pn, af)
384 logger.info('Upgraded source extracted to %s' % srctree)
385 logger.info('New recipe is %s' % rf)
386 finally:
387 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388 return 0
389
390def register_commands(subparsers, context):
391 """Register devtool subcommands from this plugin"""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500392
393 defsrctree = standard.get_default_srctree(context.config)
394
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395 parser_upgrade = subparsers.add_parser('upgrade', help='Upgrade an existing recipe',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500396 description='Upgrades an existing recipe to a new upstream version. Puts the upgraded recipe file into the workspace along with any associated files, and extracts the source tree to a specified location (in case patches need rebasing or adding to as a result of the upgrade).',
397 group='starting')
398 parser_upgrade.add_argument('recipename', help='Name of recipe to upgrade (just name - no version, path or extension)')
399 parser_upgrade.add_argument('srctree', nargs='?', help='Path to where to extract the source tree. If not specified, a subdirectory of %s will be used.' % defsrctree)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400 parser_upgrade.add_argument('--version', '-V', help='Version to upgrade to (PV)')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600401 parser_upgrade.add_argument('--srcrev', '-S', help='Source revision to upgrade to (required if fetching from an SCM such as git)')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500402 parser_upgrade.add_argument('--srcbranch', '-B', help='Branch in source repository containing the revision to use (if fetching from an SCM such as git)')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500403 parser_upgrade.add_argument('--branch', '-b', default="devtool", help='Name for new development branch to checkout (default "%(default)s")')
404 parser_upgrade.add_argument('--no-patch', action="store_true", help='Do not apply patches from the recipe to the new source code')
405 group = parser_upgrade.add_mutually_exclusive_group()
406 group.add_argument('--same-dir', '-s', help='Build in same directory as source', action="store_true")
407 group.add_argument('--no-same-dir', help='Force build in a separate build directory', action="store_true")
408 parser_upgrade.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)')
409 parser_upgrade.set_defaults(func=upgrade)