forked from ilbers/isar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepro-build-test.py
executable file
·68 lines (54 loc) · 2.5 KB
/
repro-build-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import glob
import os
import re
import tempfile
import time
from cibuilder import CIBuilder, isar_root
from avocado.utils import process
class ReproBuild(CIBuilder):
"""
Test reproducible builds by comparing the artifacts
:avocado: tags=repro-build
"""
def test_repro_build(self):
target = self.params.get('build_target', default='mc:qemuamd64-bullseye:isar-image-base')
source_date_epoch = self.params.get('source_date_epoch', default=self.git_last_commit_timestamp())
self.init()
self.build_repro_image(target, source_date_epoch, 'image1.tar.gz')
self.build_repro_image(target, source_date_epoch, 'image2.tar.gz')
self.compare_repro_image('image1.tar.gz', 'image2.tar.gz')
def git_last_commit_timestamp(self):
return process.run('git log -1 --pretty=%ct').stdout
def get_image_path(self, target_name):
image_dir = "tmp/deploy/images"
target_params = target_name.split(':')
machine = target_params[1].split('-')[0]
distro = 'debian-' + target_params[1].split('-')[1]
image_type = target_params[2]
return f'{image_dir}/{machine}/{image_type}-{distro}-{machine}.tar.gz'
def build_repro_image(self, target, source_date_epoch=None ,image_name='image.tar.gz'):
if not source_date_epoch:
self.error("Reproducible build should configure with source_date_epoch time")
# clean artifacts before build
self.clean()
# Build
self.log.info("Started Build " + image_name)
self.configure(source_date_epoch=source_date_epoch)
self.bitbake(target)
# copy the artifacts image name with given name
image_path = self.get_image_path(target)
self.log.info("Copy image " + image_path + " as " + image_name)
self.move_in_build_dir(image_path, image_name)
def clean(self):
self.delete_from_build_dir('tmp')
self.delete_from_build_dir('sstate-cache')
def compare_repro_image(self, image1, image2):
self.log.info("Compare artifacts image1: " + image1 + ", image2: " + image2)
result = process.run('diffoscope '
'--text ' + self.build_dir + '/diffoscope-output.txt'
' ' + self.build_dir + '/' + image1 +
' ' + self.build_dir + '/' + image2 ,
ignore_status = True)
if result.exit_status > 0:
self.fail(f'Images {image1} and {image2} are not reproducible')