OLD | NEW |
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 """Convert SVN based DEPS into .DEPS.git for use with NewGit.""" |
7 | 7 |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
11 | 11 |
12 import deps_utils | 12 import deps_utils |
13 import git_tools | 13 import git_tools |
14 | 14 |
15 | 15 |
16 def SplitScmUrl(url): | 16 def SplitScmUrl(url): |
17 """Given a repository, return a set containing the URL and the revision.""" | 17 """Given a repository, return a set containing the URL and the revision.""" |
18 url_split = url.split('@') | 18 url_split = url.split('@') |
19 scm_url = url_split[0] | 19 scm_url = url_split[0] |
20 scm_rev = 'HEAD' | 20 scm_rev = 'HEAD' |
21 if len(url_split) == 2: | 21 if len(url_split) == 2: |
22 scm_rev = url_split[1] | 22 scm_rev = url_split[1] |
23 return (scm_url, scm_rev) | 23 return (scm_url, scm_rev) |
24 | 24 |
25 | 25 |
26 def SvnRevToGitHash(svn_rev, git_url, repos_path, git_host): | 26 def SvnRevToGitHash(svn_rev, git_url, repos_path, workspace, dep_path, |
| 27 git_host): |
27 """Convert a SVN revision to a Git commit id.""" | 28 """Convert a SVN revision to a Git commit id.""" |
28 git_repo = None | 29 git_repo = None |
29 if git_url.startswith(git_host): | 30 if git_url.startswith(git_host): |
30 git_repo = git_url.replace(git_host, '') | 31 git_repo = git_url.replace(git_host, '') |
31 else: | 32 else: |
32 raise Exception('Unknown git server') | 33 raise Exception('Unknown git server') |
33 if repos_path is None: | 34 if repos_path is None and workspace is None: |
34 # We're running without a repository directory (i.e. no -r option). | 35 # We're running without a repository directory (i.e. no -r option). |
35 # We cannot actually find the commit id, but this mode is useful | 36 # We cannot actually find the commit id, but this mode is useful |
36 # just for testing the URL mappings. Produce an output file that | 37 # just for testing the URL mappings. Produce an output file that |
37 # can't actually be used, but can be eyeballed for correct URLs. | 38 # can't actually be used, but can be eyeballed for correct URLs. |
38 return 'xxx-r%s' % svn_rev | 39 return 'xxx-r%s' % svn_rev |
39 git_repo_path = os.path.join(repos_path, git_repo) | 40 if repos_path: |
| 41 git_repo_path = os.path.join(repos_path, git_repo) |
| 42 mirror = True |
| 43 else: |
| 44 git_repo_path = os.path.join(workspace, dep_path) |
| 45 mirror = False |
40 if not os.path.exists(git_repo_path): | 46 if not os.path.exists(git_repo_path): |
41 git_tools.Clone(git_url, git_repo_path) | 47 git_tools.Clone(git_url, git_repo_path, mirror) |
42 else: | 48 else: |
43 git_tools.Fetch(git_repo_path) | 49 git_tools.Fetch(git_repo_path, mirror) |
44 return git_tools.Search(git_repo_path, svn_rev) | 50 return git_tools.Search(git_repo_path, svn_rev, mirror) |
45 | 51 |
46 | 52 |
47 def ConvertDepsToGit(deps, repos, deps_type, deps_vars, svn_deps_vars, verify): | 53 def ConvertDepsToGit(deps, repos, workspace, deps_type, deps_vars, |
| 54 svn_deps_vars, verify): |
48 """Convert a 'deps' section in a DEPS file from SVN to Git.""" | 55 """Convert a 'deps' section in a DEPS file from SVN to Git.""" |
49 new_deps = {} | 56 new_deps = {} |
50 bad_git_urls = set([]) | 57 bad_git_urls = set([]) |
51 | 58 |
52 try: | 59 try: |
53 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) | 60 sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
54 svn_to_git = __import__('svn_to_git_%s' % deps_type) | 61 svn_to_git = __import__('svn_to_git_%s' % deps_type) |
55 except ImportError: | 62 except ImportError: |
56 raise Exception('invalid DEPS type') | 63 raise Exception('invalid DEPS type') |
57 | 64 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 '@' + svn_deps_vars[deps_overrides[dep]].lstrip('@')) | 105 '@' + svn_deps_vars[deps_overrides[dep]].lstrip('@')) |
99 # Tag this variable as needing a transform by Varify() later. | 106 # Tag this variable as needing a transform by Varify() later. |
100 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, | 107 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, |
101 deps_overrides[dep]) | 108 deps_overrides[dep]) |
102 else: | 109 else: |
103 # Pass-through the hash for Git repositories. Resolve the hash for | 110 # Pass-through the hash for Git repositories. Resolve the hash for |
104 # subversion repositories. | 111 # subversion repositories. |
105 if dep_url.endswith('.git'): | 112 if dep_url.endswith('.git'): |
106 git_hash = '@%s' % dep_rev | 113 git_hash = '@%s' % dep_rev |
107 else: | 114 else: |
108 git_hash = '@%s' % SvnRevToGitHash(dep_rev, git_url, repos, | 115 git_hash = '@%s' % SvnRevToGitHash(dep_rev, git_url, repos, workspace, |
109 svn_to_git.GIT_HOST) | 116 path, svn_to_git.GIT_HOST) |
110 | 117 |
111 # If this is webkit, we need to add the var for the hash. | 118 # If this is webkit, we need to add the var for the hash. |
112 if dep == 'src/third_party/WebKit/Source': | 119 if dep == 'src/third_party/WebKit/Source': |
113 deps_vars['webkit_rev'] = git_hash | 120 deps_vars['webkit_rev'] = git_hash |
114 git_hash = 'VAR_WEBKIT_REV' | 121 git_hash = 'VAR_WEBKIT_REV' |
115 | 122 |
116 # Add this Git dep to the new deps. | 123 # Add this Git dep to the new deps. |
117 new_deps[path] = '%s%s' % (git_url, git_hash) | 124 new_deps[path] = '%s%s' % (git_url, git_hash) |
118 | 125 |
119 return new_deps, bad_git_urls | 126 return new_deps, bad_git_urls |
120 | 127 |
121 | 128 |
122 def main(): | 129 def main(): |
123 parser = optparse.OptionParser() | 130 parser = optparse.OptionParser() |
124 parser.add_option('-d', '--deps', default='DEPS', | 131 parser.add_option('-d', '--deps', default='DEPS', |
125 help='path to the DEPS file to convert') | 132 help='path to the DEPS file to convert') |
126 parser.add_option('-o', '--out', | 133 parser.add_option('-o', '--out', |
127 help='path to the converted DEPS file (default: stdout)') | 134 help='path to the converted DEPS file (default: stdout)') |
128 parser.add_option('-t', '--type', default='public', | 135 parser.add_option('-t', '--type', default='public', |
129 help='type of DEPS file (public, etc)') | 136 help='type of DEPS file (public, etc)') |
130 parser.add_option('-r', '--repos', | 137 parser.add_option('-r', '--repos', |
131 help='path to the directory holding all the Git repos') | 138 help='path to the directory holding all the Git repos') |
| 139 parser.add_option('-w', '--workspace', metavar='PATH', |
| 140 help='top level of a git-based gclient checkout') |
132 parser.add_option('--verify', action='store_true', | 141 parser.add_option('--verify', action='store_true', |
133 help='ping each Git repo to make sure it exists') | 142 help='ping each Git repo to make sure it exists') |
134 options = parser.parse_args()[0] | 143 options = parser.parse_args()[0] |
135 | 144 |
136 # Get the content of the DEPS file. | 145 # Get the content of the DEPS file. |
137 deps_content = deps_utils.GetDepsContent(options.deps) | 146 deps_content = deps_utils.GetDepsContent(options.deps) |
138 (deps, deps_os, include_rules, skip_child_includes, hooks, | 147 (deps, deps_os, include_rules, skip_child_includes, hooks, |
139 svn_deps_vars) = deps_content | 148 svn_deps_vars) = deps_content |
140 | 149 |
141 # Create a var containing the Git and Webkit URL, this will make it easy for | 150 # Create a var containing the Git and Webkit URL, this will make it easy for |
142 # people to use a mirror instead. | 151 # people to use a mirror instead. |
143 git_url = 'http://git.chromium.org' | 152 git_url = 'http://git.chromium.org' |
144 deps_vars = { | 153 deps_vars = { |
145 'git_url': git_url, | 154 'git_url': git_url, |
146 'webkit_url': git_url + '/external/WebKit_trimmed.git' | 155 'webkit_url': git_url + '/external/WebKit_trimmed.git' |
147 } | 156 } |
148 | 157 |
149 # Convert the DEPS file to Git. | 158 # Convert the DEPS file to Git. |
150 deps, baddeps = ConvertDepsToGit(deps, options.repos, options.type, deps_vars, | 159 deps, baddeps = ConvertDepsToGit(deps, options.repos, options.workspace, |
151 svn_deps_vars, options.verify) | 160 options.type, deps_vars, svn_deps_vars, |
| 161 options.verify) |
152 for os_dep in deps_os: | 162 for os_dep in deps_os: |
153 deps_os[os_dep], os_bad_deps = ConvertDepsToGit(deps_os[os_dep], | 163 deps_os[os_dep], os_bad_deps = ConvertDepsToGit(deps_os[os_dep], |
154 options.repos, options.type, deps_vars, | 164 options.repos, options.workspace, |
155 svn_deps_vars, options.verify) | 165 options.type, deps_vars, svn_deps_vars, |
| 166 options.verify) |
156 baddeps = baddeps.union(os_bad_deps) | 167 baddeps = baddeps.union(os_bad_deps) |
157 | 168 |
158 if baddeps: | 169 if baddeps: |
159 print >>sys.stderr, ('\nUnable to resolve the following repositories. ' | 170 print >>sys.stderr, ('\nUnable to resolve the following repositories. ' |
160 'Please make sure\nthat any svn URLs have a git mirror associated with ' | 171 'Please make sure\nthat any svn URLs have a git mirror associated with ' |
161 'them.\nTo see the exact error, run `git ls-remote [repository]` where' | 172 'them.\nTo see the exact error, run `git ls-remote [repository]` where' |
162 '\n[repository] is the URL ending in .git (strip off the @revision\n' | 173 '\n[repository] is the URL ending in .git (strip off the @revision\n' |
163 'number.) For more information, visit http://code.google.com\n' | 174 'number.) For more information, visit http://code.google.com\n' |
164 '/p/chromium/wiki/UsingNewGit#Adding_new_repositories_to_DEPS.\n') | 175 '/p/chromium/wiki/UsingNewGit#Adding_new_repositories_to_DEPS.\n') |
165 for dep in baddeps: | 176 for dep in baddeps: |
166 print >>sys.stderr, ' ' + dep | 177 print >>sys.stderr, ' ' + dep |
167 return 2 | 178 return 2 |
168 else: | 179 else: |
169 if options.verify: | 180 if options.verify: |
170 print >>sys.stderr, ('\nAll referenced repositories were successfully ' | 181 print >>sys.stderr, ('\nAll referenced repositories were successfully ' |
171 'resolved.') | 182 'resolved.') |
172 return 0 | 183 return 0 |
173 | 184 |
174 # Write the DEPS file to disk. | 185 # Write the DEPS file to disk. |
175 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, | 186 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, |
176 skip_child_includes, hooks) | 187 skip_child_includes, hooks) |
177 return 0 | 188 return 0 |
178 | 189 |
179 | 190 |
180 if '__main__' == __name__: | 191 if '__main__' == __name__: |
181 sys.exit(main()) | 192 sys.exit(main()) |
OLD | NEW |