Commit 271a78ac authored by Corentin Wallez's avatar Corentin Wallez Committed by LUCI CQ

gclient: Make gclient_gn_args_file honor use_relative_paths

Without this repos that use the use_relative_paths still need to use
their absolute path for gclient_gn_args_file.

Bug: chromium:1102833
Change-Id: I470096625061a28abf495f4d1035121edbcd581f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2279874Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 0be4724e
...@@ -427,6 +427,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -427,6 +427,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# The actual revision we ended up getting, or None if that information is # The actual revision we ended up getting, or None if that information is
# unavailable # unavailable
self._got_revision = None self._got_revision = None
# Whether this dependency should use relative paths.
self._use_relative_paths = False
# recursedeps is a mutable value that selectively overrides the default # recursedeps is a mutable value that selectively overrides the default
# 'no recursion' setting on a dep-by-dep basis. # 'no recursion' setting on a dep-by-dep basis.
...@@ -751,9 +753,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -751,9 +753,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# (and therefore set self.relative on this Dependency object), then we # (and therefore set self.relative on this Dependency object), then we
# want to modify the deps and recursedeps by prepending the parent # want to modify the deps and recursedeps by prepending the parent
# directory of this dependency. # directory of this dependency.
use_relative_paths = local_scope.get('use_relative_paths', False) self._use_relative_paths = local_scope.get('use_relative_paths', False)
rel_prefix = None rel_prefix = None
if use_relative_paths: if self._use_relative_paths:
rel_prefix = self.name rel_prefix = self.name
elif self._relative: elif self._relative:
rel_prefix = os.path.dirname(self.name) rel_prefix = os.path.dirname(self.name)
...@@ -788,13 +790,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -788,13 +790,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
deps = local_scope.get('deps', {}) deps = local_scope.get('deps', {})
deps_to_add = self._deps_to_objects( deps_to_add = self._deps_to_objects(
self._postprocess_deps(deps, rel_prefix), use_relative_paths) self._postprocess_deps(deps, rel_prefix), self._use_relative_paths)
# compute which working directory should be used for hooks # compute which working directory should be used for hooks
use_relative_hooks = local_scope.get('use_relative_hooks', False) use_relative_hooks = local_scope.get('use_relative_hooks', False)
hooks_cwd = self.root.root_dir hooks_cwd = self.root.root_dir
if use_relative_hooks: if use_relative_hooks:
if not use_relative_paths: if not self._use_relative_paths:
raise gclient_utils.Error( raise gclient_utils.Error(
'ParseDepsFile(%s): use_relative_hooks must be used with ' 'ParseDepsFile(%s): use_relative_hooks must be used with '
'use_relative_paths' % self.name) 'use_relative_paths' % self.name)
...@@ -1036,7 +1038,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1036,7 +1038,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
elif isinstance(value, basestring): elif isinstance(value, basestring):
value = gclient_eval.EvaluateCondition(value, variables) value = gclient_eval.EvaluateCondition(value, variables)
lines.append('%s = %s' % (arg, ToGNString(value))) lines.append('%s = %s' % (arg, ToGNString(value)))
with open(os.path.join(self.root.root_dir, self._gn_args_file), 'wb') as f:
# When use_relative_paths is set, gn_args_file is relative to this DEPS
path_prefix = self.root.root_dir
if self._use_relative_paths:
path_prefix = self.name
with open(os.path.join(path_prefix, self._gn_args_file), 'wb') as f:
f.write('\n'.join(lines).encode('utf-8', 'replace')) f.write('\n'.join(lines).encode('utf-8', 'replace'))
@gclient_utils.lockedmethod @gclient_utils.lockedmethod
......
...@@ -204,7 +204,7 @@ class FakeReposBase(object): ...@@ -204,7 +204,7 @@ class FakeReposBase(object):
class FakeRepos(FakeReposBase): class FakeRepos(FakeReposBase):
"""Implements populateGit().""" """Implements populateGit()."""
NB_GIT_REPOS = 16 NB_GIT_REPOS = 17
def populateGit(self): def populateGit(self):
# Testing: # Testing:
...@@ -711,6 +711,19 @@ hooks = [{ ...@@ -711,6 +711,19 @@ hooks = [{
'relative.py': 'pass', 'relative.py': 'pass',
'origin': 'git/repo_16@2\n' 'origin': 'git/repo_16@2\n'
}) })
# A repo with a gclient_gn_args_file and use_relative_paths
self._commit_git('repo_17', {
'DEPS': textwrap.dedent("""\
use_relative_paths=True
vars = {
'toto': 'tata',
}
gclient_gn_args_file = 'repo17_gclient.args'
gclient_gn_args = [
'toto',
]"""),
'origin': 'git/repo_17@2\n'
})
class FakeRepoSkiaDEPS(FakeReposBase): class FakeRepoSkiaDEPS(FakeReposBase):
"""Simulates the Skia DEPS transition in Chrome.""" """Simulates the Skia DEPS transition in Chrome."""
......
...@@ -1395,6 +1395,16 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase): ...@@ -1395,6 +1395,16 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
'# ' + self.git_base + 'repo_14, DEPS', '# ' + self.git_base + 'repo_14, DEPS',
], deps_contents.splitlines()) ], deps_contents.splitlines())
def testRelativeGNArgsFile(self):
self.gclient(['config', self.git_base + 'repo_17', '--name', 'src'])
self.gclient(['sync',])
tree = self.mangle_git_tree(('repo_17@1', 'src'))
tree['src/repo17_gclient.args'] = '\n'.join([
'# Generated from \'DEPS\'',
'toto = "tata"',
])
self.assertTree(tree)
if __name__ == '__main__': if __name__ == '__main__':
if '-v' in sys.argv: if '-v' in sys.argv:
......
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