Commit 4b90e3a5 authored by piman@chromium.org's avatar piman@chromium.org

Add gclient recurse

This allows to recurse in all the entries to operate on them.

Review URL: http://codereview.chromium.org/2862039

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@51419 0039d316-1c4b-4281-b951-d872f2087c98
parent f6613be3
......@@ -57,6 +57,7 @@ import optparse
import os
import pprint
import re
import subprocess
import sys
import urlparse
import urllib
......@@ -856,6 +857,35 @@ Mostly svn-specific. Simply runs 'svn cleanup' for each module.
return client.RunOnDeps('cleanup', args)
@attr('usage', '[command] [args ...]')
def CMDrecurse(parser, args):
"""Operates on all the entries.
Runs a shell command on all entries.
"""
# Stop parsing at the first non-arg so that these go through to the command
parser.disable_interspersed_args()
parser.add_option('-s', '--scm', action='append', default=[],
help='choose scm types to operate upon')
options, args = parser.parse_args(args)
root, entries = gclient_utils.GetGClientRootAndEntries()
scm_set = set()
for scm in options.scm:
scm_set.update(scm.split(','))
# Pass in the SCM type as an env variable
env = os.environ.copy()
for path, url in entries.iteritems():
scm = gclient_scm.GetScmName(url)
if scm_set and scm not in scm_set:
continue
dir = os.path.normpath(os.path.join(root, path))
env['GCLIENT_SCM'] = scm
env['GCLIENT_URL'] = url
subprocess.Popen(args, cwd=dir, env=env).communicate()
@attr('usage', '[url] [safesync url]')
def CMDconfig(parser, args):
"""Create a .gclient file in the current directory.
......
......@@ -660,6 +660,37 @@ class GClientSmokeBoth(GClientSmokeBase):
}
self.check((out, '', 0), results)
def testRecurse(self):
if not self.enabled:
return
self.gclient(['config', '--spec',
'solutions=['
'{"name": "src",'
' "url": "' + self.svn_base + 'trunk/src/"},'
'{"name": "src-git",'
'"url": "' + self.git_base + 'repo_1"}]'])
self.gclient(['sync', '--deps', 'mac'])
results = self.gclient(['recurse', 'sh', '-c',
'echo $GCLIENT_SCM,$GCLIENT_URL,`pwd`'])
entries = [tuple(line.split(','))
for line in results[0].strip().split('\n')]
logging.debug(entries)
bases = {'svn': self.svn_base, 'git': self.git_base}
expected_source = [
('svn', 'trunk/src/', 'src'),
('git', 'repo_1', 'src-git'),
('svn', 'trunk/other', 'src/other'),
('git', 'repo_2@' + self.githash('repo_2', 1)[:7], 'src/repo2'),
('git', 'repo_3', 'src/repo2/repo_renamed'),
('svn', 'trunk/third_party/foo@1', 'src/third_party/foo'),
]
expected = [(scm, bases[scm] + url, os.path.join(self.root_dir, path))
for (scm, url, path) in expected_source]
self.assertEquals(sorted(entries), sorted(expected))
if __name__ == '__main__':
if '-c' 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