| 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 | 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, svn_deps_vars): |
| 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) | 58 |
| 59 # Pull in any DEPS overrides from svn_to_git. |
| 60 deps_overrides = {} |
| 61 if hasattr(svn_to_git, 'DEPS_OVERRIDES'): |
| 62 deps_overrides.update(svn_to_git.DEPS_OVERRIDES) |
| 56 | 63 |
| 57 for dep in deps: | 64 for dep in deps: |
| 58 # Get the SVN URL and the SVN rev for this dep. | 65 # Get the SVN URL and the SVN rev for this dep. |
| 59 (svn_url, svn_rev) = SplitSvnUrl(deps[dep]) | 66 svn_url, svn_rev = SplitSvnUrl(deps[dep]) |
| 60 | 67 |
| 61 # Convert this SVN URL to a Git URL. | 68 # Convert this SVN URL to a Git URL. |
| 62 (path, git_url) = svn_to_git.SvnUrlToGitUrl(dep, svn_url) | 69 path, git_url = svn_to_git.SvnUrlToGitUrl(dep, svn_url) |
| 63 | 70 |
| 64 if not path or not git_url: | 71 if not path or not git_url: |
| 65 # We skip this path, this must not be required with Git. | 72 # We skip this path, this must not be required with Git. |
| 66 continue | 73 continue |
| 67 | 74 |
| 68 # Get the Git hash based off the SVN rev. | 75 # Get the Git hash based off the SVN rev. |
| 69 git_hash = '' | 76 git_hash = '' |
| 70 if svn_rev != 'HEAD': | 77 if svn_rev != 'HEAD': |
| 71 git_hash = '@%s' % SvnRevToGitHash(svn_rev, git_url, repos, | 78 if dep in deps_overrides: |
| 72 svn_to_git.GIT_HOST) | 79 # Transfer any required variables over from SVN DEPS. |
| 80 if not deps_overrides[dep] in svn_deps_vars: |
| 81 raise Exception('Missing DEPS variable: %s' % deps_overrides[dep]) |
| 82 deps_vars[deps_overrides[dep]] = ( |
| 83 '@' + svn_deps_vars[deps_overrides[dep]].lstrip('@')) |
| 84 # Tag this variable as needing a transform by Varify() later. |
| 85 git_hash = '%s_%s' % (deps_utils.VARIFY_MARKER_TAG_PREFIX, |
| 86 deps_overrides[dep]) |
| 87 else: |
| 88 git_hash = '@%s' % SvnRevToGitHash(svn_rev, git_url, repos, |
| 89 svn_to_git.GIT_HOST) |
| 73 | 90 |
| 74 # If this is webkit, we need to add the var for the hash. | 91 # If this is webkit, we need to add the var for the hash. |
| 75 if dep == 'src/third_party/WebKit/Source': | 92 if dep == 'src/third_party/WebKit/Source': |
| 76 vars['webkit_rev'] = git_hash | 93 deps_vars['webkit_rev'] = git_hash |
| 77 git_hash = 'VAR_WEBKIT_REV' | 94 git_hash = 'VAR_WEBKIT_REV' |
| 78 | 95 |
| 79 # Add this Git dep to the new deps. | 96 # Add this Git dep to the new deps. |
| 80 new_deps[path] = '%s%s' % (git_url, git_hash) | 97 new_deps[path] = '%s%s' % (git_url, git_hash) |
| 81 | 98 |
| 82 return new_deps | 99 return new_deps |
| 83 | 100 |
| 84 | 101 |
| 85 def main(): | 102 def main(): |
| 86 parser = optparse.OptionParser() | 103 parser = optparse.OptionParser() |
| 87 parser.add_option('-d', '--deps', | 104 parser.add_option('-d', '--deps', |
| 88 help='path to the DEPS file to convert') | 105 help='path to the DEPS file to convert') |
| 89 parser.add_option('-o', '--out', | 106 parser.add_option('-o', '--out', |
| 90 help='path to the converted DEPS file') | 107 help='path to the converted DEPS file') |
| 91 parser.add_option('-t', '--type', default='public', | 108 parser.add_option('-t', '--type', default='public', |
| 92 help='type of DEPS file (public, etc)') | 109 help='type of DEPS file (public, etc)') |
| 93 parser.add_option('-r', '--repos', | 110 parser.add_option('-r', '--repos', |
| 94 help='path to the directory holding all the Git repos') | 111 help='path to the directory holding all the Git repos') |
| 95 options, args = parser.parse_args() | 112 options = parser.parse_args()[0] |
| 96 | 113 |
| 97 # Get the content of the DEPS file. | 114 # Get the content of the DEPS file. |
| 98 deps_content = deps_utils.GetDepsContent(options.deps) | 115 deps_content = deps_utils.GetDepsContent(options.deps) |
| 99 (deps, deps_os, include_rules, skip_child_includes, hooks) = deps_content | 116 (deps, deps_os, include_rules, skip_child_includes, hooks, |
| 117 svn_deps_vars) = deps_content |
| 100 | 118 |
| 101 # Create a var containing the Git and Webkit URL, this will make it easy for | 119 # Create a var containing the Git and Webkit URL, this will make it easy for |
| 102 # people to use a mirror instead. | 120 # people to use a mirror instead. |
| 103 vars = {'git_url': 'http://git.chromium.org', | 121 git_url = 'http://git.chromium.org' |
| 104 'webkit_url': 'http://git.chromium.org/external/WebKit_trimmed.git'} | 122 deps_vars = { |
| 123 'git_url': git_url, |
| 124 'webkit_url': git_url + '/external/WebKit_trimmed.git' |
| 125 } |
| 105 | 126 |
| 106 # Convert the DEPS file to Git. | 127 # Convert the DEPS file to Git. |
| 107 deps = ConvertDepsToGit(deps, options.repos, options.type, vars) | 128 deps = ConvertDepsToGit(deps, options.repos, options.type, deps_vars, |
| 129 svn_deps_vars) |
| 108 for os_dep in deps_os: | 130 for os_dep in deps_os: |
| 109 deps_os[os_dep] = ConvertDepsToGit(deps_os[os_dep], options.repos, | 131 deps_os[os_dep] = ConvertDepsToGit(deps_os[os_dep], options.repos, |
| 110 options.type, vars) | 132 options.type, deps_vars, svn_deps_vars) |
| 111 | 133 |
| 112 # Write the DEPS file to disk. | 134 # Write the DEPS file to disk. |
| 113 deps_utils.WriteDeps(options.out, vars, deps, deps_os, include_rules, | 135 deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, |
| 114 skip_child_includes, hooks) | 136 skip_child_includes, hooks) |
| 115 return 0 | 137 return 0 |
| 116 | 138 |
| 139 |
| 117 if '__main__' == __name__: | 140 if '__main__' == __name__: |
| 118 sys.exit(main()) | 141 sys.exit(main()) |
| OLD | NEW |