Skip to content

Commit

Permalink
implement tmpdir separate from basedir, so it doesn't mess with with the
Browse files Browse the repository at this point in the history
set output file

Signed-off-by: Zen <[email protected]>
  • Loading branch information
desultory committed Aug 21, 2024
1 parent f77601b commit 6c7c9e2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/ugrd/base/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = 'desultory'
__version__ = '3.7.1'
__version__ = '3.7.3'

from pathlib import Path
from typing import Union
Expand All @@ -12,7 +12,7 @@ def detect_tmpdir(self) -> None:
from os import environ
if tmpdir := environ.get('TMPDIR'):
self.logger.info("Detected TMPDIR: %s" % tmpdir)
self['basedir'] = Path(tmpdir)
self['tmpdir'] = Path(tmpdir)


@contains('clean', "Skipping cleaning build directory", log_level=30)
Expand Down
6 changes: 3 additions & 3 deletions src/ugrd/base/core.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
basedir = "/tmp"
tmpdir = "/tmp"
build_dir = "initramfs_build"
_build_log_level = 10
out_dir = "initramfs_out"
out_dir = "/tmp/initramfs_out"
clean = true
find_libgcc = true
hostonly = true
Expand Down Expand Up @@ -53,7 +53,7 @@ minor = 1
hostonly = "bool" # If true, the initramfs will be built specifically for the host building it
validate = "bool" # If true, the configuration of the initramfs will be validated against the host
_custom_init_file = "str" # Add the _custom_init_file propety, used to set where the custom init file is located
basedir = "Path" # The base directory to use as the base for output files
tmpdir = "Path" # The base directory for builds
build_dir = "Path" # The directory where the initramfs is built
build_logging = "bool" # If true, additional build information will be logged to the console
_build_log_level = "int" # The level of logging to use for the build log, set to 10 by default and incremeted by if build_log is true (min 20)
Expand Down
8 changes: 4 additions & 4 deletions src/ugrd/base/test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
__version__ = "0.5.2"
__version__ = "0.5.4"

from zenlib.util import unset


COPY_CONFIG = [
'mounts', 'out_dir', 'basedir', 'clean',
'mounts', 'out_dir', 'tmpdir', 'clean',
'test_image_size', 'test_flag'
]

Expand All @@ -28,8 +28,8 @@ def init_test_vars(self):

def get_qemu_cmd_args(self):
""" Gets the qemu command from the configuration """
test_initrd = self._get_out_path(self._archive_out_path)
test_rootfs = self['_test_rootfs']._get_out_path(self['_test_rootfs']['_archive_out_path'])
test_initrd = self._archive_out_path
test_rootfs = self['_test_rootfs']['_archive_out_path']
qemu_args = {'-m': self['test_memory'],
'-cpu': self['test_cpu'],
'-kernel': self['test_kernel'],
Expand Down
5 changes: 2 additions & 3 deletions src/ugrd/fs/cpio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = 'desultory'
__version__ = '3.4.0'
__version__ = '3.4.1'


from zenlib.util import contains
Expand Down Expand Up @@ -81,8 +81,7 @@ def make_cpio(self) -> None:
self.logger.debug("Adding CPIO node: %s" % node)
cpio.add_chardev(name=node['path'], mode=node['mode'], major=node['major'], minor=node['minor'])

out_cpio = self._get_out_path(self['_archive_out_path'])

out_cpio = self['_archive_out_path']
if not out_cpio.parent.exists():
self._mkdir(out_cpio.parent, resolve_build=False)

Expand Down
15 changes: 7 additions & 8 deletions src/ugrd/fs/test_image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.3"
__version__ = "0.5.4"

from zenlib.util import contains

Expand All @@ -13,22 +13,21 @@ def make_test_image(self):
""" Creates a test image from the build dir """
build_dir = self._get_build_path('/').resolve()
self.logger.info("Creating test image from: %s" % build_dir)
archive_out_path = self._get_out_path(self._archive_out_path)

rootfs_uuid = self['mounts']['root']['uuid']
rootfs_type = self['mounts']['root']['type']

if rootfs_type == 'ext4':
# Create the test image file, flll with 0s
with open(archive_out_path, "wb") as f:
with open(self._archive_out_path, "wb") as f:
self.logger.info("Creating test image file: %s" % f.name)
f.write(b"\0" * self.test_image_size * 2 ** 20)
self._run(['mkfs', '-t', rootfs_type, '-d', build_dir, '-U', rootfs_uuid, '-F', archive_out_path])
self._run(['mkfs', '-t', rootfs_type, '-d', build_dir, '-U', rootfs_uuid, '-F', self._archive_out_path])
elif rootfs_type == 'btrfs':
if self['clean'] and archive_out_path.exists():
self.logger.warning("Removing existing test image file: %s" % archive_out_path)
archive_out_path.unlink()
self._run(['mkfs', '-t', rootfs_type, '-f', '--rootdir', build_dir, '-U', rootfs_uuid, archive_out_path])
if self['clean'] and self._archive_out_path.exists():
self.logger.warning("Removing existing test image file: %s" % self._archive_out_path)
self._archive_out_path.unlink()
self._run(['mkfs', '-t', rootfs_type, '-f', '--rootdir', build_dir, '-U', rootfs_uuid, self._archive_out_path])
else:
raise Exception("Unsupported test rootfs type: %s" % rootfs_type)

10 changes: 3 additions & 7 deletions src/ugrd/generator_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from zenlib.util import pretty_print

__version__ = "1.3.2"
__version__ = "1.3.3"
__author__ = "desultory"


Expand All @@ -22,12 +22,8 @@ def get_subpath(path: Path, subpath: Union[Path, str]) -> Path:
class GeneratorHelpers:
""" Mixin class for the InitramfsGenerator class. """
def _get_build_path(self, path: Union[Path, str]) -> Path:
""" Returns the path relative to the build directory, under the basedir. """
return self._get_out_path(get_subpath(self.build_dir, path))

def _get_out_path(self, path: Union[Path, str]) -> Path:
""" Gets the path relative to the basedir. """
return get_subpath(self.basedir, path)
""" Returns the path relative to the build directory, under the tmpdir. """
return get_subpath(get_subpath(self.tmpdir, self.build_dir), path)

def _mkdir(self, path: Path, resolve_build=True) -> None:
""" Creates a directory within the build directory."""
Expand Down

0 comments on commit 6c7c9e2

Please sign in to comment.