forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomate-git.py
More file actions
1792 lines (1541 loc) · 62.8 KB
/
automate-git.py
File metadata and controls
1792 lines (1541 loc) · 62.8 KB
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
""" See automate.py. This script is for internal usage only, don't
call it directly. This is a modified copy of automate-git.py from
upstream CEF.
Some modifications were applied for CEF Python specific use case.
There is a patch file with the same name as this script that contains
differences from the original file.
-------------------------------------------------------------------------------
Usage: automate-git.py [options]
This utility implements automation for the download, update, build and
distribution of CEF.
Options:
-h, --help show this help message and exit
--download-dir=DIR Download directory with no spaces [required].
--depot-tools-dir=DIR
Download directory for depot_tools.
--depot-tools-archive=DEPOTTOOLSARCHIVE
Zip archive file that contains a single top-level
depot_tools directory.
--branch=BRANCH Branch of CEF to build (trunk, 1916, ...). This will
be used to name the CEF download directory and to
identify the correct URL if --url is not specified.
The default value is trunk.
--url=URL CEF download URL. If not specified the default URL
will be used.
--chromium-url=CHROMIUMURL
Chromium download URL. If not specified the default
URL will be used.
--checkout=CHECKOUT Version of CEF to checkout. If not specified the most
recent remote version of the branch will be used.
--chromium-checkout=CHROMIUMCHECKOUT
Version of Chromium to checkout (Git branch/hash/tag).
This overrides the value specified by CEF in
CHROMIUM_BUILD_COMPATIBILITY.txt.
--chromium-channel=CHROMIUMCHANNEL
Chromium channel to check out (canary, dev, beta or
stable). This overrides the value specified by CEF in
CHROMIUM_BUILD_COMPATIBILITY.txt.
--chromium-channel-distance=CHROMIUMCHANNELDISTANCE
The target number of commits to step in the channel,
or 0 to use the newest channel version. Used in
combination with --chromium-channel.
--force-config Force creation of a new gclient config file.
--force-clean Force a clean checkout of Chromium and CEF. This will
trigger a new update, build and distribution.
--force-clean-deps Force a clean checkout of Chromium dependencies. Used
in combination with --force-clean.
--dry-run Output commands without executing them.
--dry-run-platform=DRYRUNPLATFORM
Simulate a dry run on the specified platform (windows,
macosx, linux). Must be used in combination with the
--dry-run flag.
--force-update Force a Chromium and CEF update. This will trigger a
new build and distribution.
--no-update Do not update Chromium or CEF. Pass --force-build or
--force-distrib if you desire a new build or
distribution.
--no-cef-update Do not update CEF. Pass --force-build or --force-
distrib if you desire a new build or distribution.
--force-cef-update Force a CEF update. This will cause local changes in
the CEF checkout to be discarded and patch files to be
reapplied.
--no-chromium-update Do not update Chromium.
--no-depot-tools-update
Do not update depot_tools.
--fast-update Update existing Chromium/CEF checkouts for fast
incremental builds by attempting to minimize the
number of modified files. The update will fail if
there are unstaged CEF changes or if Chromium changes
are not included in a patch file.
--force-patch-update Force update of patch files.
--resave Resave patch files.
--log-chromium-changes
Create a log of the Chromium changes.
--force-build Force CEF debug and release builds. This builds
[build-target] on all platforms and chrome_sandbox on
Linux.
--no-build Do not build CEF.
--build-target=BUILDTARGET
Target name(s) to build (defaults to "cefclient").
--build-tests Also build the test target specified via --test-
target.
--no-debug-build Don't perform the CEF debug build.
--no-release-build Don't perform the CEF release build.
--verbose-build Show all command lines while building.
--build-failure-limit=BUILDFAILURELIMIT
Keep going until N jobs fail.
--build-log-file Write build logs to file. The file will be named
"build-[branch]-[debug|release].log" in the download
directory.
--x64-build Create a 64-bit build.
--arm-build Create an ARM build.
--run-tests Run the ceftests target.
--no-debug-tests Don't run debug build tests.
--no-release-tests Don't run release build tests.
--test-target=TESTTARGET
Test target name to build (defaults to "ceftests").
--test-prefix=TESTPREFIX
Prefix for running the test executable (e.g. `xvfb-
run` on Linux).
--test-args=TESTARGS Arguments that will be passed to the test executable.
--force-distrib Force creation of a CEF binary distribution.
--no-distrib Don't create a CEF binary distribution.
--minimal-distrib Create a minimal CEF binary distribution.
--minimal-distrib-only
Create a minimal CEF binary distribution only.
--client-distrib Create a client CEF binary distribution.
--client-distrib-only
Create a client CEF binary distribution only.
--sandbox-distrib Create a cef_sandbox static library distribution.
--sandbox-distrib-only
Create a cef_sandbox static library distribution only.
--no-distrib-docs Don't create CEF documentation.
--no-distrib-archive Don't create archives for output directories.
--clean-artifacts Clean the artifacts output directory.
--distrib-subdir=DISTRIBSUBDIR
CEF distrib dir name, child of
chromium/src/cef/binary_distrib
"""
# Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.
from datetime import datetime
import json
from optparse import OptionParser
import os
import re
import shlex
import shutil
import subprocess
import sys
import tempfile
import urllib
import urllib2
import zipfile
##
# Default URLs.
##
depot_tools_url = 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
depot_tools_archive_url = 'https://storage.googleapis.com/chrome-infra/depot_tools.zip'
cef_git_url = 'https://bitbucket.org/chromiumembedded/cef.git'
chromium_channel_json_url = 'https://omahaproxy.appspot.com/all.json'
##
# Global system variables.
##
# Script directory.
script_dir = os.path.dirname(__file__)
##
# Helper functions.
##
def msg(message):
""" Output a message. """
sys.stdout.write('--> ' + message + "\n")
def run(command_line, working_dir, depot_tools_dir=None, output_file=None):
""" Runs the specified command. """
# add depot_tools to the path
env = os.environ
if not depot_tools_dir is None:
env['PATH'] = depot_tools_dir + os.pathsep + env['PATH']
sys.stdout.write('-------- Running "'+command_line+'" in "'+\
working_dir+'"...'+"\n")
if not options.dryrun:
args = shlex.split(command_line.replace('\\', '\\\\'))
if not output_file:
return subprocess.check_call(
args, cwd=working_dir, env=env, shell=(sys.platform == 'win32'))
try:
msg('Writing %s' % output_file)
with open(output_file, "w") as f:
return subprocess.check_call(
args,
cwd=working_dir,
env=env,
shell=(sys.platform == 'win32'),
stderr=subprocess.STDOUT,
stdout=f)
except subprocess.CalledProcessError:
msg('ERROR Run failed. See %s for output.' % output_file)
raise
def create_directory(path):
""" Creates a directory if it doesn't already exist. """
if not os.path.exists(path):
msg("Creating directory %s" % (path))
if not options.dryrun:
os.makedirs(path)
def delete_directory(path):
""" Removes an existing directory. """
if os.path.exists(path):
msg("Removing directory %s" % (path))
if not options.dryrun:
shutil.rmtree(path, onerror=onerror)
def copy_directory(source, target, allow_overwrite=False):
""" Copies a directory from source to target. """
if not options.dryrun and os.path.exists(target):
if not allow_overwrite:
raise Exception("Directory %s already exists" % (target))
remove_directory(target)
if os.path.exists(source):
msg("Copying directory %s to %s" % (source, target))
if not options.dryrun:
shutil.copytree(source, target)
def move_directory(source, target, allow_overwrite=False):
""" Copies a directory from source to target. """
if not options.dryrun and os.path.exists(target):
if not allow_overwrite:
raise Exception("Directory %s already exists" % (target))
remove_directory(target)
if os.path.exists(source):
msg("Moving directory %s to %s" % (source, target))
if not options.dryrun:
shutil.move(source, target)
def is_git_checkout(path):
""" Returns true if the path represents a git checkout. """
return os.path.exists(os.path.join(path, '.git'))
def exec_cmd(cmd, path):
""" Execute the specified command and return the result. """
out = ''
err = ''
sys.stdout.write("-------- Running \"%s\" in \"%s\"...\n" % (cmd, path))
parts = cmd.split()
try:
process = subprocess.Popen(
parts,
cwd=path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=(sys.platform == 'win32'))
out, err = process.communicate()
except IOError, (errno, strerror):
raise
except:
raise
return {'out': out, 'err': err}
def get_git_hash(path, branch):
""" Returns the git hash for the specified branch/tag/hash. """
cmd = "%s rev-parse %s" % (git_exe, branch)
result = exec_cmd(cmd, path)
if result['out'] != '':
return result['out'].strip()
return 'Unknown'
def get_git_date(path, branch):
""" Returns the date for the specified branch/tag/hash. """
cmd = "%s show -s --format=%%ct %s" % (git_exe, branch)
result = exec_cmd(cmd, path)
if result['out'] != '':
return datetime.utcfromtimestamp(
int(result['out'].strip())).strftime('%Y-%m-%d %H:%M:%S UTC')
return 'Unknown'
def get_git_url(path):
""" Returns the origin url for the specified path. """
cmd = "%s config --get remote.origin.url" % (git_exe)
result = exec_cmd(cmd, path)
if result['out'] != '':
return result['out'].strip()
return 'Unknown'
def download_and_extract(src, target):
""" Extracts the contents of src, which may be a URL or local file, to the
target directory. """
temporary = False
if src[:4] == 'http':
# Attempt to download a URL.
opener = urllib.FancyURLopener({})
response = opener.open(src)
temporary = True
handle, archive_path = tempfile.mkstemp(suffix='.zip')
os.write(handle, response.read())
os.close(handle)
elif os.path.exists(src):
# Use a local file.
archive_path = src
else:
raise Exception('Path type is unsupported or does not exist: ' + src)
if not zipfile.is_zipfile(archive_path):
raise Exception('Not a valid zip archive: ' + src)
# Attempt to extract the archive file.
try:
os.makedirs(target)
zf = zipfile.ZipFile(archive_path, 'r')
zf.extractall(target)
except:
shutil.rmtree(target, onerror=onerror)
raise
zf.close()
# Delete the archive file if temporary.
if temporary and os.path.exists(archive_path):
os.remove(archive_path)
def read_file(path):
""" Read a file. """
if os.path.exists(path):
fp = open(path, 'r')
data = fp.read()
fp.close()
return data
else:
raise Exception("Path does not exist: %s" % (path))
def read_config_file(path):
""" Read a configuration file. """
# Parse the contents.
return eval(read_file(path), {'__builtins__': None}, None)
def write_config_file(path, contents):
""" Write a configuration file. """
msg('Writing file: %s' % path)
if not options.dryrun:
fp = open(path, 'w')
fp.write("{\n")
for key in sorted(contents.keys()):
fp.write(" '%s': '%s',\n" % (key, contents[key]))
fp.write("}\n")
fp.close()
def read_branch_config_file(path):
""" Read the CEF branch from the specified path. """
config_file = os.path.join(path, 'cef.branch')
if os.path.isfile(config_file):
contents = read_config_file(config_file)
if 'branch' in contents:
return contents['branch']
return ''
def write_branch_config_file(path, branch):
""" Write the CEF branch to the specified path. """
config_file = os.path.join(path, 'cef.branch')
if not os.path.isfile(config_file):
write_config_file(config_file, {'branch': branch})
def remove_deps_entry(path, entry):
""" Remove an entry from the Chromium DEPS file at the specified path. """
msg('Updating DEPS file: %s' % path)
if not options.dryrun:
# Read the DEPS file.
fp = open(path, 'r')
lines = fp.readlines()
fp.close()
# Write the DEPS file.
# Each entry takes 2 lines. Skip both lines if found.
fp = open(path, 'w')
skip_next = False
for line in lines:
if skip_next:
skip_next = False
continue
elif line.find(entry) >= 0:
skip_next = True
continue
fp.write(line)
fp.close()
def apply_deps_patch():
""" Patch the Chromium DEPS file if necessary. """
# Starting with 43.0.2357.126 the DEPS file is now 100% Git and the .DEPS.git
# file is no longer created. Look for the older file first in case we're
# building an older branch version.
deps_file = '.DEPS.git'
deps_path = os.path.join(chromium_src_dir, deps_file)
if not os.path.isfile(deps_path):
deps_file = 'DEPS'
deps_path = os.path.join(chromium_src_dir, deps_file)
if os.path.isfile(deps_path):
msg("Chromium DEPS file: %s" % (deps_path))
patch_file = os.path.join(cef_dir, 'patch', 'patches', deps_file)
if os.path.exists(patch_file + ".patch"):
# Attempt to apply the DEPS patch file that may exist with newer branches.
patch_tool = os.path.join(cef_dir, 'tools', 'patcher.py')
run('%s %s --patch-file "%s" --patch-dir "%s"' %
(python_exe, patch_tool, patch_file,
chromium_src_dir), chromium_src_dir, depot_tools_dir)
elif cef_branch != 'trunk' and int(cef_branch) <= 1916:
# Release branch DEPS files older than 37.0.2007.0 may include a 'src'
# entry. This entry needs to be removed otherwise `gclient sync` will
# fail.
remove_deps_entry(deps_path, "'src'")
else:
raise Exception("Path does not exist: %s" % (deps_path))
def run_patch_updater(args='', output_file=None):
""" Run the patch updater script. """
tool = os.path.join(cef_src_dir, 'tools', 'patch_updater.py')
if len(args) > 0:
args = ' ' + args
run('%s %s%s' % (python_exe, tool, args), cef_src_dir, depot_tools_dir,
output_file)
def onerror(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.
If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it re-raises the error.
Usage : ``shutil.rmtree(path, onerror=onerror)``
"""
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
def read_json_url(url):
""" Read a JSON URL. """
msg('Downloading %s' % url)
response = urllib2.urlopen(url)
return json.loads(response.read())
g_channel_data = None
def get_chromium_channel_data(os, channel, param=None):
""" Returns all data for the specified Chromium channel. """
global g_channel_data
if g_channel_data is None:
g_channel_data = read_json_url(chromium_channel_json_url)
assert len(g_channel_data) > 0, 'Failed to load Chromium channel data'
for oses in g_channel_data:
if oses['os'] == os:
for version in oses['versions']:
if version['channel'] == channel:
assert version['os'] == os
assert version['channel'] == channel
if param is None:
return version
else:
assert param in version, 'Missing parameter %s for Chromium channel %s %s' % (
param, os, channel)
return version[param]
raise Exception("Invalid Chromium channel value: %s" % channel)
raise Exception("Invalid Chromium os value: %s" % os)
def get_chromium_channel_commit(os, channel):
""" Returns the current branch commit for the specified Chromium channel. """
return get_chromium_channel_data(os, channel, 'branch_commit')
def get_chromium_channel_version(os, channel):
""" Returns the current version for the specified Chromium channel. """
return get_chromium_channel_data(os, channel, 'current_version')
def get_chromium_master_position(commit):
""" Returns the closest master position for the specified Chromium commit. """
# Using -2 because a "Publish DEPS" commit which does not have a master
# position may be first.
cmd = "%s log -2 %s" % (git_exe, commit)
result = exec_cmd(cmd, chromium_src_dir)
if result['out'] != '':
match = re.search(r'refs/heads/master@{#([\d]+)}', result['out'])
assert match != None, 'Failed to find position'
return int(match.groups()[0])
return None
def get_chromium_master_commit(position):
""" Returns the master commit for the specified Chromium commit position. """
cmd = '%s log -1 --grep=refs/heads/master@{#%s} origin/master' % (
git_exe, str(position))
result = exec_cmd(cmd, chromium_src_dir)
if result['out'] != '':
match = re.search(r'^commit ([a-f0-9]+)', result['out'])
assert match != None, 'Failed to find commit'
return match.groups()[0]
return None
def get_chromium_versions(commit):
""" Returns the list of Chromium versions that contain the specified commit.
Versions are listed oldest to newest. """
cmd = '%s tag --contains %s' % (git_exe, commit)
result = exec_cmd(cmd, chromium_src_dir)
if result['out'] != '':
return [line.strip() for line in result['out'].strip().split('\n')]
return None
def get_chromium_compat_version():
""" Returns the compatible Chromium version specified by the CEF checkout. """
compat_path = os.path.join(cef_dir, 'CHROMIUM_BUILD_COMPATIBILITY.txt')
msg("Reading %s" % compat_path)
config = read_config_file(compat_path)
if 'chromium_checkout' in config:
return config['chromium_checkout']
raise Exception("Missing chromium_checkout value in %s" % (compat_path))
def get_chromium_target_version(os='win', channel='canary', target_distance=0):
""" Returns the target Chromium version based on a heuristic. """
# The current compatible version from CEF.
compat_version = chromium_compat_version
compat_commit = get_git_hash(chromium_src_dir, compat_version)
if compat_version == compat_commit:
versions = get_chromium_versions(compat_commit)
if len(versions) > 0:
compat_version = 'refs/tags/' + versions[0]
# Closest version may not align with the compat position, so adjust the
# commit to match.
compat_commit = get_git_hash(chromium_src_dir, compat_version)
compat_position = get_chromium_master_position(compat_commit)
compat_date = get_git_date(chromium_src_dir, compat_commit)
# The most recent channel version from the Chromium website.
channel_version = 'refs/tags/' + get_chromium_channel_version(os, channel)
channel_commit = get_chromium_channel_commit(os, channel)
channel_position = get_chromium_master_position(channel_commit)
channel_date = get_git_date(chromium_src_dir, channel_commit)
if compat_position >= channel_position:
# Already compatible with the channel version or newer.
target_version = compat_version
target_commit = compat_commit
target_position = compat_position
target_date = compat_date
elif target_distance <= 0 or compat_position + target_distance >= channel_position:
# Channel version is within the target distance.
target_version = channel_version
target_commit = channel_commit
target_position = channel_position
target_date = channel_date
else:
# Find an intermediary version that's within the target distance.
target_position = compat_position + target_distance
target_commit = get_chromium_master_commit(target_position)
versions = get_chromium_versions(target_commit)
if len(versions) > 0:
target_version = 'refs/tags/' + versions[0]
# Closest version may not align with the target position, so adjust the
# commit and position to match.
target_commit = get_git_hash(chromium_src_dir, target_version)
target_position = get_chromium_master_position(target_commit)
else:
target_version = target_commit
target_date = get_git_date(chromium_src_dir, target_commit)
msg("")
msg("Computed Chromium update for %s %s at distance %d" % (os, channel,
target_distance))
msg("Compat: %s %s %s (#%d)" % (compat_date, compat_version, compat_commit,
compat_position))
msg("Target: %s %s %s (#%d)" % (target_date, target_version, target_commit,
target_position))
msg("Channel: %s %s %s (#%d)" % (channel_date, channel_version,
channel_commit, channel_position))
msg("")
return target_version
def get_build_directory_name(is_debug):
build_dir = ('Debug' if is_debug else 'Release') + '_'
if use_gn:
# CEF uses a consistent directory naming scheme for GN via
# GetAllPlatformConfigs in tools/gn_args.py.
if options.x64build:
build_dir += 'GN_x64'
elif options.armbuild:
build_dir += 'GN_arm'
else:
build_dir += 'GN_x86'
else:
# GYP outputs both x86 and x64 builds to the same directory on Linux and
# Mac OS X. On Windows it suffixes the directory name for x64 builds.
if platform == 'windows' and options.x64build:
build_dir += 'x64'
return build_dir
def read_update_file():
update_path = os.path.join(cef_src_dir, 'CHROMIUM_UPDATE.txt')
if not os.path.exists(update_path):
msg("Missing file: %s" % update_path)
return None
msg("Reading %s" % update_path)
return read_config_file(update_path)
def log_chromium_changes():
""" Evaluate the Chromium checkout for changes. """
config = read_update_file()
if config is None:
msg("Skipping Chromium changes log.")
return
if 'files' in config:
out_file = os.path.join(download_dir, 'chromium_update_changes.diff')
if os.path.exists(out_file):
os.remove(out_file)
old_commit = get_chromium_master_commit(
get_chromium_master_position(chromium_compat_version))
new_commit = get_chromium_master_commit(
get_chromium_master_position(chromium_checkout))
cmd = '%s diff --relative --no-prefix %s..%s -- %s' % (
git_exe, old_commit, new_commit, ' '.join(config['files']))
result = exec_cmd(cmd, chromium_src_dir)
if result['out'] != '':
msg('Writing %s' % out_file)
with open(out_file, 'w') as fp:
fp.write(result['out'])
def check_pattern_matches(output_file=None):
""" Evaluate the Chromium checkout for pattern matches. """
config = read_update_file()
if config is None:
msg("Skipping Chromium pattern matching.")
return
if 'patterns' in config:
if output_file is None:
fp = sys.stdout
else:
msg('Writing %s' % output_file)
fp = open(output_file, 'w')
has_output = False
for entry in config['patterns']:
msg("Evaluating pattern: %s" % entry['pattern'])
# Read patterns from a file to avoid formatting problems.
pattern_handle, pattern_file = tempfile.mkstemp()
os.write(pattern_handle, entry['pattern'])
os.close(pattern_handle)
cmd = '%s grep -n -f %s' % (git_exe, pattern_file)
result = exec_cmd(cmd, chromium_src_dir)
os.remove(pattern_file)
if result['out'] != '':
write_msg = True
re_exclude = re.compile(
entry['exclude_matches']) if 'exclude_matches' in entry else None
for line in result['out'].split('\n'):
line = line.strip()
if len(line) == 0:
continue
skip = not re_exclude is None and re_exclude.match(line) != None
if not skip:
if write_msg:
if has_output:
fp.write('\n')
fp.write('!!!! WARNING: FOUND PATTERN: %s\n' % entry['pattern'])
if 'message' in entry:
fp.write(entry['message'] + '\n')
fp.write('\n')
write_msg = False
fp.write(line + '\n')
has_output = True
if not output_file is None:
if has_output:
msg('ERROR Matches found. See %s for output.' % out_file)
else:
fp.write('Good news! No matches.\n')
fp.close()
if has_output:
# Don't continue when we know the build will be wrong.
sys.exit(1)
##
# Program entry point.
##
# Cannot be loaded as a module.
if __name__ != "__main__":
sys.stderr.write('This file cannot be loaded as a module!')
sys.exit()
# Parse command-line options.
disc = """
This utility implements automation for the download, update, build and
distribution of CEF.
"""
parser = OptionParser(description=disc)
# Setup options.
parser.add_option(
'--download-dir',
dest='downloaddir',
metavar='DIR',
help='Download directory with no spaces [required].')
parser.add_option(
'--depot-tools-dir',
dest='depottoolsdir',
metavar='DIR',
help='Download directory for depot_tools.',
default='')
parser.add_option('--depot-tools-archive', dest='depottoolsarchive',
help='Zip archive file that contains a single top-level '+\
'depot_tools directory.', default='')
parser.add_option('--branch', dest='branch',
help='Branch of CEF to build (trunk, 1916, ...). This '+\
'will be used to name the CEF download directory and '+\
'to identify the correct URL if --url is not '+\
'specified. The default value is trunk.',
default='trunk')
parser.add_option('--url', dest='url',
help='CEF download URL. If not specified the default URL '+\
'will be used.',
default='')
parser.add_option('--chromium-url', dest='chromiumurl',
help='Chromium download URL. If not specified the default '+\
'URL will be used.',
default='')
parser.add_option('--checkout', dest='checkout',
help='Version of CEF to checkout. If not specified the '+\
'most recent remote version of the branch will be used.',
default='')
parser.add_option('--chromium-checkout', dest='chromiumcheckout',
help='Version of Chromium to checkout (Git '+\
'branch/hash/tag). This overrides the value specified '+\
'by CEF in CHROMIUM_BUILD_COMPATIBILITY.txt.',
default='')
parser.add_option('--chromium-channel', dest='chromiumchannel',
help='Chromium channel to check out (canary, dev, beta or '+\
'stable). This overrides the value specified by CEF '+\
'in CHROMIUM_BUILD_COMPATIBILITY.txt.',
default='')
parser.add_option('--chromium-channel-distance', dest='chromiumchanneldistance',
help='The target number of commits to step in the '+\
'channel, or 0 to use the newest channel version. '+\
'Used in combination with --chromium-channel.',
default='')
# Miscellaneous options.
parser.add_option(
'--force-config',
action='store_true',
dest='forceconfig',
default=False,
help='Force creation of a new gclient config file.')
parser.add_option('--force-clean',
action='store_true', dest='forceclean', default=False,
help='Force a clean checkout of Chromium and CEF. This will'+\
' trigger a new update, build and distribution.')
parser.add_option('--force-clean-deps',
action='store_true', dest='forcecleandeps', default=False,
help='Force a clean checkout of Chromium dependencies. Used'+\
' in combination with --force-clean.')
parser.add_option(
'--dry-run',
action='store_true',
dest='dryrun',
default=False,
help="Output commands without executing them.")
parser.add_option('--dry-run-platform', dest='dryrunplatform', default=None,
help='Simulate a dry run on the specified platform '+\
'(windows, macosx, linux). Must be used in combination'+\
' with the --dry-run flag.')
# Update-related options.
parser.add_option('--force-update',
action='store_true', dest='forceupdate', default=False,
help='Force a Chromium and CEF update. This will trigger a '+\
'new build and distribution.')
parser.add_option('--no-update',
action='store_true', dest='noupdate', default=False,
help='Do not update Chromium or CEF. Pass --force-build or '+\
'--force-distrib if you desire a new build or '+\
'distribution.')
parser.add_option('--no-cef-update',
action='store_true', dest='nocefupdate', default=False,
help='Do not update CEF. Pass --force-build or '+\
'--force-distrib if you desire a new build or '+\
'distribution.')
parser.add_option('--force-cef-update',
action='store_true', dest='forcecefupdate', default=False,
help='Force a CEF update. This will cause local changes in '+\
'the CEF checkout to be discarded and patch files to '+\
'be reapplied.')
parser.add_option(
'--no-chromium-update',
action='store_true',
dest='nochromiumupdate',
default=False,
help='Do not update Chromium.')
parser.add_option(
'--no-depot-tools-update',
action='store_true',
dest='nodepottoolsupdate',
default=False,
help='Do not update depot_tools.')
parser.add_option('--fast-update',
action='store_true', dest='fastupdate', default=False,
help='Update existing Chromium/CEF checkouts for fast incremental '+\
'builds by attempting to minimize the number of modified files. '+\
'The update will fail if there are unstaged CEF changes or if '+\
'Chromium changes are not included in a patch file.')
parser.add_option(
'--force-patch-update',
action='store_true',
dest='forcepatchupdate',
default=False,
help='Force update of patch files.')
parser.add_option(
'--resave',
action='store_true',
dest='resave',
default=False,
help='Resave patch files.')
parser.add_option(
'--log-chromium-changes',
action='store_true',
dest='logchromiumchanges',
default=False,
help='Create a log of the Chromium changes.')
# Build-related options.
parser.add_option('--force-build',
action='store_true', dest='forcebuild', default=False,
help='Force CEF debug and release builds. This builds '+\
'[build-target] on all platforms and chrome_sandbox '+\
'on Linux.')
parser.add_option(
'--no-build',
action='store_true',
dest='nobuild',
default=False,
help='Do not build CEF.')
parser.add_option(
'--build-target',
dest='buildtarget',
default='cefclient',
help='Target name(s) to build (defaults to "cefclient").')
parser.add_option(
'--build-tests',
action='store_true',
dest='buildtests',
default=False,
help='Also build the test target specified via --test-target.')
parser.add_option(
'--no-debug-build',
action='store_true',
dest='nodebugbuild',
default=False,
help="Don't perform the CEF debug build.")
parser.add_option(
'--no-release-build',
action='store_true',
dest='noreleasebuild',
default=False,
help="Don't perform the CEF release build.")
parser.add_option(
'--verbose-build',
action='store_true',
dest='verbosebuild',
default=False,
help='Show all command lines while building.')
parser.add_option(
'--build-failure-limit',
dest='buildfailurelimit',
default=1,
type="int",
help='Keep going until N jobs fail.')
parser.add_option('--build-log-file',
action='store_true', dest='buildlogfile', default=False,
help='Write build logs to file. The file will be named '+\
'"build-[branch]-[debug|release].log" in the download '+\
'directory.')
parser.add_option(
'--x64-build',
action='store_true',
dest='x64build',
default=False,
help='Create a 64-bit build.')
parser.add_option(
'--arm-build',
action='store_true',
dest='armbuild',
default=False,
help='Create an ARM build.')
# Test-related options.
parser.add_option(
'--run-tests',
action='store_true',
dest='runtests',
default=False,
help='Run the ceftests target.')
parser.add_option(
'--no-debug-tests',
action='store_true',
dest='nodebugtests',
default=False,
help="Don't run debug build tests.")
parser.add_option(
'--no-release-tests',
action='store_true',
dest='noreleasetests',
default=False,
help="Don't run release build tests.")
parser.add_option(
'--test-target',
dest='testtarget',
default='ceftests',
help='Test target name to build (defaults to "ceftests").')
parser.add_option(
'--test-prefix',
dest='testprefix',
default='',
help='Prefix for running the test executable (e.g. `xvfb-run` on Linux).')
parser.add_option(
'--test-args',
dest='testargs',
default='',
help='Arguments that will be passed to the test executable.')
# Distribution-related options.
parser.add_option(
'--force-distrib',
action='store_true',
dest='forcedistrib',
default=False,
help='Force creation of a CEF binary distribution.')
parser.add_option(
'--no-distrib',
action='store_true',
dest='nodistrib',
default=False,
help="Don't create a CEF binary distribution.")
parser.add_option(
'--minimal-distrib',
action='store_true',
dest='minimaldistrib',
default=False,
help='Create a minimal CEF binary distribution.')
parser.add_option(
'--minimal-distrib-only',
action='store_true',