Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Copyright (C) 2006 OpenedHand LTD |
| 2 | |
| 3 | # Point to an empty file so any user's custom settings don't break things |
| 4 | QUILTRCFILE ?= "${STAGING_ETCDIR_NATIVE}/quiltrc" |
| 5 | |
| 6 | PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot" |
| 7 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 8 | PATCH_GIT_USER_NAME ?= "OpenEmbedded" |
| 9 | PATCH_GIT_USER_EMAIL ?= "oe.patch@oe" |
| 10 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | inherit terminal |
| 12 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 13 | python () { |
| 14 | if d.getVar('PATCHTOOL') == 'git' and d.getVar('PATCH_COMMIT_FUNCTIONS') == '1': |
| 15 | extratasks = bb.build.tasksbetween('do_unpack', 'do_patch', d) |
| 16 | try: |
| 17 | extratasks.remove('do_unpack') |
| 18 | except ValueError: |
| 19 | # For some recipes do_unpack doesn't exist, ignore it |
| 20 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 22 | d.appendVarFlag('do_patch', 'prefuncs', ' patch_task_patch_prefunc') |
| 23 | for task in extratasks: |
| 24 | d.appendVarFlag(task, 'postfuncs', ' patch_task_postfunc') |
| 25 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 27 | python patch_task_patch_prefunc() { |
| 28 | # Prefunc for do_patch |
| 29 | func = d.getVar('BB_RUNTASK') |
| 30 | srcsubdir = d.getVar('S') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 32 | patchdir = os.path.join(srcsubdir, 'patches') |
| 33 | if os.path.exists(patchdir): |
| 34 | if os.listdir(patchdir): |
| 35 | d.setVar('PATCH_HAS_PATCHES_DIR', '1') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 37 | os.rmdir(patchdir) |
| 38 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 40 | python patch_task_postfunc() { |
| 41 | # Prefunc for task functions between do_unpack and do_patch |
| 42 | import oe.patch |
| 43 | import shutil |
| 44 | func = d.getVar('BB_RUNTASK') |
| 45 | srcsubdir = d.getVar('S') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 47 | if os.path.exists(srcsubdir): |
| 48 | if func == 'do_patch': |
| 49 | haspatches = (d.getVar('PATCH_HAS_PATCHES_DIR') == '1') |
| 50 | patchdir = os.path.join(srcsubdir, 'patches') |
| 51 | if os.path.exists(patchdir): |
| 52 | shutil.rmtree(patchdir) |
| 53 | if haspatches: |
| 54 | stdout, _ = bb.process.run('git status --porcelain patches', cwd=srcsubdir) |
| 55 | if stdout: |
| 56 | bb.process.run('git checkout patches', cwd=srcsubdir) |
| 57 | stdout, _ = bb.process.run('git status --porcelain .', cwd=srcsubdir) |
| 58 | if stdout: |
| 59 | useroptions = [] |
| 60 | oe.patch.GitApplyTree.gitCommandUserOptions(useroptions, d=d) |
| 61 | bb.process.run('git add .; git %s commit -a -m "Committing changes from %s\n\n%s"' % (' '.join(useroptions), func, oe.patch.GitApplyTree.ignore_commit_prefix + ' - from %s' % func), cwd=srcsubdir) |
| 62 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 64 | def src_patches(d, all=False, expand=True): |
| 65 | import oe.patch |
| 66 | return oe.patch.src_patches(d, all, expand) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | |
| 68 | def should_apply(parm, d): |
| 69 | """Determine if we should apply the given patch""" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 70 | import oe.patch |
| 71 | return oe.patch.should_apply(parm, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | |
| 73 | should_apply[vardepsexclude] = "DATE SRCDATE" |
| 74 | |
| 75 | python patch_do_patch() { |
| 76 | import oe.patch |
| 77 | |
| 78 | patchsetmap = { |
| 79 | "patch": oe.patch.PatchTree, |
| 80 | "quilt": oe.patch.QuiltTree, |
| 81 | "git": oe.patch.GitApplyTree, |
| 82 | } |
| 83 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 84 | cls = patchsetmap[d.getVar('PATCHTOOL') or 'quilt'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | |
| 86 | resolvermap = { |
| 87 | "noop": oe.patch.NOOPResolver, |
| 88 | "user": oe.patch.UserResolver, |
| 89 | } |
| 90 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 91 | rcls = resolvermap[d.getVar('PATCHRESOLVE') or 'user'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | |
| 93 | classes = {} |
| 94 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 95 | s = d.getVar('S') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 97 | os.putenv('PATH', d.getVar('PATH')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | |
| 99 | # We must use one TMPDIR per process so that the "patch" processes |
| 100 | # don't generate the same temp file name. |
| 101 | |
| 102 | import tempfile |
| 103 | process_tmpdir = tempfile.mkdtemp() |
| 104 | os.environ['TMPDIR'] = process_tmpdir |
| 105 | |
| 106 | for patch in src_patches(d): |
| 107 | _, _, local, _, _, parm = bb.fetch.decodeurl(patch) |
| 108 | |
| 109 | if "patchdir" in parm: |
| 110 | patchdir = parm["patchdir"] |
| 111 | if not os.path.isabs(patchdir): |
| 112 | patchdir = os.path.join(s, patchdir) |
| 113 | else: |
| 114 | patchdir = s |
| 115 | |
| 116 | if not patchdir in classes: |
| 117 | patchset = cls(patchdir, d) |
| 118 | resolver = rcls(patchset, oe_terminal) |
| 119 | classes[patchdir] = (patchset, resolver) |
| 120 | patchset.Clean() |
| 121 | else: |
| 122 | patchset, resolver = classes[patchdir] |
| 123 | |
| 124 | bb.note("Applying patch '%s' (%s)" % (parm['patchname'], oe.path.format_display(local, d))) |
| 125 | try: |
| 126 | patchset.Import({"file":local, "strippath": parm['striplevel']}, True) |
| 127 | except Exception as exc: |
| 128 | bb.utils.remove(process_tmpdir, True) |
| 129 | bb.fatal(str(exc)) |
| 130 | try: |
| 131 | resolver.Resolve() |
| 132 | except bb.BBHandledException as e: |
| 133 | bb.utils.remove(process_tmpdir, True) |
| 134 | bb.fatal(str(e)) |
| 135 | |
| 136 | bb.utils.remove(process_tmpdir, True) |
| 137 | del os.environ['TMPDIR'] |
| 138 | } |
| 139 | patch_do_patch[vardepsexclude] = "PATCHRESOLVE" |
| 140 | |
| 141 | addtask patch after do_unpack |
| 142 | do_patch[dirs] = "${WORKDIR}" |
| 143 | do_patch[depends] = "${PATCHDEPENDENCY}" |
| 144 | |
| 145 | EXPORT_FUNCTIONS do_patch |