Fix use_relative_path on Windows

DEPS entries all have slashes as their path separators.

If use_relative_path is set to true, .gclient_entries will actually
contain backslashes instead slashes. This is problematic when DEPS
file transitions from using use_relative_path = False to True.

In such case, gclient thinks there are two distinct repositories
and it will delete one with slashes. As this operation is the last
step of gclient sync, it results in affected repositories being
wrongfully removed.

This change forces all deps entries to have slashes regardless of
operating system.

R=gavinmak@google.com

Bug: 1422665
Change-Id: Idb73510d911a260bccf63d24a8d3452998b147f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4348792
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Auto-Submit: Josip Sokcevic <sokcevic@chromium.org>
changes/92/4348792/2
sokcevic 2 years ago committed by LUCI CQ
parent c5b38329e6
commit 71b606ecff

@ -680,7 +680,11 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
for d, url in processed_deps.items(): for d, url in processed_deps.items():
# normpath is required to allow DEPS to use .. in their # normpath is required to allow DEPS to use .. in their
# dependency local path. # dependency local path.
rel_deps[os.path.normpath(os.path.join(rel_prefix, d))] = url # We are following the same pattern when use_relative_paths = False,
# which uses slashes.
rel_deps[os.path.normpath(os.path.join(rel_prefix,
d)).replace(os.path.sep,
'/')] = url
logging.warning('Updating deps by prepending %s.', rel_prefix) logging.warning('Updating deps by prepending %s.', rel_prefix)
return rel_deps return rel_deps
@ -842,8 +846,8 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
logging.warning('Updating recursedeps by prepending %s.', rel_prefix) logging.warning('Updating recursedeps by prepending %s.', rel_prefix)
rel_deps = {} rel_deps = {}
for depname, options in self.recursedeps.items(): for depname, options in self.recursedeps.items():
rel_deps[ rel_deps[os.path.normpath(os.path.join(rel_prefix, depname)).replace(
os.path.normpath(os.path.join(rel_prefix, depname))] = options os.path.sep, '/')] = options
self.recursedeps = rel_deps self.recursedeps = rel_deps
# To get gn_args from another DEPS, that DEPS must be recursed into. # To get gn_args from another DEPS, that DEPS must be recursed into.
if self._gn_args_from: if self._gn_args_from:

@ -440,11 +440,10 @@ class GclientTest(trial_dir.TestCase):
write(os.path.join('foo', 'baz', 'fake.txt'), write(os.path.join('foo', 'baz', 'fake.txt'),
"bogus content") "bogus content")
self.assertEqual([(h.action, h.effective_cwd) for h in self._get_hooks()], self.assertEqual(
[ [(h.action, h.effective_cwd) for h in self._get_hooks()],
(('tata', 'titi'), self.root_dir), [(('tata', 'titi'), self.root_dir),
(('fire', 'lazors'), os.path.join(self.root_dir, "foo", "baz")) (('fire', 'lazors'), os.path.join(self.root_dir, 'foo/baz'))])
])
def testTargetOS(self): def testTargetOS(self):
"""Verifies that specifying a target_os pulls in all relevant dependencies. """Verifies that specifying a target_os pulls in all relevant dependencies.
@ -847,13 +846,11 @@ class GclientTest(trial_dir.TestCase):
options, _ = gclient.OptionParser().parse_args([]) options, _ = gclient.OptionParser().parse_args([])
obj = gclient.GClient.LoadCurrentConfig(options) obj = gclient.GClient.LoadCurrentConfig(options)
obj.RunOnDeps('None', []) obj.RunOnDeps('None', [])
self.assertEqual( self.assertEqual([
[ ('foo', 'svn://example.com/foo'),
('foo', 'svn://example.com/foo'), ('foo/bar', 'svn://example.com/bar'),
(os.path.join('foo', 'bar'), 'svn://example.com/bar'), ('foo/baz', 'svn://example.com/baz'),
(os.path.join('foo', 'baz'), 'svn://example.com/baz'), ], self._get_processed())
],
self._get_processed())
def testRecursedepsCustomdepsOverride(self): def testRecursedepsCustomdepsOverride(self):
"""Verifies gclient overrides deps within recursedeps using custom deps""" """Verifies gclient overrides deps within recursedeps using custom deps"""
@ -883,15 +880,12 @@ class GclientTest(trial_dir.TestCase):
options, _ = gclient.OptionParser().parse_args([]) options, _ = gclient.OptionParser().parse_args([])
obj = gclient.GClient.LoadCurrentConfig(options) obj = gclient.GClient.LoadCurrentConfig(options)
obj.RunOnDeps('None', []) obj.RunOnDeps('None', [])
six.assertCountEqual( six.assertCountEqual(self, [
self, ('foo', 'svn://example.com/foo'),
[ ('foo/bar', 'svn://example.com/override'),
('foo', 'svn://example.com/foo'), ('foo/foo/bar', 'svn://example.com/override'),
(os.path.join('foo', 'bar'), 'svn://example.com/override'), ('foo/baz', 'svn://example.com/baz'),
(os.path.join('foo', 'foo', 'bar'), 'svn://example.com/override'), ], self._get_processed())
(os.path.join('foo', 'baz'), 'svn://example.com/baz'),
],
self._get_processed())
def testRelativeRecursion(self): def testRelativeRecursion(self):
"""Verifies that nested use_relative_paths is always respected.""" """Verifies that nested use_relative_paths is always respected."""
@ -922,13 +916,11 @@ class GclientTest(trial_dir.TestCase):
options, _ = gclient.OptionParser().parse_args([]) options, _ = gclient.OptionParser().parse_args([])
obj = gclient.GClient.LoadCurrentConfig(options) obj = gclient.GClient.LoadCurrentConfig(options)
obj.RunOnDeps('None', []) obj.RunOnDeps('None', [])
self.assertEqual( self.assertEqual([
[ ('foo', 'svn://example.com/foo'),
('foo', 'svn://example.com/foo'), ('foo/bar', 'svn://example.com/bar'),
(os.path.join('foo', 'bar'), 'svn://example.com/bar'), ('foo/bar/baz', 'svn://example.com/baz'),
(os.path.join('foo', 'bar', 'baz'), 'svn://example.com/baz'), ], self._get_processed())
],
self._get_processed())
def testRelativeRecursionInNestedDir(self): def testRelativeRecursionInNestedDir(self):
"""Verifies a gotcha of relative recursion where the parent uses relative """Verifies a gotcha of relative recursion where the parent uses relative
@ -961,13 +953,11 @@ class GclientTest(trial_dir.TestCase):
options, _ = gclient.OptionParser().parse_args([]) options, _ = gclient.OptionParser().parse_args([])
obj = gclient.GClient.LoadCurrentConfig(options) obj = gclient.GClient.LoadCurrentConfig(options)
obj.RunOnDeps('None', []) obj.RunOnDeps('None', [])
self.assertEqual( self.assertEqual([
[ ('foo', 'svn://example.com/foo'),
('foo', 'svn://example.com/foo'), ('foo/third_party/bar', 'svn://example.com/bar'),
(os.path.join('foo', 'third_party', 'bar'), 'svn://example.com/bar'), ('foo/third_party/baz', 'svn://example.com/baz'),
(os.path.join('foo', 'third_party', 'baz'), 'svn://example.com/baz'), ], self._get_processed())
],
self._get_processed())
def testRecursedepsAltfile(self): def testRecursedepsAltfile(self):
"""Verifies gclient respects the |recursedeps| var syntax with overridden """Verifies gclient respects the |recursedeps| var syntax with overridden

Loading…
Cancel
Save