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