Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: deps2git.py

Issue 9359045: Add support for non-git-svn repos. Fix syntax errors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/deps2git/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | deps_utils.py » ('j') | deps_utils.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Convert SVN based DEPS into .DEPS.git for use with NewGit."""
6 7
7 import optparse 8 import optparse
9 import os
8 import sys 10 import sys
9 11
10
11 import deps_utils 12 import deps_utils
13 import git_tools
12 14
13 15
14 def SplitSvnUrl(url): 16 def SplitSvnUrl(url):
15 """Given a SVN URL, return a set containing the URL and the revision.""" 17 """Given a SVN URL, return a set containing the URL and the revision."""
16 url_split = url.split('@') 18 url_split = url.split('@')
17 svn_url = url_split[0] 19 svn_url = url_split[0]
18 svn_rev = 'HEAD' 20 svn_rev = 'HEAD'
19 if len(url_split) == 2: 21 if len(url_split) == 2:
20 svn_rev = url_split[1] 22 svn_rev = url_split[1]
21 return (svn_url, svn_rev) 23 return (svn_url, svn_rev)
22 24
23 25
24 def SvnRevToGitHash(svn_rev, git_url, repos_path, git_host): 26 def SvnRevToGitHash(svn_rev, git_url, repos_path, git_host):
25 """Convert a SVN revision to a Git commit id.""" 27 """Convert a SVN revision to a Git commit id."""
26 git_repo = None 28 git_repo = None
27 if git_url.startswith(git_host): 29 if git_url.startswith(git_host):
28 git_repo = git_url.replace(git_host, '') 30 git_repo = git_url.replace(git_host, '')
29 else: 31 else:
30 raise Exception('Unknown git server') 32 raise Exception('Unknown git server')
31 if repos_path is None: 33 if repos_path is None:
32 # We're running without a repository directory (i.e. no -r option). 34 # We're running without a repository directory (i.e. no -r option).
33 # We cannot actually find the commit id, but this mode is useful 35 # We cannot actually find the commit id, but this mode is useful
34 # just for testing the URL mappings. Produce an output file that 36 # just for testing the URL mappings. Produce an output file that
35 # can't actually be used, but can be eyeballed for correct URLs. 37 # can't actually be used, but can be eyeballed for correct URLs.
36 return ('xxx-r%s' % svn_rev) 38 return 'xxx-r%s' % svn_rev
37 # TODO(unknown_coder): Most of the errors happen when people add new repos 39 # TODO(unknown_coder): Most of the errors happen when people add new repos
38 # that actually matches one of our expressions but dont exist yet on 40 # that actually matches one of our expressions but dont exist yet on
39 # git.chromium.org. We should probably at least ping git_url to make sure it 41 # git.chromium.org. We should probably at least ping git_url to make sure it
40 # exists. 42 # exists.
41 git_repo_path = os.path.join(repos_path, git_repo) 43 git_repo_path = os.path.join(repos_path, git_repo)
42 if not os.path.exists(git_repo_path): 44 if not os.path.exists(git_repo_path):
43 git_tools.Clone(git_url, git_repo_path) 45 git_tools.Clone(git_url, git_repo_path)
44 git_tools.Fetch(git_repo_path) 46 git_tools.Fetch(git_repo_path)
45 return git_tools.Search(git_repo_path, svn_rev) 47 return git_tools.Search(git_repo_path, svn_rev)
46 48
47 49
48 def ConvertDepsToGit(deps, repos, deps_type, vars) 50 def ConvertDepsToGit(deps, repos, deps_type, deps_vars, deps_overrides):
49 """Convert a 'deps' section in a DEPS file from SVN to Git.""" 51 """Convert a 'deps' section in a DEPS file from SVN to Git."""
50 new_deps = {} 52 new_deps = {}
51 deps_module = os.path.join(os.path.dirname(__file__), 53 try:
52 'svn_to_git_%s' % deps_type) 54 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
53 if not os.path.exists(depos_module): 55 svn_to_git = __import__('svn_to_git_%s' % deps_type)
56 except ImportError:
54 raise Exception('invalid DEPS type') 57 raise Exception('invalid DEPS type')
55 svn_to_git = __import__(deps_module)
56 58
57 for dep in deps: 59 for dep in deps:
58 # Get the SVN URL and the SVN rev for this dep. 60 # Get the SVN URL and the SVN rev for this dep.
59 (svn_url, svn_rev) = SplitSvnUrl(deps[dep]) 61 svn_url, svn_rev = SplitSvnUrl(deps[dep])
60 62
61 # Convert this SVN URL to a Git URL. 63 # Convert this SVN URL to a Git URL.
62 (path, git_url) = svn_to_git.SvnUrlToGitUrl(dep, svn_url) 64 path, git_url = svn_to_git.SvnUrlToGitUrl(dep, svn_url)
63 65
64 if not path or not git_url: 66 if not path or not git_url:
65 # We skip this path, this must not be required with Git. 67 # We skip this path, this must not be required with Git.
66 continue 68 continue
67 69
68 # Get the Git hash based off the SVN rev. 70 # Get the Git hash based off the SVN rev.
69 git_hash = '' 71 git_hash = ''
70 if svn_rev != 'HEAD': 72 if svn_rev != 'HEAD':
71 git_hash = '@%s' % SvnRevToGitHash(svn_rev, git_url, repos, 73 if dep in deps_overrides:
72 svn_to_git.GIT_HOST) 74 git_hash = 'VAR_HASH_TEMP_%s' % deps_overrides[dep]
75 else:
76 git_hash = '@%s' % SvnRevToGitHash(svn_rev, git_url, repos,
77 svn_to_git.GIT_HOST)
73 78
74 # If this is webkit, we need to add the var for the hash. 79 # If this is webkit, we need to add the var for the hash.
75 if dep == 'src/third_party/WebKit/Source': 80 if dep == 'src/third_party/WebKit/Source':
76 vars['webkit_rev'] = git_hash 81 deps_vars['webkit_rev'] = git_hash
77 git_hash = 'VAR_WEBKIT_REV' 82 git_hash = 'VAR_WEBKIT_REV'
78 83
79 # Add this Git dep to the new deps. 84 # Add this Git dep to the new deps.
80 new_deps[path] = '%s%s' % (git_url, git_hash) 85 new_deps[path] = '%s%s' % (git_url, git_hash)
81 86
82 return new_deps 87 return new_deps
83 88
84 89
85 def main(): 90 def main():
86 parser = optparse.OptionParser() 91 parser = optparse.OptionParser()
87 parser.add_option('-d', '--deps', 92 parser.add_option('-d', '--deps',
88 help='path to the DEPS file to convert') 93 help='path to the DEPS file to convert')
89 parser.add_option('-o', '--out', 94 parser.add_option('-o', '--out',
90 help='path to the converted DEPS file') 95 help='path to the converted DEPS file')
91 parser.add_option('-t', '--type', default='public', 96 parser.add_option('-t', '--type', default='public',
92 help='type of DEPS file (public, etc)') 97 help='type of DEPS file (public, etc)')
93 parser.add_option('-r', '--repos', 98 parser.add_option('-r', '--repos',
94 help='path to the directory holding all the Git repos') 99 help='path to the directory holding all the Git repos')
95 options, args = parser.parse_args() 100 options = parser.parse_args()[0]
96 101
97 # Get the content of the DEPS file. 102 # Get the content of the DEPS file.
98 deps_content = deps_utils.GetDepsContent(options.deps) 103 deps_content = deps_utils.GetDepsContent(options.deps)
99 (deps, deps_os, include_rules, skip_child_includes, hooks) = deps_content 104 (deps, deps_os, include_rules, skip_child_includes, hooks,
105 svn_deps_vars) = deps_content
100 106
101 # Create a var containing the Git and Webkit URL, this will make it easy for 107 # Create a var containing the Git and Webkit URL, this will make it easy for
102 # people to use a mirror instead. 108 # people to use a mirror instead.
103 vars = {'git_url': 'http://git.chromium.org', 109 git_url = 'http://git.chromium.org'
104 'webkit_url': 'http://git.chromium.org/external/WebKit_trimmed.git'} 110 deps_vars = {
111 'git_url': git_url,
112 'webkit_url': git_url + '/external/WebKit_trimmed.git'
113 }
114
115 # Overrides for SVN DEPS. Each entry maps a dep name to a .DEPS.git variable
116 # identifying the hash. Values are automatically pulled from svn_deps_vars
117 # and wrapped in the appropriate Var('<var_name>') syntax below.
118 deps_overrides = {
nsylvain 2012/02/15 17:43:39 Open question: Is there any way this code can be m
DaleCurtis 2012/02/15 20:49:50 Which other file? I tried to be as generic as poss
DaleCurtis 2012/02/16 02:38:37 Done.
119 'src/third_party/ffmpeg': 'ffmpeg_hash'
120 }
121
122 # Transfer any required variables over from DEPS.
123 for value in deps_overrides.values():
124 deps_vars[value] = '@' + svn_deps_vars[value].lstrip('@')
105 125
106 # Convert the DEPS file to Git. 126 # Convert the DEPS file to Git.
107 deps = ConvertDepsToGit(deps, options.repos, options.type, vars) 127 deps = ConvertDepsToGit(deps, options.repos, options.type, deps_vars,
128 deps_overrides)
108 for os_dep in deps_os: 129 for os_dep in deps_os:
109 deps_os[os_dep] = ConvertDepsToGit(deps_os[os_dep], options.repos, 130 deps_os[os_dep] = ConvertDepsToGit(deps_os[os_dep], options.repos,
110 options.type, vars) 131 options.type, deps_vars, deps_overrides)
111 132
112 # Write the DEPS file to disk. 133 # Write the DEPS file to disk.
113 deps_utils.WriteDeps(options.out, vars, deps, deps_os, include_rules, 134 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules,
114 skip_child_includes, hooks) 135 skip_child_includes, hooks, deps_overrides)
115 return 0 136 return 0
116 137
138
117 if '__main__' == __name__: 139 if '__main__' == __name__:
118 sys.exit(main()) 140 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | deps_utils.py » ('j') | deps_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698