OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A tool to archive croc code coverage to the Chromium buildbot webserver. | 6 """A tool to archive croc code coverage to the Chromium buildbot webserver. |
7 | 7 |
8 When this is run, the current directory (cwd) should be the outer build | 8 When this is run, the current directory (cwd) should be the outer build |
9 directory (e.g., chrome-release/build/). | 9 directory (e.g., chrome-release/build/). |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 | 23 |
24 from common import chromium_utils | 24 from common import chromium_utils |
25 | 25 |
26 from slave import slave_utils | 26 from slave import slave_utils |
27 import config | 27 import config |
28 | 28 |
29 | 29 |
30 class ArchiveCoverage(object): | 30 class ArchiveCoverage(object): |
31 """Class to copy coverage HTML to the buildbot webserver.""" | 31 """Class to copy coverage HTML to the buildbot webserver.""" |
32 | 32 |
33 def __init__(self, options): | 33 def __init__(self, options, coverage_folder_name): |
34 """Constructor. | 34 """Constructor. |
35 | 35 |
36 Args: | 36 Args: |
37 options: Command-line option object from optparse. | 37 options: Command-line option object from optparse. |
38 """ | 38 """ |
39 # Do platform-specific config | 39 # Do platform-specific config |
40 if sys.platform in ('win32', 'cygwin'): | 40 if sys.platform in ('win32', 'cygwin'): |
41 self.is_posix = False | 41 self.is_posix = False |
42 self.from_dir = os.path.join(options.build_dir, options.target, | 42 self.from_dir = os.path.join(options.build_dir, options.target, |
43 'coverage_croc_html') | 43 'coverage_croc_html') |
44 | 44 |
45 elif sys.platform.startswith('darwin'): | 45 elif sys.platform.startswith('darwin'): |
46 self.is_posix = True | 46 self.is_posix = True |
47 self.from_dir = os.path.join(os.path.dirname(options.build_dir), | 47 self.from_dir = os.path.join(os.path.dirname(options.build_dir), |
48 'xcodebuild', options.target, | 48 'xcodebuild', options.target, |
49 'coverage_croc_html') | 49 'coverage_croc_html') |
50 | 50 |
51 elif sys.platform.startswith('linux'): | 51 elif sys.platform.startswith('linux'): |
52 self.is_posix = True | 52 self.is_posix = True |
53 self.from_dir = os.path.join(os.path.dirname(options.build_dir), | 53 self.from_dir = os.path.join(os.path.dirname(options.build_dir), |
54 'out', options.target, # make, not scons | 54 'out', options.target, # make, not scons |
55 coverage_folder_name, | |
55 'coverage_croc_html') | 56 'coverage_croc_html') |
56 | 57 |
57 else: | 58 else: |
58 print 'Unknown/unsupported platform.' | 59 print 'Unknown/unsupported platform.' |
59 sys.exit(1) | 60 sys.exit(1) |
60 | 61 |
61 self.from_dir = os.path.normpath(self.from_dir) | 62 self.from_dir = os.path.normpath(self.from_dir) |
63 | |
cmp
2012/11/01 23:46:22
remove this line
pshenoy
2012/11/05 18:47:22
Done.
| |
62 print 'copy from: %s' % self.from_dir | 64 print 'copy from: %s' % self.from_dir |
63 | 65 |
66 if not os.path.exists(self.from_dir): | |
67 print '%s directory does not exist' % self.from_dir | |
68 sys.exit(1) | |
69 | |
64 # Extract the build name of this slave (e.g., 'chrome-release') from its | 70 # Extract the build name of this slave (e.g., 'chrome-release') from its |
65 # configuration file. | 71 # configuration file. |
66 chrome_dir = os.path.abspath(options.build_dir) | 72 chrome_dir = os.path.abspath(options.build_dir) |
67 print 'chrome_dir: %s' % chrome_dir | 73 print 'chrome_dir: %s' % chrome_dir |
68 build_name = slave_utils.SlaveBuildName(chrome_dir) | 74 build_name = slave_utils.SlaveBuildName(chrome_dir) |
69 print 'build name: %s' % build_name | 75 print 'build name: %s' % build_name |
70 | 76 |
71 # The 'last change:' line MUST appear for the buildbot output-parser to | 77 # The 'last change:' line MUST appear for the buildbot output-parser to |
72 # construct the 'view coverage' link. (See | 78 # construct the 'view coverage' link. (See |
73 # scripts/master/log_parser/archive_command.py) | 79 # scripts/master/log_parser/archive_command.py) |
(...skipping 18 matching lines...) Expand all Loading... | |
92 else: | 98 else: |
93 self.perf_subdir = build_name | 99 self.perf_subdir = build_name |
94 if options.build_number: | 100 if options.build_number: |
95 self.perf_subdir = os.path.join(self.perf_subdir, options.build_number) | 101 self.perf_subdir = os.path.join(self.perf_subdir, options.build_number) |
96 print 'build number: %s' % options.build_number | 102 print 'build number: %s' % options.build_number |
97 print 'perf subdir: %s' % self.perf_subdir | 103 print 'perf subdir: %s' % self.perf_subdir |
98 | 104 |
99 # TODO(jrg) use os.path.join here? | 105 # TODO(jrg) use os.path.join here? |
100 self.archive_path = '%scoverage/%s/%s' % ( | 106 self.archive_path = '%scoverage/%s/%s' % ( |
101 archive_config.www_dir_base, self.perf_subdir, self.last_change) | 107 archive_config.www_dir_base, self.perf_subdir, self.last_change) |
108 # If this is for collecting coverage for unittests, then create | |
109 # a separate path. | |
110 if coverage_folder_name == 'unittests_coverage': | |
111 self.archive_path = os.path.join(self.archive_path, coverage_folder_name) | |
102 self.archive_path = os.path.normpath(self.archive_path) | 112 self.archive_path = os.path.normpath(self.archive_path) |
103 print 'archive path: %s' % self.archive_path | 113 print 'archive path: %s' % self.archive_path |
104 | 114 |
105 def _MakeSourceWorldReadable(self): | 115 def _MakeSourceWorldReadable(self): |
106 """Makes the source tree world-readable.""" | 116 """Makes the source tree world-readable.""" |
107 for (dirpath, dirnames, filenames) in os.walk(self.from_dir): | 117 for (dirpath, dirnames, filenames) in os.walk(self.from_dir): |
108 for node in dirnames + filenames: | 118 for node in dirnames + filenames: |
109 chromium_utils.MakeWorldReadable(os.path.join(dirpath, node)) | 119 chromium_utils.MakeWorldReadable(os.path.join(dirpath, node)) |
110 | 120 |
111 def Run(self): | 121 def Run(self): |
112 """Does the actual upload. | 122 """Does the actual upload. |
113 | 123 |
114 Returns: | 124 Returns: |
115 0 if successful, or non-zero error code if error. | 125 0 if successful, or non-zero error code if error. |
116 """ | 126 """ |
117 if self.is_posix: | 127 if os.path.exists(self.from_dir): |
118 self._MakeSourceWorldReadable() | 128 if self.is_posix: |
cmp
2012/11/01 23:46:22
let's rewrite this so lines 127 is:
if os.path.ex
pshenoy
2012/11/05 18:47:22
Done.
| |
129 self._MakeSourceWorldReadable() | |
119 | 130 |
120 cmd = ['ssh', self.archive_host, 'mkdir', '-p', self.archive_path] | 131 cmd = ['ssh', self.archive_host, 'mkdir', '-p', self.archive_path] |
121 print 'Running: ' + ' '.join(cmd) | 132 print 'Running: ' + ' '.join(cmd) |
122 retval = subprocess.call(cmd) | 133 retval = subprocess.call(cmd) |
123 if retval: | 134 if retval: |
124 return retval | 135 return retval |
125 | 136 |
126 cmd = ['bash', '-c', 'scp -r -p %s/* %s:%s' % | 137 cmd = ['bash', '-c', 'scp -r -p %s/* %s:%s' % |
127 (self.from_dir, self.archive_host, self.archive_path)] | 138 (self.from_dir, self.archive_host, self.archive_path)] |
128 print 'Running: ' + ' '.join(cmd) | 139 print 'Running: ' + ' '.join(cmd) |
129 retval = subprocess.call(cmd) | 140 retval = subprocess.call(cmd) |
130 if retval: | 141 if retval: |
131 return retval | 142 return retval |
132 | 143 |
133 else: | 144 else: |
134 # Windows | 145 # Windows |
135 cmd = ['xcopy', '/S', '/I', '/Y', self.from_dir, self.archive_path] | 146 cmd = ['xcopy', '/S', '/I', '/Y', self.from_dir, self.archive_path] |
136 print 'Running: ' + ' '.join(cmd) | 147 print 'Running: ' + ' '.join(cmd) |
137 retval = subprocess.call(cmd) | 148 retval = subprocess.call(cmd) |
138 if retval: | 149 if retval: |
139 return retval | 150 return retval |
140 | 151 |
141 | 152 |
142 def Main(): | 153 def Main(): |
143 """Main routine.""" | 154 """Main routine.""" |
144 option_parser = optparse.OptionParser() | 155 option_parser = optparse.OptionParser() |
145 option_parser.add_option('--target', | 156 option_parser.add_option('--target', |
146 default='Debug', | 157 default='Debug', |
147 help='build target (Debug, Release) ' | 158 help='build target (Debug, Release) ' |
148 '[default: %default]') | 159 '[default: %default]') |
149 option_parser.add_option('--build-dir', | 160 option_parser.add_option('--build-dir', |
150 default='chrome', | 161 default='chrome', |
151 metavar='DIR', | 162 metavar='DIR', |
152 help='directory in which build was run ' | 163 help='directory in which build was run ' |
153 '[default: %default]') | 164 '[default: %default]') |
154 option_parser.add_option('--perf-subdir', | 165 option_parser.add_option('--perf-subdir', |
155 metavar='DIR', | 166 metavar='DIR', |
156 help='destination subdirectory under' | 167 help='destination subdirectory under' |
157 'coverage') | 168 'coverage') |
158 option_parser.add_option('--build-number', | 169 option_parser.add_option('--build-number', |
159 help='destination subdirectory under perf-subdir') | 170 help='destination subdirectory under perf-subdir') |
160 option_parser.add_option('--internal', action='store_true', | 171 option_parser.add_option('--internal', action='store_true', |
161 help='specifies if we should use Internal config') | 172 help='specifies if we should use Internal config') |
162 options, args = option_parser.parse_args() | 173 options, args = option_parser.parse_args() |
163 if args: | 174 if args: |
164 option_parser.error('Args not supported: %s' % args) | 175 option_parser.error('Args not supported: %s' % args) |
165 ac = ArchiveCoverage(options) | 176 ac = ArchiveCoverage(options, 'total_coverage') |
166 sys.exit(ac.Run()) | 177 ac.Run() |
178 | |
John Grabowski
2012/10/30 21:34:02
remove blank line
need to sys.exit(ac.run()) and
pshenoy
2012/11/05 18:47:22
Main() is called as sys.exit(Main())
| |
179 auc = ArchiveCoverage(options, 'unittests_coverage') | |
180 auc.Run() | |
167 | 181 |
168 | 182 |
169 if '__main__' == __name__: | 183 if '__main__' == __name__: |
170 Main() | 184 Main() |
cmp
2012/11/01 23:46:22
let's put the sys.exit here:
sys.exit(Main())
an
pshenoy
2012/11/05 18:47:22
Done.
| |
OLD | NEW |