summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/data_smart.py39
-rw-r--r--bitbake/lib/bb/tests/data.py39
2 files changed, 72 insertions, 6 deletions
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 17768c8f4b..5d0ed12d6e 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -116,7 +116,15 @@ class VariableParse:
116 return match.group() 116 return match.group()
117 117
118 def python_sub(self, match): 118 def python_sub(self, match):
119 code = match.group()[3:-1] 119 if isinstance(match, str):
120 code = match
121 else:
122 code = match.group()[3:-1]
123
124 if "_remote_data" in self.d:
125 connector = self.d["_remote_data"]
126 return connector.expandPythonRef(self.varname, code)
127
120 codeobj = compile(code.strip(), self.varname or "<expansion>", "eval") 128 codeobj = compile(code.strip(), self.varname or "<expansion>", "eval")
121 129
122 parser = bb.codeparser.PythonParser(self.varname, logger) 130 parser = bb.codeparser.PythonParser(self.varname, logger)
@@ -247,10 +255,15 @@ class VariableHistory(object):
247 self.variables[var].append(loginfo.copy()) 255 self.variables[var].append(loginfo.copy())
248 256
249 def variable(self, var): 257 def variable(self, var):
250 if var in self.variables: 258 remote_connector = self.dataroot.getVar('_remote_data', False)
251 return self.variables[var] 259 if remote_connector:
260 varhistory = remote_connector.getVarHistory(var)
252 else: 261 else:
253 return [] 262 varhistory = []
263
264 if var in self.variables:
265 varhistory.extend(self.variables[var])
266 return varhistory
254 267
255 def emit(self, var, oval, val, o, d): 268 def emit(self, var, oval, val, o, d):
256 history = self.variable(var) 269 history = self.variable(var)
@@ -449,6 +462,10 @@ class DataSmart(MutableMapping):
449 if var in dest: 462 if var in dest:
450 return dest[var] 463 return dest[var]
451 464
465 if "_remote_data" in dest:
466 connector = dest["_remote_data"]["_content"]
467 return connector.getVar(var)
468
452 if "_data" not in dest: 469 if "_data" not in dest:
453 break 470 break
454 dest = dest["_data"] 471 dest = dest["_data"]
@@ -471,6 +488,12 @@ class DataSmart(MutableMapping):
471 if 'parsing' in loginfo: 488 if 'parsing' in loginfo:
472 parsing=True 489 parsing=True
473 490
491 if '_remote_data' in self.dict:
492 connector = self.dict["_remote_data"]["_content"]
493 res = connector.setVar(var, value)
494 if not res:
495 return
496
474 if 'op' not in loginfo: 497 if 'op' not in loginfo:
475 loginfo['op'] = "set" 498 loginfo['op'] = "set"
476 self.expand_cache = {} 499 self.expand_cache = {}
@@ -875,7 +898,7 @@ class DataSmart(MutableMapping):
875 898
876 def localkeys(self): 899 def localkeys(self):
877 for key in self.dict: 900 for key in self.dict:
878 if key != '_data': 901 if key not in ['_data', '_remote_data']:
879 yield key 902 yield key
880 903
881 def __iter__(self): 904 def __iter__(self):
@@ -884,7 +907,7 @@ class DataSmart(MutableMapping):
884 def keylist(d): 907 def keylist(d):
885 klist = set() 908 klist = set()
886 for key in d: 909 for key in d:
887 if key == "_data": 910 if key in ["_data", "_remote_data"]:
888 continue 911 continue
889 if key in deleted: 912 if key in deleted:
890 continue 913 continue
@@ -898,6 +921,10 @@ class DataSmart(MutableMapping):
898 if "_data" in d: 921 if "_data" in d:
899 klist |= keylist(d["_data"]) 922 klist |= keylist(d["_data"])
900 923
924 if "_remote_data" in d:
925 connector = d["_remote_data"]["_content"]
926 klist |= connector.getKeys()
927
901 return klist 928 return klist
902 929
903 self.need_overrides() 930 self.need_overrides()
diff --git a/bitbake/lib/bb/tests/data.py b/bitbake/lib/bb/tests/data.py
index 1a5a28af06..2bd481b5d7 100644
--- a/bitbake/lib/bb/tests/data.py
+++ b/bitbake/lib/bb/tests/data.py
@@ -444,3 +444,42 @@ class Contains(unittest.TestCase):
444 444
445 self.assertFalse(bb.utils.contains_any("SOMEFLAG", "x", True, False, self.d)) 445 self.assertFalse(bb.utils.contains_any("SOMEFLAG", "x", True, False, self.d))
446 self.assertFalse(bb.utils.contains_any("SOMEFLAG", "x y z", True, False, self.d)) 446 self.assertFalse(bb.utils.contains_any("SOMEFLAG", "x y z", True, False, self.d))
447
448
449class Remote(unittest.TestCase):
450 def test_remote(self):
451 class TestConnector:
452 d = None
453 def __init__(self, d):
454 self.d = d
455 def getVar(self, name):
456 return self.d._findVar(name)
457 def getKeys(self):
458 return self.d.localkeys()
459 def getVarHistory(self, name):
460 return self.d.varhistory.variable(name)
461 def expandPythonRef(self, varname, expr):
462 varparse = bb.data_smart.VariableParse(varname, self.d)
463 return varparse.python_sub(expr)
464 def setVar(self, name, value):
465 self.d.setVar(name, value)
466
467 d1 = bb.data.init()
468 d1.enableTracking()
469 d2 = bb.data.init()
470 d2.enableTracking()
471 connector = TestConnector(d1)
472
473 d2.setVar('_remote_data', connector)
474
475 d1.setVar('HELLO', 'world')
476 d1.setVarFlag('OTHER', 'flagname', 'flagvalue')
477 self.assertEqual(d2.getVar('HELLO'), 'world')
478 self.assertEqual(d2.expand('${HELLO}'), 'world')
479 self.assertEqual(d2.expand('${@d.getVar("HELLO")}'), 'world')
480 self.assertIn('flagname', d2.getVarFlags('OTHER'))
481 self.assertEqual(d2.getVarFlag('OTHER', 'flagname'), 'flagvalue')
482 self.assertEqual(d1.varhistory.variable('HELLO'), d2.varhistory.variable('HELLO'))
483 # Test setVar on client side affects server
484 d2.setVar('HELLO', 'other-world')
485 self.assertEqual(d1.getVar('HELLO'), 'other-world')