Commit 67ef3f67 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

gclient: delete unversioned directory before adding cipd dep for the same path

Bug: 882611
Change-Id: I46e41cc9693b90874b5d6569a12ec638eaac1050
Reviewed-on: https://chromium-review.googlesource.com/1228655
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
parent 33f71ae4
...@@ -1614,9 +1614,6 @@ it or fix the checkout. ...@@ -1614,9 +1614,6 @@ it or fix the checkout.
patch_repo + '@' + patch_ref patch_repo + '@' + patch_ref
for patch_repo, patch_ref in patch_refs.iteritems()))) for patch_repo, patch_ref in patch_refs.iteritems())))
if self._cipd_root:
self._cipd_root.run(command)
# Once all the dependencies have been processed, it's now safe to write # Once all the dependencies have been processed, it's now safe to write
# out the gn_args_file and run the hooks. # out the gn_args_file and run the hooks.
if command == 'update': if command == 'update':
...@@ -1724,6 +1721,12 @@ it or fix the checkout. ...@@ -1724,6 +1721,12 @@ it or fix the checkout.
gclient_utils.rmtree(e_dir) gclient_utils.rmtree(e_dir)
# record the current list of entries for next time # record the current list of entries for next time
self._SaveEntries() self._SaveEntries()
# Sync CIPD dependencies once removed deps are deleted. In case a git
# dependency was moved to CIPD, we want to remove the old git directory
# first and then sync the CIPD dep.
self.GetCipdRoot().run(command)
return 0 return 0
def PrintRevInfo(self): def PrintRevInfo(self):
......
...@@ -5,10 +5,27 @@ ...@@ -5,10 +5,27 @@
import argparse import argparse
import os import os
import re
import shutil import shutil
import sys import sys
CIPD_SUBDIR_RE = '@Subdir (.*)'
def parse_cipd(root, contents):
tree = {}
current_subdir = None
for line in contents:
line = line.strip()
match = re.match(CIPD_SUBDIR_RE, line)
if match:
current_subdir = os.path.join(root, *match.group(1).split('/'))
elif line and current_subdir:
tree.setdefault(current_subdir, []).append(line)
return tree
def main(): def main():
assert sys.argv[1] == 'ensure' assert sys.argv[1] == 'ensure'
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
...@@ -16,12 +33,18 @@ def main(): ...@@ -16,12 +33,18 @@ def main():
parser.add_argument('-root') parser.add_argument('-root')
args, _ = parser.parse_known_args() args, _ = parser.parse_known_args()
cipd_root = os.path.join(args.root, '.cipd') with open(args.ensure_file) as f:
if not os.path.isdir(cipd_root): new_content = parse_cipd(args.root, f.readlines())
os.makedirs(cipd_root)
# Install new packages
for path, packages in new_content.iteritems():
if not os.path.exists(path):
os.makedirs(path)
with open(os.path.join(path, '_cipd'), 'w') as f:
f.write('\n'.join(packages))
if args.ensure_file: # Save the ensure file that we got
shutil.copy(args.ensure_file, os.path.join(cipd_root, 'ensure')) shutil.copy(args.ensure_file, os.path.join(args.root, '_cipd'))
return 0 return 0
......
...@@ -743,6 +743,23 @@ deps = { ...@@ -743,6 +743,23 @@ deps = {
'origin': 'git/repo_13@2\n', 'origin': 'git/repo_13@2\n',
}) })
# src/repo12 is now a CIPD dependency.
self._commit_git('repo_13', {
'DEPS': """
deps = {
'src/repo12': {
'packages': [
{
'package': 'foo',
'version': '1.3',
},
],
'dep_type': 'cipd',
},
}""",
'origin': 'git/repo_13@3\n'
})
self._commit_git('repo_14', { self._commit_git('repo_14', {
'DEPS': textwrap.dedent("""\ 'DEPS': textwrap.dedent("""\
vars = {} vars = {}
...@@ -932,9 +949,9 @@ class FakeReposTestBase(trial_dir.TestCase): ...@@ -932,9 +949,9 @@ class FakeReposTestBase(trial_dir.TestCase):
actual = read_tree(tree_root) actual = read_tree(tree_root)
diff = dict_diff(tree, actual) diff = dict_diff(tree, actual)
if diff: if diff:
logging.debug('Actual %s\n%s' % (tree_root, pprint.pformat(actual))) logging.error('Actual %s\n%s' % (tree_root, pprint.pformat(actual)))
logging.debug('Expected\n%s' % pprint.pformat(tree)) logging.error('Expected\n%s' % pprint.pformat(tree))
logging.debug('Diff\n%s' % pprint.pformat(diff)) logging.error('Diff\n%s' % pprint.pformat(diff))
self.assertEquals(diff, {}) self.assertEquals(diff, {})
def mangle_git_tree(self, *args): def mangle_git_tree(self, *args):
......
...@@ -514,7 +514,8 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -514,7 +514,8 @@ class GClientSmokeGIT(GClientSmokeBase):
if not self.enabled: if not self.enabled:
return return
self.gclient(['config', self.git_base + 'repo_13', '--name', 'src']) self.gclient(['config', self.git_base + 'repo_13', '--name', 'src'])
_out, _err, rc = self.gclient(['sync', '-v', '-v', '-v']) _out, _err, rc = self.gclient(
['sync', '-v', '-v', '-v', '--revision', self.githash('repo_13', 2)])
self.assertEquals(0, rc) self.assertEquals(0, rc)
def testSyncFetchUpdate(self): def testSyncFetchUpdate(self):
...@@ -529,7 +530,8 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -529,7 +530,8 @@ class GClientSmokeGIT(GClientSmokeBase):
self.assertEquals(0, rc) self.assertEquals(0, rc)
# Make sure update that pulls a non-standard ref works. # Make sure update that pulls a non-standard ref works.
_out, _err, rc = self.gclient(['sync', '-v', '-v', '-v']) _out, _err, rc = self.gclient(
['sync', '-v', '-v', '-v', '--revision', self.githash('repo_13', 2)])
self.assertEquals(0, rc) self.assertEquals(0, rc)
def testSyncDirect(self): def testSyncDirect(self):
...@@ -694,7 +696,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -694,7 +696,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'--revision', 'src@' + self.githash('repo_5', 2)], '--revision', 'src@' + self.githash('repo_5', 2)],
expectation) expectation)
self.assertEquals('Cloning into ', out[0][1][:13]) self.assertEquals('Cloning into ', out[0][1][:13])
self.assertEquals(2, len(out[1])) self.assertEquals(2, len(out[1]), out[1])
self.assertEquals('pre-deps hook', out[1][1]) self.assertEquals('pre-deps hook', out[1][1])
tree = self.mangle_git_tree(('repo_5@2', 'src'), tree = self.mangle_git_tree(('repo_5@2', 'src'),
('repo_1@2', 'src/repo1'), ('repo_1@2', 'src/repo1'),
...@@ -1893,25 +1895,103 @@ class GClientSmokeCipd(GClientSmokeBase): ...@@ -1893,25 +1895,103 @@ class GClientSmokeCipd(GClientSmokeBase):
def testSyncCipd(self): def testSyncCipd(self):
self.gclient(['config', self.git_base + 'repo_14', '--name', 'src']) self.gclient(['config', self.git_base + 'repo_14', '--name', 'src'])
self.gclient(['sync']) out, err, rc = self.gclient(['sync'])
self.assertEquals(0, rc, out + err)
tree = self.mangle_git_tree(('repo_14@1', 'src'))
tree.update({
'_cipd': '\n'.join([
'$ParanoidMode CheckPresence',
'',
'@Subdir src/another_cipd_dep',
'package1 1.1-cr0',
'package2 1.13',
'',
'@Subdir src/cipd_dep',
'package0 0.1',
'',
'@Subdir src/cipd_dep_with_cipd_variable',
'package3/${platform} 1.2',
'',
'',
]),
'src/another_cipd_dep/_cipd': '\n'.join([
'package1 1.1-cr0',
'package2 1.13',
]),
'src/cipd_dep/_cipd': 'package0 0.1',
'src/cipd_dep_with_cipd_variable/_cipd': 'package3/${platform} 1.2',
})
self.assertTree(tree)
with open(os.path.join(self.root_dir, '.cipd', 'ensure')) as f: def testConvertGitToCipd(self):
contents = f.read() self.gclient(['config', self.git_base + 'repo_13', '--name', 'src'])
self.assertEqual([ # repo_13@1 has src/repo12 as a git dependency.
'$ParanoidMode CheckPresence', out, err, rc = self.gclient(
'', ['sync', '-v', '-v', '-v', '--revision', self.githash('repo_13', 1)])
'@Subdir src/another_cipd_dep', self.assertEquals(0, rc, out + err)
'package1 1.1-cr0',
'package2 1.13', tree = self.mangle_git_tree(('repo_13@1', 'src'),
'', ('repo_12@1', 'src/repo12'))
'@Subdir src/cipd_dep', tree['_cipd'] = '$ParanoidMode CheckPresence\n\n'
'package0 0.1', self.assertTree(tree)
'',
'@Subdir src/cipd_dep_with_cipd_variable', # repo_13@3 has src/repo12 as a cipd dependency.
'package3/${platform} 1.2', out, err, rc = self.gclient(
'', ['sync', '-v', '-v', '-v', '--revision', self.githash('repo_13', 3),
], contents.splitlines()) '--delete_unversioned_trees'])
self.assertEquals(0, rc, out + err)
tree = self.mangle_git_tree(('repo_13@3', 'src'))
tree.update({
'_cipd': '\n'.join([
'$ParanoidMode CheckPresence',
'',
'@Subdir src/repo12',
'foo 1.3',
'',
'',
]),
'src/repo12/_cipd': 'foo 1.3',
})
self.assertTree(tree)
def testConvertCipdToGit(self):
self.gclient(['config', self.git_base + 'repo_13', '--name', 'src'])
# repo_13@3 has src/repo12 as a cipd dependency.
out, err, rc = self.gclient(
['sync', '-v', '-v', '-v', '--revision', self.githash('repo_13', 3),
'--delete_unversioned_trees'])
self.assertEquals(0, rc, out + err)
tree = self.mangle_git_tree(('repo_13@3', 'src'))
tree.update({
'_cipd': '\n'.join([
'$ParanoidMode CheckPresence',
'',
'@Subdir src/repo12',
'foo 1.3',
'',
'',
]),
'src/repo12/_cipd': 'foo 1.3',
})
self.assertTree(tree)
# repo_13@1 has src/repo12 as a git dependency.
out, err, rc = self.gclient(
['sync', '-v', '-v', '-v', '--revision', self.githash('repo_13', 1)])
self.assertEquals(0, rc, out + err)
tree = self.mangle_git_tree(('repo_13@1', 'src'),
('repo_12@1', 'src/repo12'))
tree.update({
'_cipd': '$ParanoidMode CheckPresence\n\n',
'src/repo12/_cipd': 'foo 1.3',
})
self.assertTree(tree)
if __name__ == '__main__': if __name__ == '__main__':
......
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