-
Notifications
You must be signed in to change notification settings - Fork 289
/
utils.py
executable file
·1001 lines (840 loc) · 40.3 KB
/
utils.py
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
#!/usr/bin/env python
# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
__author__ = 'ivinnichenko@webrtc.org (Illya Vinnichenko)'
import ntpath
import os
import posixpath
import sys
import urlparse
from buildbot.process import factory
from buildbot.process import properties
from buildbot.process.properties import WithProperties
from buildbot.status import builder
from buildbot.steps.shell import ShellCommand
from master import chromium_step
from master.factory import gclient_factory
# Defines the order of the booleans of the supported platforms in the test
# dictionaries in master.cfg.
SUPPORTED_PLATFORMS = ('Linux', 'Mac', 'Windows')
WEBRTC_SOLUTION_NAME = 'trunk'
WEBRTC_SVN_LOCATION = 'http://webrtc.googlecode.com/svn/trunk'
WEBRTC_TRUNK_DIR = 'build/trunk'
WEBRTC_BUILD_DIR = 'build'
VALGRIND_CMD = ['tools/valgrind-webrtc/webrtc_tests.sh', '-t', 'cmdline']
DEFAULT_COVERAGE_DIR = '/var/www/coverage'
DEFAULT_BLOAT_DIR = '/var/www/bloat'
DEFAULT_BLOAT_URL = 'http://webrtc-chrome.lul/bloat/webrtc_bloat.html'
DEFAULT_MASTER_WORK_DIR = '.'
GCLIENT_RETRIES = 3
# Copied from trunk/tools/build/scripts/master/factory/chromium_factory.py
# but converted to a list since we set defines instead of using an environment
# variable.
#
# On valgrind bots, override the optimizer settings so we don't inline too
# much and make the stacks harder to figure out. Use the same settings
# on all buildbot masters to make it easier to move bots.
MEMORY_TOOLS_GYP_DEFINES = [
# GCC flags
'mac_debug_optimization=1 ',
'mac_release_optimization=1 ',
'release_optimize=1 ',
'no_gc_sections=1 ',
'debug_extra_cflags="-g -fno-inline -fno-omit-frame-pointer '
'-fno-builtin -fno-optimize-sibling-calls" ',
'release_extra_cflags="-g -fno-inline -fno-omit-frame-pointer '
'-fno-builtin -fno-optimize-sibling-calls" ',
# MSVS flags
'win_debug_RuntimeChecks=0 ',
'win_debug_disable_iterator_debugging=1 ',
'win_debug_Optimization=1 ',
'win_debug_InlineFunctionExpansion=0 ',
'win_release_InlineFunctionExpansion=0 ',
'win_release_OmitFramePointers=0 ',
'linux_use_tcmalloc=1 ',
'release_valgrind_build=1 ',
'werror= ',
]
class WebRTCFactory(factory.BuildFactory):
"""Abstract superclass for all build factories.
A build factory defines a sequence of steps to take in a build process.
This class provides some helper methods and some abstract methods that
can be overridden to create customized build sequences.
"""
def __init__(self, build_status_oracle, is_try_slave=False,
gclient_solution_name=WEBRTC_SOLUTION_NAME,
svn_url=WEBRTC_SVN_LOCATION,
custom_deps_list=None, safesync_url=None):
"""Creates the abstract factory.
Args:
build_status_oracle: An instance of BuildStatusOracle which is used to
keep track of our build state.
is_try_slave: If this bot is a try slave. Needed since we're handling
some things differently between normal slaves and try slaves.
gclient_solution_name: The name of the solution used for gclient.
svn_url: The Subversion URL for gclient to sync agains.
custom_deps_list: Content to be put in the custom_deps entry of the
.gclient file. The parameter must be a list of tuples with two
strings in each: path and remote URL.
safesync_url: If a LKGR URL shall be used for the gclient sync command.
"""
factory.BuildFactory.__init__(self)
self.build_status_oracle = build_status_oracle
self.is_try_slave = is_try_slave
self.properties = properties.Properties()
self.gyp_params = ['-Dfastbuild=1'] # No debug symbols = build speedup
self.release = False
self.path_joiner = PosixPathJoin
# For GClient solution definition:
self.gclient_solution_name = gclient_solution_name
self.svn_url = svn_url
self.custom_deps_list = custom_deps_list
self.safesync_url = safesync_url
def EnableBuild(self):
"""Adds steps for building WebRTC [must be overridden].
Implementations of this method must add clean and build steps so that
when all steps have been run, we have an up-to-date, complete and correct
build of WebRTC for the platform. It is up to the method how to do this.
"""
pass
def EnableTests(self, tests):
"""Adds test run steps for all tests in the list.
This method must be run after enabling the build.
Args:
tests: list of test to be run.
"""
for test in tests:
self.EnableTest(test)
def AddCommonStep(self, cmd, descriptor='', workdir=WEBRTC_TRUNK_DIR,
halt_build_on_failure=True, warn_on_failure=False,
timeout=1200, use_pty=True):
"""Adds a step which will run as a shell command on the slave.
NOTE: you are recommended to use this method to add new shell commands
instead of the base-class addStep method, since steps added here will
work with the smart-clean system (e.g. only do a full rebuild if the
previous build failed). Steps handled outside this method will not lead
to a full rebuild on the next build if they fail.
Args:
cmd: The command to run. This command follows the contract for
ShellCommand, so see that documentation for more details.
descriptor: A string, or a list of strings, describing what the step
does. The descriptor gets printed in the waterfall display.
workdir: The working directory to run the command in, relative to
the bot's build name directory. The WebRTC root will generally be
in build/trunk/ relative to that directory. The caller is
responsible for making sure that the slashes are flipped the right
way depending on platform, which means you can't use the default
value if the step will run on a Windows machine.
halt_build_on_failure: Stops the build dead in its tracks if this step
fails. Use for critical steps. This option does not make sense with
warn_on_failure.
warn_on_failure: If true, this step isn't that important and will not
cause a failed build on failure.
timeout: The timeout for the command, in seconds.
use_pty: If Pseudo-terminal shall be enabled for the command. This is
needed if stdout and stderr output shall be collected
separately, which is useful to make it possible to color-code
stderr output with red in the web interface. Some shell
commands seem to fail when Pseudo-terminal is enabled on
Linux.
"""
flunk_on_failure = not warn_on_failure
if type(descriptor) is str:
descriptor = [descriptor]
# Add spaces to wrap long test names to make waterfall output more compact.
wrapped_text = self._WrapLongLines(descriptor)
self.addStep(MonitoredShellCommand(
build_status_oracle=self.build_status_oracle,
command=cmd,
workdir=workdir,
description=wrapped_text + ['running...'],
descriptionDone=wrapped_text,
warnOnFailure=warn_on_failure,
flunkOnFailure=flunk_on_failure,
haltOnFailure=halt_build_on_failure,
name='_'.join(descriptor),
timeout=timeout,
usePTY=use_pty))
def AddSmartCleanStep(self):
"""Adds a smart clean step.
Smart clean only cleans the whole repository if the build status oracle
thinks the last build failed. Otherwise it cleans just the build output.
"""
self.addStep(SmartClean(self.build_status_oracle, self.is_try_slave,
self.path_joiner, workdir=WEBRTC_BUILD_DIR))
def AddCommonTestRunStep(self, test, descriptor='', cmd=None):
"""Adds a step for running a single test [must be overridden].
In general, failing tests should not halt the build and allow other tests
to execute. A failing test should fail, or 'flunk', the build though.
The working directory for this command will be the WebRTC root directory
(generally build/trunk).
Implementations of this method must add new steps through AddCommonStep
and not by calling addStep.
Args:
test: The test binary name. The step will attempt to execute this
binary in the binary output folder, except if the cmd argument is
defined (in that case, we will run cmd instead and just use the
test name in the descriptor).
descriptor: This should either be a string or a list of strings. The
descriptor or descriptors are appended to the test name and
displayed in the waterfall.
cmd: If necessary, you can specify this argument to override the
default behavior, which is to just run the binary specified in
test without arguments.
"""
raise NotImplementedError('Must be overridden')
def EnableTest(self, test):
"""Makes a test run in the build sequence. May be overridden.
Override to handle special cases for specific platforms, for instance if
a particular test binary requires command line arguments.
Args:
test: The test name to enable.
"""
self.AddCommonTestRunStep(test)
def AddGclientSyncStep(self, workdir=WEBRTC_BUILD_DIR,
always_use_latest=False):
"""Helper method for invoking gclient sync.
Args:
workdir: The name of the directory to checkout the source into.
The default is 'build' which is the base working dir of
most build slaves.
always_use_latest: Set to true to always use the latest build,
otherwise the highest revision in the changeset will
be used for sync.
"""
gclient_spec = self._ConfigureWhatToBuild()
env = self._GetEnvironmentWithDisabledDepotToolsUpdate()
# Define how the GClient command shall be executed.
# Try 4+1=5 times, 10 seconds apart.
retry = (10, 4)
# Subversion timeout is by default 2 minutes; we allow 5 minutes.
timeout = 60 * 5
# Removal can take a long time. Allow 15 minutes.
rm_timeout = 60 * 15
self.addStep(chromium_step.GClient,
alwaysUseLatest=always_use_latest,
gclient_spec=gclient_spec,
workdir=workdir,
mode='update',
env=env,
retry=retry,
timeout=timeout,
rm_timeout=rm_timeout)
def AddCommonGYPStep(self, gyp_file, gyp_params=[], descriptor='gyp'):
"""Helper method for invoking GYP on WebRTC.
GYP will generate makefiles or its equivalent in a platform-specific
manner. A failed GYP step will halt the build.
This command will run in the WebRTC root directory
(generally build/trunk).
Args:
gyp_file: The root GYP file to use.
gyp_params: Custom GYP parameters (same semantics as the GYP_PARAMS
environment variable).
descriptor: The descriptor to use for the step.
"""
cmd = ['./build/gyp_chromium', '--depth=.', gyp_file]
cmd += gyp_params + self.gyp_params
self.AddCommonStep(cmd=cmd, descriptor=descriptor)
def _ConfigureWhatToBuild(self):
"""Returns a string with the contents of a .gclient file."""
solution = gclient_factory.GClientSolution(name=self.gclient_solution_name,
svn_url=self.svn_url, custom_deps_list=self.custom_deps_list,
safesync_url=self.safesync_url)
return 'solutions = [ %s ]' % solution.GetSpec()
def _GetEnvironmentWithDisabledDepotToolsUpdate(self):
"""Returns a dictionary of environment variables to be used by GClient."""
env = {}
env['DEPOT_TOOLS_UPDATE'] = '0'
return env
def _WrapLongLines(self, string_list, max_line_length=25, wrap_character='_'):
""" Creates a list with wrapped strings for lines that are too long.
This is done by inserting spaces to long lines with the wrap character
in. It's a simple way to make long test targets wrap nicer in the
waterfall display.
This method should only be used for lists that are displayed in the web
interface!
Args:
string_list: List of strings where each string represents one line.
max_line_length: Number of characters a line may have to avoid
getting wrapped.
wrap_character: The character we're looking for when inserting a
space if a string is larger than max_line_length. If no such
character is found, no space will be inserted.
Returns:
A new list of the same length as the input list, but with strings
that may contain extra spaces in them, if longer than the max length.
"""
result = []
for line in string_list:
if len(line) > max_line_length:
index = line.rfind(wrap_character)
if index != -1:
line = line[:index] + ' ' + line[index:]
result.append(line)
return result
class BuildStatusOracle:
"""Keeps track of a particular build's state.
The oracle uses files in the default master work directory to keep track
of whether a build has failed. It only keeps track of the most recent build
until told to forget it.
"""
def __init__(self, builder_name):
"""Creates the oracle.
Args:
builder_name: The name of the associated builder. This name is used
in the filename on disk. This name should be unique.
"""
self.builder_name = builder_name
self.master_work_dir = DEFAULT_MASTER_WORK_DIR
def LastBuildSucceeded(self):
failure_file_path = self._GetFailureBuildPath()
return not os.path.exists(failure_file_path)
def ForgetLastBuild(self):
if not self.LastBuildSucceeded():
os.remove(self._GetFailureBuildPath())
def SetLastBuildAsFailed(self):
open(self._GetFailureBuildPath(), 'w').close()
def _GetFailureBuildPath(self):
return os.path.join(self.master_work_dir, self.builder_name + ".failed")
class MonitoredShellCommand(ShellCommand):
"""Wraps a shell command and notifies the oracle if the command fails."""
def __init__(self, build_status_oracle, **kwargs):
ShellCommand.__init__(self, **kwargs)
self.addFactoryArguments(build_status_oracle=build_status_oracle)
self.build_status_oracle = build_status_oracle
def finished(self, results):
if (results == builder.FAILURE or results == builder.EXCEPTION):
self.build_status_oracle.SetLastBuildAsFailed()
ShellCommand.finished(self, results)
class SmartClean(ShellCommand):
"""Cleans the repository fully or partially depending on the build state."""
def __init__(self, build_status_oracle, is_try_slave, path_joiner, **kwargs):
"""Args:
build_status_oracle: class that knows if the previous build failed.
is_try_slave: if the current factory is a try slave.
path_joiner: function to create paths for the current platform, given
a number of path elements in string form.
"""
ShellCommand.__init__(self, **kwargs)
self.addFactoryArguments(build_status_oracle=build_status_oracle,
is_try_slave=is_try_slave, path_joiner=path_joiner)
self.name = "Clean"
self.haltOnFailure = True
self.build_status_oracle = build_status_oracle
self.is_try_slave = is_try_slave
self.clean_script = path_joiner(WEBRTC_BUILD_DIR, '..', '..', '..', '..',
'..', 'build_internal', 'symsrc',
'cleanup_build.py')
def start(self):
# Always do normal clean for try slaves, since nuking confuses the Chromium
# scripts' GClient sync step.
if self.is_try_slave or self.build_status_oracle.LastBuildSucceeded():
self.description = ['Clean']
cmd = 'python %s ' % self.clean_script
else:
self.build_status_oracle.ForgetLastBuild()
self.description = ['Nuke Repository', '(Previous Failed)']
cmd = 'python %s --nuke' % self.clean_script
self.setCommand(cmd)
ShellCommand.start(self)
class GenerateCodeCoverage(ShellCommand):
"""This custom shell command generates coverage HTML using genhtml.
The command will dump the HTML output into coverage_dir, in a directory
whose name is generated from the build number and slave name. We will
expect that the coverage directory is somewhere under the web server root
(i.e. public html root) that corresponds to the web server URL. That is, if
we write Foo to the coverage directory we expect that directory to be
reachable from url/Foo.
"""
def __init__(self, build_status_oracle, coverage_url, coverage_dir,
coverage_file, **kwargs):
"""Prepares the coverage command.
Args:
build_status_oracle: class that knows if the current build has failed.
coverage_url: The base URL for the serving web server we will use
when we generate the link to the coverage. This will generally
be the slave's URL (something like http://slave-hostname/).
coverage_dir: Where to write coverage HTML.
coverage_file: The LCOV file to generate the coverage from.
"""
ShellCommand.__init__(self, **kwargs)
self.addFactoryArguments(build_status_oracle=build_status_oracle,
coverage_url=coverage_url,
coverage_dir=coverage_dir,
coverage_file=coverage_file)
self.build_status_oracle = build_status_oracle
self.coverage_url = coverage_url
self.description = ['Coverage Report']
self.name = 'LCOV (Report)'
self.warnOnFailure = True
self.flunkOnFailure = False
output_dir = os.path.join(coverage_dir,
'%(buildername)s_%(buildnumber)s')
generate_script = PosixPathJoin('tools', 'continuous_build',
'build_internal', 'scripts',
'generate_coverage_html.sh')
self.setCommand([generate_script, coverage_file,
WithProperties(output_dir)])
def createSummary(self, log):
if self.build_status_oracle.LastBuildSucceeded():
output_url = urlparse.urljoin(self.coverage_url, '%s_%s'
% (self.getProperty('buildername'),
self.getProperty('buildnumber')))
self.addURL('click here', output_url)
def start(self):
if not self.build_status_oracle.LastBuildSucceeded():
self.description = ['Step skipped due to test failure.']
self.setCommand(['false']) # Dummy command that fails.
ShellCommand.start(self)
class ShellCommandWithUrl(ShellCommand):
"""A regular shell command which posts a link when it's done."""
def __init__(self, url, **kwargs):
ShellCommand.__init__(self, **kwargs)
self.addFactoryArguments(url=url)
self.url = url
def createSummary(self, log):
self.addURL('click here', self.url)
class WebRTCAndroidFactory(WebRTCFactory):
"""Sets up the Android build."""
def __init__(self, build_status_oracle, is_try_slave=False):
WebRTCFactory.__init__(self, build_status_oracle, is_try_slave)
def EnableBuild(self, product='toro'):
prefix = 'rm -rf out/target/product/%s/obj/' % product
cleanup_list = [
'rm -rf external/webrtc',
prefix + 'STATIC_LIBRARIES/libwebrtc_*',
prefix + 'SHARE_LIBRARIES/libwebrtc_*',
prefix + 'EXECUTABLES/webrtc_*'
]
cmd = ' ; '.join(cleanup_list)
self.AddCommonStep(cmd, descriptor='cleanup')
self.AddGclientSyncStep(workdir='build/trunk/external/webrtc')
# Work around lack of support for checking out into another dir than the
# last dir of the Subversion URL.
self.AddCommonStep(cmd='mv external/webrtc/trunk/* external/webrtc',
use_pty=False, descriptor='Prepare WebRTC source')
cmd = ('source build/envsetup.sh && lunch full_%s-eng '
'&& mmm external/webrtc showcommands' % product)
self.AddCommonStep(cmd, descriptor='build')
class WebRTCAndroidNDKFactory(WebRTCFactory):
"""Sets up the Android NDK build."""
def __init__(self, build_status_oracle, is_try_slave=False):
WebRTCFactory.__init__(self, build_status_oracle, is_try_slave)
def EnableBuild(self):
self.AddSmartCleanStep()
self.AddGclientSyncStep()
self._AddAndroidStep(cmd='gclient runhooks',
descriptor='gen_android_makefiles')
self._AddAndroidStep(cmd='make -j100', descriptor='build')
def _AddAndroidStep(self, cmd, descriptor):
full_cmd = ('source build/android/buildbot_functions.sh &&'
'bb_setup_environment && '
'source build/android/envsetup.sh &&'
'%s' % cmd)
self.AddCommonStep(cmd=full_cmd, descriptor=descriptor)
class WebRTCChromeFactory(WebRTCFactory):
"""Sets up the Chrome Browser+WebRTC build."""
def __init__(self, build_status_oracle,
gclient_solution_name,
svn_url,
custom_deps_list=None,
safesync_url=None):
WebRTCFactory.__init__(self, build_status_oracle=build_status_oracle,
gclient_solution_name=gclient_solution_name,
svn_url=svn_url,
custom_deps_list=custom_deps_list,
safesync_url=safesync_url)
self.build_enabled = False
def EnableBuild(self, release=False, enable_profiling=False):
self.AddCommonStep(['rm', '-rf', 'src'], workdir=WEBRTC_BUILD_DIR,
descriptor='Cleanup')
self.AddGclientSyncStep(always_use_latest=True)
if enable_profiling:
self.AddCommonStep(['./build/gyp_chromium', '-Dprofiling=1'],
descriptor="gyp_chromium",
warn_on_failure=True, workdir='build/src')
chrome_targets = ['chrome', 'pyautolib']
if release:
self.AddCommonMakeStep(chrome_targets, 'BUILDTYPE=Release')
else:
self.AddCommonMakeStep(chrome_targets)
self.build_enabled = True
self.release = release
self.profiling = enable_profiling
def EnableBloatCalculation(self):
"""Runs a bloat calculation, which will yield a size breakdown for Chrome.
If running in Release mode, you should also run with profiling to get the
symbols right. Running this on Debug mode will work but it will probably
take hours.
"""
assert self.build_enabled is True
assert (self.release and self.profiling) or not self.release
bloat_path = PosixPathJoin(WEBRTC_BUILD_DIR, '..', '..', '..', '..', '..',
'..', 'build_internal', 'symsrc',
'calculate_bloat.py')
output_filename = PosixPathJoin(DEFAULT_BLOAT_DIR, 'bloat_latest.json')
build_directory = 'Release' if self.release else 'Debug'
chrome_binary = PosixPathJoin('out', build_directory, 'chrome')
cmd = [bloat_path, '--binary', chrome_binary, '--source-path', '.',
'--output-file', output_filename]
self.addStep(ShellCommandWithUrl(command=cmd,
url=DEFAULT_BLOAT_URL,
description='calculate_bloat.py',
warnOnFailure=True,
workdir='build/src',
timeout=7200))
def AddCommonMakeStep(self, targets, make_extra=None):
descriptor = ['make'] + targets
cmd = ['make', '-j100'] + targets
if make_extra is not None:
cmd.append(make_extra)
self.AddCommonStep(cmd=cmd, descriptor=descriptor,
warn_on_failure=True, workdir='build/src')
def AddCommonTestRunStep(self, test):
# We currently only support PyAuto tests on this bot.
self._AddPyAutoTestRunStep(test)
def _AddPyAutoTestRunStep(self, test):
assert self.build_enabled
# Set up the test under Xvfb since it will probably launch browser windows.
# Replace any slashes in the test's path with underscores for the name since
# the buildbot web pages will become confused otherwise.
descriptor = test.replace('/', '_')
pyauto_flags = (' --chrome-flags "--enable-media-stream'
' --enable-peer-connection"')
cmd = MakeCommandToRunTestInXvfb(test + pyauto_flags)
self.AddCommonStep(cmd=cmd, descriptor=descriptor, workdir='build/src')
class WebRTCLinuxFactory(WebRTCFactory):
"""Sets up the Linux build.
This factory is quite configurable and can run a variety of builds.
"""
def __init__(self, build_status_oracle, is_try_slave=False,
valgrind_enabled=False, custom_deps_list=None):
WebRTCFactory.__init__(self, build_status_oracle=build_status_oracle,
is_try_slave=is_try_slave,
custom_deps_list=custom_deps_list)
self.build_enabled = False
self.coverage_enabled = False
self.valgrind_enabled = valgrind_enabled
def EnableCoverage(self, coverage_url, coverage_dir=DEFAULT_COVERAGE_DIR):
"""Enables coverage measurements using LCOV/GCOV.
This method must be called before enabling build.
Args:
coverage_url: See the GenerateCodeCoverage command's contract for
this argument.
coverage_dir: See the GenerateCodeCoverage command's contract for
this argument.
"""
assert self.build_enabled is False
self.coverage_enabled = True
self.coverage_url = coverage_url
self.coverage_dir = coverage_dir
def EnableBuild(self, release=False, build32=False, chrome_os=False,
clang=False):
if build32:
self.gyp_params.append('-Dtarget_arch=ia32')
self.build_enabled = True
self.release = release
self.AddSmartCleanStep()
# Valgrind bots need special GYP defines to enable memory profiling
# friendly compilation. They already has a custom .gclient configuration
# file created so they don't need one being generated like the other bots.
if self.valgrind_enabled:
for gyp_define in MEMORY_TOOLS_GYP_DEFINES:
self.gyp_params.append('-D' + gyp_define)
self.AddGclientSyncStep()
if chrome_os:
self.gyp_params.append('-Dchromeos=1')
if clang:
self.gyp_params.append('-Dclang=1')
if self.coverage_enabled:
self.gyp_params.append('-Dcoverage=1')
self.AddCommonGYPStep('webrtc.gyp', descriptor='CommonGYP')
if clang:
self.AddCommonStep(['trunk/tools/clang/scripts/update.sh'],
workdir=WEBRTC_BUILD_DIR,
descriptor='Update_Clang')
if self.release:
self.AddCommonMakeStep('all', make_extra='BUILDTYPE=Release')
else:
self.AddCommonMakeStep('all')
def AddCommonTestRunStep(self, test, extra_text=None, cmd=None):
descriptor = [test, extra_text] if extra_text else [test]
if cmd is None:
test_folder = 'Release' if self.release else 'Debug'
cmd = ['out/%s/%s' % (test_folder, test)]
if self.valgrind_enabled:
cmd = VALGRIND_CMD + cmd
self.AddCommonStep(cmd, descriptor=descriptor, halt_build_on_failure=False)
def AddXvfbTestRunStep(self, test_name, test_binary, test_arguments=''):
""" Adds a test to be run inside a XVFB window manager."""
cmd = MakeCommandToRunTestInXvfb('%s %s' % (test_binary, test_arguments))
self.AddCommonTestRunStep(test=test_name, cmd=cmd)
def AddCommonMakeStep(self, target, extra_text=None, make_extra=None):
descriptor = ['make ' + target, extra_text] if extra_text else ['make ' +
target]
cmd = ['make', target, '-j100']
if make_extra:
cmd.append(make_extra)
self.AddCommonStep(cmd=cmd, descriptor=descriptor)
def AddStepsToEstablishCoverageBaseline(self):
self.AddCommonStep(['lcov', '--directory', '.', '--capture', '-b',
'.', '--initial',
'--output-file', 'webrtc_base.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Baseline Capture)')
self.AddCommonStep(['lcov', '--extract', 'webrtc_base.info', '*/src/*',
'--output', 'filtered.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Baseline Extract)')
self.AddCommonStep(['lcov', '--remove', 'filtered.info', '*/usr/include/*',
'/third*', '/testing/*', '*/test/*', '*_unittest.*',
'*/mock/*', '--output',
'webrtc_base_filtered_final.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Baseline Filter)')
def AddStepsToComputeCoverage(self):
"""Enable coverage data."""
# Delete all third-party .gcda files to save time and work around a bug
# in lcov which tends to hang when capturing on libjpgturbo.
clean_script = PosixPathJoin('tools', 'continuous_build', 'build_internal',
'scripts', 'clean_third_party_gcda.sh')
self.AddCommonStep([clean_script],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Delete 3rd party)')
self.AddCommonStep(['lcov', '--directory', '.', '--capture', '-b',
'.', '--output-file', 'webrtc.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Capture)')
self.AddCommonStep(['lcov', '--extract', 'webrtc.info', '*/src/*',
'--output', 'test.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Extract)')
self.AddCommonStep(['lcov', '--remove', 'test.info', '*/usr/include/*',
'/third*', '/testing/*', '*/test/*', '*_unittest.*',
'*/mock/*', '--output',
'final.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Filter)')
self.AddCommonStep(['lcov', '-a', 'webrtc_base_filtered_final.info', '-a',
'final.info', '-o', 'final.info'],
warn_on_failure=True,
halt_build_on_failure=False,
descriptor='LCOV (Merge)')
# This step isn't monitored but it's fine since it's not critical.
self.addStep(
GenerateCodeCoverage(build_status_oracle=self.build_status_oracle,
coverage_url=self.coverage_url,
coverage_dir=self.coverage_dir,
coverage_file='final.info',
workdir=WEBRTC_TRUNK_DIR))
def EnableTests(self, tests):
if self.coverage_enabled:
self.AddStepsToEstablishCoverageBaseline()
WebRTCFactory.EnableTests(self, tests)
if self.coverage_enabled:
self.AddStepsToComputeCoverage()
def EnableTest(self, test):
"""Adds a step for running a test on Linux.
In general, this method will interpret the name as the name of a binary
in the default build output directory, except for a few special cases
which require custom command lines.
Args:
test: the test name as a string.
"""
if test == 'audioproc_unittest':
self.AddCommonTestRunStep(test)
self.AddCommonGYPStep('webrtc.gyp', gyp_params=['-Dprefer_fixed_point=1'],
descriptor='GYP fixed point')
self.AddCommonMakeStep(test, extra_text='(fixed point)')
self.AddCommonTestRunStep(test, extra_text='(fixed point)')
elif test == 'vie_auto_test':
# TODO(phoglund): Enable the full stack test once it is completed and
# nonflaky.
binary = 'out/Debug/vie_auto_test'
args = (
'--automated --gtest_filter="'
'-ViEVideoVerificationTest.RunsFullStackWithoutErrors" '
'--capture_test_ensure_resolution_alignment_in_capture_device=false')
self.AddXvfbTestRunStep(test_name=test, test_binary=binary,
test_arguments=args)
elif test == 'video_render_module_test':
self.AddXvfbTestRunStep(test_name=test,
test_binary='out/Debug/video_render_module_test')
elif test == 'voe_auto_test':
cmd = 'out/Debug/voe_auto_test --automated'
self.AddCommonTestRunStep(test=test, cmd=cmd)
else:
self.AddCommonTestRunStep(test)
class WebRTCMacFactory(WebRTCFactory):
"""Sets up the Mac build, both for make and xcode."""
def __init__(self, build_status_oracle, is_try_slave=False):
WebRTCFactory.__init__(self, build_status_oracle, is_try_slave)
self.build_type = 'both'
self.allowed_build_types = ['both', 'xcode', 'make']
def EnableBuild(self, build_type='both', release=False):
self.release = release
if build_type not in self.allowed_build_types:
print '*** INCORRECT BUILD TYPE (%s)!!! ***' % build_type
sys.exit(0)
else:
self.build_type = build_type
self.AddSmartCleanStep()
self.AddGclientSyncStep()
if self.build_type == 'make' or self.build_type == 'both':
self.AddCommonGYPStep('webrtc.gyp', gyp_params=['-f', 'make'],
descriptor='EnableMake')
self.AddCommonMakeStep('all')
def AddCommonTestRunStep(self, test, extra_text=None, cmd=None):
descriptor = [test, extra_text] if extra_text else [test]
if cmd is None:
out_path = 'xcodebuild' if self.build_type == 'xcode' else 'out'
test_folder = 'Release' if self.release else 'Debug'
cmd = ['%s/%s/%s' % (out_path, test_folder, test)]
if self.build_type == 'xcode' or self.build_type == 'both':
self.AddCommonStep(cmd, descriptor=descriptor + ['(xcode)'],
halt_build_on_failure=False)
# Execute test only for 'make' build type.
# If 'both' is enabled we'll only execute the 'xcode' built ones.
if self.build_type == 'make':
self.AddCommonStep(cmd, descriptor=descriptor + ['(make)'],
halt_build_on_failure=False)
def AddCommonMakeStep(self, target, extra_text=None, make_extra=None):
descriptor = [target, extra_text] if extra_text else [target]
if self.build_type == 'make' or self.build_type == 'both':
cmd = ['make', target, '-j100']
if make_extra is not None:
cmd.append(make_extra)
if self.release:
cmd.append('BUILDTYPE=Release')
self.AddCommonStep(cmd, descriptor=descriptor + ['(make)'])
if self.build_type == 'xcode' or self.build_type == 'both':
configuration = 'Release' if self.release else 'Debug'
cmd = ['xcodebuild', '-project', 'webrtc.xcodeproj', '-configuration',
configuration, '-target', 'All']
self.AddCommonStep(cmd, descriptor=descriptor + ['(xcode)'])
class WebRTCWinFactory(WebRTCFactory):
"""Sets up the Windows build.
Allows building with Debug, Release or both in sequence.
"""
# Must provide full path to the command since we cannot add custom paths to
# the PATH environment variable when using Chromium buildbot startup scripts.
BUILD_CMD = r'C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe'
def __init__(self, build_status_oracle, is_try_slave=False):
WebRTCFactory.__init__(self, build_status_oracle, is_try_slave)
self.configuration = 'Debug'
self.platform = 'x64'
self.allowed_platforms = ['x64', 'Win32']
self.allowed_configurations = ['Debug', 'Release', 'both']
self.path_joiner = WindowsPathJoin
def AddCommonStep(self, cmd, descriptor='', workdir=WEBRTC_TRUNK_DIR,
halt_build_on_failure=True, warn_on_failure=False):
workdir = workdir.replace('/', '\\')
WebRTCFactory.AddCommonStep(self, cmd, descriptor, workdir,
halt_build_on_failure, warn_on_failure)
def EnableBuild(self, platform='Win32', configuration='Debug'):
if platform not in self.allowed_platforms:
raise UnsupportedConfigurationError('Platform %s is not supported.'
% platform)
if configuration not in self.allowed_configurations:
raise UnsupportedConfigurationError('Configuration %s is not supported.'
% configuration)
self.platform = platform
self.configuration = configuration
# List possible interfering processes here to make it easier to debug what
# processes can interfere with us.
cmd = '%WINDIR%\\system32\\tasklist || set ERRORLEVEL=0'
self.AddCommonStep(cmd, 'list_processes')
# Since Windows is very picky about locking files, make sure to kill
# any interfering processes. Feel free to add more process kill steps if
# necessary.
cmd = '%WINDIR%\\system32\\taskkill /f /im svn.exe || set ERRORLEVEL=0'
self.AddCommonStep(cmd, 'svnkill')
# TODO(kjellander): Enable for normal slaves too when all are moved over to
# the new slave architecture.
if self.is_try_slave:
# Run the Chromium kill process script. It requires the handle.exe to be
# copied into third_party/psutils in order to not fail.
# Download from:
# http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
# To avoid having to modify kill_processes.py, we set the working dir to
# the build dir (three levels up from the build dir that contains
# third_party/psutils). Must reference outside the checkout since it may
# have been wiped completely in the previous build.
kill_script = WindowsPathJoin(WEBRTC_BUILD_DIR, '..', '..', '..', '..',
'scripts', 'slave', 'kill_processes.py')
cmd = 'python %s' % kill_script
self.AddCommonStep(cmd, 'taskkill', workdir=WEBRTC_BUILD_DIR)
# Now do the clean + build.
self.AddSmartCleanStep()
self.AddGclientSyncStep()
if self.configuration == 'Debug' or self.configuration == 'both':
cmd = [WebRTCWinFactory.BUILD_CMD, 'webrtc.sln', '/t:Clean',
'/p:Configuration=Debug;Platform=%s' % (self.platform)]
self.AddCommonStep(cmd, descriptor='Build(Clean)')
cmd = [WebRTCWinFactory.BUILD_CMD, 'webrtc.sln',
'/p:Configuration=Debug;Platform=%s' % (self.platform)]
self.AddCommonStep(cmd, descriptor='Build(Debug)')
if self.configuration == 'Release' or self.configuration == 'both':
cmd = [WebRTCWinFactory.BUILD_CMD, 'webrtc.sln', '/t:Clean',
'/p:Configuration=Release;Platform=%s' % (self.platform)]
self.AddCommonStep(cmd, descriptor='Build(Clean)')
cmd = [WebRTCWinFactory.BUILD_CMD, 'webrtc.sln',
'/p:Configuration=Release;Platform=%s' % (self.platform)]
self.AddCommonStep(cmd, descriptor='Build(Release)')
def AddCommonTestRunStep(self, test, cmd=None):
descriptor = [test]
if self.configuration == 'Debug' or self.configuration == 'both':
if cmd is None:
cmd = ['build\Debug\%s.exe' % test]
self.AddCommonStep(cmd, descriptor=descriptor,
halt_build_on_failure=False)
if self.configuration == 'Release' or self.configuration == 'both':
if cmd is None:
cmd = ['build\Release\%s.exe' % test]
self.AddCommonStep(cmd, descriptor=descriptor,
halt_build_on_failure=False)
# Utility functions
def PosixPathJoin(*args):
return posixpath.normpath(posixpath.join(*args))
def WindowsPathJoin(*args):
return ntpath.normpath(ntpath.join(*args))
def MakeCommandToRunTestInXvfb(cmd):
return ('xvfb-run --server-args="-screen 0 800x600x24 -extension Composite" '
'%s' % cmd)
class UnsupportedConfigurationError(Exception):
pass
def GetEnabledTests(test_dict, platform):
"""Returns a list of enabled test names for the provided platform.
Args:
test_dict: Dictionary mapping test names to tuples representing if the
test shall be enabled on each platform. Each tuple contains one
boolean for each platform. The platforms are in the order specified
by SUPPORTED_PLATFORMS.
platform: The platform we're looking to get the tests for.
Returns:
A list of test names, sorted alphabetically.
Raises:
UnsupportedConfigurationError: if the platform supplied is not supported.
"""
if platform not in SUPPORTED_PLATFORMS:
raise UnsupportedConfigurationError('Platform %s is not supported.'
% platform)
result = []
platform_index = SUPPORTED_PLATFORMS.index(platform)
for test_name, enabled_platforms in test_dict.iteritems():
if enabled_platforms[platform_index]:
result.append(test_name)
result.sort()