Jürg Billeter pushed to branch element-path_not_validated at BuildStream / buildstream
Commits:
-
6f4351ec
by Benjamin Schubert at 2018-11-09T16:53:42Z
-
e6e03451
by richardmaw-codethink at 2018-11-12T11:05:15Z
-
ae5ccd76
by Phillip Smyth at 2018-11-12T14:57:51Z
-
56a54161
by Phillip Smyth at 2018-11-12T14:57:51Z
4 changed files:
- buildstream/_project.py
- buildstream/source.py
- + tests/frontend/invalid_element_path/project.conf
- tests/frontend/show.py
Changes:
| ... | ... | @@ -219,6 +219,19 @@ class Project(): |
| 219 | 219 |
|
| 220 | 220 |
return self._cache_key
|
| 221 | 221 |
|
| 222 |
+ def _validate_node(self, node):
|
|
| 223 |
+ _yaml.node_validate(node, [
|
|
| 224 |
+ 'format-version',
|
|
| 225 |
+ 'element-path', 'variables',
|
|
| 226 |
+ 'environment', 'environment-nocache',
|
|
| 227 |
+ 'split-rules', 'elements', 'plugins',
|
|
| 228 |
+ 'aliases', 'name',
|
|
| 229 |
+ 'artifacts', 'options',
|
|
| 230 |
+ 'fail-on-overlap', 'shell', 'fatal-warnings',
|
|
| 231 |
+ 'ref-storage', 'sandbox', 'mirrors', 'remote-execution',
|
|
| 232 |
+ 'sources', '(@)'
|
|
| 233 |
+ ])
|
|
| 234 |
+ |
|
| 222 | 235 |
# create_element()
|
| 223 | 236 |
#
|
| 224 | 237 |
# Instantiate and return an element
|
| ... | ... | @@ -402,6 +415,8 @@ class Project(): |
| 402 | 415 |
"Project requested format version {}, but BuildStream {}.{} only supports up until format version {}"
|
| 403 | 416 |
.format(format_version, major, minor, BST_FORMAT_VERSION))
|
| 404 | 417 |
|
| 418 |
+ self._validate_node(pre_config_node)
|
|
| 419 |
+ |
|
| 405 | 420 |
# FIXME:
|
| 406 | 421 |
#
|
| 407 | 422 |
# Performing this check manually in the absense
|
| ... | ... | @@ -467,16 +482,7 @@ class Project(): |
| 467 | 482 |
|
| 468 | 483 |
self._load_pass(config, self.config)
|
| 469 | 484 |
|
| 470 |
- _yaml.node_validate(config, [
|
|
| 471 |
- 'format-version',
|
|
| 472 |
- 'element-path', 'variables',
|
|
| 473 |
- 'environment', 'environment-nocache',
|
|
| 474 |
- 'split-rules', 'elements', 'plugins',
|
|
| 475 |
- 'aliases', 'name',
|
|
| 476 |
- 'artifacts', 'options',
|
|
| 477 |
- 'fail-on-overlap', 'shell', 'fatal-warnings',
|
|
| 478 |
- 'ref-storage', 'sandbox', 'mirrors', 'remote-execution'
|
|
| 479 |
- ])
|
|
| 485 |
+ self._validate_node(config)
|
|
| 480 | 486 |
|
| 481 | 487 |
#
|
| 482 | 488 |
# Now all YAML composition is done, from here on we just load
|
| ... | ... | @@ -973,32 +973,34 @@ class Source(Plugin): |
| 973 | 973 |
# the items of source_fetchers, if it happens to be a generator.
|
| 974 | 974 |
#
|
| 975 | 975 |
source_fetchers = iter(source_fetchers)
|
| 976 |
- try:
|
|
| 977 | 976 |
|
| 978 |
- while True:
|
|
| 977 |
+ while True:
|
|
| 979 | 978 |
|
| 980 |
- with context.silence():
|
|
| 979 |
+ with context.silence():
|
|
| 980 |
+ try:
|
|
| 981 | 981 |
fetcher = next(source_fetchers)
|
| 982 |
- |
|
| 983 |
- alias = fetcher._get_alias()
|
|
| 984 |
- for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
|
|
| 985 |
- try:
|
|
| 986 |
- fetcher.fetch(uri)
|
|
| 987 |
- # FIXME: Need to consider temporary vs. permanent failures,
|
|
| 988 |
- # and how this works with retries.
|
|
| 989 |
- except BstError as e:
|
|
| 990 |
- last_error = e
|
|
| 991 |
- continue
|
|
| 992 |
- |
|
| 993 |
- # No error, we're done with this fetcher
|
|
| 982 |
+ except StopIteration:
|
|
| 983 |
+ # as per PEP479, we are not allowed to let StopIteration
|
|
| 984 |
+ # thrown from a context manager.
|
|
| 985 |
+ # Catching it here and breaking instead.
|
|
| 994 | 986 |
break
|
| 995 | 987 |
|
| 996 |
- else:
|
|
| 997 |
- # No break occurred, raise the last detected error
|
|
| 998 |
- raise last_error
|
|
| 988 |
+ alias = fetcher._get_alias()
|
|
| 989 |
+ for uri in project.get_alias_uris(alias, first_pass=self.__first_pass):
|
|
| 990 |
+ try:
|
|
| 991 |
+ fetcher.fetch(uri)
|
|
| 992 |
+ # FIXME: Need to consider temporary vs. permanent failures,
|
|
| 993 |
+ # and how this works with retries.
|
|
| 994 |
+ except BstError as e:
|
|
| 995 |
+ last_error = e
|
|
| 996 |
+ continue
|
|
| 999 | 997 |
|
| 1000 |
- except StopIteration:
|
|
| 1001 |
- pass
|
|
| 998 |
+ # No error, we're done with this fetcher
|
|
| 999 |
+ break
|
|
| 1000 |
+ |
|
| 1001 |
+ else:
|
|
| 1002 |
+ # No break occurred, raise the last detected error
|
|
| 1003 |
+ raise last_error
|
|
| 1002 | 1004 |
|
| 1003 | 1005 |
# Default codepath is to reinstantiate the Source
|
| 1004 | 1006 |
#
|
| 1 |
+# Project config for frontend build test
|
|
| 2 |
+name: test
|
|
| 3 |
+ |
|
| 4 |
+elephant-path: elements
|
| ... | ... | @@ -36,6 +36,19 @@ def test_show(cli, datafiles, target, format, expected): |
| 36 | 36 |
.format(expected, result.output))
|
| 37 | 37 |
|
| 38 | 38 |
|
| 39 |
+@pytest.mark.datafiles(os.path.join(
|
|
| 40 |
+ os.path.dirname(os.path.realpath(__file__)),
|
|
| 41 |
+ "invalid_element_path",
|
|
| 42 |
+))
|
|
| 43 |
+def test_show_invalid_element_path(cli, datafiles):
|
|
| 44 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 45 |
+ result = cli.run(project=project, silent=True, args=[
|
|
| 46 |
+ 'show',
|
|
| 47 |
+ "foo.bst"])
|
|
| 48 |
+ |
|
| 49 |
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
|
| 50 |
+ |
|
| 51 |
+ |
|
| 39 | 52 |
@pytest.mark.datafiles(DATA_DIR)
|
| 40 | 53 |
@pytest.mark.parametrize("target,except_,expected", [
|
| 41 | 54 |
('target.bst', 'import-bin.bst', ['import-dev.bst', 'compose-all.bst', 'target.bst']),
|
