summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-12-30 19:56:09 +0000
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-12-31 19:54:25 +0000
commit8a020a5ae0063957ffccc7594fd754485953c3a3 (patch)
tree6cb0589e7a0fe0bad779102297b58bff3abd2d90
parent560a634256839de4c9e8bcc41215a17c525d0e61 (diff)
downloadbuildstream-8a020a5ae0063957ffccc7594fd754485953c3a3.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)