diff options
Diffstat (limited to 'meta/lib/oe/patch.py')
| -rw-r--r-- | meta/lib/oe/patch.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index e1f1c53bef..afb0013a4b 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py | |||
| @@ -92,6 +92,69 @@ class PatchSet(object): | |||
| 92 | def Refresh(self, remote = None, all = None): | 92 | def Refresh(self, remote = None, all = None): |
| 93 | raise NotImplementedError() | 93 | raise NotImplementedError() |
| 94 | 94 | ||
| 95 | @staticmethod | ||
| 96 | def getPatchedFiles(patchfile, striplevel, srcdir=None): | ||
| 97 | """ | ||
| 98 | Read a patch file and determine which files it will modify. | ||
| 99 | Params: | ||
| 100 | patchfile: the patch file to read | ||
| 101 | striplevel: the strip level at which the patch is going to be applied | ||
| 102 | srcdir: optional path to join onto the patched file paths | ||
| 103 | Returns: | ||
| 104 | A list of tuples of file path and change mode ('A' for add, | ||
| 105 | 'D' for delete or 'M' for modify) | ||
| 106 | """ | ||
| 107 | |||
| 108 | def patchedpath(patchline): | ||
| 109 | filepth = patchline.split()[1] | ||
| 110 | if filepth.endswith('/dev/null'): | ||
| 111 | return '/dev/null' | ||
| 112 | filesplit = filepth.split(os.sep) | ||
| 113 | if striplevel > len(filesplit): | ||
| 114 | bb.error('Patch %s has invalid strip level %d' % (patchfile, striplevel)) | ||
| 115 | return None | ||
| 116 | return os.sep.join(filesplit[striplevel:]) | ||
| 117 | |||
| 118 | copiedmode = False | ||
| 119 | filelist = [] | ||
| 120 | with open(patchfile) as f: | ||
| 121 | for line in f: | ||
| 122 | if line.startswith('--- '): | ||
| 123 | patchpth = patchedpath(line) | ||
| 124 | if not patchpth: | ||
| 125 | break | ||
| 126 | if copiedmode: | ||
| 127 | addedfile = patchpth | ||
| 128 | else: | ||
| 129 | removedfile = patchpth | ||
| 130 | elif line.startswith('+++ '): | ||
| 131 | addedfile = patchedpath(line) | ||
| 132 | if not addedfile: | ||
| 133 | break | ||
| 134 | elif line.startswith('*** '): | ||
| 135 | copiedmode = True | ||
| 136 | removedfile = patchedpath(line) | ||
| 137 | if not removedfile: | ||
| 138 | break | ||
| 139 | else: | ||
| 140 | removedfile = None | ||
| 141 | addedfile = None | ||
| 142 | |||
| 143 | if addedfile and removedfile: | ||
| 144 | if removedfile == '/dev/null': | ||
| 145 | mode = 'A' | ||
| 146 | elif addedfile == '/dev/null': | ||
| 147 | mode = 'D' | ||
| 148 | else: | ||
| 149 | mode = 'M' | ||
| 150 | if srcdir: | ||
| 151 | fullpath = os.path.abspath(os.path.join(srcdir, addedfile)) | ||
| 152 | else: | ||
| 153 | fullpath = addedfile | ||
| 154 | filelist.append((fullpath, mode)) | ||
| 155 | |||
| 156 | return filelist | ||
| 157 | |||
| 95 | 158 | ||
| 96 | class PatchTree(PatchSet): | 159 | class PatchTree(PatchSet): |
| 97 | def __init__(self, dir, d): | 160 | def __init__(self, dir, d): |
