summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-12-30 19:56:09 +0000
committerChandan Singh <csingh43@bloomberg.net>2018-12-30 20:52:22 +0000
commitd8e8e8325ecd091dfe6c9c0a46b76ca1f01968b4 (patch)
tree1d89b367a5056166be1a05acf37de1786dba7edd
parent32a101f67a5a1e751117a1b8976fe72bdd85526f (diff)
downloadbuildstream-d8e8e8325ecd091dfe6c9c0a46b76ca1f01968b4.tar.gz
_loader/loader.py: Refactor warnings about element names in one method
Currently we some duplication in the way we check for invalid filenames. To make it more robust and allow room for adding more warnings, refactor it into a separate method `_warn_invalid_elements()` that handles just this.
-rw-r--r--buildstream/_loader/loader.py51
1 files changed, 33 insertions, 18 deletions
diff --git a/buildstream/_loader/loader.py b/buildstream/_loader/loader.py
index 0de0e2b9c..8dda0468e 100644
--- a/buildstream/_loader/loader.py
+++ b/buildstream/_loader/loader.py
@@ -99,7 +99,6 @@ class Loader():
# Returns: The toplevel LoadElement
def load(self, targets, rewritable=False, ticker=None, fetch_subprojects=False):
- invalid_elements = []
for filename in targets:
if os.path.isabs(filename):
# XXX Should this just be an assertion ?
@@ -109,14 +108,8 @@ class Loader():
"path to the base project directory: {}"
.format(filename, self._basedir))
- if not filename.endswith(".bst"):
- invalid_elements.append(filename)
+ self._warn_invalid_elements(targets)
- if invalid_elements:
- self._warn("Target elements '{}' do not have expected file extension `.bst` "
- "Improperly named elements will not be discoverable by commands"
- .format(invalid_elements),
- warning_token=CoreWarnings.BAD_ELEMENT_SUFFIX)
# First pass, recursively load files and populate our table of LoadElements
#
deps = []
@@ -280,12 +273,7 @@ class Loader():
self._elements[filename] = element
# Load all dependency files for the new LoadElement
- invalid_elements = []
for dep in element.deps:
- if not dep.name.endswith(".bst"):
- invalid_elements.append(dep.name)
- continue
-
if dep.junction:
self._load_file(dep.junction, rewritable, ticker, fetch_subprojects, yaml_cache)
loader = self._get_loader(dep.junction, rewritable=rewritable, ticker=ticker,
@@ -300,11 +288,9 @@ class Loader():
"{}: Cannot depend on junction"
.format(dep.provenance))
- if invalid_elements:
- self._warn("The following dependencies do not have expected file extension `.bst`: {} "
- "Improperly named elements will not be discoverable by commands"
- .format(invalid_elements),
- warning_token=CoreWarnings.BAD_ELEMENT_SUFFIX)
+ deps_names = [dep.name for dep in element.deps]
+ self._warn_invalid_elements(deps_names)
+
return element
# _check_circular_deps():
@@ -679,3 +665,32 @@ class Loader():
message = Message(None, MessageType.WARN, brief)
self._context.message(message)
+
+ # Print warning messages if any of the specified elements have invalid names.
+ #
+ # Valid filenames should end with ".bst" extension.
+ #
+ # Args:
+ # elements (list): List of element names
+ #
+ # Raises:
+ # (:class:`.LoadError`): When warning_token is considered fatal by the project configuration
+ #
+ def _warn_invalid_elements(self, elements):
+
+ # invalid_elements
+ #
+ # A dict that maps warning types to the matching elements.
+ invalid_elements = {
+ CoreWarnings.BAD_ELEMENT_SUFFIX: [],
+ }
+
+ for filename in elements:
+ if not filename.endswith(".bst"):
+ invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX].append(filename)
+
+ if invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX]:
+ self._warn("Target elements '{}' do not have expected file extension `.bst` "
+ "Improperly named elements will not be discoverable by commands"
+ .format(invalid_elements[CoreWarnings.BAD_ELEMENT_SUFFIX]),
+ warning_token=CoreWarnings.BAD_ELEMENT_SUFFIX)