diff options
-rw-r--r-- | morphlib/builder2.py | 24 | ||||
-rw-r--r-- | morphlib/morph2.py | 1 | ||||
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 1 |
3 files changed, 26 insertions, 0 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 14d73630..82a95820 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -20,6 +20,7 @@ import json import logging import os import shutil +import stat import time from collections import defaultdict import tarfile @@ -265,6 +266,28 @@ class ChunkBuilder(BuilderBase): else: return morphology[which] + def create_devices(self, destdir): # pragma: no cover + '''Creates device nodes if the morphology specifies them''' + morphology = self.artifact.source.morphology + perms_mask = stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO + if 'devices' in morphology and morphology['devices'] is not None: + for dev in morphology['devices']: + destfile = os.path.join(destdir, './' + dev['filename']) + mode = int(dev['permissions'], 8) & perms_mask + if dev['type'] == 'c': + mode = mode | stat.S_IFCHR + elif dev['type'] == 'b': + mode = mode | stat.S_IFBLK + else: + raise IOError('Cannot create device node %s,' + 'unrecognized device type "%s"' + % (destfile, dev['type'])) + self.app.status(msg="Creating device node %s" + % destfile) + os.mknod(destfile, mode, + os.makedev(dev['major'], dev['minor'])) + os.chown(destfile, dev['uid'], dev['gid']) + def build_and_cache(self): # pragma: no cover with self.build_watch('overall-build'): @@ -279,6 +302,7 @@ class ChunkBuilder(BuilderBase): 'build-log') as log: log_name = log.real_filename self.run_commands(builddir, destdir, log) + self.create_devices(destdir) except: self.staging_area.chroot_close() if log_name: diff --git a/morphlib/morph2.py b/morphlib/morph2.py index a95312c6..ee58ecdc 100644 --- a/morphlib/morph2.py +++ b/morphlib/morph2.py @@ -36,6 +36,7 @@ class Morphology(object): ('build-commands', None), ('test-commands', None), ('install-commands', None), + ('devices', None), ('chunks', []), ('max-jobs', None), ('build-system', 'manual') diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index f9595f98..cbc41acf 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -348,6 +348,7 @@ class BranchAndMergePlugin(cliapp.Plugin): 'install-commands', 'max-jobs', 'chunks', + 'devices', ] } |