Index: deps2git.py |
=================================================================== |
--- deps2git.py (revision 121912) |
+++ deps2git.py (working copy) |
@@ -3,12 +3,14 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+"""Convert SVN based DEPS into .DEPS.git for use with NewGit.""" |
import optparse |
+import os |
import sys |
- |
import deps_utils |
+import git_tools |
def SplitSvnUrl(url): |
@@ -33,7 +35,7 @@ |
# We cannot actually find the commit id, but this mode is useful |
# just for testing the URL mappings. Produce an output file that |
# can't actually be used, but can be eyeballed for correct URLs. |
- return ('xxx-r%s' % svn_rev) |
+ return 'xxx-r%s' % svn_rev |
# TODO(unknown_coder): Most of the errors happen when people add new repos |
# that actually matches one of our expressions but dont exist yet on |
# git.chromium.org. We should probably at least ping git_url to make sure it |
@@ -45,21 +47,21 @@ |
return git_tools.Search(git_repo_path, svn_rev) |
-def ConvertDepsToGit(deps, repos, deps_type, vars) |
+def ConvertDepsToGit(deps, repos, deps_type, deps_vars, deps_overrides): |
"""Convert a 'deps' section in a DEPS file from SVN to Git.""" |
new_deps = {} |
- deps_module = os.path.join(os.path.dirname(__file__), |
- 'svn_to_git_%s' % deps_type) |
- if not os.path.exists(depos_module): |
+ try: |
+ sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
+ svn_to_git = __import__('svn_to_git_%s' % deps_type) |
+ except ImportError: |
raise Exception('invalid DEPS type') |
- svn_to_git = __import__(deps_module) |
for dep in deps: |
# Get the SVN URL and the SVN rev for this dep. |
- (svn_url, svn_rev) = SplitSvnUrl(deps[dep]) |
+ svn_url, svn_rev = SplitSvnUrl(deps[dep]) |
# Convert this SVN URL to a Git URL. |
- (path, git_url) = svn_to_git.SvnUrlToGitUrl(dep, svn_url) |
+ path, git_url = svn_to_git.SvnUrlToGitUrl(dep, svn_url) |
if not path or not git_url: |
# We skip this path, this must not be required with Git. |
@@ -68,12 +70,15 @@ |
# Get the Git hash based off the SVN rev. |
git_hash = '' |
if svn_rev != 'HEAD': |
- git_hash = '@%s' % SvnRevToGitHash(svn_rev, git_url, repos, |
- svn_to_git.GIT_HOST) |
+ if dep in deps_overrides: |
+ git_hash = 'VAR_HASH_TEMP_%s' % deps_overrides[dep] |
+ else: |
+ git_hash = '@%s' % SvnRevToGitHash(svn_rev, git_url, repos, |
+ svn_to_git.GIT_HOST) |
# If this is webkit, we need to add the var for the hash. |
if dep == 'src/third_party/WebKit/Source': |
- vars['webkit_rev'] = git_hash |
+ deps_vars['webkit_rev'] = git_hash |
git_hash = 'VAR_WEBKIT_REV' |
# Add this Git dep to the new deps. |
@@ -92,27 +97,44 @@ |
help='type of DEPS file (public, etc)') |
parser.add_option('-r', '--repos', |
help='path to the directory holding all the Git repos') |
- options, args = parser.parse_args() |
+ options = parser.parse_args()[0] |
# Get the content of the DEPS file. |
- deps_content = deps_utils.GetDepsContent(options.deps) |
- (deps, deps_os, include_rules, skip_child_includes, hooks) = deps_content |
+ deps_content = deps_utils.GetDepsContent(options.deps) |
+ (deps, deps_os, include_rules, skip_child_includes, hooks, |
+ svn_deps_vars) = deps_content |
# Create a var containing the Git and Webkit URL, this will make it easy for |
# people to use a mirror instead. |
- vars = {'git_url': 'http://git.chromium.org', |
- 'webkit_url': 'http://git.chromium.org/external/WebKit_trimmed.git'} |
+ git_url = 'http://git.chromium.org' |
+ deps_vars = { |
+ 'git_url': git_url, |
+ 'webkit_url': git_url + '/external/WebKit_trimmed.git' |
+ } |
+ # Overrides for SVN DEPS. Each entry maps a dep name to a .DEPS.git variable |
+ # identifying the hash. Values are automatically pulled from svn_deps_vars |
+ # and wrapped in the appropriate Var('<var_name>') syntax below. |
+ 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.
|
+ 'src/third_party/ffmpeg': 'ffmpeg_hash' |
+ } |
+ |
+ # Transfer any required variables over from DEPS. |
+ for value in deps_overrides.values(): |
+ deps_vars[value] = '@' + svn_deps_vars[value].lstrip('@') |
+ |
# Convert the DEPS file to Git. |
- deps = ConvertDepsToGit(deps, options.repos, options.type, vars) |
+ deps = ConvertDepsToGit(deps, options.repos, options.type, deps_vars, |
+ deps_overrides) |
for os_dep in deps_os: |
deps_os[os_dep] = ConvertDepsToGit(deps_os[os_dep], options.repos, |
- options.type, vars) |
+ options.type, deps_vars, deps_overrides) |
# Write the DEPS file to disk. |
- deps_utils.WriteDeps(options.out, vars, deps, deps_os, include_rules, |
- skip_child_includes, hooks) |
+ deps_utils.WriteDeps(options.out, deps_vars, deps, deps_os, include_rules, |
+ skip_child_includes, hooks, deps_overrides) |
return 0 |
+ |
if '__main__' == __name__: |
sys.exit(main()) |