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):
def WriteGNArgsFile(self):
lines = ['# Generated from %r' % self.deps_file]
variables = self.get_vars()
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:
f.write('\n'.join(lines))
......
......@@ -329,9 +329,16 @@ class FakeRepos(FakeReposBase):
'DEPS': """
vars = {
'DummyVariable': 'repo',
'false_var': 'False',
'true_var': 'True',
'str_var': '"abc"',
}
gclient_gn_args_file = 'src/gclient.args'
gclient_gn_args = ['DummyVariable']
gclient_gn_args = [
'false_var',
'true_var',
'str_var',
]
deps = {
'src/repo2': {
'url': '%(git_base)srepo_2',
......@@ -467,9 +474,19 @@ vars = {
'git_base': '%(git_base)s',
'hook1_contents': 'git_hooked1',
'repo5_var': '/repo_5',
'false_var': 'False',
'true_var': 'True',
'str_var': '"abc"',
}
gclient_gn_args_file = 'src/gclient.args'
gclient_gn_args = ['DummyVariable']
gclient_gn_args = [
'false_var',
'true_var',
'str_var',
]
allowed_hosts = [
'%(git_base)s',
]
......
......@@ -326,7 +326,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'',
'DummyVariable = "repo"',
'false_var = false',
'true_var = true',
'str_var = "abc"',
])
self.assertTree(tree)
# Test incremental sync: delete-unversioned_trees isn't there.
......@@ -342,7 +344,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'',
'DummyVariable = "repo"',
'false_var = false',
'true_var = true',
'str_var = "abc"',
])
self.assertTree(tree)
......@@ -379,7 +383,9 @@ class GClientSmokeGIT(GClientSmokeBase):
('repo_4@2', 'src/repo4'))
tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'',
'DummyVariable = "repo"',
'false_var = false',
'true_var = true',
'str_var = "abc"',
])
self.assertTree(tree)
......@@ -419,7 +425,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'',
'DummyVariable = "repo"',
'false_var = false',
'true_var = true',
'str_var = "abc"',
])
self.assertTree(tree)
# Test incremental sync: delete-unversioned_trees isn't there.
......@@ -436,7 +444,9 @@ class GClientSmokeGIT(GClientSmokeBase):
tree['src/git_hooked2'] = 'git_hooked2'
tree['src/gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'',
'DummyVariable = "repo"',
'false_var = false',
'true_var = true',
'str_var = "abc"',
])
self.assertTree(tree)
......@@ -616,7 +626,7 @@ class GClientSmokeGIT(GClientSmokeBase):
self.maxDiff = None
self.assertEqual([
'gclient_gn_args_file = "src/gclient.args"',
'gclient_gn_args = [\'DummyVariable\']',
'gclient_gn_args = [\'false_var\', \'true_var\', \'str_var\']',
'allowed_hosts = [',
' "git://127.0.0.1:20000/git/",',
']',
......@@ -738,6 +748,9 @@ class GClientSmokeGIT(GClientSmokeBase):
' "DummyVariable": \'repo\',',
'',
' # src',
' "false_var": \'False\',',
'',
' # src',
' "git_base": \'git://127.0.0.1:20000/git/\',',
'',
' # src',
......@@ -746,6 +759,12 @@ class GClientSmokeGIT(GClientSmokeBase):
' # src',
' "repo5_var": \'/repo_5\',',
'',
' # src',
' "str_var": \'"abc"\',',
'',
' # src',
' "true_var": \'True\',',
'',
'}',
'',
'# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % (
......@@ -770,7 +789,7 @@ class GClientSmokeGIT(GClientSmokeBase):
self.assertEqual([
'gclient_gn_args_file = "src/gclient.args"',
'gclient_gn_args = [\'DummyVariable\']',
'gclient_gn_args = [\'false_var\', \'true_var\', \'str_var\']',
'allowed_hosts = [',
' "git://127.0.0.1:20000/git/",',
']',
......@@ -893,6 +912,9 @@ class GClientSmokeGIT(GClientSmokeBase):
' "DummyVariable": \'repo\',',
'',
' # src',
' "false_var": \'False\',',
'',
' # src',
' "git_base": \'git://127.0.0.1:20000/git/\',',
'',
' # src',
......@@ -901,6 +923,12 @@ class GClientSmokeGIT(GClientSmokeBase):
' # src',
' "repo5_var": \'/repo_5\',',
'',
' # src',
' "str_var": \'"abc"\',',
'',
' # src',
' "true_var": \'True\',',
'',
'}',
'',
'# 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