From 6d357226a9eab2ae74df4bb5fc584a33bba84b62 Mon Sep 17 00:00:00 2001 From: Dor Askayo Date: Mon, 23 May 2022 14:18:52 +0300 Subject: [PATCH] Call prepare() externally to the sysa and sysc classes This keeps the prepartion and bootstrap initiation logic in the same place for each bootstrap mode, and allows each mode to specify its own requirements and expectations from the different bootstrap steps. --- rootfs.py | 20 ++++++++++++++++++-- sysa.py | 4 +--- sysc.py | 4 +--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/rootfs.py b/rootfs.py index efcc546..fa69565 100755 --- a/rootfs.py +++ b/rootfs.py @@ -109,10 +109,10 @@ def main(): pass system_c = SysC(arch=args.arch, preserve_tmp=args.preserve, - tmpdir=args.tmpdir, chroot=args.chroot) + tmpdir=args.tmpdir) system_b = SysB(arch=args.arch, preserve_tmp=args.preserve) system_a = SysA(arch=args.arch, preserve_tmp=args.preserve, - tmpdir=args.tmpdir, chroot=args.chroot, + tmpdir=args.tmpdir, sysb_dir=system_b.sys_dir, sysc_tmp=system_c.tmp_dir) bootstrap(args, system_a, system_b, system_c) @@ -128,6 +128,10 @@ print(shutil.which('chroot')) chroot_binary = run('sudo', 'python3', '-c', find_chroot, capture_output=True).stdout.decode().strip() + system_c.prepare(create_disk_image=False) + system_a.prepare(copy_sysc=True, + create_initramfs=False) + # sysa arch = stage0_arch_map.get(args.arch, args.arch) init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed') @@ -137,6 +141,10 @@ print(shutil.which('chroot')) if os.path.isdir('kritis-linux'): shutil.rmtree('kritis-linux') + system_c.prepare(create_disk_image=True) + system_a.prepare(copy_sysc=False, + create_initramfs=True) + run('git', 'clone', '--depth', '1', '--branch', 'v0.7', 'https://github.com/bittorf/kritis-linux.git') @@ -154,11 +162,19 @@ print(shutil.which('chroot')) '--log', '/tmp/bootstrap.log') elif args.bare_metal: + system_c.prepare(create_disk_image=True) + system_a.prepare(copy_sysc=False, + create_initramfs=True) + print("Please:") print(" 1. Take sysa/tmp/initramfs and your kernel, boot using this.") print(" 2. Take sysc/tmp/disk.img and put this on a writable storage medium.") else: + system_c.prepare(create_disk_image=True) + system_a.prepare(copy_sysc=False, + create_initramfs=True) + run(args.qemu_cmd, '-enable-kvm', '-m', str(args.qemu_ram) + 'M', diff --git a/sysa.py b/sysa.py index 58163bc..673b510 100755 --- a/sysa.py +++ b/sysa.py @@ -17,7 +17,7 @@ class SysA(SysGeneral): Class responsible for preparing sources for System A. """ # pylint: disable=too-many-instance-attributes,too-many-arguments - def __init__(self, arch, preserve_tmp, tmpdir, chroot, sysb_dir, sysc_tmp): + def __init__(self, arch, preserve_tmp, tmpdir, sysb_dir, sysc_tmp): self.git_dir = os.path.dirname(os.path.join(__file__)) self.arch = arch self.preserve_tmp = preserve_tmp @@ -34,8 +34,6 @@ class SysA(SysGeneral): self.sysb_dir = sysb_dir self.sysc_tmp = sysc_tmp - self.prepare(chroot, not chroot) - def prepare(self, copy_sysc, create_initramfs): """ Prepare directory structure for System A. diff --git a/sysc.py b/sysc.py index 2404f32..c4eb427 100755 --- a/sysc.py +++ b/sysc.py @@ -20,7 +20,7 @@ class SysC(SysGeneral): dev_name = None # pylint: disable=too-many-instance-attributes - def __init__(self, arch, preserve_tmp, tmpdir, chroot): + def __init__(self, arch, preserve_tmp, tmpdir): self.git_dir = os.path.dirname(os.path.join(__file__)) self.arch = arch self.preserve_tmp = preserve_tmp @@ -33,8 +33,6 @@ class SysC(SysGeneral): self.tmp_dir = os.path.join(tmpdir, 'sysc') os.mkdir(self.tmp_dir) - self.prepare(not chroot) - def __del__(self): if not self.preserve_tmp: if self.dev_name is not None: