Phillip Smyth pushed to branch mandatory_suffix at BuildStream / buildstream
Commits:
-
30f4b800
by Phillip Smyth at 2018-11-23T15:42:47Z
-
d8a6594d
by Phillip Smyth at 2018-11-23T15:42:56Z
-
1c32bf58
by Phillip Smyth at 2018-11-23T15:42:56Z
-
ee69d0a8
by Phillip Smyth at 2018-11-23T15:42:56Z
5 changed files:
- NEWS
- buildstream/_frontend/cli.py
- buildstream/_loader/loadelement.py
- tests/completions/completions.py
- tests/frontend/buildcheckout.py
Changes:
... | ... | @@ -2,6 +2,10 @@ |
2 | 2 |
buildstream 1.3.1
|
3 | 3 |
=================
|
4 | 4 |
|
5 |
+ o BREAKING CHANGE: Attempting to use an element that does not have the `.bst`
|
|
6 |
+ extension, will result in an error message.
|
|
7 |
+ All elements must now be suffixed with `.bst`
|
|
8 |
+ |
|
5 | 9 |
o BREAKING CHANGE: The 'manual' element lost its default 'MAKEFLAGS' and 'V'
|
6 | 10 |
environment variables. There is already a 'make' element with the same
|
7 | 11 |
variables. Note that this is a breaking change, it will require users to
|
... | ... | @@ -109,7 +109,11 @@ def complete_target(args, incomplete): |
109 | 109 |
if element_directory:
|
110 | 110 |
base_directory = os.path.join(base_directory, element_directory)
|
111 | 111 |
|
112 |
- return complete_path("File", incomplete, base_directory=base_directory)
|
|
112 |
+ complete_list = []
|
|
113 |
+ for p in complete_path("File", incomplete, base_directory=base_directory):
|
|
114 |
+ if p.endswith(".bst ") or p.endswith("/") or p.endswith(".conf "):
|
|
115 |
+ complete_list.append(p)
|
|
116 |
+ return complete_list
|
|
113 | 117 |
|
114 | 118 |
|
115 | 119 |
def override_completions(cmd, cmd_param, args, incomplete):
|
... | ... | @@ -145,8 +145,12 @@ def _extract_depends_from_node(node, *, key=None): |
145 | 145 |
|
146 | 146 |
depends = _yaml.node_get(node, list, key, default_value=[])
|
147 | 147 |
output_deps = []
|
148 |
+ invalid_elements = []
|
|
148 | 149 |
|
149 | 150 |
for index, dep in enumerate(depends):
|
151 |
+ if not dep.endswith(".bst"):
|
|
152 |
+ invalid_elements.append(dep)
|
|
153 |
+ |
|
150 | 154 |
dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index])
|
151 | 155 |
|
152 | 156 |
if isinstance(dep, str):
|
... | ... | @@ -182,6 +186,11 @@ def _extract_depends_from_node(node, *, key=None): |
182 | 186 |
|
183 | 187 |
output_deps.append(dependency)
|
184 | 188 |
|
189 |
+ if invalid_elements:
|
|
190 |
+ raise LoadError(LoadErrorReason.INVALID_DATA,
|
|
191 |
+ "Target elements '{}' do not have expected file extension `.bst`\n"
|
|
192 |
+ "Improperly named elements will not be discoverable by commands".format(invalid_elements))
|
|
193 |
+ |
|
185 | 194 |
# Now delete the field, we dont want it anymore
|
186 | 195 |
del node[key]
|
187 | 196 |
|
... | ... | @@ -66,6 +66,16 @@ PROJECT_ELEMENTS = [ |
66 | 66 |
"target.bst"
|
67 | 67 |
]
|
68 | 68 |
|
69 |
+INVALID_ELEMENT = [
|
|
70 |
+ "target.foo"
|
|
71 |
+ "compose-all.bst",
|
|
72 |
+ "compose-exclude-dev.bst",
|
|
73 |
+ "compose-include-bin.bst",
|
|
74 |
+ "import-bin.bst",
|
|
75 |
+ "import-dev.bst",
|
|
76 |
+ "target.bst"
|
|
77 |
+]
|
|
78 |
+ |
|
69 | 79 |
|
70 | 80 |
def assert_completion(cli, cmd, word_idx, expected, cwd=None):
|
71 | 81 |
result = cli.run(cwd=cwd, env={
|
... | ... | @@ -85,6 +95,24 @@ def assert_completion(cli, cmd, word_idx, expected, cwd=None): |
85 | 95 |
assert words == expected
|
86 | 96 |
|
87 | 97 |
|
98 |
+def assert_completion_failed(cli, cmd, word_idx, expected, cwd=None):
|
|
99 |
+ result = cli.run(cwd=cwd, env={
|
|
100 |
+ '_BST_COMPLETION': 'complete',
|
|
101 |
+ 'COMP_WORDS': cmd,
|
|
102 |
+ 'COMP_CWORD': str(word_idx)
|
|
103 |
+ })
|
|
104 |
+ words = []
|
|
105 |
+ if result.output:
|
|
106 |
+ words = result.output.splitlines()
|
|
107 |
+ |
|
108 |
+ # The order is meaningless, bash will
|
|
109 |
+ # take the results and order it by its
|
|
110 |
+ # own little heuristics
|
|
111 |
+ words = sorted(words)
|
|
112 |
+ expected = sorted(expected)
|
|
113 |
+ assert words != expected
|
|
114 |
+ |
|
115 |
+ |
|
88 | 116 |
@pytest.mark.parametrize("cmd,word_idx,expected", [
|
89 | 117 |
('bst', 0, []),
|
90 | 118 |
('bst ', 1, MAIN_COMMANDS),
|
... | ... | @@ -226,6 +254,19 @@ def test_argument_element(datafiles, cli, project, cmd, word_idx, expected, subd |
226 | 254 |
assert_completion(cli, cmd, word_idx, expected, cwd=cwd)
|
227 | 255 |
|
228 | 256 |
|
257 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
258 |
+@pytest.mark.parametrize("project,cmd,word_idx,expected,subdir", [
|
|
259 |
+ |
|
260 |
+ # When element has invalid suffix
|
|
261 |
+ ('project', 'bst --directory ../ show ', 4, [e + ' ' for e in INVALID_ELEMENT], 'files')
|
|
262 |
+])
|
|
263 |
+def test_argument_element_invalid(datafiles, cli, project, cmd, word_idx, expected, subdir):
|
|
264 |
+ cwd = os.path.join(str(datafiles), project)
|
|
265 |
+ if subdir:
|
|
266 |
+ cwd = os.path.join(cwd, subdir)
|
|
267 |
+ assert_completion_failed(cli, cmd, word_idx, expected, cwd=cwd)
|
|
268 |
+ |
|
269 |
+ |
|
229 | 270 |
@pytest.mark.parametrize("cmd,word_idx,expected", [
|
230 | 271 |
('bst he', 1, ['help ']),
|
231 | 272 |
('bst help ', 2, MAIN_COMMANDS),
|
... | ... | @@ -60,6 +60,18 @@ def test_build_checkout(datafiles, cli, strict, hardlinks): |
60 | 60 |
assert os.path.exists(filename)
|
61 | 61 |
|
62 | 62 |
|
63 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
64 |
+@pytest.mark.parametrize("strict,hardlinks", [
|
|
65 |
+ ("non-strict", "hardlinks"),
|
|
66 |
+])
|
|
67 |
+def test_build_invalid_suffix(datafiles, cli, strict, hardlinks):
|
|
68 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
69 |
+ checkout = os.path.join(cli.directory, 'checkout')
|
|
70 |
+ |
|
71 |
+ result = cli.run(project=project, args=strict_args(['build', 'target.foo'], strict))
|
|
72 |
+ result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_DATA)
|
|
73 |
+ |
|
74 |
+ |
|
63 | 75 |
@pytest.mark.datafiles(DATA_DIR)
|
64 | 76 |
@pytest.mark.parametrize("deps", [("run"), ("none")])
|
65 | 77 |
def test_build_checkout_deps(datafiles, cli, deps):
|