|
1
|
+import os
|
|
2
|
+import pytest
|
|
3
|
+from tests.testutils import cli
|
|
4
|
+from tests.testutils.site import IS_LINUX
|
|
5
|
+
|
|
6
|
+from buildstream import _site, _yaml
|
|
7
|
+from buildstream._exceptions import ErrorDomain
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+pytestmark = pytest.mark.integration
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+# Project directory
|
|
14
|
+DATA_DIR = os.path.join(
|
|
15
|
+ os.path.dirname(os.path.realpath(__file__)),
|
|
16
|
+ 'project',
|
|
17
|
+)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+@pytest.fixture
|
|
21
|
+def clean_bwrap_cache():
|
|
22
|
+ _site._bwrap_major = None
|
|
23
|
+ _site._bwrap_minor = None
|
|
24
|
+ _site._bwrap_patch = None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on Linux')
|
|
28
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
29
|
+@pytest.mark.usefixtures("clean_bwrap_cache")
|
|
30
|
+def test_missing_brwap_has_nice_error_message(cli, datafiles):
|
|
31
|
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
32
|
+ element_path = os.path.join(project, 'elements', 'element.bst')
|
|
33
|
+
|
|
34
|
+ # Write out our test target
|
|
35
|
+ element = {
|
|
36
|
+ 'kind': 'script',
|
|
37
|
+ 'depends': [
|
|
38
|
+ {
|
|
39
|
+ 'filename': 'base.bst',
|
|
40
|
+ 'type': 'build',
|
|
41
|
+ },
|
|
42
|
+ ],
|
|
43
|
+ 'config': {
|
|
44
|
+ 'commands': [
|
|
45
|
+ 'false',
|
|
46
|
+ ],
|
|
47
|
+ },
|
|
48
|
+ }
|
|
49
|
+ _yaml.dump(element, element_path)
|
|
50
|
+
|
|
51
|
+ # Build without access to host tools, this should fail with a nice error
|
|
52
|
+ result = cli.run(
|
|
53
|
+ project=project, args=['build', 'element.bst'], env={'PATH': ''})
|
|
54
|
+ result.assert_task_error(ErrorDomain.SANDBOX, 'unavailable-local-sandbox')
|
|
55
|
+ assert "not found" in result.stderr
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+@pytest.mark.skipif(not IS_LINUX, reason='Only available on Linux')
|
|
59
|
+@pytest.mark.datafiles(DATA_DIR)
|
|
60
|
+@pytest.mark.usefixtures("clean_bwrap_cache")
|
|
61
|
+def test_old_brwap_has_nice_error_message(cli, datafiles, tmp_path):
|
|
62
|
+ import buildstream._platform
|
|
63
|
+ buildstream._platform.Platform._instance = None
|
|
64
|
+
|
|
65
|
+ bwrap = tmp_path.joinpath('bin/bwrap')
|
|
66
|
+ bwrap.parent.mkdir()
|
|
67
|
+ with bwrap.open('w') as fp:
|
|
68
|
+ fp.write('''
|
|
69
|
+ #!/bin/bash
|
|
70
|
+ echo bubblewrap 0.0.1
|
|
71
|
+ '''.strip())
|
|
72
|
+
|
|
73
|
+ bwrap.chmod(0o755)
|
|
74
|
+
|
|
75
|
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
76
|
+ element_path = os.path.join(project, 'elements', 'element3.bst')
|
|
77
|
+
|
|
78
|
+ # Write out our test target
|
|
79
|
+ element = {
|
|
80
|
+ 'kind': 'script',
|
|
81
|
+ 'depends': [
|
|
82
|
+ {
|
|
83
|
+ 'filename': 'base.bst',
|
|
84
|
+ 'type': 'build',
|
|
85
|
+ },
|
|
86
|
+ ],
|
|
87
|
+ 'config': {
|
|
88
|
+ 'commands': [
|
|
89
|
+ 'true && true && false',
|
|
90
|
+ ],
|
|
91
|
+ },
|
|
92
|
+ }
|
|
93
|
+ _yaml.dump(element, element_path)
|
|
94
|
+
|
|
95
|
+ # Build without access to host tools, this should fail with a nice error
|
|
96
|
+ result = cli.run(
|
|
97
|
+ project=project,
|
|
98
|
+ args=['--debug', '--verbose', 'build', 'element3.bst'],
|
|
99
|
+ env={'PATH': str(tmp_path.joinpath('bin'))})
|
|
100
|
+ result.assert_task_error(ErrorDomain.SANDBOX, 'unavailable-local-sandbox')
|
|
101
|
+ assert "too old" in result.stderr
|