Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Development tool - upgrade command plugin |
| 2 | # |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 3 | # Copyright (C) 2014-2017 Intel Corporation |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # |
| 7 | """Devtool upgrade plugin""" |
| 8 | |
| 9 | import os |
| 10 | import sys |
| 11 | import re |
| 12 | import shutil |
| 13 | import tempfile |
| 14 | import logging |
| 15 | import argparse |
| 16 | import scriptutils |
| 17 | import errno |
| 18 | import bb |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | |
| 20 | devtool_path = os.path.dirname(os.path.realpath(__file__)) + '/../../../meta/lib' |
| 21 | sys.path = sys.path + [devtool_path] |
| 22 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | import oe.recipeutils |
| 24 | from devtool import standard |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 25 | from devtool import exec_build_env_command, setup_tinfoil, DevtoolError, parse_recipe, use_external_build, update_unlockedsigs, check_prerelease_version |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | |
| 27 | logger = logging.getLogger('devtool') |
| 28 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | def _run(cmd, cwd=''): |
| 30 | logger.debug("Running command %s> %s" % (cwd,cmd)) |
| 31 | return bb.process.run('%s' % cmd, cwd=cwd) |
| 32 | |
| 33 | def _get_srctree(tmpdir): |
| 34 | srctree = tmpdir |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 35 | dirs = scriptutils.filter_src_subdirs(tmpdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | if len(dirs) == 1: |
| 37 | srctree = os.path.join(tmpdir, dirs[0]) |
| 38 | return srctree |
| 39 | |
| 40 | def _copy_source_code(orig, dest): |
| 41 | for path in standard._ls_tree(orig): |
| 42 | dest_dir = os.path.join(dest, os.path.dirname(path)) |
| 43 | bb.utils.mkdirhier(dest_dir) |
| 44 | dest_path = os.path.join(dest, path) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 45 | shutil.move(os.path.join(orig, path), dest_path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | def _remove_patch_dirs(recipefolder): |
| 48 | for root, dirs, files in os.walk(recipefolder): |
| 49 | for d in dirs: |
| 50 | shutil.rmtree(os.path.join(root,d)) |
| 51 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 52 | def _recipe_contains(rd, var): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | rf = rd.getVar('FILE') |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 54 | varfiles = oe.recipeutils.get_var_files(rf, [var], rd) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 55 | for var, fn in varfiles.items(): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 56 | if fn and fn.startswith(os.path.dirname(rf) + os.sep): |
| 57 | return True |
| 58 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
| 60 | def _rename_recipe_dirs(oldpv, newpv, path): |
| 61 | for root, dirs, files in os.walk(path): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 62 | # Rename directories with the version in their name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | for olddir in dirs: |
| 64 | if olddir.find(oldpv) != -1: |
| 65 | newdir = olddir.replace(oldpv, newpv) |
| 66 | if olddir != newdir: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | shutil.move(os.path.join(path, olddir), os.path.join(path, newdir)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 68 | # Rename any inc files with the version in their name (unusual, but possible) |
| 69 | for oldfile in files: |
| 70 | if oldfile.endswith('.inc'): |
| 71 | if oldfile.find(oldpv) != -1: |
| 72 | newfile = oldfile.replace(oldpv, newpv) |
| 73 | if oldfile != newfile: |
| 74 | os.rename(os.path.join(path, oldfile), os.path.join(path, newfile)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 76 | def _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path): |
| 77 | oldrecipe = os.path.basename(oldrecipe) |
| 78 | if oldrecipe.endswith('_%s.bb' % oldpv): |
| 79 | newrecipe = '%s_%s.bb' % (bpn, newpv) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | if oldrecipe != newrecipe: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 81 | shutil.move(os.path.join(path, oldrecipe), os.path.join(path, newrecipe)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | else: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 83 | newrecipe = oldrecipe |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | return os.path.join(path, newrecipe) |
| 85 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 86 | def _rename_recipe_files(oldrecipe, bpn, oldpv, newpv, path): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | _rename_recipe_dirs(oldpv, newpv, path) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 88 | return _rename_recipe_file(oldrecipe, bpn, oldpv, newpv, path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 90 | def _write_append(rc, srctree, same_dir, no_same_dir, rev, copied, workspace, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | """Writes an append file""" |
| 92 | if not os.path.exists(rc): |
| 93 | raise DevtoolError("bbappend not created because %s does not exist" % rc) |
| 94 | |
| 95 | appendpath = os.path.join(workspace, 'appends') |
| 96 | if not os.path.exists(appendpath): |
| 97 | bb.utils.mkdirhier(appendpath) |
| 98 | |
| 99 | brf = os.path.basename(os.path.splitext(rc)[0]) # rc basename |
| 100 | |
| 101 | srctree = os.path.abspath(srctree) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 102 | pn = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | af = os.path.join(appendpath, '%s.bbappend' % brf) |
| 104 | with open(af, 'w') as f: |
| 105 | f.write('FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n\n') |
| 106 | f.write('inherit externalsrc\n') |
| 107 | f.write(('# NOTE: We use pn- overrides here to avoid affecting' |
| 108 | 'multiple variants in the case where the recipe uses BBCLASSEXTEND\n')) |
| 109 | f.write('EXTERNALSRC_pn-%s = "%s"\n' % (pn, srctree)) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 110 | b_is_s = use_external_build(same_dir, no_same_dir, d) |
| 111 | if b_is_s: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | f.write('EXTERNALSRC_BUILD_pn-%s = "%s"\n' % (pn, srctree)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 113 | f.write('\n') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | if rev: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 115 | f.write('# initial_rev: %s\n' % rev) |
| 116 | if copied: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 117 | f.write('# original_path: %s\n' % os.path.dirname(d.getVar('FILE'))) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 118 | f.write('# original_files: %s\n' % ' '.join(copied)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | return af |
| 120 | |
| 121 | def _cleanup_on_error(rf, srctree): |
| 122 | rfp = os.path.split(rf)[0] # recipe folder |
| 123 | rfpp = os.path.split(rfp)[0] # recipes folder |
| 124 | if os.path.exists(rfp): |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 125 | shutil.rmtree(rfp) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | if not len(os.listdir(rfpp)): |
| 127 | os.rmdir(rfpp) |
| 128 | srctree = os.path.abspath(srctree) |
| 129 | if os.path.exists(srctree): |
| 130 | shutil.rmtree(srctree) |
| 131 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 132 | def _upgrade_error(e, rf, srctree, keep_failure=False, extramsg=None): |
| 133 | if rf and not keep_failure: |
| 134 | _cleanup_on_error(rf, srctree) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | logger.error(e) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 136 | if extramsg: |
| 137 | logger.error(extramsg) |
| 138 | if keep_failure: |
| 139 | logger.info('Preserving failed upgrade files (--keep-failure)') |
| 140 | sys.exit(1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | |
| 142 | def _get_uri(rd): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 143 | srcuris = rd.getVar('SRC_URI').split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | if not len(srcuris): |
| 145 | raise DevtoolError('SRC_URI not found on recipe') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 146 | # Get first non-local entry in SRC_URI - usually by convention it's |
| 147 | # the first entry, but not always! |
| 148 | srcuri = None |
| 149 | for entry in srcuris: |
| 150 | if not entry.startswith('file://'): |
| 151 | srcuri = entry |
| 152 | break |
| 153 | if not srcuri: |
| 154 | raise DevtoolError('Unable to find non-local entry in SRC_URI') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | srcrev = '${AUTOREV}' |
| 156 | if '://' in srcuri: |
| 157 | # Fetch a URL |
| 158 | rev_re = re.compile(';rev=([^;]+)') |
| 159 | res = rev_re.search(srcuri) |
| 160 | if res: |
| 161 | srcrev = res.group(1) |
| 162 | srcuri = rev_re.sub('', srcuri) |
| 163 | return srcuri, srcrev |
| 164 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 165 | def _extract_new_source(newpv, srctree, no_patch, srcrev, srcbranch, branch, keep_temp, tinfoil, rd): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | """Extract sources of a recipe with a new version""" |
| 167 | |
| 168 | def __run(cmd): |
| 169 | """Simple wrapper which calls _run with srctree as cwd""" |
| 170 | return _run(cmd, srctree) |
| 171 | |
| 172 | crd = rd.createCopy() |
| 173 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 174 | pv = crd.getVar('PV') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | crd.setVar('PV', newpv) |
| 176 | |
| 177 | tmpsrctree = None |
| 178 | uri, rev = _get_uri(crd) |
| 179 | if srcrev: |
| 180 | rev = srcrev |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 181 | if uri.startswith('git://') or uri.startswith('gitsm://'): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 182 | __run('git fetch') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | __run('git checkout %s' % rev) |
| 184 | __run('git tag -f devtool-base-new') |
| 185 | md5 = None |
| 186 | sha256 = None |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 187 | _, _, _, _, _, params = bb.fetch2.decodeurl(uri) |
| 188 | srcsubdir_rel = params.get('destsuffix', 'git') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 189 | if not srcbranch: |
| 190 | check_branch, check_branch_err = __run('git branch -r --contains %s' % srcrev) |
| 191 | get_branch = [x.strip() for x in check_branch.splitlines()] |
| 192 | # Remove HEAD reference point and drop remote prefix |
| 193 | get_branch = [x.split('/', 1)[1] for x in get_branch if not x.startswith('origin/HEAD')] |
| 194 | if 'master' in get_branch: |
| 195 | # If it is master, we do not need to append 'branch=master' as this is default. |
| 196 | # Even with the case where get_branch has multiple objects, if 'master' is one |
| 197 | # of them, we should default take from 'master' |
| 198 | srcbranch = '' |
| 199 | elif len(get_branch) == 1: |
| 200 | # If 'master' isn't in get_branch and get_branch contains only ONE object, then store result into 'srcbranch' |
| 201 | srcbranch = get_branch[0] |
| 202 | else: |
| 203 | # If get_branch contains more than one objects, then display error and exit. |
| 204 | mbrch = '\n ' + '\n '.join(get_branch) |
| 205 | raise DevtoolError('Revision %s was found on multiple branches: %s\nPlease provide the correct branch in the devtool command with "--srcbranch" or "-B" option.' % (srcrev, mbrch)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 206 | else: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 207 | __run('git checkout devtool-base -b devtool-%s' % newpv) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | |
| 209 | tmpdir = tempfile.mkdtemp(prefix='devtool') |
| 210 | try: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 211 | checksums, ftmpdir = scriptutils.fetch_url(tinfoil, uri, rev, tmpdir, logger, preserve_tmp=keep_temp) |
| 212 | except scriptutils.FetchUrlFailure as e: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 213 | raise DevtoolError(e) |
| 214 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 215 | if ftmpdir and keep_temp: |
| 216 | logger.info('Fetch temp directory is %s' % ftmpdir) |
| 217 | |
| 218 | md5 = checksums['md5sum'] |
| 219 | sha256 = checksums['sha256sum'] |
| 220 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 221 | tmpsrctree = _get_srctree(tmpdir) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 222 | srctree = os.path.abspath(srctree) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 223 | srcsubdir_rel = os.path.relpath(tmpsrctree, tmpdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 225 | # Delete all sources so we ensure no stray files are left over |
| 226 | for item in os.listdir(srctree): |
| 227 | if item in ['.git', 'oe-local-files']: |
| 228 | continue |
| 229 | itempath = os.path.join(srctree, item) |
| 230 | if os.path.isdir(itempath): |
| 231 | shutil.rmtree(itempath) |
| 232 | else: |
| 233 | os.remove(itempath) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 235 | # Copy in new ones |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 236 | _copy_source_code(tmpsrctree, srctree) |
| 237 | |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 238 | (stdout,_) = __run('git ls-files --modified --others') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 239 | filelist = stdout.splitlines() |
| 240 | pbar = bb.ui.knotty.BBProgress('Adding changed files', len(filelist)) |
| 241 | pbar.start() |
| 242 | batchsize = 100 |
| 243 | for i in range(0, len(filelist), batchsize): |
| 244 | batch = filelist[i:i+batchsize] |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 245 | __run('git add -f -A %s' % ' '.join(['"%s"' % item for item in batch])) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 246 | pbar.update(i) |
| 247 | pbar.finish() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 249 | useroptions = [] |
| 250 | oe.patch.GitApplyTree.gitCommandUserOptions(useroptions, d=rd) |
| 251 | __run('git %s commit -q -m "Commit of upstream changes at version %s" --allow-empty' % (' '.join(useroptions), newpv)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | __run('git tag -f devtool-base-%s' % newpv) |
| 253 | |
| 254 | (stdout, _) = __run('git rev-parse HEAD') |
| 255 | rev = stdout.rstrip() |
| 256 | |
| 257 | if no_patch: |
| 258 | patches = oe.recipeutils.get_recipe_patches(crd) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 259 | if patches: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 260 | logger.warning('By user choice, the following patches will NOT be applied to the new source tree:\n %s' % '\n '.join([os.path.basename(patch) for patch in patches])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 261 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 262 | __run('git checkout devtool-patched -b %s' % branch) |
| 263 | skiptag = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | try: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | __run('git rebase %s' % rev) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 266 | except bb.process.ExecutionError as e: |
| 267 | skiptag = True |
| 268 | if 'conflict' in e.stdout: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 269 | logger.warning('Command \'%s\' failed:\n%s\n\nYou will need to resolve conflicts in order to complete the upgrade.' % (e.command, e.stdout.rstrip())) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 270 | else: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 271 | logger.warning('Command \'%s\' failed:\n%s' % (e.command, e.stdout)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 272 | if not skiptag: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 273 | if uri.startswith('git://') or uri.startswith('gitsm://'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | suffix = 'new' |
| 275 | else: |
| 276 | suffix = newpv |
| 277 | __run('git tag -f devtool-patched-%s' % suffix) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | |
| 279 | if tmpsrctree: |
| 280 | if keep_temp: |
| 281 | logger.info('Preserving temporary directory %s' % tmpsrctree) |
| 282 | else: |
| 283 | shutil.rmtree(tmpsrctree) |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 284 | if tmpdir != tmpsrctree: |
| 285 | shutil.rmtree(tmpdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 286 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 287 | return (rev, md5, sha256, srcbranch, srcsubdir_rel) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 288 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 289 | def _add_license_diff_to_recipe(path, diff): |
| 290 | notice_text = """# FIXME: the LIC_FILES_CHKSUM values have been updated by 'devtool upgrade'. |
| 291 | # The following is the difference between the old and the new license text. |
| 292 | # Please update the LICENSE value if needed, and summarize the changes in |
| 293 | # the commit message via 'License-Update:' tag. |
| 294 | # (example: 'License-Update: copyright years updated.') |
| 295 | # |
| 296 | # The changes: |
| 297 | # |
| 298 | """ |
| 299 | commented_diff = "\n".join(["# {}".format(l) for l in diff.split('\n')]) |
| 300 | with open(path, 'rb') as f: |
| 301 | orig_content = f.read() |
| 302 | with open(path, 'wb') as f: |
| 303 | f.write(notice_text.encode()) |
| 304 | f.write(commented_diff.encode()) |
| 305 | f.write("\n#\n\n".encode()) |
| 306 | f.write(orig_content) |
| 307 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 308 | def _create_new_recipe(newpv, md5, sha256, srcrev, srcbranch, srcsubdir_old, srcsubdir_new, workspace, tinfoil, rd, license_diff, new_licenses, srctree, keep_failure): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | """Creates the new recipe under workspace""" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 311 | bpn = rd.getVar('BPN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 312 | path = os.path.join(workspace, 'recipes', bpn) |
| 313 | bb.utils.mkdirhier(path) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 314 | copied, _ = oe.recipeutils.copy_recipe_files(rd, path, all_variants=True) |
| 315 | if not copied: |
| 316 | raise DevtoolError('Internal error - no files were copied for recipe %s' % bpn) |
| 317 | logger.debug('Copied %s to %s' % (copied, path)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 319 | oldpv = rd.getVar('PV') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 320 | if not newpv: |
| 321 | newpv = oldpv |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 322 | origpath = rd.getVar('FILE') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 323 | fullpath = _rename_recipe_files(origpath, bpn, oldpv, newpv, path) |
| 324 | logger.debug('Upgraded %s => %s' % (origpath, fullpath)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 326 | newvalues = {} |
| 327 | if _recipe_contains(rd, 'PV') and newpv != oldpv: |
| 328 | newvalues['PV'] = newpv |
| 329 | |
| 330 | if srcrev: |
| 331 | newvalues['SRCREV'] = srcrev |
| 332 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 333 | if srcbranch: |
| 334 | src_uri = oe.recipeutils.split_var_value(rd.getVar('SRC_URI', False) or '') |
| 335 | changed = False |
| 336 | replacing = True |
| 337 | new_src_uri = [] |
| 338 | for entry in src_uri: |
| 339 | scheme, network, path, user, passwd, params = bb.fetch2.decodeurl(entry) |
| 340 | if replacing and scheme in ['git', 'gitsm']: |
| 341 | branch = params.get('branch', 'master') |
| 342 | if rd.expand(branch) != srcbranch: |
| 343 | # Handle case where branch is set through a variable |
| 344 | res = re.match(r'\$\{([^}@]+)\}', branch) |
| 345 | if res: |
| 346 | newvalues[res.group(1)] = srcbranch |
| 347 | # We know we won't change SRC_URI now, so break out |
| 348 | break |
| 349 | else: |
| 350 | params['branch'] = srcbranch |
| 351 | entry = bb.fetch2.encodeurl((scheme, network, path, user, passwd, params)) |
| 352 | changed = True |
| 353 | replacing = False |
| 354 | new_src_uri.append(entry) |
| 355 | if changed: |
| 356 | newvalues['SRC_URI'] = ' '.join(new_src_uri) |
| 357 | |
| 358 | newvalues['PR'] = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 359 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 360 | # Work out which SRC_URI entries have changed in case the entry uses a name |
| 361 | crd = rd.createCopy() |
| 362 | crd.setVar('PV', newpv) |
| 363 | for var, value in newvalues.items(): |
| 364 | crd.setVar(var, value) |
| 365 | old_src_uri = (rd.getVar('SRC_URI') or '').split() |
| 366 | new_src_uri = (crd.getVar('SRC_URI') or '').split() |
| 367 | newnames = [] |
| 368 | addnames = [] |
| 369 | for newentry in new_src_uri: |
| 370 | _, _, _, _, _, params = bb.fetch2.decodeurl(newentry) |
| 371 | if 'name' in params: |
| 372 | newnames.append(params['name']) |
| 373 | if newentry not in old_src_uri: |
| 374 | addnames.append(params['name']) |
| 375 | # Find what's been set in the original recipe |
| 376 | oldnames = [] |
| 377 | noname = False |
| 378 | for varflag in rd.getVarFlags('SRC_URI'): |
| 379 | if varflag.endswith(('.md5sum', '.sha256sum')): |
| 380 | name = varflag.rsplit('.', 1)[0] |
| 381 | if name not in oldnames: |
| 382 | oldnames.append(name) |
| 383 | elif varflag in ['md5sum', 'sha256sum']: |
| 384 | noname = True |
| 385 | # Even if SRC_URI has named entries it doesn't have to actually use the name |
| 386 | if noname and addnames and addnames[0] not in oldnames: |
| 387 | addnames = [] |
| 388 | # Drop any old names (the name actually might include ${PV}) |
| 389 | for name in oldnames: |
| 390 | if name not in newnames: |
| 391 | newvalues['SRC_URI[%s.md5sum]' % name] = None |
| 392 | newvalues['SRC_URI[%s.sha256sum]' % name] = None |
| 393 | |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 394 | if sha256: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 395 | if addnames: |
| 396 | nameprefix = '%s.' % addnames[0] |
| 397 | else: |
| 398 | nameprefix = '' |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 399 | newvalues['SRC_URI[%smd5sum]' % nameprefix] = None |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 400 | newvalues['SRC_URI[%ssha256sum]' % nameprefix] = sha256 |
| 401 | |
| 402 | if srcsubdir_new != srcsubdir_old: |
| 403 | s_subdir_old = os.path.relpath(os.path.abspath(rd.getVar('S')), rd.getVar('WORKDIR')) |
| 404 | s_subdir_new = os.path.relpath(os.path.abspath(crd.getVar('S')), crd.getVar('WORKDIR')) |
| 405 | if srcsubdir_old == s_subdir_old and srcsubdir_new != s_subdir_new: |
| 406 | # Subdir for old extracted source matches what S points to (it should!) |
| 407 | # but subdir for new extracted source doesn't match what S will be |
| 408 | newvalues['S'] = '${WORKDIR}/%s' % srcsubdir_new.replace(newpv, '${PV}') |
| 409 | if crd.expand(newvalues['S']) == crd.expand('${WORKDIR}/${BP}'): |
| 410 | # It's the default, drop it |
| 411 | # FIXME what if S is being set in a .inc? |
| 412 | newvalues['S'] = None |
| 413 | logger.info('Source subdirectory has changed, dropping S value since it now matches the default ("${WORKDIR}/${BP}")') |
| 414 | else: |
| 415 | logger.info('Source subdirectory has changed, updating S value') |
| 416 | |
| 417 | if license_diff: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 418 | newlicchksum = " ".join(["file://{}".format(l['path']) + |
| 419 | (";beginline={}".format(l['beginline']) if l['beginline'] else "") + |
| 420 | (";endline={}".format(l['endline']) if l['endline'] else "") + |
| 421 | (";md5={}".format(l['actual_md5'])) for l in new_licenses]) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 422 | newvalues["LIC_FILES_CHKSUM"] = newlicchksum |
| 423 | _add_license_diff_to_recipe(fullpath, license_diff) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 424 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 425 | try: |
| 426 | rd = tinfoil.parse_recipe_file(fullpath, False) |
| 427 | except bb.tinfoil.TinfoilCommandFailed as e: |
| 428 | _upgrade_error(e, fullpath, srctree, keep_failure, 'Parsing of upgraded recipe failed') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 429 | oe.recipeutils.patch_recipe(rd, fullpath, newvalues) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 430 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 431 | return fullpath, copied |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 432 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 433 | |
| 434 | def _check_git_config(): |
| 435 | def getconfig(name): |
| 436 | try: |
| 437 | value = bb.process.run('git config --global %s' % name)[0].strip() |
| 438 | except bb.process.ExecutionError as e: |
| 439 | if e.exitcode == 1: |
| 440 | value = None |
| 441 | else: |
| 442 | raise |
| 443 | return value |
| 444 | |
| 445 | username = getconfig('user.name') |
| 446 | useremail = getconfig('user.email') |
| 447 | configerr = [] |
| 448 | if not username: |
| 449 | configerr.append('Please set your name using:\n git config --global user.name') |
| 450 | if not useremail: |
| 451 | configerr.append('Please set your email using:\n git config --global user.email') |
| 452 | if configerr: |
| 453 | raise DevtoolError('Your git configuration is incomplete which will prevent rebases from working:\n' + '\n'.join(configerr)) |
| 454 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 455 | def _extract_licenses(srcpath, recipe_licenses): |
| 456 | licenses = [] |
| 457 | for url in recipe_licenses.split(): |
| 458 | license = {} |
| 459 | (type, host, path, user, pswd, parm) = bb.fetch.decodeurl(url) |
| 460 | license['path'] = path |
| 461 | license['md5'] = parm.get('md5', '') |
| 462 | license['beginline'], license['endline'] = 0, 0 |
| 463 | if 'beginline' in parm: |
| 464 | license['beginline'] = int(parm['beginline']) |
| 465 | if 'endline' in parm: |
| 466 | license['endline'] = int(parm['endline']) |
| 467 | license['text'] = [] |
| 468 | with open(os.path.join(srcpath, path), 'rb') as f: |
| 469 | import hashlib |
| 470 | actual_md5 = hashlib.md5() |
| 471 | lineno = 0 |
| 472 | for line in f: |
| 473 | lineno += 1 |
| 474 | if (lineno >= license['beginline']) and ((lineno <= license['endline']) or not license['endline']): |
| 475 | license['text'].append(line.decode(errors='ignore')) |
| 476 | actual_md5.update(line) |
| 477 | license['actual_md5'] = actual_md5.hexdigest() |
| 478 | licenses.append(license) |
| 479 | return licenses |
| 480 | |
| 481 | def _generate_license_diff(old_licenses, new_licenses): |
| 482 | need_diff = False |
| 483 | for l in new_licenses: |
| 484 | if l['md5'] != l['actual_md5']: |
| 485 | need_diff = True |
| 486 | break |
| 487 | if need_diff == False: |
| 488 | return None |
| 489 | |
| 490 | import difflib |
| 491 | diff = '' |
| 492 | for old, new in zip(old_licenses, new_licenses): |
| 493 | for line in difflib.unified_diff(old['text'], new['text'], old['path'], new['path']): |
| 494 | diff = diff + line |
| 495 | return diff |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 496 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 497 | def upgrade(args, config, basepath, workspace): |
| 498 | """Entry point for the devtool 'upgrade' subcommand""" |
| 499 | |
| 500 | if args.recipename in workspace: |
| 501 | raise DevtoolError("recipe %s is already in your workspace" % args.recipename) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 502 | if args.srcbranch and not args.srcrev: |
| 503 | raise DevtoolError("If you specify --srcbranch/-B then you must use --srcrev/-S to specify the revision" % args.recipename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 504 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 505 | _check_git_config() |
| 506 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 507 | tinfoil = setup_tinfoil(basepath=basepath, tracking=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 508 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 509 | rd = parse_recipe(config, tinfoil, args.recipename, True) |
| 510 | if not rd: |
| 511 | return 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 512 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 513 | pn = rd.getVar('PN') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 514 | if pn != args.recipename: |
| 515 | logger.info('Mapping %s to %s' % (args.recipename, pn)) |
| 516 | if pn in workspace: |
| 517 | raise DevtoolError("recipe %s is already in your workspace" % pn) |
| 518 | |
| 519 | if args.srctree: |
| 520 | srctree = os.path.abspath(args.srctree) |
| 521 | else: |
| 522 | srctree = standard.get_default_srctree(config, pn) |
| 523 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 524 | # try to automatically discover latest version and revision if not provided on command line |
| 525 | if not args.version and not args.srcrev: |
| 526 | version_info = oe.recipeutils.get_recipe_upstream_version(rd) |
| 527 | if version_info['version'] and not version_info['version'].endswith("new-commits-available"): |
| 528 | args.version = version_info['version'] |
| 529 | if version_info['revision']: |
| 530 | args.srcrev = version_info['revision'] |
| 531 | if not args.version and not args.srcrev: |
| 532 | raise DevtoolError("Automatic discovery of latest version/revision failed - 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.") |
| 533 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 534 | standard._check_compatible_recipe(pn, rd) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 535 | old_srcrev = rd.getVar('SRCREV') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 536 | if old_srcrev == 'INVALID': |
| 537 | old_srcrev = None |
| 538 | if old_srcrev and not args.srcrev: |
| 539 | raise DevtoolError("Recipe specifies a SRCREV value; you must specify a new one when upgrading") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 540 | old_ver = rd.getVar('PV') |
| 541 | if old_ver == args.version and old_srcrev == args.srcrev: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 542 | raise DevtoolError("Current and upgrade versions are the same version") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 543 | if args.version: |
| 544 | if bb.utils.vercmp_string(args.version, old_ver) < 0: |
| 545 | logger.warning('Upgrade version %s compares as less than the current version %s. If you are using a package feed for on-target upgrades or providing this recipe for general consumption, then you should increment PE in the recipe (or if there is no current PE value set, set it to "1")' % (args.version, old_ver)) |
| 546 | check_prerelease_version(args.version, 'devtool upgrade') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 547 | |
| 548 | rf = None |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 549 | license_diff = None |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 550 | try: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 551 | logger.info('Extracting current version source...') |
| 552 | rev1, srcsubdir1 = standard._extract_source(srctree, False, 'devtool-orig', False, config, basepath, workspace, args.fixed_setup, rd, tinfoil, no_overrides=args.no_overrides) |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 553 | old_licenses = _extract_licenses(srctree, (rd.getVar('LIC_FILES_CHKSUM') or "")) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 554 | logger.info('Extracting upgraded version source...') |
| 555 | rev2, md5, sha256, srcbranch, srcsubdir2 = _extract_new_source(args.version, srctree, args.no_patch, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 556 | args.srcrev, args.srcbranch, args.branch, args.keep_temp, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 557 | tinfoil, rd) |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 558 | new_licenses = _extract_licenses(srctree, (rd.getVar('LIC_FILES_CHKSUM') or "")) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 559 | license_diff = _generate_license_diff(old_licenses, new_licenses) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 560 | rf, copied = _create_new_recipe(args.version, md5, sha256, args.srcrev, srcbranch, srcsubdir1, srcsubdir2, config.workspace_path, tinfoil, rd, license_diff, new_licenses, srctree, args.keep_failure) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 561 | except bb.process.CmdError as e: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 562 | _upgrade_error(e, rf, srctree, args.keep_failure) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 563 | except DevtoolError as e: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 564 | _upgrade_error(e, rf, srctree, args.keep_failure) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 565 | standard._add_md5(config, pn, os.path.dirname(rf)) |
| 566 | |
| 567 | af = _write_append(rf, srctree, args.same_dir, args.no_same_dir, rev2, |
| 568 | copied, config.workspace_path, rd) |
| 569 | standard._add_md5(config, pn, af) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 570 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 571 | update_unlockedsigs(basepath, workspace, args.fixed_setup, [pn]) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 572 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 573 | logger.info('Upgraded source extracted to %s' % srctree) |
| 574 | logger.info('New recipe is %s' % rf) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 575 | if license_diff: |
| 576 | logger.info('License checksums have been updated in the new recipe; please refer to it for the difference between the old and the new license texts.') |
| 577 | finally: |
| 578 | tinfoil.shutdown() |
| 579 | return 0 |
| 580 | |
| 581 | def latest_version(args, config, basepath, workspace): |
| 582 | """Entry point for the devtool 'latest_version' subcommand""" |
| 583 | tinfoil = setup_tinfoil(basepath=basepath, tracking=True) |
| 584 | try: |
| 585 | rd = parse_recipe(config, tinfoil, args.recipename, True) |
| 586 | if not rd: |
| 587 | return 1 |
| 588 | version_info = oe.recipeutils.get_recipe_upstream_version(rd) |
| 589 | # "new-commits-available" is an indication that upstream never issues version tags |
| 590 | if not version_info['version'].endswith("new-commits-available"): |
| 591 | logger.info("Current version: {}".format(version_info['current_version'])) |
| 592 | logger.info("Latest version: {}".format(version_info['version'])) |
| 593 | if version_info['revision']: |
| 594 | logger.info("Latest version's commit: {}".format(version_info['revision'])) |
| 595 | else: |
| 596 | logger.info("Latest commit: {}".format(version_info['revision'])) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 597 | finally: |
| 598 | tinfoil.shutdown() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 599 | return 0 |
| 600 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 601 | def check_upgrade_status(args, config, basepath, workspace): |
| 602 | if not args.recipe: |
| 603 | logger.info("Checking the upstream status for all recipes may take a few minutes") |
| 604 | results = oe.recipeutils.get_recipe_upgrade_status(args.recipe) |
| 605 | for result in results: |
| 606 | # pn, update_status, current, latest, maintainer, latest_commit, no_update_reason |
| 607 | if args.all or result[1] != 'MATCH': |
| 608 | logger.info("{:25} {:15} {:15} {} {} {}".format( result[0], |
| 609 | result[2], |
| 610 | result[1] if result[1] != 'UPDATE' else (result[3] if not result[3].endswith("new-commits-available") else "new commits"), |
| 611 | result[4], |
| 612 | result[5] if result[5] != 'N/A' else "", |
| 613 | "cannot be updated due to: %s" %(result[6]) if result[6] else "")) |
| 614 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 615 | def register_commands(subparsers, context): |
| 616 | """Register devtool subcommands from this plugin""" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 617 | |
| 618 | defsrctree = standard.get_default_srctree(context.config) |
| 619 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 620 | parser_upgrade = subparsers.add_parser('upgrade', help='Upgrade an existing recipe', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 621 | 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).', |
| 622 | group='starting') |
| 623 | parser_upgrade.add_argument('recipename', help='Name of recipe to upgrade (just name - no version, path or extension)') |
| 624 | 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) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 625 | parser_upgrade.add_argument('--version', '-V', help='Version to upgrade to (PV). If omitted, latest upstream version will be determined and used, if possible.') |
| 626 | parser_upgrade.add_argument('--srcrev', '-S', help='Source revision to upgrade to (useful when fetching from an SCM such as git)') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 627 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 628 | parser_upgrade.add_argument('--branch', '-b', default="devtool", help='Name for new development branch to checkout (default "%(default)s")') |
| 629 | parser_upgrade.add_argument('--no-patch', action="store_true", help='Do not apply patches from the recipe to the new source code') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 630 | parser_upgrade.add_argument('--no-overrides', '-O', action="store_true", help='Do not create branches for other override configurations') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 631 | group = parser_upgrade.add_mutually_exclusive_group() |
| 632 | group.add_argument('--same-dir', '-s', help='Build in same directory as source', action="store_true") |
| 633 | group.add_argument('--no-same-dir', help='Force build in a separate build directory', action="store_true") |
| 634 | parser_upgrade.add_argument('--keep-temp', action="store_true", help='Keep temporary directory (for debugging)') |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 635 | parser_upgrade.add_argument('--keep-failure', action="store_true", help='Keep failed upgrade recipe and associated files (for debugging)') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 636 | parser_upgrade.set_defaults(func=upgrade, fixed_setup=context.fixed_setup) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 637 | |
| 638 | parser_latest_version = subparsers.add_parser('latest-version', help='Report the latest version of an existing recipe', |
| 639 | description='Queries the upstream server for what the latest upstream release is (for git, tags are checked, for tarballs, a list of them is obtained, and one with the highest version number is reported)', |
| 640 | group='info') |
| 641 | parser_latest_version.add_argument('recipename', help='Name of recipe to query (just name - no version, path or extension)') |
| 642 | parser_latest_version.set_defaults(func=latest_version) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 643 | |
| 644 | parser_check_upgrade_status = subparsers.add_parser('check-upgrade-status', help="Report upgradability for multiple (or all) recipes", |
| 645 | description="Prints a table of recipes together with versions currently provided by recipes, and latest upstream versions, when there is a later version available", |
| 646 | group='info') |
| 647 | parser_check_upgrade_status.add_argument('recipe', help='Name of the recipe to report (omit to report upgrade info for all recipes)', nargs='*') |
| 648 | parser_check_upgrade_status.add_argument('--all', '-a', help='Show all recipes, not just recipes needing upgrade', action="store_true") |
| 649 | parser_check_upgrade_status.set_defaults(func=check_upgrade_status) |