Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / tools / deps2git / buildspec_to_git.py
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Public buildspec to GIT mapping."""
6
7 import re
8 from deps2git import SplitScmUrl
9
10 GIT_HOST = 'https://chromium.googlesource.com/'
11 webkit_git = GIT_HOST + 'chromium/blink.git'
12
13 # Remove the ffmpeg overrides, since the buildspec DEPS have stripped out these
14 # (and other) vars that they don't use, and without them in the DEPS, deps2git
15 # complains about missing vars.
16 DEPS_OVERRIDES = {
17   'src/third_party/ffmpeg': None
18 }
19
20
21 # pylint: disable=W0613
22 def CleanDeps(deps, deps_os, include_rules, skip_child_includes, hooks):
23   global webkit_git
24   webkit_rev = None
25   for os, deps_section in ([(None, deps)] +
26                            [(os, deps_os[os]) for os in deps_os]):
27     del_deps = []
28     add_deps = {}
29     for dep, dep_url in deps_section.iteritems():
30       # Skip 'None' exclusion entries.
31       if not dep_url:
32         continue
33
34       url, rev = SplitScmUrl(dep_url)
35
36       # Some m27 DEPS have blink entries that are just paths. Prepend the host
37       # info so the rest of the processing can proceed as normal.
38       m = re.match('/branches/chromium/[^/]+/'
39                    '(LayoutTests|Source|Tools)(/.*)?$', url)
40       if m:
41         dep_url = 'https://src.chromium.org/blink' + dep_url
42         deps_section[dep] = dep_url
43         url, rev = SplitScmUrl(dep_url)
44
45       # During m29 (and maybe earlier), there was some fetching (and branching)
46       # of just blink LayoutTests, rather than the whole repo, with entries to
47       # checkout a bunch of individual sub-paths to
48       # 'src/content/test/data/layout_tests/*'.
49       # Consolidate all of those deps into a single, top-level 'layout_tests'
50       # entry so the whole blink repo can be checkout out there (putting
51       # LayoutTests in the expected 'layout_tests/LayoutTests/' path).
52       m = re.match('^https?://src.chromium.org/blink/'
53                    '(trunk|branches/chromium/[^/]+)/LayoutTests(/.*)?', url)
54       if m:
55         if not add_deps.get('src/content/test/data/layout_tests'):
56           add_deps['src/content/test/data/layout_tests'] = dep_url
57         del_deps.append(dep)
58         continue
59
60       # Ignore webkit sub-path entries since git checks out all in one repo,
61       is_webkit = False
62       if url.startswith('/trunk/deps/third_party/WebKit/'):
63         is_webkit = True
64       else:
65         m = re.match('https?://(svn.webkit.org/repository/webkit|'
66                      'src.chromium.org/blink)'
67                      '/(trunk|branches/chromium/[^/]+)/', url)
68         if m:
69           # Don't remove 'ios' sub-path entries, which are set explicitly to
70           # just pull the headers or something. Unfortunately, the sub-path
71           # repos don't mirror the branches, so if the dep is for a branch, even
72           # 'ios' will have to pull the full WebKit.
73           if os == 'ios' and m.group(2) == 'trunk':
74             continue
75           is_webkit = True
76           # If svn DEPS refers to the webkit.org repo, rather than blink, use
77           # the old mirror of that repo instead of blink.git.
78           if 'svn.webkit.org' in m.group(1):
79             webkit_git = GIT_HOST + 'external/WebKit_trimmed.git'
80       if is_webkit:
81         if not webkit_rev:
82           webkit_rev = rev
83         else:
84           # All the sub-path repos should be pinned to the same revision. If
85           # they're not, then not sure how to decide what revision to use for
86           # the umbrella git repo.
87           if rev != webkit_rev:
88             raise Exception('WebKit entry revision mismatch: %s != %s' %
89                             (rev, webkit_rev))
90         del_deps.append(dep)
91         continue
92
93       # Some older DEPS have a split selenium py/test|selenium checkout but the
94       # git selenium py repo encompasses both, so delete everything except the
95       # base checkout to python/selenium.
96       if dep.startswith('src/third_party/webdriver/python/selenium/'):
97         del_deps.append(dep)
98         continue
99
100       # Ugh. For a while during m29, there was an entry with an incomplete URL
101       # and incorrect path. How this worked even once, let alone through
102       # multiple releases, is a mystery.
103       if url.startswith('sctp-refimpl'):
104         dep_url = 'https://' + dep_url.replace('/snv/', '/svn/')
105         deps_section[dep] = dep_url
106         continue
107
108     for dep in del_deps:
109       del deps_section[dep]
110     deps_section.update(add_deps)
111
112   # Make sure the top-level webkit entry that's left refers to the common
113   # revision from the sub-path entries, and not to the revision of the
114   # top-level "placeholder" repository. webkit_rev won't be set for recent
115   # DEPS, since they use the blink repo and have no webkit sub-path entries.
116   if webkit_rev:
117     dep_url = deps['src/third_party/WebKit']
118     url, rev = SplitScmUrl(dep_url)
119     deps['src/third_party/WebKit'] = '%s@%s' % (url, webkit_rev)
120
121 def SvnUrlToGitUrl(path, svn_url):
122   """Convert a chromium SVN URL to a chromium Git URL."""
123
124   match = re.match(
125       '(https?://src.chromium.org/svn|svn://svn.chromium.org/chrome)(/.*)',
126       svn_url)
127   if match:
128     svn_url = match.group(2)
129
130   # Handle the main 'src' repo which only appears in buildspecs.
131   match = re.match('/(branches/(?P<branch>[^/]+)|trunk)/src$', svn_url)
132   if match:
133     if match.groupdict().get('branch'):
134       return (path, GIT_HOST + 'chromium/src.git', GIT_HOST,
135               match.groupdict().get('branch'))
136     else:
137       return (path, GIT_HOST + 'chromium/src.git', GIT_HOST)
138
139   # libvpx branches in the chrome branches area.
140   match = re.match('/branches/libvpx/(?P<branch>[^/]+)', svn_url)
141   if match:
142     return (path, GIT_HOST + 'chromium/deps/libvpx.git', GIT_HOST,
143             match.group('branch'))
144
145   # Since the ffmpeg overrides are gone, we can't use the upstream git repo
146   # (which is what those overrides referenced), so use the mirror of the svn
147   # repo.
148   if svn_url == '/trunk/deps/third_party/ffmpeg':
149     return (path, GIT_HOST + 'chromium/deps/ffmpeg.git', GIT_HOST)
150
151   match = re.match('/branches/ffmpeg/(?P<branch>[^/]+)', svn_url)
152   if match:
153     return (path, GIT_HOST + 'chromium/deps/ffmpeg.git', GIT_HOST,
154             match.group('branch'))
155
156   # openssl branches
157   match = re.match('/branches/third_party/openssl/(?P<branch>[^/]+)', svn_url)
158   if match:
159     return (path, GIT_HOST + 'chromium/deps/openssl.git', GIT_HOST,
160             match.group('branch'))
161
162   # The webrtc repo used to be mirrored into multiple stable/trunk repos,
163   # but branches were mirrored to both, so either would work here.
164   match = re.match('^https?://webrtc.googlecode.com/svn/branches/([^/]+)/(.*)',
165                    svn_url)
166   if match:
167     branch = match.group(1)
168     if match.group(2) == 'src':
169       repo = 'webrtc/src.git'
170     else:
171       repo = 'webrtc/trunk/%s.git' % match.group(2)
172     return (path, GIT_HOST + 'external/%s' % repo, GIT_HOST, branch)
173
174   # Skia also split into multiple repos, and has unusual chrome-specific branch
175   # naming.
176   # https://chromium.googlesource.com/external/skia/m25_1364/src.git
177   match = re.match('^https?://skia.googlecode.com/svn/branches/'
178                    'chrome/([^/]+)/(?:trunk/)?(.*)', svn_url)
179   if match:
180     branch = match.group(1)
181     repo = 'skia/%s.git' % match.group(2)
182     return (path, GIT_HOST + 'external/%s' % repo, GIT_HOST, 'chrome/' + branch)
183
184   # Make the top-level webkit entry checkout the full webkit git repository,
185   # which replaces all the (non-iOS) sub-path entries.
186   if svn_url == '/trunk/deps/third_party/WebKit':
187     return (path, webkit_git, GIT_HOST)
188
189   # Make the top-level python/selenium entry checkout the full selenium/py git
190   # repository, which replaces all the sub-path entries.
191   if svn_url == 'http://selenium.googlecode.com/svn/trunk/py/selenium':
192     return (path, GIT_HOST + 'external/selenium/py.git', GIT_HOST)
193
194   # Projects that are subdirectories of the native_client repository.
195   match = re.match('^https?://src.chromium.org/native_client/branches/'
196                    '(?P<branch>[^/]+)/(?P<path>.*)',
197                    svn_url)
198   if match:
199     if match.group('path'):
200       repo = '%s.git' % match.group('path')
201     else:
202       repo = 'src/native_client.git'
203     return (path, GIT_HOST + 'native_client/%s' % repo, GIT_HOST,
204             match.group('branch'))
205
206   # blink LayoutTests.
207   match = re.match('^https?://src.chromium.org/blink/'
208                    '(trunk|branches/(?P<branch>chromium/[^/]+))/'
209                    'LayoutTests(/.*)?',
210                    svn_url)
211   if match:
212     repo = GIT_HOST + 'chromium/blink.git'
213     if match.group('branch'):
214       return (path, repo, GIT_HOST, match.group('branch'))
215     else:
216       return (path, repo, GIT_HOST)
217
218   # blink branches.
219   match = re.match('^https?://src.chromium.org/blink/branches/'
220                    '(?P<branch>chromium/[^/]+)(?P<path>/public)?/?$',
221                    svn_url)
222   if match:
223     # ios has a special headers-only repo
224     if match.group('path'):
225       repo = GIT_HOST + 'chromium/blink-public.git'
226     else:
227       repo = GIT_HOST + 'chromium/blink.git'
228     return (path, repo, GIT_HOST, match.group('branch'))
229
230   # reference builds
231   if svn_url.startswith('/trunk/deps/reference_builds/chrome'):
232     return (path, GIT_HOST + 'chromium/reference_builds/chrome.git',
233             GIT_HOST)