mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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/+/2279874 Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
18
gclient.py
18
gclient.py
@@ -427,6 +427,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
|
||||
# The actual revision we ended up getting, or None if that information is
|
||||
# unavailable
|
||||
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
|
||||
# 'no recursion' setting on a dep-by-dep basis.
|
||||
@@ -751,9 +753,9 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
|
||||
# (and therefore set self.relative on this Dependency object), then we
|
||||
# want to modify the deps and recursedeps by prepending the parent
|
||||
# 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
|
||||
if use_relative_paths:
|
||||
if self._use_relative_paths:
|
||||
rel_prefix = self.name
|
||||
elif self._relative:
|
||||
rel_prefix = os.path.dirname(self.name)
|
||||
@@ -788,13 +790,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
|
||||
|
||||
deps = local_scope.get('deps', {})
|
||||
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
|
||||
use_relative_hooks = local_scope.get('use_relative_hooks', False)
|
||||
hooks_cwd = self.root.root_dir
|
||||
if use_relative_hooks:
|
||||
if not use_relative_paths:
|
||||
if not self._use_relative_paths:
|
||||
raise gclient_utils.Error(
|
||||
'ParseDepsFile(%s): use_relative_hooks must be used with '
|
||||
'use_relative_paths' % self.name)
|
||||
@@ -1036,7 +1038,13 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
|
||||
elif isinstance(value, basestring):
|
||||
value = gclient_eval.EvaluateCondition(value, variables)
|
||||
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'))
|
||||
|
||||
@gclient_utils.lockedmethod
|
||||
|
||||
@@ -204,7 +204,7 @@ class FakeReposBase(object):
|
||||
|
||||
class FakeRepos(FakeReposBase):
|
||||
"""Implements populateGit()."""
|
||||
NB_GIT_REPOS = 16
|
||||
NB_GIT_REPOS = 17
|
||||
|
||||
def populateGit(self):
|
||||
# Testing:
|
||||
@@ -711,6 +711,19 @@ hooks = [{
|
||||
'relative.py': 'pass',
|
||||
'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):
|
||||
"""Simulates the Skia DEPS transition in Chrome."""
|
||||
|
||||
@@ -1395,6 +1395,16 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
|
||||
'# ' + self.git_base + 'repo_14, DEPS',
|
||||
], 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 '-v' in sys.argv:
|
||||
|
||||
Reference in New Issue
Block a user