Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: tools/mb/mb_unittest.py

Issue 2298403002: Update MB to use `gn analyze`. (Closed)
Patch Set: add mapping for remaining targets Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« testing/buildbot/trybot_analyze_config.json ('K') | « tools/mb/mb.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 """Tests for mb.py.""" 6 """Tests for mb.py."""
7 7
8 import json 8 import json
9 import StringIO 9 import StringIO
10 import os 10 import os
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 }, 209 },
210 } 210 }
211 """ 211 """
212 212
213 213
214 class UnitTest(unittest.TestCase): 214 class UnitTest(unittest.TestCase):
215 def fake_mbw(self, files=None, win32=False): 215 def fake_mbw(self, files=None, win32=False):
216 mbw = FakeMBW(win32=win32) 216 mbw = FakeMBW(win32=win32)
217 mbw.files.setdefault(mbw.default_config, TEST_CONFIG) 217 mbw.files.setdefault(mbw.default_config, TEST_CONFIG)
218 mbw.files.setdefault( 218 mbw.files.setdefault(
219 mbw.ToAbsPath('//testing/buildbot/gn_isolate_map.pyl'),
220 '''{
221 "foo_unittests": {
222 "label": "//foo:foo_unittests",
223 "type": "console_test_launcher",
224 "args": [],
225 },
226 }''')
227 mbw.files.setdefault(
219 mbw.ToAbsPath('//build/args/bots/fake_master/fake_gn_args_bot.gn'), 228 mbw.ToAbsPath('//build/args/bots/fake_master/fake_gn_args_bot.gn'),
220 'is_debug = false\n') 229 'is_debug = false\n')
221 if files: 230 if files:
222 for path, contents in files.items(): 231 for path, contents in files.items():
223 mbw.files[path] = contents 232 mbw.files[path] = contents
224 return mbw 233 return mbw
225 234
226 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None): 235 def check(self, args, mbw=None, files=None, out=None, err=None, ret=None):
227 if not mbw: 236 if not mbw:
228 mbw = self.fake_mbw(files) 237 mbw = self.fake_mbw(files)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 270
262 # Now we delete mb_type; this checks the case where the build dir 271 # Now we delete mb_type; this checks the case where the build dir
263 # exists but wasn't populated by mb; this should also result in a clobber. 272 # exists but wasn't populated by mb; this should also result in a clobber.
264 del mbw.files['/fake_src/out/Debug/mb_type'] 273 del mbw.files['/fake_src/out/Debug/mb_type']
265 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0) 274 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0)
266 self.assertEqual(mbw.rmdirs, 275 self.assertEqual(mbw.rmdirs,
267 ['/fake_src/out/Debug', '/fake_src/out/Debug']) 276 ['/fake_src/out/Debug', '/fake_src/out/Debug'])
268 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp') 277 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp')
269 278
270 def test_gn_analyze(self): 279 def test_gn_analyze(self):
271 files = {'/tmp/in.json': """{\ 280 files = {'/tmp/in.json': '''{\
272 "files": ["foo/foo_unittest.cc"], 281 "files": ["foo/foo_unittest.cc"],
273 "test_targets": ["foo_unittests", "bar_unittests"], 282 "test_targets": ["foo_unittests"],
274 "additional_compile_targets": [] 283 "additional_compile_targets": ["all"]
275 }"""} 284 }''',
285 '/tmp/out.json.gn': '''{\
286 "status": "Found dependency",
287 "compile_targets": ["//foo:foo_unittests"],
288 "test_targets": ["//foo:foo_unittests"]
289 }'''}
276 290
277 mbw = self.fake_mbw(files) 291 mbw = self.fake_mbw(files)
278 mbw.Call = lambda cmd, env=None, buffer_output=True: ( 292 mbw.Call = lambda cmd, env=None, buffer_output=True: (0, '', '')
279 0, 'out/Default/foo_unittests\n', '')
280 293
281 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default', 294 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default',
282 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) 295 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
283 out = json.loads(mbw.files['/tmp/out.json']) 296 out = json.loads(mbw.files['/tmp/out.json'])
284 self.assertEqual(out, { 297 self.assertEqual(out, {
285 'status': 'Found dependency', 298 'status': 'Found dependency',
286 'compile_targets': ['foo_unittests'], 299 'compile_targets': ['foo:foo_unittests'],
287 'test_targets': ['foo_unittests'] 300 'test_targets': ['foo_unittests']
288 }) 301 })
289 302
290 def test_gn_analyze_fails(self):
291 files = {'/tmp/in.json': """{\
292 "files": ["foo/foo_unittest.cc"],
293 "test_targets": ["foo_unittests", "bar_unittests"],
294 "additional_compile_targets": []
295 }"""}
296
297 mbw = self.fake_mbw(files)
298 mbw.Call = lambda cmd, env=None, buffer_output=True: (1, '', '')
299
300 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default',
301 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=1)
302
303 def test_gn_analyze_all(self):
304 files = {'/tmp/in.json': """{\
305 "files": ["foo/foo_unittest.cc"],
306 "test_targets": ["bar_unittests"],
307 "additional_compile_targets": ["all"]
308 }"""}
309 mbw = self.fake_mbw(files)
310 mbw.Call = lambda cmd, env=None, buffer_output=True: (
311 0, 'out/Default/foo_unittests\n', '')
312 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default',
313 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
314 out = json.loads(mbw.files['/tmp/out.json'])
315 self.assertEqual(out, {
316 'status': 'Found dependency (all)',
317 'compile_targets': ['all', 'bar_unittests'],
318 'test_targets': ['bar_unittests'],
319 })
320
321 def test_gn_analyze_missing_file(self):
322 files = {'/tmp/in.json': """{\
323 "files": ["foo/foo_unittest.cc"],
324 "test_targets": ["bar_unittests"],
325 "additional_compile_targets": []
326 }"""}
327 mbw = self.fake_mbw(files)
328 mbw.cmds = [
329 (0, '', ''),
330 (1, 'The input matches no targets, configs, or files\n', ''),
331 (1, 'The input matches no targets, configs, or files\n', ''),
332 ]
333
334 self.check(['analyze', '-c', 'gn_debug_goma', '//out/Default',
335 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
336 out = json.loads(mbw.files['/tmp/out.json'])
337 self.assertEqual(out, {
338 'status': 'No dependency',
339 'compile_targets': [],
340 'test_targets': [],
341 })
342
343 def test_gn_gen(self): 303 def test_gn_gen(self):
344 mbw = self.fake_mbw() 304 mbw = self.fake_mbw()
345 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'], 305 self.check(['gen', '-c', 'gn_debug_goma', '//out/Default', '-g', '/goma'],
346 mbw=mbw, ret=0) 306 mbw=mbw, ret=0)
347 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'], 307 self.assertMultiLineEqual(mbw.files['/fake_src/out/Default/args.gn'],
348 ('goma_dir = "/goma"\n' 308 ('goma_dir = "/goma"\n'
349 'is_debug = true\n' 309 'is_debug = true\n'
350 'use_goma = true\n')) 310 'use_goma = true\n'))
351 311
352 # Make sure we log both what is written to args.gn and the command line. 312 # Make sure we log both what is written to args.gn and the command line.
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 self.check(['lookup', '-c', 'fake_config'], mbw=mbw, 527 self.check(['lookup', '-c', 'fake_config'], mbw=mbw,
568 ret=0, 528 ret=0,
569 out=("GYP_DEFINES='foo=bar baz=1'\n" 529 out=("GYP_DEFINES='foo=bar baz=1'\n"
570 "GYP_LINK_CONCURRENCY=1\n" 530 "GYP_LINK_CONCURRENCY=1\n"
571 "LLVM_FORCE_HEAD_REVISION=1\n" 531 "LLVM_FORCE_HEAD_REVISION=1\n"
572 "python build/gyp_chromium -G output_dir=_path_\n")) 532 "python build/gyp_chromium -G output_dir=_path_\n"))
573 533
574 534
575 if __name__ == '__main__': 535 if __name__ == '__main__':
576 unittest.main() 536 unittest.main()
OLDNEW
« testing/buildbot/trybot_analyze_config.json ('K') | « tools/mb/mb.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698