Tom Pollard pushed to branch tpollard/829 at BuildStream / buildstream
Commits:
-
f29a0995
by Tristan Van Berkom at 2019-01-09T19:51:14Z
-
d364ad02
by Tristan Van Berkom at 2019-01-09T19:52:22Z
-
1e352434
by Tristan Van Berkom at 2019-01-09T20:36:06Z
-
116c1070
by Tristan Van Berkom at 2019-01-09T20:39:15Z
-
c8f3616d
by Tristan Van Berkom at 2019-01-09T21:12:29Z
-
71189577
by Tom Pollard at 2019-01-10T10:50:38Z
8 changed files:
- .coveragerc
- .gitignore
- .gitlab-ci.yml
- CONTRIBUTING.rst
- buildstream/_frontend/cli.py
- buildstream/_stream.py
- tests/integration/build-tree.py
- tox.ini
Changes:
... | ... | @@ -4,11 +4,15 @@ include = |
4 | 4 |
*/buildstream/*
|
5 | 5 |
|
6 | 6 |
omit =
|
7 |
- # Omit profiling helper module
|
|
7 |
+ # Omit some internals
|
|
8 | 8 |
*/buildstream/_profile.py
|
9 |
+ */buildstream/__main__.py
|
|
10 |
+ */buildstream/_version.py
|
|
9 | 11 |
# Omit generated code
|
10 | 12 |
*/buildstream/_protos/*
|
11 | 13 |
*/.eggs/*
|
14 |
+ # Omit .tox directory
|
|
15 |
+ */.tox/*
|
|
12 | 16 |
|
13 | 17 |
[report]
|
14 | 18 |
show_missing = True
|
... | ... | @@ -13,11 +13,12 @@ tests/**/*.pyc |
13 | 13 |
integration-cache/
|
14 | 14 |
tmp
|
15 | 15 |
.coverage
|
16 |
+.coverage-reports/
|
|
16 | 17 |
.coverage.*
|
17 | 18 |
.cache
|
18 | 19 |
.pytest_cache/
|
19 | 20 |
*.bst/
|
20 |
-.tox
|
|
21 |
+.tox/
|
|
21 | 22 |
|
22 | 23 |
# Pycache, in case buildstream is ran directly from within the source
|
23 | 24 |
# tree
|
... | ... | @@ -13,6 +13,7 @@ variables: |
13 | 13 |
PYTEST_ADDOPTS: "--color=yes"
|
14 | 14 |
INTEGRATION_CACHE: "${CI_PROJECT_DIR}/cache/integration-cache"
|
15 | 15 |
TEST_COMMAND: "tox -- --color=yes --integration"
|
16 |
+ COVERAGE_PREFIX: "${CI_JOB_NAME}."
|
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
#####################################################
|
... | ... | @@ -24,9 +25,6 @@ variables: |
24 | 25 |
.tests-template: &tests
|
25 | 26 |
stage: test
|
26 | 27 |
|
27 |
- variables:
|
|
28 |
- COVERAGE_DIR: coverage-linux
|
|
29 |
- |
|
30 | 28 |
before_script:
|
31 | 29 |
# Diagnostics
|
32 | 30 |
- mount
|
... | ... | @@ -40,14 +38,11 @@ variables: |
40 | 38 |
- su buildstream -c "${TEST_COMMAND}"
|
41 | 39 |
|
42 | 40 |
after_script:
|
43 |
- # Collect our reports
|
|
44 |
- - mkdir -p ${COVERAGE_DIR}
|
|
45 |
- - cp .coverage ${COVERAGE_DIR}/coverage."${CI_JOB_NAME}"
|
|
46 | 41 |
except:
|
47 | 42 |
- schedules
|
48 | 43 |
artifacts:
|
49 | 44 |
paths:
|
50 |
- - ${COVERAGE_DIR}
|
|
45 |
+ - .coverage-reports
|
|
51 | 46 |
|
52 | 47 |
tests-debian-9:
|
53 | 48 |
image: buildstream/testsuite-debian:9-5da27168-32c47d1c
|
... | ... | @@ -83,7 +78,6 @@ tests-unix: |
83 | 78 |
<<: *tests
|
84 | 79 |
variables:
|
85 | 80 |
BST_FORCE_BACKEND: "unix"
|
86 |
- COVERAGE_DIR: coverage-unix
|
|
87 | 81 |
|
88 | 82 |
script:
|
89 | 83 |
|
... | ... | @@ -239,22 +233,22 @@ coverage: |
239 | 233 |
stage: post
|
240 | 234 |
coverage: '/TOTAL +\d+ +\d+ +(\d+\.\d+)%/'
|
241 | 235 |
script:
|
242 |
- - pip3 install -r requirements/requirements.txt -r requirements/dev-requirements.txt
|
|
243 |
- - pip3 install --no-index .
|
|
244 |
- - mkdir report
|
|
245 |
- - cd report
|
|
246 |
- - cp ../coverage-unix/coverage.* .
|
|
247 |
- - cp ../coverage-linux/coverage.* .
|
|
248 |
- - ls coverage.*
|
|
249 |
- - coverage combine --rcfile=../.coveragerc -a coverage.*
|
|
250 |
- - coverage report --rcfile=../.coveragerc -m
|
|
236 |
+ - cp -a .coverage-reports/ ./coverage-sources
|
|
237 |
+ - tox -e coverage
|
|
238 |
+ - cp -a .coverage-reports/ ./coverage-report
|
|
251 | 239 |
dependencies:
|
252 | 240 |
- tests-debian-9
|
253 | 241 |
- tests-fedora-27
|
254 | 242 |
- tests-fedora-28
|
243 |
+ - tests-fedora-missing-deps
|
|
244 |
+ - tests-ubuntu-18.04
|
|
255 | 245 |
- tests-unix
|
256 | 246 |
except:
|
257 | 247 |
- schedules
|
248 |
+ artifacts:
|
|
249 |
+ paths:
|
|
250 |
+ - coverage-sources/
|
|
251 |
+ - coverage-report/
|
|
258 | 252 |
|
259 | 253 |
# Deploy, only for merges which land on master branch.
|
260 | 254 |
#
|
... | ... | @@ -1498,6 +1498,13 @@ option when running tox:: |
1498 | 1498 |
|
1499 | 1499 |
tox -e py37
|
1500 | 1500 |
|
1501 |
+If you would like to test and lint at the same time, or if you do have multiple
|
|
1502 |
+python versions installed and would like to test against multiple versions, then
|
|
1503 |
+we recommend using `detox <https://github.com/tox-dev/detox>`_, just run it with
|
|
1504 |
+the same arguments you would give `tox`::
|
|
1505 |
+ |
|
1506 |
+ detox -e lint,py36,py37
|
|
1507 |
+ |
|
1501 | 1508 |
Linting is performed separately from testing. In order to run the linting step which
|
1502 | 1509 |
consists of running the ``pycodestyle`` and ``pylint`` tools, run the following::
|
1503 | 1510 |
|
... | ... | @@ -1574,6 +1581,19 @@ can run ``tox`` with ``-r`` or ``--recreate`` option. |
1574 | 1581 |
./setup.py test --addopts 'tests/frontend/buildtrack.py::test_build_track'
|
1575 | 1582 |
|
1576 | 1583 |
|
1584 |
+Observing coverage
|
|
1585 |
+~~~~~~~~~~~~~~~~~~
|
|
1586 |
+Once you have run the tests using `tox` (or `detox`), some coverage reports will
|
|
1587 |
+have been left behind.
|
|
1588 |
+ |
|
1589 |
+To view the coverage report of the last test run, simply run::
|
|
1590 |
+ |
|
1591 |
+ tox -e coverage
|
|
1592 |
+ |
|
1593 |
+This will collate any reports from separate python environments that may be
|
|
1594 |
+under test before displaying the combined coverage.
|
|
1595 |
+ |
|
1596 |
+ |
|
1577 | 1597 |
Adding tests
|
1578 | 1598 |
~~~~~~~~~~~~
|
1579 | 1599 |
Tests are found in the tests subdirectory, inside of which
|
... | ... | @@ -560,7 +560,7 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command) |
560 | 560 |
else:
|
561 | 561 |
scope = Scope.RUN
|
562 | 562 |
|
563 |
- use_buildtree = False
|
|
563 |
+ use_buildtree = None
|
|
564 | 564 |
|
565 | 565 |
with app.initialized():
|
566 | 566 |
if not element:
|
... | ... | @@ -568,7 +568,8 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command) |
568 | 568 |
if not element:
|
569 | 569 |
raise AppError('Missing argument "ELEMENT".')
|
570 | 570 |
|
571 |
- dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE)
|
|
571 |
+ dependencies = app.stream.load_selection((element,), selection=PipelineSelection.NONE,
|
|
572 |
+ use_artifact_config=True)
|
|
572 | 573 |
element = dependencies[0]
|
573 | 574 |
prompt = app.shell_prompt(element)
|
574 | 575 |
mounts = [
|
... | ... | @@ -577,18 +578,19 @@ def shell(app, element, sysroot, mount, isolate, build_, cli_buildtree, command) |
577 | 578 |
]
|
578 | 579 |
|
579 | 580 |
cached = element._cached_buildtree()
|
580 |
- if cli_buildtree == "always":
|
|
581 |
- if cached:
|
|
582 |
- use_buildtree = True
|
|
583 |
- else:
|
|
584 |
- raise AppError("No buildtree is cached but the use buildtree option was specified")
|
|
585 |
- elif cli_buildtree == "never":
|
|
586 |
- pass
|
|
587 |
- elif cli_buildtree == "try":
|
|
588 |
- use_buildtree = cached
|
|
581 |
+ if cli_buildtree in ("always", "try"):
|
|
582 |
+ use_buildtree = cli_buildtree
|
|
583 |
+ if not cached and use_buildtree == "always":
|
|
584 |
+ click.echo("Warning: buildtree is not cached locally, will attempt to pull from available remotes")
|
|
589 | 585 |
else:
|
590 |
- if app.interactive and cached:
|
|
591 |
- use_buildtree = bool(click.confirm('Do you want to use the cached buildtree?'))
|
|
586 |
+ # If the value has defaulted to ask and in non interactive mode, don't consider the buildtree, this
|
|
587 |
+ # being the default behaviour of the command
|
|
588 |
+ if app.interactive and cli_buildtree == "ask":
|
|
589 |
+ if cached and bool(click.confirm('Do you want to use the cached buildtree?')):
|
|
590 |
+ use_buildtree = "always"
|
|
591 |
+ elif not cached and bool(click.confirm('Do you want to attempt to pull the cached buildtree?')):
|
|
592 |
+ use_buildtree = "try"
|
|
593 |
+ |
|
592 | 594 |
if use_buildtree and not element._cached_success():
|
593 | 595 |
click.echo("Warning: using a buildtree from a failed build.")
|
594 | 596 |
|
... | ... | @@ -100,16 +100,19 @@ class Stream(): |
100 | 100 |
# targets (list of str): Targets to pull
|
101 | 101 |
# selection (PipelineSelection): The selection mode for the specified targets
|
102 | 102 |
# except_targets (list of str): Specified targets to except from fetching
|
103 |
+ # use_artifact_config (bool): If artifact remote config should be loaded
|
|
103 | 104 |
#
|
104 | 105 |
# Returns:
|
105 | 106 |
# (list of Element): The selected elements
|
106 | 107 |
def load_selection(self, targets, *,
|
107 | 108 |
selection=PipelineSelection.NONE,
|
108 |
- except_targets=()):
|
|
109 |
+ except_targets=(),
|
|
110 |
+ use_artifact_config=False):
|
|
109 | 111 |
elements, _ = self._load(targets, (),
|
110 | 112 |
selection=selection,
|
111 | 113 |
except_targets=except_targets,
|
112 |
- fetch_subprojects=False)
|
|
114 |
+ fetch_subprojects=False,
|
|
115 |
+ use_artifact_config=use_artifact_config)
|
|
113 | 116 |
return elements
|
114 | 117 |
|
115 | 118 |
# shell()
|
... | ... | @@ -124,7 +127,7 @@ class Stream(): |
124 | 127 |
# mounts (list of HostMount): Additional directories to mount into the sandbox
|
125 | 128 |
# isolate (bool): Whether to isolate the environment like we do in builds
|
126 | 129 |
# command (list): An argv to launch in the sandbox, or None
|
127 |
- # usebuildtree (bool): Wheather to use a buildtree as the source.
|
|
130 |
+ # usebuildtree (str): Whether to use a buildtree as the source, given cli option
|
|
128 | 131 |
#
|
129 | 132 |
# Returns:
|
130 | 133 |
# (int): The exit code of the launched shell
|
... | ... | @@ -134,7 +137,7 @@ class Stream(): |
134 | 137 |
mounts=None,
|
135 | 138 |
isolate=False,
|
136 | 139 |
command=None,
|
137 |
- usebuildtree=False):
|
|
140 |
+ usebuildtree=None):
|
|
138 | 141 |
|
139 | 142 |
# Assert we have everything we need built, unless the directory is specified
|
140 | 143 |
# in which case we just blindly trust the directory, using the element
|
... | ... | @@ -149,8 +152,30 @@ class Stream(): |
149 | 152 |
raise StreamError("Elements need to be built or downloaded before staging a shell environment",
|
150 | 153 |
detail="\n".join(missing_deps))
|
151 | 154 |
|
155 |
+ # Check if we require a pull queue attempt, with given artifact state and context
|
|
156 |
+ if usebuildtree:
|
|
157 |
+ if not element._cached_buildtree():
|
|
158 |
+ buildtree = False
|
|
159 |
+ require_buildtree = self._buildtree_pull_required([element])
|
|
160 |
+ # Attempt a pull queue for the given element if remote and context allow it
|
|
161 |
+ if require_buildtree:
|
|
162 |
+ self._message(MessageType.INFO, "Attempting to fetch missing artifact buildtree")
|
|
163 |
+ self._add_queue(PullQueue(self._scheduler))
|
|
164 |
+ self._enqueue_plan(require_buildtree)
|
|
165 |
+ self._run()
|
|
166 |
+ # Now check if the buildtree was successfully fetched
|
|
167 |
+ if element._cached_buildtree():
|
|
168 |
+ buildtree = True
|
|
169 |
+ if not buildtree:
|
|
170 |
+ if usebuildtree == "always":
|
|
171 |
+ raise StreamError("Buildtree is not cached locally or in available remotes")
|
|
172 |
+ else:
|
|
173 |
+ self._message(MessageType.INFO, """Buildtree is not cached locally or in available remotes,
|
|
174 |
+ shell will be loaded without it""")
|
|
175 |
+ usebuildtree = False
|
|
176 |
+ |
|
152 | 177 |
return element._shell(scope, directory, mounts=mounts, isolate=isolate, prompt=prompt, command=command,
|
153 |
- usebuildtree=usebuildtree)
|
|
178 |
+ usebuildtree=bool(usebuildtree))
|
|
154 | 179 |
|
155 | 180 |
# build()
|
156 | 181 |
#
|
... | ... | @@ -140,7 +140,7 @@ def test_buildtree_pulled(cli, tmpdir, datafiles): |
140 | 140 |
res.assert_success()
|
141 | 141 |
|
142 | 142 |
|
143 |
-# This test checks for correct behaviour if a buildtree is not present.
|
|
143 |
+# This test checks for correct behaviour if a buildtree is not present in the local cache.
|
|
144 | 144 |
@pytest.mark.datafiles(DATA_DIR)
|
145 | 145 |
@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
|
146 | 146 |
def test_buildtree_options(cli, tmpdir, datafiles):
|
... | ... | @@ -155,6 +155,7 @@ def test_buildtree_options(cli, tmpdir, datafiles): |
155 | 155 |
result = cli.run(project=project, args=['build', element_name])
|
156 | 156 |
result.assert_success()
|
157 | 157 |
assert cli.get_element_state(project, element_name) == 'cached'
|
158 |
+ assert share.has_artifact('test', element_name, cli.get_element_key(project, element_name))
|
|
158 | 159 |
|
159 | 160 |
# Discard the cache
|
160 | 161 |
cli.configure({
|
... | ... | @@ -167,8 +168,6 @@ def test_buildtree_options(cli, tmpdir, datafiles): |
167 | 168 |
result = cli.run(project=project, args=['pull', '--deps', 'all', element_name])
|
168 | 169 |
result.assert_success()
|
169 | 170 |
|
170 |
- # The above is the simplest way I know to create a local cache without any buildtrees.
|
|
171 |
- |
|
172 | 171 |
# Check it's not using the cached build tree
|
173 | 172 |
res = cli.run(project=project, args=[
|
174 | 173 |
'shell', '--build', element_name, '--use-buildtree', 'never', '--', 'cat', 'test'
|
... | ... | @@ -176,24 +175,51 @@ def test_buildtree_options(cli, tmpdir, datafiles): |
176 | 175 |
res.assert_shell_error()
|
177 | 176 |
assert 'Hi' not in res.output
|
178 | 177 |
|
179 |
- # Check it's not correctly handling the lack of buildtree
|
|
178 |
+ # Check it's not using the cached build tree, default is to ask, and fall back to not
|
|
179 |
+ # for non interactive behavior
|
|
180 | 180 |
res = cli.run(project=project, args=[
|
181 |
- 'shell', '--build', element_name, '--use-buildtree', 'try', '--', 'cat', 'test'
|
|
181 |
+ 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
182 | 182 |
])
|
183 | 183 |
res.assert_shell_error()
|
184 | 184 |
assert 'Hi' not in res.output
|
185 | 185 |
|
186 |
- # Check it's not using the cached build tree, default is to ask, and fall back to not
|
|
187 |
- # for non interactive behavior
|
|
186 |
+ # Check correctly handling the lack of buildtree, with 'try' not attempting to
|
|
187 |
+ # pull the buildtree as the user context is by default set to not pull them
|
|
188 | 188 |
res = cli.run(project=project, args=[
|
189 |
- 'shell', '--build', element_name, '--', 'cat', 'test'
|
|
189 |
+ 'shell', '--build', element_name, '--use-buildtree', 'try', '--', 'cat', 'test'
|
|
190 | 190 |
])
|
191 |
- res.assert_shell_error()
|
|
192 | 191 |
assert 'Hi' not in res.output
|
192 |
+ assert 'Attempting to fetch missing artifact buildtrees' not in res.stderr
|
|
193 |
+ assert """Buildtree is not cached locally or in available remotes,
|
|
194 |
+ shell will be loaded without it"""
|
|
193 | 195 |
|
194 |
- # Check it's using the cached build tree
|
|
196 |
+ # Check correctly handling the lack of buildtree, with 'try' attempting and succeeding
|
|
197 |
+ # to pull the buildtree as the user context allow the pulling of buildtrees and it is
|
|
198 |
+ # available in the remote
|
|
199 |
+ res = cli.run(project=project, args=[
|
|
200 |
+ '--pull-buildtrees', 'shell', '--build', element_name, '--use-buildtree', 'try', '--', 'cat', 'test'
|
|
201 |
+ ])
|
|
202 |
+ assert 'Attempting to fetch missing artifact buildtree' in res.stderr
|
|
203 |
+ assert 'Hi' in res.output
|
|
204 |
+ shutil.rmtree(os.path.join(os.path.join(cli.directory, 'artifacts2')))
|
|
205 |
+ assert cli.get_element_state(project, element_name) != 'cached'
|
|
206 |
+ |
|
207 |
+ # Check it's not loading the shell at all with always set for the buildtree, when the
|
|
208 |
+ # user context does not allow for buildtree pulling
|
|
209 |
+ result = cli.run(project=project, args=['pull', '--deps', 'all', element_name])
|
|
210 |
+ result.assert_success()
|
|
195 | 211 |
res = cli.run(project=project, args=[
|
196 | 212 |
'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
197 | 213 |
])
|
198 | 214 |
res.assert_main_error(ErrorDomain.PROG_NOT_FOUND, None)
|
215 |
+ assert 'Buildtree is not cached locally or in available remotes' in res.stderr
|
|
199 | 216 |
assert 'Hi' not in res.output
|
217 |
+ assert 'Attempting to fetch missing artifact buildtree' not in res.stderr
|
|
218 |
+ |
|
219 |
+ # Check that when user context is set to pull buildtrees and a remote has the buildtree,
|
|
220 |
+ # 'always' will attempt and succeed at pulling the missing buildtree.
|
|
221 |
+ res = cli.run(project=project, args=[
|
|
222 |
+ '--pull-buildtrees', 'shell', '--build', element_name, '--use-buildtree', 'always', '--', 'cat', 'test'
|
|
223 |
+ ])
|
|
224 |
+ assert 'Hi' in res.output
|
|
225 |
+ assert 'Attempting to fetch missing artifact buildtree' in res.stderr
|
1 |
+#
|
|
2 |
+# Tox global configuration
|
|
3 |
+#
|
|
1 | 4 |
[tox]
|
2 | 5 |
envlist = py35,py36,py37
|
3 | 6 |
skip_missing_interpreters = true
|
4 | 7 |
|
8 |
+#
|
|
9 |
+# Defaults for all environments
|
|
10 |
+#
|
|
11 |
+# Anything specified here is iherited by the sections
|
|
12 |
+#
|
|
5 | 13 |
[testenv]
|
6 |
-commands = pytest {posargs}
|
|
14 |
+commands =
|
|
15 |
+ pytest --basetemp {envtmpdir} {posargs}
|
|
16 |
+ mkdir -p .coverage-reports
|
|
17 |
+ mv {envtmpdir}/.coverage {toxinidir}/.coverage-reports/.coverage.{env:COVERAGE_PREFIX:}{envname}
|
|
7 | 18 |
deps =
|
8 | 19 |
-rrequirements/requirements.txt
|
9 | 20 |
-rrequirements/dev-requirements.txt
|
... | ... | @@ -13,6 +24,32 @@ passenv = |
13 | 24 |
GI_TYPELIB_PATH
|
14 | 25 |
INTEGRATION_CACHE
|
15 | 26 |
|
27 |
+#
|
|
28 |
+# These keys are not inherited by any other sections
|
|
29 |
+#
|
|
30 |
+setenv =
|
|
31 |
+ py{35,36,37}: COVERAGE_FILE = {envtmpdir}/.coverage
|
|
32 |
+whitelist_externals =
|
|
33 |
+ py{35,36,37}:
|
|
34 |
+ mv
|
|
35 |
+ mkdir
|
|
36 |
+ |
|
37 |
+#
|
|
38 |
+# Coverage reporting
|
|
39 |
+#
|
|
40 |
+[testenv:coverage]
|
|
41 |
+commands =
|
|
42 |
+ - coverage combine --rcfile={toxinidir}/.coveragerc {toxinidir}/.coverage-reports/
|
|
43 |
+ coverage report --rcfile={toxinidir}/.coveragerc -m
|
|
44 |
+deps =
|
|
45 |
+ -rrequirements/requirements.txt
|
|
46 |
+ -rrequirements/dev-requirements.txt
|
|
47 |
+setenv =
|
|
48 |
+ COVERAGE_FILE = {toxinidir}/.coverage-reports/.coverage
|
|
49 |
+ |
|
50 |
+#
|
|
51 |
+# Running linters
|
|
52 |
+#
|
|
16 | 53 |
[testenv:lint]
|
17 | 54 |
commands =
|
18 | 55 |
pycodestyle
|
... | ... | @@ -22,6 +59,9 @@ deps = |
22 | 59 |
-rrequirements/dev-requirements.txt
|
23 | 60 |
-rrequirements/plugin-requirements.txt
|
24 | 61 |
|
62 |
+#
|
|
63 |
+# Building documentation
|
|
64 |
+#
|
|
25 | 65 |
[testenv:docs]
|
26 | 66 |
commands =
|
27 | 67 |
make -C doc
|