Phillip Smyth pushed to branch issue_640-Build-All at BuildStream / buildstream
Commits:
22 changed files:
- buildstream/_frontend/cli.py
- buildstream/_project.py
- buildstream/data/projectconfig.yaml
- tests/frontend/buildcheckout.py
- + tests/frontend/project_default/elements/target.bst
- + tests/frontend/project_default/elements/target2.bst
- + tests/frontend/project_default/project.conf
- + tests/frontend/project_world/elements/compose-all.bst
- + tests/frontend/project_world/elements/compose-exclude-dev.bst
- + tests/frontend/project_world/elements/compose-include-bin.bst
- + tests/frontend/project_world/elements/import-bin.bst
- + tests/frontend/project_world/elements/import-dev.bst
- + tests/frontend/project_world/elements/rebuild-target.bst
- + tests/frontend/project_world/elements/source-bundle/source-bundle-hello.bst
- + tests/frontend/project_world/elements/target.bst
- + tests/frontend/project_world/files/bar
- + tests/frontend/project_world/files/bin-files/usr/bin/hello
- + tests/frontend/project_world/files/build-files/buildstream/build/test
- + tests/frontend/project_world/files/dev-files/usr/include/pony.h
- + tests/frontend/project_world/files/foo
- + tests/frontend/project_world/files/source-bundle/llamas.txt
- + tests/frontend/project_world/project.conf
Changes:
| ... | ... | @@ -170,6 +170,30 @@ original_main = click.BaseCommand.main |
| 170 | 170 |
click.BaseCommand.main = override_main
|
| 171 | 171 |
|
| 172 | 172 |
|
| 173 |
+def get_elements(app):
|
|
| 174 |
+ project = app.project
|
|
| 175 |
+ project_conf = project._project_conf
|
|
| 176 |
+ output = []
|
|
| 177 |
+ |
|
| 178 |
+ # The project is not required to have an element-path
|
|
| 179 |
+ element_directory = project_conf.get('element-path')
|
|
| 180 |
+ |
|
| 181 |
+ # The project may have a default element defined
|
|
| 182 |
+ default_element = project_conf.get("defaults", {}).get("target-element", None)
|
|
| 183 |
+ |
|
| 184 |
+ if default_element:
|
|
| 185 |
+ return (default_element,)
|
|
| 186 |
+ |
|
| 187 |
+ directory = os.path.abspath(element_directory)
|
|
| 188 |
+ for root, _, files in os.walk(directory):
|
|
| 189 |
+ for file in files:
|
|
| 190 |
+ if file.endswith(".bst"):
|
|
| 191 |
+ rel_dir = os.path.relpath(root, directory)
|
|
| 192 |
+ rel_file = os.path.join(rel_dir, file).lstrip("./")
|
|
| 193 |
+ output.append(rel_file)
|
|
| 194 |
+ return tuple(output)
|
|
| 195 |
+ |
|
| 196 |
+ |
|
| 173 | 197 |
##################################################################
|
| 174 | 198 |
# Main Options #
|
| 175 | 199 |
##################################################################
|
| ... | ... | @@ -313,9 +337,14 @@ def init(app, project_name, format_version, element_path, force): |
| 313 | 337 |
help="Deprecated: This is ignored")
|
| 314 | 338 |
@click.argument('elements', nargs=-1,
|
| 315 | 339 |
type=click.Path(readable=False))
|
| 340 |
+ |
|
| 316 | 341 |
@click.pass_obj
|
| 317 | 342 |
def build(app, elements, all_, track_, track_save, track_all, track_except, track_cross_junctions):
|
| 318 |
- """Build elements in a pipeline"""
|
|
| 343 |
+ """Build elements in a pipeline
|
|
| 344 |
+ |
|
| 345 |
+ Declaring no elements with result in building a default element if one is declared in the project configuration.
|
|
| 346 |
+ |
|
| 347 |
+ If no default is declared, all elements in the project will be built"""
|
|
| 319 | 348 |
|
| 320 | 349 |
if (track_except or track_cross_junctions) and not (track_ or track_all):
|
| 321 | 350 |
click.echo("ERROR: The --track-except and --track-cross-junctions options "
|
| ... | ... | @@ -329,6 +358,8 @@ def build(app, elements, all_, track_, track_save, track_all, track_except, trac |
| 329 | 358 |
track_ = elements
|
| 330 | 359 |
|
| 331 | 360 |
with app.initialized(session_name="Build"):
|
| 361 |
+ if not elements:
|
|
| 362 |
+ elements = get_elements(app)
|
|
| 332 | 363 |
app.stream.build(elements,
|
| 333 | 364 |
track_targets=track_,
|
| 334 | 365 |
track_except=track_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
|
| ... | ... | @@ -60,6 +60,64 @@ def test_build_checkout(datafiles, cli, strict, hardlinks): |
| 60 | 60 |
assert os.path.exists(filename)
|
| 61 | 61 |
|
| 62 | 62 |
|
| 63 |
+@pytest.mark.datafiles(os.path.join(os.path.dirname(
|
|
| 64 |
+ os.path.realpath(__file__)),
|
|
| 65 |
+ "project_world",
|
|
| 66 |
+))
|
|
| 67 |
+@pytest.mark.parametrize("strict,hardlinks", [
|
|
| 68 |
+ ("strict", "copies"),
|
|
| 69 |
+ ("strict", "hardlinks"),
|
|
| 70 |
+ ("non-strict", "copies"),
|
|
| 71 |
+ ("non-strict", "hardlinks"),
|
|
| 72 |
+])
|
|
| 73 |
+def test_build_default_all_checkout(datafiles, cli, strict, hardlinks):
|
|
| 74 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 75 |
+ checkout = os.path.join(cli.directory, 'checkout')
|
|
| 76 |
+ |
|
| 77 |
+ # First build it
|
|
| 78 |
+ result = cli.run(project=project, args=strict_args(['build'], strict))
|
|
| 79 |
+ result.assert_success()
|
|
| 80 |
+ |
|
| 81 |
+ # Assert that after a successful build, the builddir is empty
|
|
| 82 |
+ builddir = os.path.join(cli.directory, 'build')
|
|
| 83 |
+ assert os.path.isdir(builddir)
|
|
| 84 |
+ assert not os.listdir(builddir)
|
|
| 85 |
+ |
|
| 86 |
+ # Prepare checkout args
|
|
| 87 |
+ checkout_args = strict_args(['checkout'], strict)
|
|
| 88 |
+ if hardlinks == "hardlinks":
|
|
| 89 |
+ checkout_args += ['--hardlinks']
|
|
| 90 |
+ checkout_args += ['target.bst', checkout]
|
|
| 91 |
+ |
|
| 92 |
+ # Now check it out
|
|
| 93 |
+ result = cli.run(project=project, args=checkout_args)
|
|
| 94 |
+ result.assert_success()
|
|
| 95 |
+ |
|
| 96 |
+ # Check that the executable hello file is found in the checkout
|
|
| 97 |
+ filename = os.path.join(checkout, 'usr', 'bin', 'hello')
|
|
| 98 |
+ assert os.path.exists(filename)
|
|
| 99 |
+ |
|
| 100 |
+ filename = os.path.join(checkout, 'usr', 'include', 'pony.h')
|
|
| 101 |
+ assert os.path.exists(filename)
|
|
| 102 |
+ |
|
| 103 |
+ |
|
| 104 |
+@pytest.mark.datafiles(DATA_DIR + "_default")
|
|
| 105 |
+def test_show_default(cli, datafiles):
|
|
| 106 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
| 107 |
+ prev_dir = os.getcwd()
|
|
| 108 |
+ os.chdir(project)
|
|
| 109 |
+ result = cli.run(project=project, silent=True, args=[
|
|
| 110 |
+ 'build'])
|
|
| 111 |
+ os.chdir(prev_dir)
|
|
| 112 |
+ |
|
| 113 |
+ result.assert_success()
|
|
| 114 |
+ results = cli.get_element_state(project, "target2.bst")
|
|
| 115 |
+ expected = "cached"
|
|
| 116 |
+ if results != expected:
|
|
| 117 |
+ raise AssertionError("Expected output:\n{}\nInstead received output:\n{}"
|
|
| 118 |
+ .format(expected, result))
|
|
| 119 |
+ |
|
| 120 |
+ |
|
| 63 | 121 |
@pytest.mark.datafiles(DATA_DIR)
|
| 64 | 122 |
@pytest.mark.parametrize("strict,hardlinks", [
|
| 65 | 123 |
("non-strict", "hardlinks"),
|
| 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-bin.bst
|
|
| 5 |
+ type: build
|
|
| 6 |
+- filename: import-dev.bst
|
|
| 7 |
+ type: build
|
|
| 8 |
+ |
|
| 9 |
+config:
|
|
| 10 |
+ # Dont try running the sandbox, we dont have a
|
|
| 11 |
+ # runtime to run anything in this context.
|
|
| 12 |
+ integrate: False
|
| 1 |
+kind: compose
|
|
| 2 |
+ |
|
| 3 |
+depends:
|
|
| 4 |
+- filename: import-bin.bst
|
|
| 5 |
+ type: build
|
|
| 6 |
+- filename: import-dev.bst
|
|
| 7 |
+ type: build
|
|
| 8 |
+ |
|
| 9 |
+config:
|
|
| 10 |
+ # Dont try running the sandbox, we dont have a
|
|
| 11 |
+ # runtime to run anything in this context.
|
|
| 12 |
+ integrate: False
|
|
| 13 |
+ |
|
| 14 |
+ # Exclude the dev domain
|
|
| 15 |
+ exclude:
|
|
| 16 |
+ - devel
|
| 1 |
+kind: compose
|
|
| 2 |
+ |
|
| 3 |
+depends:
|
|
| 4 |
+- filename: import-bin.bst
|
|
| 5 |
+ type: build
|
|
| 6 |
+- filename: import-dev.bst
|
|
| 7 |
+ type: build
|
|
| 8 |
+ |
|
| 9 |
+config:
|
|
| 10 |
+ # Dont try running the sandbox, we dont have a
|
|
| 11 |
+ # runtime to run anything in this context.
|
|
| 12 |
+ integrate: False
|
|
| 13 |
+ |
|
| 14 |
+ # Only include the runtim
|
|
| 15 |
+ include:
|
|
| 16 |
+ - runtime
|
| 1 |
+kind: import
|
|
| 2 |
+sources:
|
|
| 3 |
+- kind: local
|
|
| 4 |
+ path: files/bin-files
|
| 1 |
+kind: import
|
|
| 2 |
+sources:
|
|
| 3 |
+- kind: local
|
|
| 4 |
+ path: files/dev-files
|
| 1 |
+kind: compose
|
|
| 2 |
+ |
|
| 3 |
+build-depends:
|
|
| 4 |
+- target.bst
|
| 1 |
+kind: import
|
|
| 2 |
+description: the kind of this element must implement generate_script() method
|
|
| 3 |
+ |
|
| 4 |
+sources:
|
|
| 5 |
+- kind: local
|
|
| 6 |
+ path: files/source-bundle
|
| 1 |
+kind: stack
|
|
| 2 |
+description: |
|
|
| 3 |
+ |
|
| 4 |
+ Main stack target for the bst build test
|
|
| 5 |
+ |
|
| 6 |
+depends:
|
|
| 7 |
+- import-bin.bst
|
|
| 8 |
+- compose-all.bst
|
| 1 |
+#!/bin/bash
|
|
| 2 |
+ |
|
| 3 |
+echo "Hello !"
|
| 1 |
+test
|
| 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 |
+llamas
|
| 1 |
+# Project config for frontend build test
|
|
| 2 |
+name: test
|
|
| 3 |
+ |
|
| 4 |
+element-path: elements
|
