blob: 3e86a46a3f7c583de0c89d6bc1577bc1fc9e0282 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Report significant differences in the buildhistory repository since a specific revision
2#
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003# Copyright (C) 2012-2013, 2016-2017 Intel Corporation
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004# Author: Paul Eggleton <paul.eggleton@linux.intel.com>
5#
6# Note: requires GitPython 0.3.1+
7#
8# You can use this from the command line by running scripts/buildhistory-diff
9#
10
11import sys
12import os.path
13import difflib
14import git
15import re
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016import hashlib
17import collections
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018import bb.utils
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019import bb.tinfoil
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020
21
22# How to display fields
23list_fields = ['DEPENDS', 'RPROVIDES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RREPLACES', 'RCONFLICTS', 'FILES', 'FILELIST', 'USER_CLASSES', 'IMAGE_CLASSES', 'IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS', 'PACKAGE_EXCLUDE']
24list_order_fields = ['PACKAGES']
25defaultval_map = {'PKG': 'PKG', 'PKGE': 'PE', 'PKGV': 'PV', 'PKGR': 'PR'}
26numeric_fields = ['PKGSIZE', 'IMAGESIZE']
27# Fields to monitor
28monitor_fields = ['RPROVIDES', 'RDEPENDS', 'RRECOMMENDS', 'RREPLACES', 'RCONFLICTS', 'PACKAGES', 'FILELIST', 'PKGSIZE', 'IMAGESIZE', 'PKG']
29ver_monitor_fields = ['PKGE', 'PKGV', 'PKGR']
30# Percentage change to alert for numeric fields
31monitor_numeric_threshold = 10
32# Image files to monitor (note that image-info.txt is handled separately)
33img_monitor_files = ['installed-package-names.txt', 'files-in-image.txt']
34# Related context fields for reporting (note: PE, PV & PR are always reported for monitored package fields)
35related_fields = {}
36related_fields['RDEPENDS'] = ['DEPENDS']
37related_fields['RRECOMMENDS'] = ['DEPENDS']
38related_fields['FILELIST'] = ['FILES']
39related_fields['PKGSIZE'] = ['FILELIST']
40related_fields['files-in-image.txt'] = ['installed-package-names.txt', 'USER_CLASSES', 'IMAGE_CLASSES', 'ROOTFS_POSTPROCESS_COMMAND', 'IMAGE_POSTPROCESS_COMMAND']
41related_fields['installed-package-names.txt'] = ['IMAGE_FEATURES', 'IMAGE_LINGUAS', 'IMAGE_INSTALL', 'BAD_RECOMMENDATIONS', 'NO_RECOMMENDATIONS', 'PACKAGE_EXCLUDE']
42
43
44class ChangeRecord:
45 def __init__(self, path, fieldname, oldvalue, newvalue, monitored):
46 self.path = path
47 self.fieldname = fieldname
48 self.oldvalue = oldvalue
49 self.newvalue = newvalue
50 self.monitored = monitored
51 self.related = []
52 self.filechanges = None
53
54 def __str__(self):
55 return self._str_internal(True)
56
57 def _str_internal(self, outer):
58 if outer:
59 if '/image-files/' in self.path:
60 prefix = '%s: ' % self.path.split('/image-files/')[0]
61 else:
62 prefix = '%s: ' % self.path
63 else:
64 prefix = ''
65
66 def pkglist_combine(depver):
67 pkglist = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068 for k,v in depver.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069 if v:
70 pkglist.append("%s (%s)" % (k,v))
71 else:
72 pkglist.append(k)
73 return pkglist
74
Brad Bishop6e60e8b2018-02-01 10:27:11 -050075 def detect_renamed_dirs(aitems, bitems):
76 adirs = set(map(os.path.dirname, aitems))
77 bdirs = set(map(os.path.dirname, bitems))
78 files_ab = [(name, sorted(os.path.basename(item) for item in aitems if os.path.dirname(item) == name)) \
79 for name in adirs - bdirs]
80 files_ba = [(name, sorted(os.path.basename(item) for item in bitems if os.path.dirname(item) == name)) \
81 for name in bdirs - adirs]
82 renamed_dirs = [(dir1, dir2) for dir1, files1 in files_ab for dir2, files2 in files_ba if files1 == files2]
83 # remove files that belong to renamed dirs from aitems and bitems
84 for dir1, dir2 in renamed_dirs:
85 aitems = [item for item in aitems if os.path.dirname(item) not in (dir1, dir2)]
86 bitems = [item for item in bitems if os.path.dirname(item) not in (dir1, dir2)]
87 return renamed_dirs, aitems, bitems
88
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 if self.fieldname in list_fields or self.fieldname in list_order_fields:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090 renamed_dirs = []
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 if self.fieldname in ['RPROVIDES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RREPLACES', 'RCONFLICTS']:
92 (depvera, depverb) = compare_pkg_lists(self.oldvalue, self.newvalue)
93 aitems = pkglist_combine(depvera)
94 bitems = pkglist_combine(depverb)
95 else:
96 aitems = self.oldvalue.split()
97 bitems = self.newvalue.split()
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 if self.fieldname == 'FILELIST':
99 renamed_dirs, aitems, bitems = detect_renamed_dirs(aitems, bitems)
100
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101 removed = list(set(aitems) - set(bitems))
102 added = list(set(bitems) - set(aitems))
103
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 lines = []
105 if renamed_dirs:
106 for dfrom, dto in renamed_dirs:
107 lines.append('directory renamed %s -> %s' % (dfrom, dto))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 if removed or added:
109 if removed and not bitems:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500110 lines.append('removed all items "%s"' % ' '.join(removed))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 if removed:
113 lines.append('removed "%s"' % ' '.join(removed))
114 if added:
115 lines.append('added "%s"' % ' '.join(added))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500116 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500117 lines.append('changed order')
118
119 out = '%s: %s' % (self.fieldname, ', '.join(lines))
120
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121 elif self.fieldname in numeric_fields:
122 aval = int(self.oldvalue or 0)
123 bval = int(self.newvalue or 0)
124 if aval != 0:
125 percentchg = ((bval - aval) / float(aval)) * 100
126 else:
127 percentchg = 100
128 out = '%s changed from %s to %s (%s%d%%)' % (self.fieldname, self.oldvalue or "''", self.newvalue or "''", '+' if percentchg > 0 else '', percentchg)
129 elif self.fieldname in defaultval_map:
130 out = '%s changed from %s to %s' % (self.fieldname, self.oldvalue, self.newvalue)
131 if self.fieldname == 'PKG' and '[default]' in self.newvalue:
132 out += ' - may indicate debian renaming failure'
133 elif self.fieldname in ['pkg_preinst', 'pkg_postinst', 'pkg_prerm', 'pkg_postrm']:
134 if self.oldvalue and self.newvalue:
135 out = '%s changed:\n ' % self.fieldname
136 elif self.newvalue:
137 out = '%s added:\n ' % self.fieldname
138 elif self.oldvalue:
139 out = '%s cleared:\n ' % self.fieldname
140 alines = self.oldvalue.splitlines()
141 blines = self.newvalue.splitlines()
142 diff = difflib.unified_diff(alines, blines, self.fieldname, self.fieldname, lineterm='')
143 out += '\n '.join(list(diff)[2:])
144 out += '\n --'
145 elif self.fieldname in img_monitor_files or '/image-files/' in self.path:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500146 if self.filechanges or (self.oldvalue and self.newvalue):
147 fieldname = self.fieldname
148 if '/image-files/' in self.path:
149 fieldname = os.path.join('/' + self.path.split('/image-files/')[1], self.fieldname)
150 out = 'Changes to %s:\n ' % fieldname
151 else:
152 if outer:
153 prefix = 'Changes to %s ' % self.path
154 out = '(%s):\n ' % self.fieldname
155 if self.filechanges:
156 out += '\n '.join(['%s' % i for i in self.filechanges])
157 else:
158 alines = self.oldvalue.splitlines()
159 blines = self.newvalue.splitlines()
160 diff = difflib.unified_diff(alines, blines, fieldname, fieldname, lineterm='')
161 out += '\n '.join(list(diff))
162 out += '\n --'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164 out = ''
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165 else:
166 out = '%s changed from "%s" to "%s"' % (self.fieldname, self.oldvalue, self.newvalue)
167
168 if self.related:
169 for chg in self.related:
170 if not outer and chg.fieldname in ['PE', 'PV', 'PR']:
171 continue
172 for line in chg._str_internal(False).splitlines():
173 out += '\n * %s' % line
174
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500175 return '%s%s' % (prefix, out) if out else ''
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
177class FileChange:
178 changetype_add = 'A'
179 changetype_remove = 'R'
180 changetype_type = 'T'
181 changetype_perms = 'P'
182 changetype_ownergroup = 'O'
183 changetype_link = 'L'
184
185 def __init__(self, path, changetype, oldvalue = None, newvalue = None):
186 self.path = path
187 self.changetype = changetype
188 self.oldvalue = oldvalue
189 self.newvalue = newvalue
190
191 def _ftype_str(self, ftype):
192 if ftype == '-':
193 return 'file'
194 elif ftype == 'd':
195 return 'directory'
196 elif ftype == 'l':
197 return 'symlink'
198 elif ftype == 'c':
199 return 'char device'
200 elif ftype == 'b':
201 return 'block device'
202 elif ftype == 'p':
203 return 'fifo'
204 elif ftype == 's':
205 return 'socket'
206 else:
207 return 'unknown (%s)' % ftype
208
209 def __str__(self):
210 if self.changetype == self.changetype_add:
211 return '%s was added' % self.path
212 elif self.changetype == self.changetype_remove:
213 return '%s was removed' % self.path
214 elif self.changetype == self.changetype_type:
215 return '%s changed type from %s to %s' % (self.path, self._ftype_str(self.oldvalue), self._ftype_str(self.newvalue))
216 elif self.changetype == self.changetype_perms:
217 return '%s changed permissions from %s to %s' % (self.path, self.oldvalue, self.newvalue)
218 elif self.changetype == self.changetype_ownergroup:
219 return '%s changed owner/group from %s to %s' % (self.path, self.oldvalue, self.newvalue)
220 elif self.changetype == self.changetype_link:
221 return '%s changed symlink target from %s to %s' % (self.path, self.oldvalue, self.newvalue)
222 else:
223 return '%s changed (unknown)' % self.path
224
225
226def blob_to_dict(blob):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600227 alines = [line for line in blob.data_stream.read().decode('utf-8').splitlines()]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 adict = {}
229 for line in alines:
230 splitv = [i.strip() for i in line.split('=',1)]
231 if len(splitv) > 1:
232 adict[splitv[0]] = splitv[1]
233 return adict
234
235
236def file_list_to_dict(lines):
237 adict = {}
238 for line in lines:
239 # Leave the last few fields intact so we handle file names containing spaces
240 splitv = line.split(None,4)
241 # Grab the path and remove the leading .
242 path = splitv[4][1:].strip()
243 # Handle symlinks
244 if(' -> ' in path):
245 target = path.split(' -> ')[1]
246 path = path.split(' -> ')[0]
247 adict[path] = splitv[0:3] + [target]
248 else:
249 adict[path] = splitv[0:3]
250 return adict
251
252
253def compare_file_lists(alines, blines):
254 adict = file_list_to_dict(alines)
255 bdict = file_list_to_dict(blines)
256 filechanges = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600257 for path, splitv in adict.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 newsplitv = bdict.pop(path, None)
259 if newsplitv:
260 # Check type
261 oldvalue = splitv[0][0]
262 newvalue = newsplitv[0][0]
263 if oldvalue != newvalue:
264 filechanges.append(FileChange(path, FileChange.changetype_type, oldvalue, newvalue))
265 # Check permissions
266 oldvalue = splitv[0][1:]
267 newvalue = newsplitv[0][1:]
268 if oldvalue != newvalue:
269 filechanges.append(FileChange(path, FileChange.changetype_perms, oldvalue, newvalue))
270 # Check owner/group
271 oldvalue = '%s/%s' % (splitv[1], splitv[2])
272 newvalue = '%s/%s' % (newsplitv[1], newsplitv[2])
273 if oldvalue != newvalue:
274 filechanges.append(FileChange(path, FileChange.changetype_ownergroup, oldvalue, newvalue))
275 # Check symlink target
276 if newsplitv[0][0] == 'l':
277 if len(splitv) > 3:
278 oldvalue = splitv[3]
279 else:
280 oldvalue = None
281 newvalue = newsplitv[3]
282 if oldvalue != newvalue:
283 filechanges.append(FileChange(path, FileChange.changetype_link, oldvalue, newvalue))
284 else:
285 filechanges.append(FileChange(path, FileChange.changetype_remove))
286
287 # Whatever is left over has been added
288 for path in bdict:
289 filechanges.append(FileChange(path, FileChange.changetype_add))
290
291 return filechanges
292
293
294def compare_lists(alines, blines):
295 removed = list(set(alines) - set(blines))
296 added = list(set(blines) - set(alines))
297
298 filechanges = []
299 for pkg in removed:
300 filechanges.append(FileChange(pkg, FileChange.changetype_remove))
301 for pkg in added:
302 filechanges.append(FileChange(pkg, FileChange.changetype_add))
303
304 return filechanges
305
306
307def compare_pkg_lists(astr, bstr):
308 depvera = bb.utils.explode_dep_versions2(astr)
309 depverb = bb.utils.explode_dep_versions2(bstr)
310
311 # Strip out changes where the version has increased
312 remove = []
313 for k in depvera:
314 if k in depverb:
315 dva = depvera[k]
316 dvb = depverb[k]
317 if dva and dvb and len(dva) == len(dvb):
318 # Since length is the same, sort so that prefixes (e.g. >=) will line up
319 dva.sort()
320 dvb.sort()
321 removeit = True
322 for dvai, dvbi in zip(dva, dvb):
323 if dvai != dvbi:
324 aiprefix = dvai.split(' ')[0]
325 biprefix = dvbi.split(' ')[0]
326 if aiprefix == biprefix and aiprefix in ['>=', '=']:
327 if bb.utils.vercmp(bb.utils.split_version(dvai), bb.utils.split_version(dvbi)) > 0:
328 removeit = False
329 break
330 else:
331 removeit = False
332 break
333 if removeit:
334 remove.append(k)
335
336 for k in remove:
337 depvera.pop(k)
338 depverb.pop(k)
339
340 return (depvera, depverb)
341
342
343def compare_dict_blobs(path, ablob, bblob, report_all, report_ver):
344 adict = blob_to_dict(ablob)
345 bdict = blob_to_dict(bblob)
346
347 pkgname = os.path.basename(path)
348
349 defaultvals = {}
350 defaultvals['PKG'] = pkgname
351 defaultvals['PKGE'] = '0'
352
353 changes = []
354 keys = list(set(adict.keys()) | set(bdict.keys()) | set(defaultval_map.keys()))
355 for key in keys:
356 astr = adict.get(key, '')
357 bstr = bdict.get(key, '')
358 if key in ver_monitor_fields:
359 monitored = report_ver or astr or bstr
360 else:
361 monitored = key in monitor_fields
362 mapped_key = defaultval_map.get(key, '')
363 if mapped_key:
364 if not astr:
365 astr = '%s [default]' % adict.get(mapped_key, defaultvals.get(key, ''))
366 if not bstr:
367 bstr = '%s [default]' % bdict.get(mapped_key, defaultvals.get(key, ''))
368
369 if astr != bstr:
370 if (not report_all) and key in numeric_fields:
371 aval = int(astr or 0)
372 bval = int(bstr or 0)
373 if aval != 0:
374 percentchg = ((bval - aval) / float(aval)) * 100
375 else:
376 percentchg = 100
377 if abs(percentchg) < monitor_numeric_threshold:
378 continue
379 elif (not report_all) and key in list_fields:
380 if key == "FILELIST" and path.endswith("-dbg") and bstr.strip() != '':
381 continue
382 if key in ['RPROVIDES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RREPLACES', 'RCONFLICTS']:
383 (depvera, depverb) = compare_pkg_lists(astr, bstr)
384 if depvera == depverb:
385 continue
386 alist = astr.split()
387 alist.sort()
388 blist = bstr.split()
389 blist.sort()
390 # We don't care about the removal of self-dependencies
391 if pkgname in alist and not pkgname in blist:
392 alist.remove(pkgname)
393 if ' '.join(alist) == ' '.join(blist):
394 continue
395
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600396 if key == 'PKGR' and not report_all:
397 vers = []
398 # strip leading 'r' and dots
399 for ver in (astr.split()[0], bstr.split()[0]):
400 if ver.startswith('r'):
401 ver = ver[1:]
402 vers.append(ver.replace('.', ''))
403 maxlen = max(len(vers[0]), len(vers[1]))
404 try:
405 # pad with '0' and convert to int
406 vers = [int(ver.ljust(maxlen, '0')) for ver in vers]
407 except ValueError:
408 pass
409 else:
410 # skip decrements and increments
411 if abs(vers[0] - vers[1]) == 1:
412 continue
413
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500414 chg = ChangeRecord(path, key, astr, bstr, monitored)
415 changes.append(chg)
416 return changes
417
418
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500419def compare_siglists(a_blob, b_blob, taskdiff=False):
420 # FIXME collapse down a recipe's tasks?
421 alines = a_blob.data_stream.read().decode('utf-8').splitlines()
422 blines = b_blob.data_stream.read().decode('utf-8').splitlines()
423 keys = []
424 pnmap = {}
425 def readsigs(lines):
426 sigs = {}
427 for line in lines:
428 linesplit = line.split()
429 if len(linesplit) > 2:
430 sigs[linesplit[0]] = linesplit[2]
431 if not linesplit[0] in keys:
432 keys.append(linesplit[0])
433 pnmap[linesplit[1]] = linesplit[0].rsplit('.', 1)[0]
434 return sigs
435 adict = readsigs(alines)
436 bdict = readsigs(blines)
437 out = []
438
439 changecount = 0
440 addcount = 0
441 removecount = 0
442 if taskdiff:
443 with bb.tinfoil.Tinfoil() as tinfoil:
444 tinfoil.prepare(config_only=True)
445
446 changes = collections.OrderedDict()
447
448 def compare_hashfiles(pn, taskname, hash1, hash2):
449 hashes = [hash1, hash2]
450 hashfiles = bb.siggen.find_siginfo(pn, taskname, hashes, tinfoil.config_data)
451
452 if not taskname:
453 (pn, taskname) = pn.rsplit('.', 1)
454 pn = pnmap.get(pn, pn)
455 desc = '%s.%s' % (pn, taskname)
456
457 if len(hashfiles) == 0:
458 out.append("Unable to find matching sigdata for %s with hashes %s or %s" % (desc, hash1, hash2))
459 elif not hash1 in hashfiles:
460 out.append("Unable to find matching sigdata for %s with hash %s" % (desc, hash1))
461 elif not hash2 in hashfiles:
462 out.append("Unable to find matching sigdata for %s with hash %s" % (desc, hash2))
463 else:
464 out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb, collapsed=True)
465 for line in out2:
466 m = hashlib.sha256()
467 m.update(line.encode('utf-8'))
468 entry = changes.get(m.hexdigest(), (line, []))
469 if desc not in entry[1]:
470 changes[m.hexdigest()] = (line, entry[1] + [desc])
471
472 # Define recursion callback
473 def recursecb(key, hash1, hash2):
474 compare_hashfiles(key, None, hash1, hash2)
475 return []
476
477 for key in keys:
478 siga = adict.get(key, None)
479 sigb = bdict.get(key, None)
480 if siga is not None and sigb is not None and siga != sigb:
481 changecount += 1
482 (pn, taskname) = key.rsplit('.', 1)
483 compare_hashfiles(pn, taskname, siga, sigb)
484 elif siga is None:
485 addcount += 1
486 elif sigb is None:
487 removecount += 1
488 for key, item in changes.items():
489 line, tasks = item
490 if len(tasks) == 1:
491 desc = tasks[0]
492 elif len(tasks) == 2:
493 desc = '%s and %s' % (tasks[0], tasks[1])
494 else:
495 desc = '%s and %d others' % (tasks[-1], len(tasks)-1)
496 out.append('%s: %s' % (desc, line))
497 else:
498 for key in keys:
499 siga = adict.get(key, None)
500 sigb = bdict.get(key, None)
501 if siga is not None and sigb is not None and siga != sigb:
502 out.append('%s changed from %s to %s' % (key, siga, sigb))
503 changecount += 1
504 elif siga is None:
505 out.append('%s was added' % key)
506 addcount += 1
507 elif sigb is None:
508 out.append('%s was removed' % key)
509 removecount += 1
510 out.append('Summary: %d tasks added, %d tasks removed, %d tasks modified (%.1f%%)' % (addcount, removecount, changecount, (changecount / float(len(bdict)) * 100)))
511 return '\n'.join(out)
512
513
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500514def process_changes(repopath, revision1, revision2='HEAD', report_all=False, report_ver=False,
515 sigs=False, sigsdiff=False, exclude_path=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500516 repo = git.Repo(repopath)
517 assert repo.bare == False
518 commit = repo.commit(revision1)
519 diff = commit.diff(revision2)
520
521 changes = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500522
523 if sigs or sigsdiff:
524 for d in diff.iter_change_type('M'):
525 if d.a_blob.path == 'siglist.txt':
526 changes.append(compare_siglists(d.a_blob, d.b_blob, taskdiff=sigsdiff))
527 return changes
528
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500529 for d in diff.iter_change_type('M'):
530 path = os.path.dirname(d.a_blob.path)
531 if path.startswith('packages/'):
532 filename = os.path.basename(d.a_blob.path)
533 if filename == 'latest':
534 changes.extend(compare_dict_blobs(path, d.a_blob, d.b_blob, report_all, report_ver))
535 elif filename.startswith('latest.'):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600536 chg = ChangeRecord(path, filename, d.a_blob.data_stream.read().decode('utf-8'), d.b_blob.data_stream.read().decode('utf-8'), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500537 changes.append(chg)
538 elif path.startswith('images/'):
539 filename = os.path.basename(d.a_blob.path)
540 if filename in img_monitor_files:
541 if filename == 'files-in-image.txt':
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600542 alines = d.a_blob.data_stream.read().decode('utf-8').splitlines()
543 blines = d.b_blob.data_stream.read().decode('utf-8').splitlines()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500544 filechanges = compare_file_lists(alines,blines)
545 if filechanges:
546 chg = ChangeRecord(path, filename, None, None, True)
547 chg.filechanges = filechanges
548 changes.append(chg)
549 elif filename == 'installed-package-names.txt':
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600550 alines = d.a_blob.data_stream.read().decode('utf-8').splitlines()
551 blines = d.b_blob.data_stream.read().decode('utf-8').splitlines()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500552 filechanges = compare_lists(alines,blines)
553 if filechanges:
554 chg = ChangeRecord(path, filename, None, None, True)
555 chg.filechanges = filechanges
556 changes.append(chg)
557 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600558 chg = ChangeRecord(path, filename, d.a_blob.data_stream.read().decode('utf-8'), d.b_blob.data_stream.read().decode('utf-8'), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500559 changes.append(chg)
560 elif filename == 'image-info.txt':
561 changes.extend(compare_dict_blobs(path, d.a_blob, d.b_blob, report_all, report_ver))
562 elif '/image-files/' in path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600563 chg = ChangeRecord(path, filename, d.a_blob.data_stream.read().decode('utf-8'), d.b_blob.data_stream.read().decode('utf-8'), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500564 changes.append(chg)
565
566 # Look for added preinst/postinst/prerm/postrm
567 # (without reporting newly added recipes)
568 addedpkgs = []
569 addedchanges = []
570 for d in diff.iter_change_type('A'):
571 path = os.path.dirname(d.b_blob.path)
572 if path.startswith('packages/'):
573 filename = os.path.basename(d.b_blob.path)
574 if filename == 'latest':
575 addedpkgs.append(path)
576 elif filename.startswith('latest.'):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600577 chg = ChangeRecord(path, filename[7:], '', d.b_blob.data_stream.read().decode('utf-8'), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500578 addedchanges.append(chg)
579 for chg in addedchanges:
580 found = False
581 for pkg in addedpkgs:
582 if chg.path.startswith(pkg):
583 found = True
584 break
585 if not found:
586 changes.append(chg)
587
588 # Look for cleared preinst/postinst/prerm/postrm
589 for d in diff.iter_change_type('D'):
590 path = os.path.dirname(d.a_blob.path)
591 if path.startswith('packages/'):
592 filename = os.path.basename(d.a_blob.path)
593 if filename != 'latest' and filename.startswith('latest.'):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600594 chg = ChangeRecord(path, filename[7:], d.a_blob.data_stream.read().decode('utf-8'), '', True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500595 changes.append(chg)
596
597 # Link related changes
598 for chg in changes:
599 if chg.monitored:
600 for chg2 in changes:
601 # (Check dirname in the case of fields from recipe info files)
602 if chg.path == chg2.path or os.path.dirname(chg.path) == chg2.path:
603 if chg2.fieldname in related_fields.get(chg.fieldname, []):
604 chg.related.append(chg2)
605 elif chg.path == chg2.path and chg.path.startswith('packages/') and chg2.fieldname in ['PE', 'PV', 'PR']:
606 chg.related.append(chg2)
607
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500608 # filter out unwanted paths
609 if exclude_path:
610 for chg in changes:
611 if chg.filechanges:
612 fchgs = []
613 for fchg in chg.filechanges:
614 for epath in exclude_path:
615 if fchg.path.startswith(epath):
616 break
617 else:
618 fchgs.append(fchg)
619 chg.filechanges = fchgs
620
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 if report_all:
622 return changes
623 else:
624 return [chg for chg in changes if chg.monitored]