blob: 8f35cb4f9532b51e40e56e6ddc45105b69cabf32 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Copyright (C) 2006 OpenedHand LTD
2
3# Point to an empty file so any user's custom settings don't break things
4QUILTRCFILE ?= "${STAGING_ETCDIR_NATIVE}/quiltrc"
5
6PATCHDEPENDENCY = "${PATCHTOOL}-native:do_populate_sysroot"
7
Patrick Williamsc0f7c042017-02-23 20:41:17 -06008PATCH_GIT_USER_NAME ?= "OpenEmbedded"
9PATCH_GIT_USER_EMAIL ?= "oe.patch@oe"
10
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011inherit terminal
12
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013python () {
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 Williamsc124f4f2015-09-15 14:41:29 -050021
Brad Bishop6e60e8b2018-02-01 10:27:11 -050022 d.appendVarFlag('do_patch', 'prefuncs', ' patch_task_patch_prefunc')
23 for task in extratasks:
24 d.appendVarFlag(task, 'postfuncs', ' patch_task_postfunc')
25}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027python patch_task_patch_prefunc() {
28 # Prefunc for do_patch
29 func = d.getVar('BB_RUNTASK')
30 srcsubdir = d.getVar('S')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 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 Williamsc124f4f2015-09-15 14:41:29 -050036 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037 os.rmdir(patchdir)
38}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040python 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 Williamsc124f4f2015-09-15 14:41:29 -050046
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047 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 Williamsc124f4f2015-09-15 14:41:29 -050063
Brad Bishop6e60e8b2018-02-01 10:27:11 -050064def src_patches(d, all=False, expand=True):
65 import oe.patch
66 return oe.patch.src_patches(d, all, expand)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
68def should_apply(parm, d):
69 """Determine if we should apply the given patch"""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050070 import oe.patch
71 return oe.patch.should_apply(parm, d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072
73should_apply[vardepsexclude] = "DATE SRCDATE"
74
75python 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 Bishop6e60e8b2018-02-01 10:27:11 -050084 cls = patchsetmap[d.getVar('PATCHTOOL') or 'quilt']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085
86 resolvermap = {
87 "noop": oe.patch.NOOPResolver,
88 "user": oe.patch.UserResolver,
89 }
90
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091 rcls = resolvermap[d.getVar('PATCHRESOLVE') or 'user']
Patrick Williamsc124f4f2015-09-15 14:41:29 -050092
93 classes = {}
94
Brad Bishop6e60e8b2018-02-01 10:27:11 -050095 s = d.getVar('S')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096
Brad Bishop6e60e8b2018-02-01 10:27:11 -050097 os.putenv('PATH', d.getVar('PATH'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098
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}
139patch_do_patch[vardepsexclude] = "PATCHRESOLVE"
140
141addtask patch after do_unpack
142do_patch[dirs] = "${WORKDIR}"
143do_patch[depends] = "${PATCHDEPENDENCY}"
144
145EXPORT_FUNCTIONS do_patch