def prepare(self): """ Prepare directory structure for System C. """ self.mount_tmpfs() if not self.chroot: # Create + mount a disk for QEMU to use disk_path = os.path.join(self.tmp_dir, 'disk.img') self.dev_name = create_disk(disk_path, "msdos", "ext4", '8G') self.rootfs_dir = os.path.join(self.tmp_dir, 'mnt') os.mkdir(self.rootfs_dir) mount(self.dev_name + "p1", self.rootfs_dir, 'ext4') # Use chown to allow executing user to access it run('sudo', 'chown', getpass.getuser(), self.dev_name) run('sudo', 'chown', getpass.getuser(), self.rootfs_dir) else: self.rootfs_dir = self.tmp_dir self.get_packages() copytree(self.sys_dir, self.rootfs_dir, ignore=shutil.ignore_patterns("tmp")) # Unmount tmp/mnt if it exists if not self.chroot: umount(self.rootfs_dir)
def get_file(self, url, mkbuild=False, output=None): """ Download and prepare source packages url can be either: 1. a single URL 2. list of URLs to download. In this case the first URL is the primary URL from which we derive the name of package directory output can be used to override file name of the downloaded file(s). mkbuild=True can be used to pre-create build directories before mkdir is available. """ # Single URL if isinstance(url, str): assert output is None or isinstance(output, str) file_name = url if output is None else output urls = [url] outputs = [output] # Multiple URLs elif isinstance(url, list): assert output is None or len(output) == len(url) file_name = url[0] if output is None else output[0] urls = url outputs = output if output is not None else [None] * len(url) else: raise TypeError("url must be either a string or a list of strings") # Determine installation directory target_name = get_target(file_name) target_src_dir = os.path.join(self.after_dir, target_name, 'src') # Install base files src_tree = os.path.join(self.sysa_dir, target_name) copytree(src_tree, self.after_dir) if not os.path.isdir(target_src_dir): os.mkdir(target_src_dir) for i, _ in enumerate(urls): # Download files into cache directory tarball = self.download_file(urls[i], outputs[i]) # Install sources into target directory shutil.copy2(tarball, target_src_dir) if mkbuild: os.mkdir(os.path.join(self.after_dir, target_name, 'build'))
def stage0_posix(self): """Copy in all the stage0-posix (formerly known as mescc-tools-seed)""" mescc_tools_seed_base_dir = os.path.join(self.sysa_dir, 'mescc-tools-seed', 'src', 'mescc-tools-seed') mescc_tools_seed_dir = os.path.join(mescc_tools_seed_base_dir, self.arch) copy_tree(mescc_tools_seed_dir, self.tmp_dir) m2_planet_dir = os.path.join(mescc_tools_seed_base_dir, 'M2-Planet') copytree(m2_planet_dir, self.tmp_dir) # At the moment not useful for bootstrap but easier to keep it mes_m2_dir = os.path.join(mescc_tools_seed_base_dir, 'mes-m2') copytree(mes_m2_dir, self.tmp_dir) mescc_tools_patched_dir = os.path.join(self.sysa_dir, 'mescc-tools-seed', 'src', 'mescc-tools-patched') shutil.copytree(mescc_tools_patched_dir, os.path.join(self.tmp_dir, 'mescc-tools'), shutil.ignore_patterns('*.git*')) # bootstrap seeds bootstrap_seeds_dir = os.path.join(self.sysa_dir, 'bootstrap-seeds') copytree(bootstrap_seeds_dir, self.tmp_dir) kaem_optional_seed = os.path.join(bootstrap_seeds_dir, 'POSIX', self.arch, 'kaem-optional-seed') shutil.copy2(kaem_optional_seed, os.path.join(self.tmp_dir, 'init')) # replace the init kaem with our own custom one shutil.move(os.path.join(self.tmp_dir, 'kaem.run'), os.path.join(self.tmp_dir, 'mescc-tools-seed.kaem.run')) shutil.copy2(os.path.join(self.sysa_dir, 'base.kaem.run'), os.path.join(self.tmp_dir, 'kaem.run')) # create directories needed os.mkdir(os.path.join(self.tmp_dir, 'bin'))
def tcc_0_9_26(self): """TinyCC 0.9.26 (patched by janneke)""" copytree(os.path.join(self.sysa_dir, 'tcc-0.9.26'), self.after_dir)
def mes(self): """GNU Mes""" copytree(os.path.join(self.sysa_dir, 'mes'), self.after_dir) mes_dir = os.path.join(self.after_dir, 'mes', 'src', 'mes') os.mkdir(os.path.join(mes_dir, 'bin')) os.mkdir(os.path.join(mes_dir, 'm2'))
def mescc_tools_extra(self): """Some additional tools such as cp and chmod (for M2-Planet)""" copytree(os.path.join(self.sysa_dir, 'mescc-tools-extra'), self.after_dir)