summaryrefslogtreecommitdiff
path: root/morphlib/morphloader.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/morphloader.py')
-rw-r--r--morphlib/morphloader.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py
index 66f4763a..0160e419 100644
--- a/morphlib/morphloader.py
+++ b/morphlib/morphloader.py
@@ -15,6 +15,7 @@
# =*= License: GPL-2 =*=
+import os
import collections
import warnings
import yaml
@@ -79,6 +80,13 @@ class InvalidTypeError(MorphologyValidationError):
(field, expected, actual, morphology_name))
+class InvalidPathError(MorphologyValidationError):
+
+ def __init__(self, path, spec, morph_filename):
+ self.msg = ("Invalid path '%s' in %s from morphology %s"
+ % (path, spec, morph_filename))
+
+
class UnknownArchitectureError(MorphologyValidationError):
def __init__(self, arch, morph_filename):
@@ -246,6 +254,7 @@ class MorphologyDumper(yaml.SafeDumper):
'build-mode',
'artifacts',
'max-jobs',
+ 'extra-sources',
'products',
'chunks',
'build-system',
@@ -357,6 +366,7 @@ class MorphologyLoader(object):
'strip-commands': None,
'post-strip-commands': None,
'devices': [],
+ 'extra-sources': [],
'products': [],
'max-jobs': None,
'build-system': 'manual',
@@ -561,6 +571,27 @@ class MorphologyLoader(object):
raise ChunkSpecNoBuildInstructionsError(
chunk_name, morph.filename)
+ def validate_extra_sources(extra_sources, morph_filename):
+ for extra_source in extra_sources:
+ validate_chunk_str_field('repo', extra_source,
+ morph.filename)
+ path = extra_source.get('path')
+ if not path:
+ raise MissingFieldError("'path' in %s" % extra_source,
+ morph.filename)
+ path = os.path.normpath(path)
+ if os.path.isabs(path) or path.startswith('..') or (
+ path == '.') or not path.strip():
+ raise InvalidPathError(extra_source['path'],
+ extra_source,
+ morph_filename)
+ if 'extra-sources' in extra_source:
+ validate_extra_sources(extra_source['extra-sources'],
+ morph.filename)
+
+ if 'extra-sources' in spec:
+ validate_extra_sources(spec['extra-sources'], morph.filename)
+
@classmethod
def _validate_chunk(cls, morphology):
errors = []
@@ -704,6 +735,9 @@ class MorphologyLoader(object):
if 'prefix' not in spec:
spec['prefix'] = \
self._static_defaults['chunk']['prefix']
+ if 'extra-sources' not in spec:
+ spec['extra-sources'] = \
+ self._static_defaults['chunk']['extra-sources']
def _set_chunk_defaults(self, morph):
if morph['max-jobs'] is not None: