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