Add a --deps-file flag to gclient to allow using a deps file other than DEPS.

TEST=covered by gclient_smoketest.py
Review URL: http://codereview.chromium.org/7062029

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@87367 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
nsylvain@google.com 14 years ago
parent 9842a0c754
commit efc8093168

@ -138,7 +138,6 @@ class GClientKeywords(object):
class Dependency(GClientKeywords, gclient_utils.WorkItem): class Dependency(GClientKeywords, gclient_utils.WorkItem):
"""Object that represents a dependency checkout.""" """Object that represents a dependency checkout."""
DEPS_FILE = 'DEPS'
def __init__(self, parent, name, url, safesync_url, custom_deps, def __init__(self, parent, name, url, safesync_url, custom_deps,
custom_vars, deps_file, should_process): custom_vars, deps_file, should_process):
@ -154,7 +153,7 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem):
self.custom_deps = custom_deps or {} self.custom_deps = custom_deps or {}
self.deps_hooks = [] self.deps_hooks = []
self.dependencies = [] self.dependencies = []
self.deps_file = deps_file or self.DEPS_FILE self.deps_file = deps_file
# A cache of the files affected by the current operation, necessary for # A cache of the files affected by the current operation, necessary for
# hooks. # hooks.
self._file_list = [] self._file_list = []
@ -266,7 +265,8 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem):
} }
filepath = os.path.join(self.root_dir(), self.name, self.deps_file) filepath = os.path.join(self.root_dir(), self.name, self.deps_file)
if not os.path.isfile(filepath): if not os.path.isfile(filepath):
logging.info('%s: No DEPS file found at %s' % (self.name, filepath)) logging.info('%s: No %s file found at %s' % (self.name, self.deps_file,
filepath))
else: else:
deps_content = gclient_utils.FileRead(filepath) deps_content = gclient_utils.FileRead(filepath)
logging.debug(deps_content) logging.debug(deps_content)
@ -331,7 +331,7 @@ class Dependency(GClientKeywords, gclient_utils.WorkItem):
'Dependency %s specified more than once:\n %s\nvs\n %s' % 'Dependency %s specified more than once:\n %s\nvs\n %s' %
(name, tree[name].hierarchy(), self.hierarchy())) (name, tree[name].hierarchy(), self.hierarchy()))
self.dependencies.append(Dependency(self, name, url, None, None, None, self.dependencies.append(Dependency(self, name, url, None, None, None,
None, should_process)) self.deps_file, should_process))
logging.debug('Loaded: %s' % str(self)) logging.debug('Loaded: %s' % str(self))
# Arguments number differs from overridden method # Arguments number differs from overridden method
@ -585,6 +585,7 @@ class GClient(Dependency):
solutions = [ solutions = [
{ "name" : "%(solution_name)s", { "name" : "%(solution_name)s",
"url" : "%(solution_url)s", "url" : "%(solution_url)s",
"deps_file" : "%(deps_file)s",
"custom_deps" : { "custom_deps" : {
}, },
"safesync_url": "%(safesync_url)s", "safesync_url": "%(safesync_url)s",
@ -595,6 +596,7 @@ solutions = [
DEFAULT_SNAPSHOT_SOLUTION_TEXT = ("""\ DEFAULT_SNAPSHOT_SOLUTION_TEXT = ("""\
{ "name" : "%(solution_name)s", { "name" : "%(solution_name)s",
"url" : "%(solution_url)s", "url" : "%(solution_url)s",
"deps_file" : "%(deps_file)s",
"custom_deps" : { "custom_deps" : {
%(solution_deps)s }, %(solution_deps)s },
"safesync_url": "%(safesync_url)s", "safesync_url": "%(safesync_url)s",
@ -611,7 +613,8 @@ solutions = [
# Do not change previous behavior. Only solution level and immediate DEPS # Do not change previous behavior. Only solution level and immediate DEPS
# are processed. # are processed.
self._recursion_limit = 2 self._recursion_limit = 2
Dependency.__init__(self, None, None, None, None, None, None, None, True) Dependency.__init__(self, None, None, None, None, None, None, 'unused',
True)
self._options = options self._options = options
if options.deps_os: if options.deps_os:
enforced_os = options.deps_os.split(',') enforced_os = options.deps_os.split(',')
@ -642,7 +645,7 @@ solutions = [
s.get('safesync_url', None), s.get('safesync_url', None),
s.get('custom_deps', {}), s.get('custom_deps', {}),
s.get('custom_vars', {}), s.get('custom_vars', {}),
None, s.get('deps_file', 'DEPS'),
True)) True))
except KeyError: except KeyError:
raise gclient_utils.Error('Invalid .gclient file. Solution is ' raise gclient_utils.Error('Invalid .gclient file. Solution is '
@ -668,10 +671,12 @@ solutions = [
os.path.join(path, options.config_filename))) os.path.join(path, options.config_filename)))
return client return client
def SetDefaultConfig(self, solution_name, solution_url, safesync_url): def SetDefaultConfig(self, solution_name, deps_file, solution_url,
safesync_url):
self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % {
'solution_name': solution_name, 'solution_name': solution_name,
'solution_url': solution_url, 'solution_url': solution_url,
'deps_file': deps_file,
'safesync_url' : safesync_url, 'safesync_url' : safesync_url,
}) })
@ -846,6 +851,7 @@ solutions = [
new_gclient += self.DEFAULT_SNAPSHOT_SOLUTION_TEXT % { new_gclient += self.DEFAULT_SNAPSHOT_SOLUTION_TEXT % {
'solution_name': d.name, 'solution_name': d.name,
'solution_url': d.url, 'solution_url': d.url,
'deps_file': d.deps_file,
'safesync_url' : d.safesync_url or '', 'safesync_url' : d.safesync_url or '',
'solution_deps': ''.join(custom_deps), 'solution_deps': ''.join(custom_deps),
} }
@ -964,6 +970,11 @@ URL.
'probably can\'t contain any newlines.') 'probably can\'t contain any newlines.')
parser.add_option('--name', parser.add_option('--name',
help='overrides the default name for the solution') help='overrides the default name for the solution')
parser.add_option('--deps-file', default='DEPS',
help='overrides the default name for the DEPS file for the'
'main solutions and all sub-dependencies')
parser.add_option('--git-deps', action='store_true',
help='sets the deps file to ".DEPS.git" instead of "DEPS"')
(options, args) = parser.parse_args(args) (options, args) = parser.parse_args(args)
if ((options.spec and args) or len(args) > 2 or if ((options.spec and args) or len(args) > 2 or
(not options.spec and not args)): (not options.spec and not args)):
@ -982,10 +993,13 @@ URL.
else: else:
# specify an alternate relpath for the given URL. # specify an alternate relpath for the given URL.
name = options.name name = options.name
deps_file = options.deps_file
if options.git_deps:
deps_file = '.DEPS.git'
safesync_url = '' safesync_url = ''
if len(args) > 1: if len(args) > 1:
safesync_url = args[1] safesync_url = args[1]
client.SetDefaultConfig(name, base_url, safesync_url) client.SetDefaultConfig(name, deps_file, base_url, safesync_url)
client.SaveConfig() client.SaveConfig()
return 0 return 0

@ -433,7 +433,7 @@ class FakeRepos(FakeReposBase):
'-q', '--non-interactive', '--no-auth-cache', '-q', '--non-interactive', '--no-auth-cache',
'--username', self.USERS[0][0], '--password', self.USERS[0][1]]) '--username', self.USERS[0][0], '--password', self.USERS[0][1]])
assert os.path.isdir(join(self.svn_checkout, '.svn')) assert os.path.isdir(join(self.svn_checkout, '.svn'))
def file_system(rev, DEPS): def file_system(rev, DEPS, DEPS_ALT=None):
fs = { fs = {
'origin': 'svn@%(rev)d\n', 'origin': 'svn@%(rev)d\n',
'trunk/origin': 'svn/trunk@%(rev)d\n', 'trunk/origin': 'svn/trunk@%(rev)d\n',
@ -447,6 +447,8 @@ class FakeRepos(FakeReposBase):
for k in fs.iterkeys(): for k in fs.iterkeys():
fs[k] = fs[k] % { 'rev': rev } fs[k] = fs[k] % { 'rev': rev }
fs['trunk/src/DEPS'] = DEPS fs['trunk/src/DEPS'] = DEPS
if DEPS_ALT:
fs['trunk/src/DEPS.alt'] = DEPS_ALT
return fs return fs
# Testing: # Testing:
@ -462,7 +464,7 @@ class FakeRepos(FakeReposBase):
# TODO(maruel): # TODO(maruel):
# - $matching_files # - $matching_files
# - use_relative_paths # - use_relative_paths
fs = file_system(1, """ DEPS = """
vars = { vars = {
'DummyVariable': 'third_party', 'DummyVariable': 'third_party',
} }
@ -474,7 +476,15 @@ deps_os = {
'mac': { 'mac': {
'src/third_party/prout': '/trunk/third_party/prout', 'src/third_party/prout': '/trunk/third_party/prout',
}, },
}""" % { 'svn_base': self.svn_base }) }""" % { 'svn_base': self.svn_base }
DEPS_ALT = """
deps = {
'src/other2': '%(svn_base)strunk/other@2'
}
""" % { 'svn_base': self.svn_base }
fs = file_system(1, DEPS, DEPS_ALT)
self._commit_svn(fs) self._commit_svn(fs)
fs = file_system(2, """ fs = file_system(2, """

@ -199,6 +199,7 @@ class GClientSmoke(GClientSmokeBase):
('solutions = [\n' ('solutions = [\n'
' { "name" : "src",\n' ' { "name" : "src",\n'
' "url" : "%strunk/src",\n' ' "url" : "%strunk/src",\n'
' "deps_file" : "DEPS",\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "safesync_url": "",\n' ' "safesync_url": "",\n'
@ -209,6 +210,7 @@ class GClientSmoke(GClientSmokeBase):
('solutions = [\n' ('solutions = [\n'
' { "name" : "src",\n' ' { "name" : "src",\n'
' "url" : "%srepo_1",\n' ' "url" : "%srepo_1",\n'
' "deps_file" : "DEPS",\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "safesync_url": "",\n' ' "safesync_url": "",\n'
@ -219,12 +221,24 @@ class GClientSmoke(GClientSmokeBase):
'solutions = [\n' 'solutions = [\n'
' { "name" : "foo",\n' ' { "name" : "foo",\n'
' "url" : "foo",\n' ' "url" : "foo",\n'
' "deps_file" : "DEPS",\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' },\n' ' },\n'
' "safesync_url": "faa",\n' ' "safesync_url": "faa",\n'
' },\n' ' },\n'
']\n') ']\n')
test(['config', 'foo', '--deps', 'blah'],
'solutions = [\n'
' { "name" : "foo",\n'
' "url" : "foo",\n'
' "deps_file" : "blah",\n'
' "custom_deps" : {\n'
' },\n'
' "safesync_url": "",\n'
' },\n'
']\n')
test(['config', '--spec', '["blah blah"]'], '["blah blah"]') test(['config', '--spec', '["blah blah"]'], '["blah blah"]')
os.remove(p) os.remove(p)
@ -672,6 +686,7 @@ class GClientSmokeSVN(GClientSmokeBase):
'solutions = [\n' 'solutions = [\n'
' { "name" : "src",\n' ' { "name" : "src",\n'
' "url" : "%(base)s/src",\n' ' "url" : "%(base)s/src",\n'
' "deps_file" : "DEPS",\n'
' "custom_deps" : {\n' ' "custom_deps" : {\n'
' "foo/bar": None,\n' ' "foo/bar": None,\n'
' "invalid": None,\n' ' "invalid": None,\n'
@ -686,6 +701,28 @@ class GClientSmokeSVN(GClientSmokeBase):
{ 'base': self.svn_base + 'trunk' }) { 'base': self.svn_base + 'trunk' })
self.check((out, '', 0), results) self.check((out, '', 0), results)
def testRevInfoAltDeps(self):
if not self.enabled:
return
self.gclient(['config', self.svn_base + 'trunk/src/', '--deps-file',
'DEPS.alt'])
self.gclient(['sync'])
results = self.gclient(['revinfo', '--snapshot'])
out = ('# Snapshot generated with gclient revinfo --snapshot\n'
'solutions = [\n'
' { "name" : "src",\n'
' "url" : "%(base)s/src",\n'
' "deps_file" : "DEPS.alt",\n'
' "custom_deps" : {\n'
' "src/other2": \'%(base)s/other@2\',\n'
' },\n'
' "safesync_url": "",\n'
' },\n'
']\n\n' %
{ 'base': self.svn_base + 'trunk' })
self.check((out, '', 0), results)
def testWrongDirectory(self): def testWrongDirectory(self):
# Check that we're not using a .gclient configuration which only talks # Check that we're not using a .gclient configuration which only talks
# about a subdirectory src when we're in a different subdirectory src-other. # about a subdirectory src when we're in a different subdirectory src-other.

Loading…
Cancel
Save