Commit b495bf50 authored by Paweł Hajdan, Jr's avatar Paweł Hajdan, Jr Committed by Commit Bot

gclient: evaluate variables before passing them to GN

This helps make sure they have proper types (e.g. True
instead of "True" for booleans).

Also see https://chromium-review.googlesource.com/c/chromium/src/+/681854
for context.

Bug: 756688, 570091
Change-Id: I1e4d26df724e8e94cc3daba361191856f80a1b2c
Reviewed-on: https://chromium-review.googlesource.com/681705Reviewed-by: 's avatarDirk Pranke <dpranke@chromium.org>
Commit-Queue: Paweł Hajdan Jr. <phajdan.jr@chromium.org>
parent df64ee13
...@@ -959,8 +959,10 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -959,8 +959,10 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
def WriteGNArgsFile(self): def WriteGNArgsFile(self):
lines = ['# Generated from %r' % self.deps_file] lines = ['# Generated from %r' % self.deps_file]
variables = self.get_vars()
for arg in self._gn_args: for arg in self._gn_args:
lines.append('%s = %s' % (arg, ToGNString(self.get_vars()[arg]))) value = gclient_eval.EvaluateCondition(variables[arg], variables)
lines.append('%s = %s' % (arg, ToGNString(value)))
with open(os.path.join(self.root.root_dir, self._gn_args_file), 'w') as f: with open(os.path.join(self.root.root_dir, self._gn_args_file), 'w') as f:
f.write('\n'.join(lines)) f.write('\n'.join(lines))
......
...@@ -329,9 +329,16 @@ class FakeRepos(FakeReposBase): ...@@ -329,9 +329,16 @@ class FakeRepos(FakeReposBase):
'DEPS': """ 'DEPS': """
vars = { vars = {
'DummyVariable': 'repo', 'DummyVariable': 'repo',
'false_var': 'False',
'true_var': 'True',
'str_var': '"abc"',
} }
gclient_gn_args_file = 'src/gclient.args' gclient_gn_args_file = 'src/gclient.args'
gclient_gn_args = ['DummyVariable'] gclient_gn_args = [
'false_var',
'true_var',
'str_var',
]
deps = { deps = {
'src/repo2': { 'src/repo2': {
'url': '%(git_base)srepo_2', 'url': '%(git_base)srepo_2',
...@@ -467,9 +474,19 @@ vars = { ...@@ -467,9 +474,19 @@ vars = {
'git_base': '%(git_base)s', 'git_base': '%(git_base)s',
'hook1_contents': 'git_hooked1', 'hook1_contents': 'git_hooked1',
'repo5_var': '/repo_5', 'repo5_var': '/repo_5',
'false_var': 'False',
'true_var': 'True',
'str_var': '"abc"',
} }
gclient_gn_args_file = 'src/gclient.args' gclient_gn_args_file = 'src/gclient.args'
gclient_gn_args = ['DummyVariable'] gclient_gn_args = [
'false_var',
'true_var',
'str_var',
]
allowed_hosts = [ allowed_hosts = [
'%(git_base)s', '%(git_base)s',
] ]
......
...@@ -326,7 +326,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -326,7 +326,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2' tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([ tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'', '# Generated from \'DEPS\'',
'DummyVariable = "repo"', 'false_var = false',
'true_var = true',
'str_var = "abc"',
]) ])
self.assertTree(tree) self.assertTree(tree)
# Test incremental sync: delete-unversioned_trees isn't there. # Test incremental sync: delete-unversioned_trees isn't there.
...@@ -342,7 +344,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -342,7 +344,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2' tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([ tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'', '# Generated from \'DEPS\'',
'DummyVariable = "repo"', 'false_var = false',
'true_var = true',
'str_var = "abc"',
]) ])
self.assertTree(tree) self.assertTree(tree)
...@@ -379,7 +383,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -379,7 +383,9 @@ class GClientSmokeGIT(GClientSmokeBase):
('repo_4@2', 'src/repo4')) ('repo_4@2', 'src/repo4'))
tree['src/gclient.args'] = '\n'.join([ tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'', '# Generated from \'DEPS\'',
'DummyVariable = "repo"', 'false_var = false',
'true_var = true',
'str_var = "abc"',
]) ])
self.assertTree(tree) self.assertTree(tree)
...@@ -419,7 +425,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -419,7 +425,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2' tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([ tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'', '# Generated from \'DEPS\'',
'DummyVariable = "repo"', 'false_var = false',
'true_var = true',
'str_var = "abc"',
]) ])
self.assertTree(tree) self.assertTree(tree)
# Test incremental sync: delete-unversioned_trees isn't there. # Test incremental sync: delete-unversioned_trees isn't there.
...@@ -436,7 +444,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -436,7 +444,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2' tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([ tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'', '# Generated from \'DEPS\'',
'DummyVariable = "repo"', 'false_var = false',
'true_var = true',
'str_var = "abc"',
]) ])
self.assertTree(tree) self.assertTree(tree)
...@@ -616,7 +626,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -616,7 +626,7 @@ class GClientSmokeGIT(GClientSmokeBase):
self.maxDiff = None self.maxDiff = None
self.assertEqual([ self.assertEqual([
'gclient_gn_args_file = "src/gclient.args"', 'gclient_gn_args_file = "src/gclient.args"',
'gclient_gn_args = [\'DummyVariable\']', 'gclient_gn_args = [\'false_var\', \'true_var\', \'str_var\']',
'allowed_hosts = [', 'allowed_hosts = [',
' "git://127.0.0.1:20000/git/",', ' "git://127.0.0.1:20000/git/",',
']', ']',
...@@ -738,6 +748,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -738,6 +748,9 @@ class GClientSmokeGIT(GClientSmokeBase):
' "DummyVariable": \'repo\',', ' "DummyVariable": \'repo\',',
'', '',
' # src', ' # src',
' "false_var": \'False\',',
'',
' # src',
' "git_base": \'git://127.0.0.1:20000/git/\',', ' "git_base": \'git://127.0.0.1:20000/git/\',',
'', '',
' # src', ' # src',
...@@ -746,6 +759,12 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -746,6 +759,12 @@ class GClientSmokeGIT(GClientSmokeBase):
' # src', ' # src',
' "repo5_var": \'/repo_5\',', ' "repo5_var": \'/repo_5\',',
'', '',
' # src',
' "str_var": \'"abc"\',',
'',
' # src',
' "true_var": \'True\',',
'',
'}', '}',
'', '',
'# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % ( '# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % (
...@@ -770,7 +789,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -770,7 +789,7 @@ class GClientSmokeGIT(GClientSmokeBase):
self.assertEqual([ self.assertEqual([
'gclient_gn_args_file = "src/gclient.args"', 'gclient_gn_args_file = "src/gclient.args"',
'gclient_gn_args = [\'DummyVariable\']', 'gclient_gn_args = [\'false_var\', \'true_var\', \'str_var\']',
'allowed_hosts = [', 'allowed_hosts = [',
' "git://127.0.0.1:20000/git/",', ' "git://127.0.0.1:20000/git/",',
']', ']',
...@@ -893,6 +912,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -893,6 +912,9 @@ class GClientSmokeGIT(GClientSmokeBase):
' "DummyVariable": \'repo\',', ' "DummyVariable": \'repo\',',
'', '',
' # src', ' # src',
' "false_var": \'False\',',
'',
' # src',
' "git_base": \'git://127.0.0.1:20000/git/\',', ' "git_base": \'git://127.0.0.1:20000/git/\',',
'', '',
' # src', ' # src',
...@@ -901,6 +923,12 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -901,6 +923,12 @@ class GClientSmokeGIT(GClientSmokeBase):
' # src', ' # src',
' "repo5_var": \'/repo_5\',', ' "repo5_var": \'/repo_5\',',
'', '',
' # src',
' "str_var": \'"abc"\',',
'',
' # src',
' "true_var": \'True\',',
'',
'}', '}',
'', '',
'# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % ( '# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment