summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.van.berkom@gmail.com>2016-12-12 10:47:06 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2016-12-12 10:47:06 +0000
commitc05e27d1d3656dd1394a2d2f16e851345872b6b2 (patch)
tree27c0c653182433f00ecb704cab6eaa743c53392c
parentdd4e8da492df076f637d06a03dec885db13bd4a8 (diff)
parent24523b1569896cd48d384d1b9d515c461dba767d (diff)
downloadbuildstream-c05e27d1d3656dd1394a2d2f16e851345872b6b2.tar.gz
Merge branch 'dep-types' into 'master'
Dependency types See merge request !5
-rw-r--r--buildstream/_loader.py26
-rw-r--r--buildstream/_metaelement.py1
-rw-r--r--tests/loader/dependencies.py60
-rw-r--r--tests/loader/dependencies/elements/builddep.bst5
-rw-r--r--tests/loader/dependencies/elements/invaliddeptype.bst5
-rw-r--r--tests/loader/dependencies/elements/runtimedep.bst5
6 files changed, 98 insertions, 4 deletions
diff --git a/buildstream/_loader.py b/buildstream/_loader.py
index fc333b1b0..861e59d2d 100644
--- a/buildstream/_loader.py
+++ b/buildstream/_loader.py
@@ -49,16 +49,20 @@ class Symbol():
SOURCES = "sources"
CONFIG = "config"
NAME = "name"
+ TYPE = "type"
+ BUILD = "build"
+ RUNTIME = "runtime"
# A simple dependency object
#
class Dependency():
- def __init__(self, owner_name, name, variant_name=None, filename=None):
+ def __init__(self, owner_name, name, variant_name=None, filename=None, type=None):
self.owner = owner_name
self.name = name
self.variant_name = variant_name
self.filename = filename
+ self.type = type
# Holds a variant dictionary and normalized Dependency list
@@ -387,13 +391,24 @@ def extract_depends_from_node(owner, data, stack=False):
if not variant:
variant = None
+ # Make type optional, for this we set it to None after
+ type = _yaml.node_get(dep, str, Symbol.TYPE, default_value="")
+ if not type:
+ type = None
+ elif type not in [Symbol.BUILD, Symbol.RUNTIME]:
+ provenance = _yaml.node_get_provenance(dep, key=Symbol.TYPE)
+
+ raise LoadError(LoadErrorReason.INVALID_DATA,
+ "%s [line %s column %s]: Dependency type is not 'build' or 'runtime'" %
+ (provenance.filename, provenance.line, provenance.col))
+
if stack:
name = _yaml.node_get(dep, str, Symbol.NAME)
- dependency = Dependency(owner, name, variant_name=variant)
+ dependency = Dependency(owner, name, variant_name=variant, type=type)
else:
filename = _yaml.node_get(dep, str, Symbol.FILENAME)
name = element_name_from_filename(filename)
- dependency = Dependency(owner, name, variant_name=variant, filename=filename)
+ dependency = Dependency(owner, name, variant_name=variant, filename=filename, type=type)
else:
index = depends.index(dep)
@@ -824,7 +839,10 @@ class Loader():
for dep in element.deps:
meta_dep = self.collect_element(dep.name)
- meta_element.dependencies.append(meta_dep)
+ if dep.type != 'runtime':
+ meta_element.build_dependencies.append(meta_dep)
+ if dep.type != 'build':
+ meta_element.dependencies.append(meta_dep)
# Cache it, just to make sure we dont build the same one twice !
self.meta_elements[element_name] = meta_element
diff --git a/buildstream/_metaelement.py b/buildstream/_metaelement.py
index 643fdcdf4..86eeb3aa0 100644
--- a/buildstream/_metaelement.py
+++ b/buildstream/_metaelement.py
@@ -37,4 +37,5 @@ class MetaElement():
self.sources = sources
self.config = config
+ self.build_dependencies = []
self.dependencies = []
diff --git a/tests/loader/dependencies.py b/tests/loader/dependencies.py
index e301e6057..8a88bcaf8 100644
--- a/tests/loader/dependencies.py
+++ b/tests/loader/dependencies.py
@@ -109,3 +109,63 @@ def test_circular_dependency(datafiles):
element = loader.load()
assert (exc.value.reason == LoadErrorReason.CIRCULAR_DEPENDENCY)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_invalid_dependency_type(datafiles):
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+ loader = Loader(basedir, 'elements/invaliddeptype.bst', None, None)
+
+ with pytest.raises(LoadError) as exc:
+ element = loader.load()
+
+ assert (exc.value.reason == LoadErrorReason.INVALID_DATA)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_dependency(datafiles):
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+ loader = Loader(basedir, 'elements/builddep.bst', None, None)
+ element = loader.load()
+
+ assert(isinstance(element, MetaElement))
+ assert(element.kind == 'pony')
+
+ assert(len(element.build_dependencies) == 1)
+ firstdep = element.build_dependencies[0]
+ assert(isinstance(firstdep, MetaElement))
+
+ assert(len(element.dependencies) == 0)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_runtime_dependency(datafiles):
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+ loader = Loader(basedir, 'elements/runtimedep.bst', None, None)
+ element = loader.load()
+
+ assert(isinstance(element, MetaElement))
+ assert(element.kind == 'pony')
+
+ assert(len(element.dependencies) == 1)
+ firstdep = element.dependencies[0]
+ assert(isinstance(firstdep, MetaElement))
+
+ assert(len(element.build_dependencies) == 0)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_build_runtime_dependency(datafiles):
+ basedir = os.path.join(datafiles.dirname, datafiles.basename)
+ loader = Loader(basedir, 'elements/target.bst', None, None)
+ element = loader.load()
+
+ assert(isinstance(element, MetaElement))
+ assert(element.kind == 'pony')
+
+ assert(len(element.dependencies) == 1)
+ assert(len(element.build_dependencies) == 1)
+ firstdep = element.dependencies[0]
+ assert(isinstance(firstdep, MetaElement))
+ firstbuilddep = element.build_dependencies[0]
+ assert(firstdep == firstbuilddep)
diff --git a/tests/loader/dependencies/elements/builddep.bst b/tests/loader/dependencies/elements/builddep.bst
new file mode 100644
index 000000000..6d17f8498
--- /dev/null
+++ b/tests/loader/dependencies/elements/builddep.bst
@@ -0,0 +1,5 @@
+kind: pony
+description: This element has a build-only dependency
+depends:
+ - filename: elements/firstdep.bst
+ type: build
diff --git a/tests/loader/dependencies/elements/invaliddeptype.bst b/tests/loader/dependencies/elements/invaliddeptype.bst
new file mode 100644
index 000000000..50ed798f0
--- /dev/null
+++ b/tests/loader/dependencies/elements/invaliddeptype.bst
@@ -0,0 +1,5 @@
+kind: pony
+description: This is an invalid dependency type
+depends:
+ - filename: elements/firstdep.bst
+ type: should be build or runtime
diff --git a/tests/loader/dependencies/elements/runtimedep.bst b/tests/loader/dependencies/elements/runtimedep.bst
new file mode 100644
index 000000000..a08b59ebf
--- /dev/null
+++ b/tests/loader/dependencies/elements/runtimedep.bst
@@ -0,0 +1,5 @@
+kind: pony
+description: This element has a runtime-only dependency
+depends:
+ - filename: elements/firstdep.bst
+ type: runtime