blob: 3a5b7b6b445d88e3fa9cab4f9cda663051ff133e [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:
146 fieldname = self.fieldname
147 if '/image-files/' in self.path:
148 fieldname = os.path.join('/' + self.path.split('/image-files/')[1], self.fieldname)
149 out = 'Changes to %s:\n ' % fieldname
150 else:
151 if outer:
152 prefix = 'Changes to %s ' % self.path
153 out = '(%s):\n ' % self.fieldname
154 if self.filechanges:
155 out += '\n '.join(['%s' % i for i in self.filechanges])
156 else:
157 alines = self.oldvalue.splitlines()
158 blines = self.newvalue.splitlines()
159 diff = difflib.unified_diff(alines, blines, fieldname, fieldname, lineterm='')
160 out += '\n '.join(list(diff))
161 out += '\n --'
162 else:
163 out = '%s changed from "%s" to "%s"' % (self.fieldname, self.oldvalue, self.newvalue)
164
165 if self.related:
166 for chg in self.related:
167 if not outer and chg.fieldname in ['PE', 'PV', 'PR']:
168 continue
169 for line in chg._str_internal(False).splitlines():
170 out += '\n * %s' % line
171
172 return '%s%s' % (prefix, out)
173
174class FileChange:
175 changetype_add = 'A'
176 changetype_remove = 'R'
177 changetype_type = 'T'
178 changetype_perms = 'P'
179 changetype_ownergroup = 'O'
180 changetype_link = 'L'
181
182 def __init__(self, path, changetype, oldvalue = None, newvalue = None):
183 self.path = path
184 self.changetype = changetype
185 self.oldvalue = oldvalue
186 self.newvalue = newvalue
187
188 def _ftype_str(self, ftype):
189 if ftype == '-':
190 return 'file'
191 elif ftype == 'd':
192 return 'directory'
193 elif ftype == 'l':
194 return 'symlink'
195 elif ftype == 'c':
196 return 'char device'
197 elif ftype == 'b':
198 return 'block device'
199 elif ftype == 'p':
200 return 'fifo'
201 elif ftype == 's':
202 return 'socket'
203 else:
204 return 'unknown (%s)' % ftype
205
206 def __str__(self):
207 if self.changetype == self.changetype_add:
208 return '%s was added' % self.path
209 elif self.changetype == self.changetype_remove:
210 return '%s was removed' % self.path
211 elif self.changetype == self.changetype_type:
212 return '%s changed type from %s to %s' % (self.path, self._ftype_str(self.oldvalue), self._ftype_str(self.newvalue))
213 elif self.changetype == self.changetype_perms:
214 return '%s changed permissions from %s to %s' % (self.path, self.oldvalue, self.newvalue)
215 elif self.changetype == self.changetype_ownergroup:
216 return '%s changed owner/group from %s to %s' % (self.path, self.oldvalue, self.newvalue)
217 elif self.changetype == self.changetype_link:
218 return '%s changed symlink target from %s to %s' % (self.path, self.oldvalue, self.newvalue)
219 else:
220 return '%s changed (unknown)' % self.path
221
222
223def blob_to_dict(blob):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600224 alines = [line for line in blob.data_stream.read().decode('utf-8').splitlines()]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500225 adict = {}
226 for line in alines:
227 splitv = [i.strip() for i in line.split('=',1)]
228 if len(splitv) > 1:
229 adict[splitv[0]] = splitv[1]
230 return adict
231
232
233def file_list_to_dict(lines):
234 adict = {}
235 for line in lines:
236 # Leave the last few fields intact so we handle file names containing spaces
237 splitv = line.split(None,4)
238 # Grab the path and remove the leading .
239 path = splitv[4][1:].strip()
240 # Handle symlinks
241 if(' -> ' in path):
242 target = path.split(' -> ')[1]
243 path = path.split(' -> ')[0]
244 adict[path] = splitv[0:3] + [target]
245 else:
246 adict[path] = splitv[0:3]
247 return adict
248
249
250def compare_file_lists(alines, blines):
251 adict = file_list_to_dict(alines)
252 bdict = file_list_to_dict(blines)
253 filechanges = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600254 for path, splitv in adict.items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255 newsplitv = bdict.pop(path, None)
256 if newsplitv:
257 # Check type
258 oldvalue = splitv[0][0]
259 newvalue = newsplitv[0][0]
260 if oldvalue != newvalue:
261 filechanges.append(FileChange(path, FileChange.changetype_type, oldvalue, newvalue))
262 # Check permissions
263 oldvalue = splitv[0][1:]
264 newvalue = newsplitv[0][1:]
265 if oldvalue != newvalue:
266 filechanges.append(FileChange(path, FileChange.changetype_perms, oldvalue, newvalue))
267 # Check owner/group
268 oldvalue = '%s/%s' % (splitv[1], splitv[2])
269 newvalue = '%s/%s' % (newsplitv[1], newsplitv[2])
270 if oldvalue != newvalue:
271 filechanges.append(FileChange(path, FileChange.changetype_ownergroup, oldvalue, newvalue))
272 # Check symlink target
273 if newsplitv[0][0] == 'l':
274 if len(splitv) > 3:
275 oldvalue = splitv[3]
276 else:
277 oldvalue = None
278 newvalue = newsplitv[3]
279 if oldvalue != newvalue:
280 filechanges.append(FileChange(path, FileChange.changetype_link, oldvalue, newvalue))
281 else:
282 filechanges.append(FileChange(path, FileChange.changetype_remove))
283
284 # Whatever is left over has been added
285 for path in bdict:
286 filechanges.append(FileChange(path, FileChange.changetype_add))
287
288 return filechanges
289
290
291def compare_lists(alines, blines):
292 removed = list(set(alines) - set(blines))
293 added = list(set(blines) - set(alines))
294
295 filechanges = []
296 for pkg in removed:
297 filechanges.append(FileChange(pkg, FileChange.changetype_remove))
298 for pkg in added:
299 filechanges.append(FileChange(pkg, FileChange.changetype_add))
300
301 return filechanges
302
303
304def compare_pkg_lists(astr, bstr):
305 depvera = bb.utils.explode_dep_versions2(astr)
306 depverb = bb.utils.explode_dep_versions2(bstr)
307
308 # Strip out changes where the version has increased
309 remove = []
310 for k in depvera:
311 if k in depverb:
312 dva = depvera[k]
313 dvb = depverb[k]
314 if dva and dvb and len(dva) == len(dvb):
315 # Since length is the same, sort so that prefixes (e.g. >=) will line up
316 dva.sort()
317 dvb.sort()
318 removeit = True
319 for dvai, dvbi in zip(dva, dvb):
320 if dvai != dvbi:
321 aiprefix = dvai.split(' ')[0]
322 biprefix = dvbi.split(' ')[0]
323 if aiprefix == biprefix and aiprefix in ['>=', '=']:
324 if bb.utils.vercmp(bb.utils.split_version(dvai), bb.utils.split_version(dvbi)) > 0:
325 removeit = False
326 break
327 else:
328 removeit = False
329 break
330 if removeit:
331 remove.append(k)
332
333 for k in remove:
334 depvera.pop(k)
335 depverb.pop(k)
336
337 return (depvera, depverb)
338
339
340def compare_dict_blobs(path, ablob, bblob, report_all, report_ver):
341 adict = blob_to_dict(ablob)
342 bdict = blob_to_dict(bblob)
343
344 pkgname = os.path.basename(path)
345
346 defaultvals = {}
347 defaultvals['PKG'] = pkgname
348 defaultvals['PKGE'] = '0'
349
350 changes = []
351 keys = list(set(adict.keys()) | set(bdict.keys()) | set(defaultval_map.keys()))
352 for key in keys:
353 astr = adict.get(key, '')
354 bstr = bdict.get(key, '')
355 if key in ver_monitor_fields:
356 monitored = report_ver or astr or bstr
357 else:
358 monitored = key in monitor_fields
359 mapped_key = defaultval_map.get(key, '')
360 if mapped_key:
361 if not astr:
362 astr = '%s [default]' % adict.get(mapped_key, defaultvals.get(key, ''))
363 if not bstr:
364 bstr = '%s [default]' % bdict.get(mapped_key, defaultvals.get(key, ''))
365
366 if astr != bstr:
367 if (not report_all) and key in numeric_fields:
368 aval = int(astr or 0)
369 bval = int(bstr or 0)
370 if aval != 0:
371 percentchg = ((bval - aval) / float(aval)) * 100
372 else:
373 percentchg = 100
374 if abs(percentchg) < monitor_numeric_threshold:
375 continue
376 elif (not report_all) and key in list_fields:
377 if key == "FILELIST" and path.endswith("-dbg") and bstr.strip() != '':
378 continue
379 if key in ['RPROVIDES', 'RDEPENDS', 'RRECOMMENDS', 'RSUGGESTS', 'RREPLACES', 'RCONFLICTS']:
380 (depvera, depverb) = compare_pkg_lists(astr, bstr)
381 if depvera == depverb:
382 continue
383 alist = astr.split()
384 alist.sort()
385 blist = bstr.split()
386 blist.sort()
387 # We don't care about the removal of self-dependencies
388 if pkgname in alist and not pkgname in blist:
389 alist.remove(pkgname)
390 if ' '.join(alist) == ' '.join(blist):
391 continue
392
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600393 if key == 'PKGR' and not report_all:
394 vers = []
395 # strip leading 'r' and dots
396 for ver in (astr.split()[0], bstr.split()[0]):
397 if ver.startswith('r'):
398 ver = ver[1:]
399 vers.append(ver.replace('.', ''))
400 maxlen = max(len(vers[0]), len(vers[1]))
401 try:
402 # pad with '0' and convert to int
403 vers = [int(ver.ljust(maxlen, '0')) for ver in vers]
404 except ValueError:
405 pass
406 else:
407 # skip decrements and increments
408 if abs(vers[0] - vers[1]) == 1:
409 continue
410
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500411 chg = ChangeRecord(path, key, astr, bstr, monitored)
412 changes.append(chg)
413 return changes
414
415
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500416def compare_siglists(a_blob, b_blob, taskdiff=False):
417 # FIXME collapse down a recipe's tasks?
418 alines = a_blob.data_stream.read().decode('utf-8').splitlines()
419 blines = b_blob.data_stream.read().decode('utf-8').splitlines()
420 keys = []
421 pnmap = {}
422 def readsigs(lines):
423 sigs = {}
424 for line in lines:
425 linesplit = line.split()
426 if len(linesplit) > 2:
427 sigs[linesplit[0]] = linesplit[2]
428 if not linesplit[0] in keys:
429 keys.append(linesplit[0])
430 pnmap[linesplit[1]] = linesplit[0].rsplit('.', 1)[0]
431 return sigs
432 adict = readsigs(alines)
433 bdict = readsigs(blines)
434 out = []
435
436 changecount = 0
437 addcount = 0
438 removecount = 0
439 if taskdiff:
440 with bb.tinfoil.Tinfoil() as tinfoil:
441 tinfoil.prepare(config_only=True)
442
443 changes = collections.OrderedDict()
444
445 def compare_hashfiles(pn, taskname, hash1, hash2):
446 hashes = [hash1, hash2]
447 hashfiles = bb.siggen.find_siginfo(pn, taskname, hashes, tinfoil.config_data)
448
449 if not taskname:
450 (pn, taskname) = pn.rsplit('.', 1)
451 pn = pnmap.get(pn, pn)
452 desc = '%s.%s' % (pn, taskname)
453
454 if len(hashfiles) == 0:
455 out.append("Unable to find matching sigdata for %s with hashes %s or %s" % (desc, hash1, hash2))
456 elif not hash1 in hashfiles:
457 out.append("Unable to find matching sigdata for %s with hash %s" % (desc, hash1))
458 elif not hash2 in hashfiles:
459 out.append("Unable to find matching sigdata for %s with hash %s" % (desc, hash2))
460 else:
461 out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb, collapsed=True)
462 for line in out2:
463 m = hashlib.sha256()
464 m.update(line.encode('utf-8'))
465 entry = changes.get(m.hexdigest(), (line, []))
466 if desc not in entry[1]:
467 changes[m.hexdigest()] = (line, entry[1] + [desc])
468
469 # Define recursion callback
470 def recursecb(key, hash1, hash2):
471 compare_hashfiles(key, None, hash1, hash2)
472 return []
473
474 for key in keys:
475 siga = adict.get(key, None)
476 sigb = bdict.get(key, None)
477 if siga is not None and sigb is not None and siga != sigb:
478 changecount += 1
479 (pn, taskname) = key.rsplit('.', 1)
480 compare_hashfiles(pn, taskname, siga, sigb)
481 elif siga is None:
482 addcount += 1
483 elif sigb is None:
484 removecount += 1
485 for key, item in changes.items():
486 line, tasks = item
487 if len(tasks) == 1:
488 desc = tasks[0]
489 elif len(tasks) == 2:
490 desc = '%s and %s' % (tasks[0], tasks[1])
491 else:
492 desc = '%s and %d others' % (tasks[-1], len(tasks)-1)
493 out.append('%s: %s' % (desc, line))
494 else:
495 for key in keys:
496 siga = adict.get(key, None)
497 sigb = bdict.get(key, None)
498 if siga is not None and sigb is not None and siga != sigb:
499 out.append('%s changed from %s to %s' % (key, siga, sigb))
500 changecount += 1
501 elif siga is None:
502 out.append('%s was added' % key)
503 addcount += 1
504 elif sigb is None:
505 out.append('%s was removed' % key)
506 removecount += 1
507 out.append('Summary: %d tasks added, %d tasks removed, %d tasks modified (%.1f%%)' % (addcount, removecount, changecount, (changecount / float(len(bdict)) * 100)))
508 return '\n'.join(out)
509
510
511def process_changes(repopath, revision1, revision2='HEAD', report_all=False, report_ver=False, sigs=False, sigsdiff=False):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500512 repo = git.Repo(repopath)
513 assert repo.bare == False
514 commit = repo.commit(revision1)
515 diff = commit.diff(revision2)
516
517 changes = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500518
519 if sigs or sigsdiff:
520 for d in diff.iter_change_type('M'):
521 if d.a_blob.path == 'siglist.txt':
522 changes.append(compare_siglists(d.a_blob, d.b_blob, taskdiff=sigsdiff))
523 return changes
524
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500525 for d in diff.iter_change_type('M'):
526 path = os.path.dirname(d.a_blob.path)
527 if path.startswith('packages/'):
528 filename = os.path.basename(d.a_blob.path)
529 if filename == 'latest':
530 changes.extend(compare_dict_blobs(path, d.a_blob, d.b_blob, report_all, report_ver))
531 elif filename.startswith('latest.'):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600532 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 -0500533 changes.append(chg)
534 elif path.startswith('images/'):
535 filename = os.path.basename(d.a_blob.path)
536 if filename in img_monitor_files:
537 if filename == 'files-in-image.txt':
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600538 alines = d.a_blob.data_stream.read().decode('utf-8').splitlines()
539 blines = d.b_blob.data_stream.read().decode('utf-8').splitlines()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500540 filechanges = compare_file_lists(alines,blines)
541 if filechanges:
542 chg = ChangeRecord(path, filename, None, None, True)
543 chg.filechanges = filechanges
544 changes.append(chg)
545 elif filename == 'installed-package-names.txt':
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600546 alines = d.a_blob.data_stream.read().decode('utf-8').splitlines()
547 blines = d.b_blob.data_stream.read().decode('utf-8').splitlines()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500548 filechanges = compare_lists(alines,blines)
549 if filechanges:
550 chg = ChangeRecord(path, filename, None, None, True)
551 chg.filechanges = filechanges
552 changes.append(chg)
553 else:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600554 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 -0500555 changes.append(chg)
556 elif filename == 'image-info.txt':
557 changes.extend(compare_dict_blobs(path, d.a_blob, d.b_blob, report_all, report_ver))
558 elif '/image-files/' in path:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600559 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 -0500560 changes.append(chg)
561
562 # Look for added preinst/postinst/prerm/postrm
563 # (without reporting newly added recipes)
564 addedpkgs = []
565 addedchanges = []
566 for d in diff.iter_change_type('A'):
567 path = os.path.dirname(d.b_blob.path)
568 if path.startswith('packages/'):
569 filename = os.path.basename(d.b_blob.path)
570 if filename == 'latest':
571 addedpkgs.append(path)
572 elif filename.startswith('latest.'):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600573 chg = ChangeRecord(path, filename[7:], '', d.b_blob.data_stream.read().decode('utf-8'), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500574 addedchanges.append(chg)
575 for chg in addedchanges:
576 found = False
577 for pkg in addedpkgs:
578 if chg.path.startswith(pkg):
579 found = True
580 break
581 if not found:
582 changes.append(chg)
583
584 # Look for cleared preinst/postinst/prerm/postrm
585 for d in diff.iter_change_type('D'):
586 path = os.path.dirname(d.a_blob.path)
587 if path.startswith('packages/'):
588 filename = os.path.basename(d.a_blob.path)
589 if filename != 'latest' and filename.startswith('latest.'):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600590 chg = ChangeRecord(path, filename[7:], d.a_blob.data_stream.read().decode('utf-8'), '', True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500591 changes.append(chg)
592
593 # Link related changes
594 for chg in changes:
595 if chg.monitored:
596 for chg2 in changes:
597 # (Check dirname in the case of fields from recipe info files)
598 if chg.path == chg2.path or os.path.dirname(chg.path) == chg2.path:
599 if chg2.fieldname in related_fields.get(chg.fieldname, []):
600 chg.related.append(chg2)
601 elif chg.path == chg2.path and chg.path.startswith('packages/') and chg2.fieldname in ['PE', 'PV', 'PR']:
602 chg.related.append(chg2)
603
604 if report_all:
605 return changes
606 else:
607 return [chg for chg in changes if chg.monitored]