1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
#!/usr/bin/python
# vim:expandtab:shiftwidth=2:tabstop=2:
# Copyright (C) 2013 Canonical Ltd.
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import print_function
from ConfigParser import ConfigParser, NoOptionError
from optparse import OptionParser
import os
import os.path
import re
import shutil
import sys
from urlparse import urljoin, urlsplit
sys.dont_write_bytecode = True
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "build", "python"))
from oxide_utils import CheckCall, CheckOutput, GetChecksum, GetFileChecksum, CHROMIUMSRCDIR, TOPSRCDIR
from patch_utils import SyncablePatchSet, SyncError
DEPOT_TOOLS_GIT_URL = "https://chromium.googlesource.com/chromium/tools/depot_tools.git"
DEPOT_TOOLS_GIT_REV = "c1ae89ecd635abfea2d94e5b49c7d92f49f28f22"
DEPOT_TOOLS_PATH = os.path.join(TOPSRCDIR, "third_party", "depot_tools")
DEPOT_TOOLS_OLD_PATH = os.path.join(TOPSRCDIR, "chromium", "depot_tools")
CHROMIUM_GIT_URL = "https://chromium.googlesource.com/chromium/src.git"
CHROMIUM_GCLIENT_SPEC = (
"solutions = ["
"{ \"name\": \"src\", "
"\"url\": \"%s\", "
"\"deps_file\": \".DEPS.git\", "
"\"managed\": False, "
"\"custom_deps\": "
"{ \"build/scripts/command_wrapper/bin\": None, "
"\"build/scripts/private/data/reliability\": None, "
"\"build/scripts/tools/deps2git\": None, "
"\"build/scripts/gsd_generate_index\": None, "
"\"build/scripts/private/data/reliability\": None, "
"\"build/third_party/cbuildbot_chromite\": None, "
"\"build/third_party/lighttpd\": None, "
"\"build/third_party/xvfb\": None, "
"\"depot_tools\": None, "
"\"src/chrome/tools/test/reference_build/chrome_win\": None, "
"\"src/chrome/tools/test/reference_build/chrome_linux\": None, "
"\"src/chrome/tools/test/reference_build/chrome_mac\": None, "
"\"src/third_party/hunspell_dictionaries\": None, "
"}, "
"\"safesync_url\": \"\", "
"} "
"]"
)
CHROMIUM_GCLIENT_FILE = os.path.join(os.path.dirname(CHROMIUMSRCDIR), ".gclient")
def IsGitRepo(path):
try:
CheckCall(["git", "status"], path, quiet=True)
except:
return False
return True
def GitRepoHeadMatchesId(path, id):
head = CheckOutput(["git", "rev-parse", "HEAD"], path).strip()
if head == id:
return True
for tag in CheckOutput(["git", "tag", "--contains", head], path).splitlines():
if tag.strip() == id:
return True
return False
def GetMirrorPath(cachedir, url):
try:
return CheckOutput([sys.executable, os.path.join(DEPOT_TOOLS_PATH, "git_cache.py"),
"exists", "--cache-dir", cachedir, url]).strip()
except subprocess.CalledProcessError:
return None
def PopulateGitMirror(cachedir, url, refs = []):
args = [sys.executable, os.path.join(DEPOT_TOOLS_PATH, "git_cache.py"),
"populate", "--cache-dir", cachedir]
for r in refs:
args.extend(["--ref", r])
args.append(url)
CheckCall(args)
def InitGitRepo(url, path, cachedir = None, additional_refs = []):
if IsGitRepo(path):
return
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.isfile(path):
os.remove(path)
args = ["git", "clone"]
if cachedir:
PopulateGitMirror(cachedir, url, additional_refs)
url = GetMirrorPath(cachedir, url)
args.append("--shared")
args.extend([url, path])
CheckCall(args)
for r in additional_refs:
CheckCall(["git", "config", "--add", "remote.origin.fetch",
"+%s:%s" % (r, r)], CHROMIUMSRCDIR)
def UpdateGitRepo(url, path, commit, cachedir = None):
newly_cloned = False
if not IsGitRepo(path):
InitGitRepo(url, path, cachedir)
newly_cloned = True
if cachedir:
if not newly_cloned:
PopulateGitMirror(cachedir, url)
url = GetMirrorPath(cachedir, url)
current_url = CheckOutput(["git", "config", "remote.origin.url"], path).strip()
if current_url != url:
CheckCall(["git", "remote", "set-url", "origin", url], path)
CheckCall(["git", "fetch"], path)
CheckCall(["git", "checkout", commit], path)
def GetDesiredChromiumVersion():
with open(os.path.join(TOPSRCDIR, "CHROMIUM_VERSION"), "r") as fd:
return fd.read().strip()
def GetChromiumGclientSpec(cachedir):
spec = CHROMIUM_GCLIENT_SPEC % CHROMIUM_GIT_URL
if cachedir:
spec = "%s\ncache_dir = \"%s\"" % (spec, cachedir)
return spec
def PrepareDepotTools():
if IsGitRepo(DEPOT_TOOLS_OLD_PATH) and not IsGitRepo(DEPOT_TOOLS_PATH):
os.rename(DEPOT_TOOLS_OLD_PATH, DEPOT_TOOLS_PATH)
UpdateGitRepo(DEPOT_TOOLS_GIT_URL, DEPOT_TOOLS_PATH, DEPOT_TOOLS_GIT_REV)
sys.path.insert(0, DEPOT_TOOLS_PATH)
os.environ["PATH"] = DEPOT_TOOLS_PATH + ":" + os.getenv("PATH")
def EnsurePatchConsistency():
patchset = SyncablePatchSet()
for patch in patchset.hg_patches:
if (patch in patchset.old_patches and
patch.checksum == patchset.old_patches[patch.filename].checksum):
continue
# For pre-r238 checkouts
if (patch in patchset.src_patches and
patch.checksum == patchset.src_patches[patch.filename].checksum):
continue
print("Patch %s in your Chromium source checkout has been "
"modified. Please resolve this manually. Note, you may "
"see this error if your Chromium checkout was created "
"using a revision of Oxide before r238" % patch.filename,
file=sys.stderr)
sys.exit(1)
def NeedsChromiumSync(config):
# Check that CHROMIUMSRCDIR is a git repo
if not IsGitRepo(CHROMIUMSRCDIR):
return True
if not GitRepoHeadMatchesId(CHROMIUMSRCDIR,
GetDesiredChromiumVersion()):
return True
# Need a sync if there is no .hg folder
if not os.path.isdir(os.path.join(CHROMIUMSRCDIR, ".hg")):
return True
# Sync if there is no .gclient file
if not os.path.isfile(CHROMIUM_GCLIENT_FILE):
return True
# Sync if the gclient spec has changed
if (GetFileChecksum(CHROMIUM_GCLIENT_FILE) !=
GetChecksum(GetChromiumGclientSpec(config.cachedir))):
return True
return False
def SyncChromium(config):
if os.path.isdir(os.path.join(CHROMIUMSRCDIR, ".hg")):
SyncablePatchSet().hg_patches.unapply_all()
shutil.rmtree(os.path.join(CHROMIUMSRCDIR, ".hg"))
os.remove(os.path.join(CHROMIUMSRCDIR, ".hgignore"))
chromium_dir = os.path.dirname(CHROMIUMSRCDIR)
if not os.path.isdir(chromium_dir):
os.makedirs(chromium_dir)
# We don't use gclient.py config here, because it doesn't support both
# --spec and --cache-dir, and --spec doesn't support newlines
with open(os.path.join(chromium_dir, ".gclient"), "w") as f:
f.write(GetChromiumGclientSpec(config.cachedir))
refs = [ "refs/tags/*", "refs/branch-heads/*" ]
if not IsGitRepo(CHROMIUMSRCDIR):
InitGitRepo(CHROMIUM_GIT_URL, CHROMIUMSRCDIR, config.cachedir, refs)
CheckCall(["git", "submodule", "foreach",
"git config -f $toplevel/.git/config submodule.$name.ignore all"],
CHROMIUMSRCDIR)
CheckCall(["git", "config", "diff.ignoreSubmodules", "all"],
CHROMIUMSRCDIR)
UpdateGitRepo(CHROMIUM_GIT_URL, CHROMIUMSRCDIR,
GetDesiredChromiumVersion(), config.cachedir)
CheckCall([sys.executable, os.path.join(DEPOT_TOOLS_PATH, "gclient.py"),
"sync", "-D", "--with_branch_heads"], chromium_dir)
with open(os.path.join(CHROMIUMSRCDIR, ".hgignore"), "w") as f:
f.write("~$\n")
f.write("\.svn/\n")
f.write("\.git/\n")
f.write("^out/\n")
f.write("\.host\.(.*\.|)mk$\n")
f.write("\.target\.(.*\.|)mk$\n")
f.write("Makefile(\.*|)$\n")
f.write("^\.hgignore$\n")
f.write("\.pyc$\n")
f.write("\.tmp$\n")
CheckCall(["hg", "init"], CHROMIUMSRCDIR)
hgrc = os.path.join(CHROMIUMSRCDIR, ".hg", "hgrc")
if not os.path.isfile(hgrc):
with open(hgrc, "w") as f:
f.write("[ui]\n")
f.write("username = oxide\n\n")
f.write("[extensions]\n")
f.write("mq =\n")
CheckCall(["hg", "addremove"], CHROMIUMSRCDIR)
CheckCall(["hg", "ci", "-m", "Base checkout with client.py"], CHROMIUMSRCDIR)
CheckCall(["hg", "qinit"], CHROMIUMSRCDIR)
def SyncChromiumPatches():
patchset = SyncablePatchSet()
try:
patchset.calculate_sync()
patchset.do_sync()
patchset.hg_patches.apply_all()
except SyncError as e:
print(e, file=sys.stderr)
sys.exit(1)
class Options(OptionParser):
def __init__(self):
OptionParser.__init__(self)
self.add_option("-c", "--cache-dir", dest="cache_dir",
help="Specify a directory for a local mirror")
class Config(ConfigParser):
def __init__(self, opts):
ConfigParser.__init__(self, allow_no_value=True)
filename = os.path.join(TOPSRCDIR, ".client.cfg")
try:
with open(filename, "r") as f:
self.readfp(f)
except IOError as e:
if e.errno != 2:
raise
if opts.cache_dir:
self.set("DEFAULT", "cachedir", opts.cache_dir)
if opts.cache_dir and opts.cache_dir != self.cachedir:
print("Ignoring value passed to --cache-dir, as it doesn't match the "
"value passed when the checkout was created", file=sys.stderr)
with open(filename, "w") as f:
self.write(f)
@property
def cachedir(self):
try:
return self.get("DEFAULT", "cachedir")
except NoOptionError:
return None
def main():
o = Options()
(options, args) = o.parse_args()
if options.cache_dir:
options.cache_dir = os.path.abspath(options.cache_dir)
c = Config(options)
PrepareDepotTools()
EnsurePatchConsistency()
old_chromium_dir = os.path.join(TOPSRCDIR, "chromium")
if os.path.isdir(old_chromium_dir):
shutil.rmtree(old_chromium_dir)
release_deps_dir = os.path.join(os.path.dirname(CHROMIUMSRCDIR), "release_deps")
if os.path.isdir(release_deps_dir):
shutil.rmtree(release_deps_dir)
if NeedsChromiumSync(c):
SyncChromium(c)
SyncChromiumPatches()
if __name__ == "__main__":
main()
|