diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-01 23:38:00 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-03-02 16:22:48 +0000 |
commit | d1168cc12a7640b509aa3b49a4e25be794c61875 (patch) | |
tree | 555f96c86a35251fd89e38d0c004d2e745711232 /meta/lib | |
parent | 01954b9c65c979e03b7f07ab30889ceb20ed0d05 (diff) | |
download | poky-d1168cc12a7640b509aa3b49a4e25be794c61875.tar.gz |
lib/oe/patch.py: Fix and improve PatchTree() resolver logic
Currently, if PATCHRESOLVE is user and and PatchTree() is being used, you can
get backtraces if patch application fails. This is because even in the failure
case, self._current is incremented, meaning second time around, there are array
range issues.
This patch changes the code so _current is only incremented upon successful
patch application, thereby resolving this failure.
Secondly, if you bitbake -c patch -f a recipe using PatchTree(), the
clean method was unimplemented leading to patch failures.
The other part of this patch changes the logic so a series file and
set of applied patches are maintained in a quilt like fashion. This
means a the Clean method can be implemented correctly and rerunning
the patch task of an existing patches source now works reliably.
[YOCTO #2043 partially]
(From OE-Core rev: f0fc47aea37793a62c43f10eea27ca014c420924)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/patch.py | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index 6f7f90095c..a5b31b8f8d 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py | |||
@@ -98,7 +98,37 @@ class PatchSet(object): | |||
98 | class PatchTree(PatchSet): | 98 | class PatchTree(PatchSet): |
99 | def __init__(self, dir, d): | 99 | def __init__(self, dir, d): |
100 | PatchSet.__init__(self, dir, d) | 100 | PatchSet.__init__(self, dir, d) |
101 | 101 | self.patchdir = os.path.join(self.dir, 'patches') | |
102 | self.seriespath = os.path.join(self.dir, 'patches', 'series') | ||
103 | bb.utils.mkdirhier(self.patchdir) | ||
104 | |||
105 | def _appendPatchFile(self, patch, strippath): | ||
106 | with open(self.seriespath, 'a') as f: | ||
107 | f.write(os.path.basename(patch) + "," + strippath + "\n") | ||
108 | shellcmd = ["cat", patch, ">" , self.patchdir + "/" + os.path.basename(patch)] | ||
109 | runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) | ||
110 | |||
111 | def _removePatch(self, p): | ||
112 | patch = {} | ||
113 | patch['file'] = p.split(",")[0] | ||
114 | patch['strippath'] = p.split(",")[1] | ||
115 | self._applypatch(patch, False, True) | ||
116 | |||
117 | def _removePatchFile(self, all = False): | ||
118 | if not os.path.exists(self.seriespath): | ||
119 | return | ||
120 | patches = open(self.seriespath, 'r+').readlines() | ||
121 | if all: | ||
122 | for p in reversed(patches): | ||
123 | self._removePatch(os.path.join(self.patchdir, p.strip())) | ||
124 | patches = [] | ||
125 | else: | ||
126 | self._removePatch(os.path.join(self.patchdir, patches[-1].strip())) | ||
127 | patches.pop() | ||
128 | with open(self.seriespath, 'w') as f: | ||
129 | for p in patches: | ||
130 | f.write(p) | ||
131 | |||
102 | def Import(self, patch, force = None): | 132 | def Import(self, patch, force = None): |
103 | """""" | 133 | """""" |
104 | PatchSet.Import(self, patch, force) | 134 | PatchSet.Import(self, patch, force) |
@@ -127,6 +157,10 @@ class PatchTree(PatchSet): | |||
127 | 157 | ||
128 | shellcmd.pop(len(shellcmd) - 1) | 158 | shellcmd.pop(len(shellcmd) - 1) |
129 | output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) | 159 | output = runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) |
160 | |||
161 | if not reverse: | ||
162 | self._appendPatchFile(patch['file'], patch['strippath']) | ||
163 | |||
130 | return output | 164 | return output |
131 | 165 | ||
132 | def Push(self, force = False, all = False, run = True): | 166 | def Push(self, force = False, all = False, run = True): |
@@ -134,30 +168,37 @@ class PatchTree(PatchSet): | |||
134 | bb.note("patches is %s" % self.patches) | 168 | bb.note("patches is %s" % self.patches) |
135 | if all: | 169 | if all: |
136 | for i in self.patches: | 170 | for i in self.patches: |
137 | if self._current is not None: | ||
138 | self._current = self._current + 1 | ||
139 | else: | ||
140 | self._current = 0 | ||
141 | bb.note("applying patch %s" % i) | 171 | bb.note("applying patch %s" % i) |
142 | self._applypatch(i, force) | 172 | self._applypatch(i, force) |
173 | self._current = i | ||
143 | else: | 174 | else: |
144 | if self._current is not None: | 175 | if self._current is not None: |
145 | self._current = self._current + 1 | 176 | next = self._current + 1 |
146 | else: | 177 | else: |
147 | self._current = 0 | 178 | next = 0 |
148 | bb.note("applying patch %s" % self.patches[self._current]) | 179 | |
149 | return self._applypatch(self.patches[self._current], force) | 180 | bb.note("applying patch %s" % self.patches[next]) |
181 | ret = self._applypatch(self.patches[next], force) | ||
150 | 182 | ||
183 | self._current = next | ||
184 | return ret | ||
151 | 185 | ||
152 | def Pop(self, force = None, all = None): | 186 | def Pop(self, force = None, all = None): |
153 | if all: | 187 | if all: |
154 | for i in self.patches: | 188 | self._removePatchFile(True) |
155 | self._applypatch(i, force, True) | 189 | self._current = None |
156 | else: | 190 | else: |
157 | self._applypatch(self.patches[self._current], force, True) | 191 | self._removePatchFile(False) |
192 | |||
193 | if self._current == 0: | ||
194 | self._current = None | ||
195 | |||
196 | if self._current is not None: | ||
197 | self._current = self._current - 1 | ||
158 | 198 | ||
159 | def Clean(self): | 199 | def Clean(self): |
160 | """""" | 200 | """""" |
201 | self.Pop(all=True) | ||
161 | 202 | ||
162 | class GitApplyTree(PatchTree): | 203 | class GitApplyTree(PatchTree): |
163 | def __init__(self, dir, d): | 204 | def __init__(self, dir, d): |