Phillip Smyth pushed to branch issue-638-validate-all-files at BuildStream / buildstream
Commits:
12 changed files:
- buildstream/_frontend/cli.py
- buildstream/_project.py
- buildstream/data/projectconfig.yaml
- + tests/frontend/project_default/elements/target.bst
- + tests/frontend/project_default/elements/target2.bst
- + tests/frontend/project_default/project.conf
- + tests/frontend/project_fail/elements/compose-all.bst
- + tests/frontend/project_fail/elements/import-dev.bst
- + tests/frontend/project_fail/elements/target.bst
- + tests/frontend/project_fail/files/dev-files/usr/include/pony.h
- + tests/frontend/project_fail/project.conf
- tests/frontend/show.py
Changes:
... | ... | @@ -170,6 +170,37 @@ original_main = click.BaseCommand.main |
170 | 170 |
click.BaseCommand.main = override_main
|
171 | 171 |
|
172 | 172 |
|
173 |
+def get_default_elements(app):
|
|
174 |
+ """
|
|
175 |
+ This function is used to gather either:
|
|
176 |
+ The project default element (if defined in project.conf)
|
|
177 |
+ or
|
|
178 |
+ All elements in the project
|
|
179 |
+ """
|
|
180 |
+ directory = app._main_options.get("directory")
|
|
181 |
+ project_conf = app.project._project_conf
|
|
182 |
+ output = []
|
|
183 |
+ |
|
184 |
+ # The project is not required to have an element-path
|
|
185 |
+ element_directory = project_conf.get('element-path')
|
|
186 |
+ |
|
187 |
+ # The project may have a default element defined
|
|
188 |
+ default_element = project_conf.get("defaults", {}).get("target-element", None)
|
|
189 |
+ |
|
190 |
+ if default_element:
|
|
191 |
+ return (default_element,)
|
|
192 |
+ |
|
193 |
+ directory = os.path.abspath(directory)
|
|
194 |
+ for root, _, files in os.walk(directory):
|
|
195 |
+ for file in files:
|
|
196 |
+ if file.endswith(".bst"):
|
|
197 |
+ rel_dir = os.path.relpath(root, directory)
|
|
198 |
+ rel_file = os.path.join(rel_dir, file).lstrip("./")
|
|
199 |
+ rel_file = rel_file.lstrip(element_directory).lstrip('/')
|
|
200 |
+ output.append(rel_file)
|
|
201 |
+ return tuple(output)
|
|
202 |
+ |
|
203 |
+ |
|
173 | 204 |
##################################################################
|
174 | 205 |
# Main Options #
|
175 | 206 |
##################################################################
|
... | ... | @@ -509,6 +540,11 @@ def push(app, elements, deps, remote): |
509 | 540 |
def show(app, elements, deps, except_, order, format_):
|
510 | 541 |
"""Show elements in the pipeline
|
511 | 542 |
|
543 |
+ Declaring no elements with result in showing a default element if one is declared in the project configuration.
|
|
544 |
+ |
|
545 |
+ If no default is declared, all elements in the project will be shown
|
|
546 |
+ |
|
547 |
+ |
|
512 | 548 |
By default this will show all of the dependencies of the
|
513 | 549 |
specified target element.
|
514 | 550 |
|
... | ... | @@ -553,7 +589,11 @@ def show(app, elements, deps, except_, order, format_): |
553 | 589 |
bst show target.bst --format \\
|
554 | 590 |
$'---------- %{name} ----------\\n%{vars}'
|
555 | 591 |
"""
|
592 |
+ |
|
556 | 593 |
with app.initialized():
|
594 |
+ if not elements:
|
|
595 |
+ elements = get_elements(app)
|
|
596 |
+ |
|
557 | 597 |
dependencies = app.stream.load_selection(elements,
|
558 | 598 |
selection=deps,
|
559 | 599 |
except_targets=except_)
|
... | ... | @@ -226,7 +226,7 @@ class Project(): |
226 | 226 |
'element-path', 'variables',
|
227 | 227 |
'environment', 'environment-nocache',
|
228 | 228 |
'split-rules', 'elements', 'plugins',
|
229 |
- 'aliases', 'name',
|
|
229 |
+ 'aliases', 'name', 'defaults',
|
|
230 | 230 |
'artifacts', 'options',
|
231 | 231 |
'fail-on-overlap', 'shell', 'fatal-warnings',
|
232 | 232 |
'ref-storage', 'sandbox', 'mirrors', 'remote-execution',
|
... | ... | @@ -196,4 +196,11 @@ shell: |
196 | 196 |
|
197 | 197 |
# Command to run when `bst shell` does not provide a command
|
198 | 198 |
#
|
199 |
- command: [ 'sh', '-i' ]
|
|
\ No newline at end of file | ||
199 |
+ command: [ 'sh', '-i' ]
|
|
200 |
+ |
|
201 |
+# Default Targets
|
|
202 |
+#
|
|
203 |
+defaults:
|
|
204 |
+ |
|
205 |
+ # Set a Default element to build when none are defined
|
|
206 |
+ target-element: None
|
1 |
+kind: stack
|
|
2 |
+description: |
|
|
3 |
+ |
|
4 |
+ Main stack target for the bst build test
|
1 |
+kind: stack
|
|
2 |
+description: |
|
|
3 |
+ |
|
4 |
+ Main stack target for the bst build test
|
1 |
+# Project config for frontend build test
|
|
2 |
+name: test
|
|
3 |
+ |
|
4 |
+element-path: elements
|
|
5 |
+ |
|
6 |
+fatal-warnings:
|
|
7 |
+- bad-element-suffix
|
|
8 |
+ |
|
9 |
+defaults:
|
|
10 |
+ target-element: target2.bst
|
1 |
+kind: compose
|
|
2 |
+ |
|
3 |
+depends:
|
|
4 |
+- fileNAME: import-dev.bst
|
|
5 |
+ type: build
|
|
6 |
+ |
|
7 |
+config:
|
|
8 |
+ # Dont try running the sandbox, we dont have a
|
|
9 |
+ # runtime to run anything in this context.
|
|
10 |
+ integrate: False
|
1 |
+kind: import
|
|
2 |
+sources:
|
|
3 |
+- kind: local
|
|
4 |
+ path: files/dev-files
|
1 |
+kind: stack
|
|
2 |
+description: |
|
|
3 |
+ |
|
4 |
+ Main stack target for the bst build test
|
|
5 |
+ |
|
6 |
+depends:
|
|
7 |
+- compose-all.bst
|
1 |
+#ifndef __PONY_H__
|
|
2 |
+#define __PONY_H__
|
|
3 |
+ |
|
4 |
+#define PONY_BEGIN "Once upon a time, there was a pony."
|
|
5 |
+#define PONY_END "And they lived happily ever after, the end."
|
|
6 |
+ |
|
7 |
+#define MAKE_PONY(story) \
|
|
8 |
+ PONY_BEGIN \
|
|
9 |
+ story \
|
|
10 |
+ PONY_END
|
|
11 |
+ |
|
12 |
+#endif /* __PONY_H__ */
|
1 |
+# Project config for frontend build test
|
|
2 |
+name: test
|
|
3 |
+ |
|
4 |
+element-path: elements
|
... | ... | @@ -46,6 +46,33 @@ def test_show_invalid_element_path(cli, datafiles): |
46 | 46 |
'show',
|
47 | 47 |
"foo.bst"])
|
48 | 48 |
|
49 |
+ |
|
50 |
+@pytest.mark.datafiles(DATA_DIR + "_default")
|
|
51 |
+def test_show_default(cli, datafiles):
|
|
52 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
53 |
+ prev_dir = os.getcwd()
|
|
54 |
+ os.chdir(project)
|
|
55 |
+ result = cli.run(project=project, silent=True, args=[
|
|
56 |
+ 'show'])
|
|
57 |
+ os.chdir(prev_dir)
|
|
58 |
+ |
|
59 |
+ result.assert_success()
|
|
60 |
+ results = result.output.strip().splitlines()
|
|
61 |
+ expected = 'buildable ca4321107f0f529170d345af19372c57a6672f62afdcbdd36ca067b67124ef60 target2.bst'
|
|
62 |
+ if result.output.strip() != expected:
|
|
63 |
+ raise AssertionError("Expected output:\n{}\nInstead received output:\n{}"
|
|
64 |
+ .format(expected, result.output))
|
|
65 |
+ |
|
66 |
+ |
|
67 |
+@pytest.mark.datafiles(DATA_DIR + "_fail")
|
|
68 |
+def test_show_fail(cli, datafiles):
|
|
69 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
70 |
+ prev_dir = os.getcwd()
|
|
71 |
+ os.chdir(project)
|
|
72 |
+ result = cli.run(project=project, silent=True, args=[
|
|
73 |
+ 'show'])
|
|
74 |
+ os.chdir(prev_dir)
|
|
75 |
+ |
|
49 | 76 |
result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
50 | 77 |
|
51 | 78 |
|