diff options
| author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-07-07 11:57:09 +1200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-12 23:10:16 +0100 |
| commit | 029e3ebcb2fc603bba264b589cbcfeb0ef963fc8 (patch) | |
| tree | 9767b6fc6da0e8f72acc8bf40c86cb33660e1657 /meta/lib/oe/patch.py | |
| parent | f465039737112a3975ad3b224a9351e4ac780088 (diff) | |
| download | poky-029e3ebcb2fc603bba264b589cbcfeb0ef963fc8.tar.gz | |
lib/oe/patch: handle encoding differences in patch files
With Python 3, the encoding of a file is significant; several recipes in
OE-Core have patches which are not fully utf-8 decodable e.g. man,
lrzsz, and gstreamer1.0-libav, leading to errors when using devtool's
modify, upgrade or extract subcommands on these recipes. To work around
this, try reading the patch file as utf-8 first and if that fails try
latin-1 before giving up.
(From OE-Core rev: 7f4d7a6f51569954e204f110827a8ce256bcdc68)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/patch.py')
| -rw-r--r-- | meta/lib/oe/patch.py | 100 |
1 files changed, 57 insertions, 43 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index 4a0d3f7149..af3adec140 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py | |||
| @@ -117,43 +117,50 @@ class PatchSet(object): | |||
| 117 | return None | 117 | return None |
| 118 | return os.sep.join(filesplit[striplevel:]) | 118 | return os.sep.join(filesplit[striplevel:]) |
| 119 | 119 | ||
| 120 | copiedmode = False | 120 | for encoding in ['utf-8', 'latin-1']: |
| 121 | filelist = [] | 121 | try: |
| 122 | with open(patchfile) as f: | 122 | copiedmode = False |
| 123 | for line in f: | 123 | filelist = [] |
| 124 | if line.startswith('--- '): | 124 | with open(patchfile) as f: |
| 125 | patchpth = patchedpath(line) | 125 | for line in f: |
| 126 | if not patchpth: | 126 | if line.startswith('--- '): |
| 127 | break | 127 | patchpth = patchedpath(line) |
| 128 | if copiedmode: | 128 | if not patchpth: |
| 129 | addedfile = patchpth | 129 | break |
| 130 | else: | 130 | if copiedmode: |
| 131 | removedfile = patchpth | 131 | addedfile = patchpth |
| 132 | elif line.startswith('+++ '): | 132 | else: |
| 133 | addedfile = patchedpath(line) | 133 | removedfile = patchpth |
| 134 | if not addedfile: | 134 | elif line.startswith('+++ '): |
| 135 | break | 135 | addedfile = patchedpath(line) |
| 136 | elif line.startswith('*** '): | 136 | if not addedfile: |
| 137 | copiedmode = True | 137 | break |
| 138 | removedfile = patchedpath(line) | 138 | elif line.startswith('*** '): |
| 139 | if not removedfile: | 139 | copiedmode = True |
| 140 | break | 140 | removedfile = patchedpath(line) |
| 141 | else: | 141 | if not removedfile: |
| 142 | removedfile = None | 142 | break |
| 143 | addedfile = None | 143 | else: |
| 144 | 144 | removedfile = None | |
| 145 | if addedfile and removedfile: | 145 | addedfile = None |
| 146 | if removedfile == '/dev/null': | 146 | |
| 147 | mode = 'A' | 147 | if addedfile and removedfile: |
| 148 | elif addedfile == '/dev/null': | 148 | if removedfile == '/dev/null': |
| 149 | mode = 'D' | 149 | mode = 'A' |
| 150 | else: | 150 | elif addedfile == '/dev/null': |
| 151 | mode = 'M' | 151 | mode = 'D' |
| 152 | if srcdir: | 152 | else: |
| 153 | fullpath = os.path.abspath(os.path.join(srcdir, addedfile)) | 153 | mode = 'M' |
| 154 | else: | 154 | if srcdir: |
| 155 | fullpath = addedfile | 155 | fullpath = os.path.abspath(os.path.join(srcdir, addedfile)) |
| 156 | filelist.append((fullpath, mode)) | 156 | else: |
| 157 | fullpath = addedfile | ||
| 158 | filelist.append((fullpath, mode)) | ||
| 159 | except UnicodeDecodeError: | ||
| 160 | continue | ||
| 161 | break | ||
| 162 | else: | ||
| 163 | raise PatchError('Unable to decode %s' % patchfile) | ||
| 157 | 164 | ||
| 158 | return filelist | 165 | return filelist |
| 159 | 166 | ||
| @@ -280,12 +287,19 @@ class GitApplyTree(PatchTree): | |||
| 280 | """ | 287 | """ |
| 281 | Extract just the header lines from the top of a patch file | 288 | Extract just the header lines from the top of a patch file |
| 282 | """ | 289 | """ |
| 283 | lines = [] | 290 | for encoding in ['utf-8', 'latin-1']: |
| 284 | with open(patchfile, 'r') as f: | 291 | lines = [] |
| 285 | for line in f.readlines(): | 292 | try: |
| 286 | if line.startswith('Index: ') or line.startswith('diff -') or line.startswith('---'): | 293 | with open(patchfile, 'r', encoding=encoding) as f: |
| 287 | break | 294 | for line in f: |
| 288 | lines.append(line) | 295 | if line.startswith('Index: ') or line.startswith('diff -') or line.startswith('---'): |
| 296 | break | ||
| 297 | lines.append(line) | ||
| 298 | except UnicodeDecodeError: | ||
| 299 | continue | ||
| 300 | break | ||
| 301 | else: | ||
| 302 | raise PatchError('Unable to find a character encoding to decode %s' % patchfile) | ||
| 289 | return lines | 303 | return lines |
| 290 | 304 | ||
| 291 | @staticmethod | 305 | @staticmethod |
