summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2018-10-16 14:16:27 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-10-18 10:59:26 +0100
commita9aa1d24c7c4518173f622a1fab55a98a16150f9 (patch)
tree688a3602fce0b04eab7119930ad41d730029244a /bitbake
parent58530c6e481a2d237291af9e75d4417ecac7636b (diff)
downloadpoky-a9aa1d24c7c4518173f622a1fab55a98a16150f9.tar.gz
bitbake: data: Fix whitespace on _remove operations
We have some slightly odd behaviours with the current implementation of _remove operations. For example: TEST = " A B" TEST_remove = "C" would trigger TEST to become "A B" even thought it doesn't contain "C". In particular, this means that an inactive remove operator added in a bbappend could change the task checksum which is not desireable. Fix the operation to preserve whitespace, adding new tests to make this explict and test further corner cases. Also update the manual to match. (Bitbake rev: c0a23dd9155c50a6b7df796980bc7b612cac7994) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml6
-rw-r--r--bitbake/lib/bb/data_smart.py5
-rw-r--r--bitbake/lib/bb/tests/data.py20
3 files changed, 22 insertions, 9 deletions
diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml
index bc08c814d1..fc55ef6483 100644
--- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml
@@ -342,7 +342,7 @@
342 342
343 <para> 343 <para>
344 When you use this syntax, BitBake expects one or more strings. 344 When you use this syntax, BitBake expects one or more strings.
345 Surrounding spaces are removed as well. 345 Surrounding spaces and spacing are preserved.
346 Here is an example: 346 Here is an example:
347 <literallayout class='monospaced'> 347 <literallayout class='monospaced'>
348 FOO = "123 456 789 123456 123 456 123 456" 348 FOO = "123 456 789 123456 123 456 123 456"
@@ -352,8 +352,8 @@
352 FOO2_remove = "abc def" 352 FOO2_remove = "abc def"
353 </literallayout> 353 </literallayout>
354 The variable <filename>FOO</filename> becomes 354 The variable <filename>FOO</filename> becomes
355 "789 123456" and <filename>FOO2</filename> becomes 355 " 789 123456 " and <filename>FOO2</filename> becomes
356 "ghi abcdef". 356 " ghi abcdef ".
357 </para> 357 </para>
358 358
359 <para> 359 <para>
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 4434142a02..0a8488ca1b 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -42,6 +42,7 @@ __setvar_keyword__ = ["_append", "_prepend", "_remove"]
42__setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend|_remove)(_(?P<add>[^A-Z]*))?$') 42__setvar_regexp__ = re.compile('(?P<base>.*?)(?P<keyword>_append|_prepend|_remove)(_(?P<add>[^A-Z]*))?$')
43__expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}") 43__expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}")
44__expand_python_regexp__ = re.compile(r"\${@.+?}") 44__expand_python_regexp__ = re.compile(r"\${@.+?}")
45__whitespace_split__ = re.compile('(\s)')
45 46
46def infer_caller_details(loginfo, parent = False, varval = True): 47def infer_caller_details(loginfo, parent = False, varval = True):
47 """Save the caller the trouble of specifying everything.""" 48 """Save the caller the trouble of specifying everything."""
@@ -818,8 +819,8 @@ class DataSmart(MutableMapping):
818 819
819 if removes: 820 if removes:
820 filtered = filter(lambda v: v not in removes, 821 filtered = filter(lambda v: v not in removes,
821 value.split()) 822 __whitespace_split__.split(value))
822 value = " ".join(filtered) 823 value = "".join(filtered)
823 if expand and var in self.expand_cache: 824 if expand and var in self.expand_cache:
824 # We need to ensure the expand cache has the correct value 825 # We need to ensure the expand cache has the correct value
825 # flag == "_content" here 826 # flag == "_content" here
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py
index a4a9dd30fb..8279115e03 100644
--- a/bitbake/lib/bb/tests/data.py
+++ b/bitbake/lib/bb/tests/data.py
@@ -281,7 +281,7 @@ class TestConcatOverride(unittest.TestCase):
281 def test_remove(self): 281 def test_remove(self):
282 self.d.setVar("TEST", "${VAL} ${BAR}") 282 self.d.setVar("TEST", "${VAL} ${BAR}")
283 self.d.setVar("TEST_remove", "val") 283 self.d.setVar("TEST_remove", "val")
284 self.assertEqual(self.d.getVar("TEST"), "bar") 284 self.assertEqual(self.d.getVar("TEST"), " bar")
285 285
286 def test_remove_cleared(self): 286 def test_remove_cleared(self):
287 self.d.setVar("TEST", "${VAL} ${BAR}") 287 self.d.setVar("TEST", "${VAL} ${BAR}")
@@ -300,7 +300,7 @@ class TestConcatOverride(unittest.TestCase):
300 self.d.setVar("TEST", "${VAL} ${BAR}") 300 self.d.setVar("TEST", "${VAL} ${BAR}")
301 self.d.setVar("TEST_remove", "val") 301 self.d.setVar("TEST_remove", "val")
302 self.d.setVar("TEST_TEST", "${TEST} ${TEST}") 302 self.d.setVar("TEST_TEST", "${TEST} ${TEST}")
303 self.assertEqual(self.d.getVar("TEST_TEST"), "bar bar") 303 self.assertEqual(self.d.getVar("TEST_TEST"), " bar bar")
304 304
305 def test_empty_remove(self): 305 def test_empty_remove(self):
306 self.d.setVar("TEST", "") 306 self.d.setVar("TEST", "")
@@ -311,13 +311,25 @@ class TestConcatOverride(unittest.TestCase):
311 self.d.setVar("BAR", "Z") 311 self.d.setVar("BAR", "Z")
312 self.d.setVar("TEST", "${BAR}/X Y") 312 self.d.setVar("TEST", "${BAR}/X Y")
313 self.d.setVar("TEST_remove", "${BAR}/X") 313 self.d.setVar("TEST_remove", "${BAR}/X")
314 self.assertEqual(self.d.getVar("TEST"), "Y") 314 self.assertEqual(self.d.getVar("TEST"), " Y")
315 315
316 def test_remove_expansion_items(self): 316 def test_remove_expansion_items(self):
317 self.d.setVar("TEST", "A B C D") 317 self.d.setVar("TEST", "A B C D")
318 self.d.setVar("BAR", "B D") 318 self.d.setVar("BAR", "B D")
319 self.d.setVar("TEST_remove", "${BAR}") 319 self.d.setVar("TEST_remove", "${BAR}")
320 self.assertEqual(self.d.getVar("TEST"), "A C") 320 self.assertEqual(self.d.getVar("TEST"), "A C ")
321
322 def test_remove_preserve_whitespace(self):
323 # When the removal isn't active, the original value should be preserved
324 self.d.setVar("TEST", " A B")
325 self.d.setVar("TEST_remove", "C")
326 self.assertEqual(self.d.getVar("TEST"), " A B")
327
328 def test_remove_preserve_whitespace2(self):
329 # When the removal is active preserve the whitespace
330 self.d.setVar("TEST", " A B")
331 self.d.setVar("TEST_remove", "B")
332 self.assertEqual(self.d.getVar("TEST"), " A ")
321 333
322class TestOverrides(unittest.TestCase): 334class TestOverrides(unittest.TestCase):
323 def setUp(self): 335 def setUp(self):