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