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

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

Issue 1348153003: Reland "Remove the 'gyp_config' concept from MB." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win32 test on non-win32 platform Created 5 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
« no previous file with comments | « tools/mb/mb_config.pyl ('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 sys 11 import sys
11 import unittest 12 import unittest
12 13
13 import mb 14 import mb
14 15
15 16
16 class FakeMBW(mb.MetaBuildWrapper): 17 class FakeMBW(mb.MetaBuildWrapper):
17 def __init__(self): 18 def __init__(self):
18 super(FakeMBW, self).__init__() 19 super(FakeMBW, self).__init__()
20
21 # Override vars for test portability.
22 self.chromium_src_dir = '/fake_src'
23 self.default_config = '/fake_src/tools/mb/mb_config.pyl'
24 self.executable = 'python'
25 self.platform = 'linux2'
26 self.sep = '/'
27
19 self.files = {} 28 self.files = {}
20 self.calls = [] 29 self.calls = []
21 self.cmds = [] 30 self.cmds = []
22 self.cross_compile = None 31 self.cross_compile = None
23 self.out = '' 32 self.out = ''
24 self.err = '' 33 self.err = ''
25 self.platform = 'linux2'
26 self.chromium_src_dir = '/fake_src'
27 self.default_config = '/fake_src/tools/mb/mb_config.pyl'
28 self.rmdirs = [] 34 self.rmdirs = []
29 35
30 def ExpandUser(self, path): 36 def ExpandUser(self, path):
31 return '$HOME/%s' % path 37 return '$HOME/%s' % path
32 38
33 def Exists(self, path): 39 def Exists(self, path):
34 return self.files.get(path) is not None 40 return self.files.get(path) is not None
35 41
36 def MaybeMakeDirectory(self, path): 42 def MaybeMakeDirectory(self, path):
37 self.files[path] = True 43 self.files[path] = True
38 44
45 def PathJoin(self, *comps):
46 return self.sep.join(comps)
47
39 def ReadFile(self, path): 48 def ReadFile(self, path):
40 return self.files[path] 49 return self.files[path]
41 50
42 def WriteFile(self, path, contents, force_verbose=False): 51 def WriteFile(self, path, contents, force_verbose=False):
43 self.files[path] = contents 52 self.files[path] = contents
44 53
45 def Call(self, cmd, env=None): 54 def Call(self, cmd, env=None):
46 if env: 55 if env:
47 self.cross_compile = env.get('GYP_CROSSCOMPILE') 56 self.cross_compile = env.get('GYP_CROSSCOMPILE')
48 self.calls.append(cmd) 57 self.calls.append(cmd)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 'gyp_defaults': 'doom_melon=0', 123 'gyp_defaults': 'doom_melon=0',
115 }, 124 },
116 'gyp': {'type': 'gyp'}, 125 'gyp': {'type': 'gyp'},
117 'gn': {'type': 'gn'}, 126 'gn': {'type': 'gn'},
118 'goma': { 127 'goma': {
119 'gn_args': 'use_goma=true goma_dir="$(goma_dir)"', 128 'gn_args': 'use_goma=true goma_dir="$(goma_dir)"',
120 'gyp_defines': 'goma=1 gomadir="$(goma_dir)"', 129 'gyp_defines': 'goma=1 gomadir="$(goma_dir)"',
121 }, 130 },
122 'rel': { 131 'rel': {
123 'gn_args': 'is_debug=false', 132 'gn_args': 'is_debug=false',
124 'gyp_config': 'Release',
125 }, 133 },
126 'debug': { 134 'debug': {
127 'gn_args': 'is_debug=true', 135 'gn_args': 'is_debug=true',
128 'gyp_config': 'Debug',
129 }, 136 },
130 }, 137 },
131 'private_configs': ['private'], 138 'private_configs': ['private'],
132 'unsupported_configs': ['unsupported'], 139 'unsupported_configs': ['unsupported'],
133 } 140 }
134 """ 141 """
135 142
136 143
137 class UnitTest(unittest.TestCase): 144 class UnitTest(unittest.TestCase):
138 def fake_mbw(self, files=None): 145 def fake_mbw(self, files=None):
(...skipping 20 matching lines...) Expand all
159 def test_clobber(self): 166 def test_clobber(self):
160 files = { 167 files = {
161 '/fake_src/out/Debug': None, 168 '/fake_src/out/Debug': None,
162 '/fake_src/out/Debug/mb_type': None, 169 '/fake_src/out/Debug/mb_type': None,
163 } 170 }
164 mbw = self.fake_mbw(files) 171 mbw = self.fake_mbw(files)
165 172
166 # The first time we run this, the build dir doesn't exist, so no clobber. 173 # The first time we run this, the build dir doesn't exist, so no clobber.
167 self.check(['gen', '-c', 'gn_debug', '//out/Debug'], mbw=mbw, ret=0) 174 self.check(['gen', '-c', 'gn_debug', '//out/Debug'], mbw=mbw, ret=0)
168 self.assertEqual(mbw.rmdirs, []) 175 self.assertEqual(mbw.rmdirs, [])
169 self.assertTrue(mbw.files['/fake_src/out/Debug/mb_type'], 'gn') 176 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn')
170 177
171 # The second time we run this, the build dir exists and matches, so no 178 # The second time we run this, the build dir exists and matches, so no
172 # clobber. 179 # clobber.
173 self.check(['gen', '-c', 'gn_debug', '//out/Debug'], mbw=mbw, ret=0) 180 self.check(['gen', '-c', 'gn_debug', '//out/Debug'], mbw=mbw, ret=0)
174 self.assertEqual(mbw.rmdirs, []) 181 self.assertEqual(mbw.rmdirs, [])
175 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn') 182 self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn')
176 183
177 # Now we switch build types; this should result in a clobber. 184 # Now we switch build types; this should result in a clobber.
178 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0) 185 self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0)
179 self.assertEqual(mbw.rmdirs, ['/fake_src/out/Debug']) 186 self.assertEqual(mbw.rmdirs, ['/fake_src/out/Debug'])
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 '/tmp/in.json', '/tmp/out.json'], 294 '/tmp/in.json', '/tmp/out.json'],
288 ret=0) 295 ret=0)
289 self.assertIn('analyzer', mbw.calls[0]) 296 self.assertIn('analyzer', mbw.calls[0])
290 297
291 def test_gyp_crosscompile(self): 298 def test_gyp_crosscompile(self):
292 mbw = self.fake_mbw() 299 mbw = self.fake_mbw()
293 self.check(['gen', '-c', 'private', '//out/Release'], mbw=mbw) 300 self.check(['gen', '-c', 'private', '//out/Release'], mbw=mbw)
294 self.assertTrue(mbw.cross_compile) 301 self.assertTrue(mbw.cross_compile)
295 302
296 def test_gyp_gen(self): 303 def test_gyp_gen(self):
297 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0) 304 self.check(['gen', '-c', 'gyp_rel_bot', '-g', '/goma', '//out/Release'],
305 ret=0,
306 out=("python build/gyp_chromium -G output_dir=out "
307 "-D goma=1 -D gomadir=/goma\n"))
308
309 # simulate win32
310 mbw = self.fake_mbw()
311 mbw.sep = '\\'
312 self.check(['gen', '-c', 'gyp_rel_bot', '-g', 'c:\\goma', '//out/Release'],
313 mbw=mbw, ret=0,
314 out=("python 'build\\gyp_chromium' -G output_dir=out "
315 "-D goma=1 -D 'gomadir=c:\\goma'\n"))
298 316
299 def test_gyp_gen_fails(self): 317 def test_gyp_gen_fails(self):
300 mbw = self.fake_mbw() 318 mbw = self.fake_mbw()
301 mbw.Call = lambda cmd, env=None: (1, '', '') 319 mbw.Call = lambda cmd, env=None: (1, '', '')
302 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], mbw=mbw, ret=1) 320 self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], mbw=mbw, ret=1)
303 321
304 def test_gyp_lookup_goma_dir_expansion(self): 322 def test_gyp_lookup_goma_dir_expansion(self):
305 self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0, 323 self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0,
306 out=("python build/gyp_chromium -G 'output_dir=<path>' " 324 out=("python build/gyp_chromium -G 'output_dir=<path>' "
307 "-G config=Release -D goma=1 -D gomadir=/foo\n")) 325 "-D goma=1 -D gomadir=/foo\n"))
308 326
309 def test_help(self): 327 def test_help(self):
310 orig_stdout = sys.stdout 328 orig_stdout = sys.stdout
311 try: 329 try:
312 sys.stdout = StringIO.StringIO() 330 sys.stdout = StringIO.StringIO()
313 self.assertRaises(SystemExit, self.check, ['-h']) 331 self.assertRaises(SystemExit, self.check, ['-h'])
314 self.assertRaises(SystemExit, self.check, ['help']) 332 self.assertRaises(SystemExit, self.check, ['help'])
315 self.assertRaises(SystemExit, self.check, ['help', 'gen']) 333 self.assertRaises(SystemExit, self.check, ['help', 'gen'])
316 finally: 334 finally:
317 sys.stdout = orig_stdout 335 sys.stdout = orig_stdout
318 336
319 337
320 def test_validate(self): 338 def test_validate(self):
321 self.check(['validate'], ret=0) 339 self.check(['validate'], ret=0)
322 340
323 341
324 if __name__ == '__main__': 342 if __name__ == '__main__':
325 unittest.main() 343 unittest.main()
OLDNEW
« no previous file with comments | « tools/mb/mb_config.pyl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698