| Index: tools/mb/mb_unittest.py
|
| diff --git a/tools/mb/mb_unittest.py b/tools/mb/mb_unittest.py
|
| index 942defb9f98cc8ca6fdb03d726d0e846f2e15832..64f53123612505b423f3c6b24a5c958595094897 100755
|
| --- a/tools/mb/mb_unittest.py
|
| +++ b/tools/mb/mb_unittest.py
|
| @@ -7,6 +7,7 @@
|
|
|
| import json
|
| import StringIO
|
| +import os
|
| import sys
|
| import unittest
|
|
|
| @@ -14,17 +15,30 @@ import mb
|
|
|
|
|
| class FakeMBW(mb.MetaBuildWrapper):
|
| - def __init__(self):
|
| + def __init__(self, win32=False):
|
| super(FakeMBW, self).__init__()
|
| +
|
| + # Override vars for test portability.
|
| + if win32:
|
| + self.chromium_src_dir = 'c:\\fake_src'
|
| + self.default_config = 'c:\\fake_src\\tools\\mb\\mb_config.pyl'
|
| + self.platform = 'win32'
|
| + self.executable = 'c:\\python\\python.exe'
|
| + self.sep = '\\'
|
| + else:
|
| + self.chromium_src_dir = '/fake_src'
|
| + self.default_config = '/fake_src/tools/mb/mb_config.pyl'
|
| + self.executable = '/usr/bin/python'
|
| + self.platform = 'linux2'
|
| + self.sep = '/'
|
| +
|
| self.files = {}
|
| self.calls = []
|
| self.cmds = []
|
| self.cross_compile = None
|
| self.out = ''
|
| self.err = ''
|
| - self.platform = 'linux2'
|
| - self.chromium_src_dir = '/fake_src'
|
| - self.default_config = '/fake_src/tools/mb/mb_config.pyl'
|
| + self.rmdirs = []
|
|
|
| def ExpandUser(self, path):
|
| return '$HOME/%s' % path
|
| @@ -33,12 +47,15 @@ class FakeMBW(mb.MetaBuildWrapper):
|
| return self.files.get(path) is not None
|
|
|
| def MaybeMakeDirectory(self, path):
|
| - pass
|
| + self.files[path] = True
|
| +
|
| + def PathJoin(self, *comps):
|
| + return self.sep.join(comps)
|
|
|
| def ReadFile(self, path):
|
| return self.files[path]
|
|
|
| - def WriteFile(self, path, contents):
|
| + def WriteFile(self, path, contents, force_verbose=False):
|
| self.files[path] = contents
|
|
|
| def Call(self, cmd, env=None):
|
| @@ -64,6 +81,12 @@ class FakeMBW(mb.MetaBuildWrapper):
|
| def RemoveFile(self, path):
|
| del self.files[path]
|
|
|
| + def RemoveDirectory(self, path):
|
| + self.rmdirs.append(path)
|
| + files_to_delete = [f for f in self.files if f.startswith(path)]
|
| + for f in files_to_delete:
|
| + self.files[f] = None
|
| +
|
|
|
| class FakeFile(object):
|
| def __init__(self, files):
|
| @@ -83,7 +106,8 @@ TEST_CONFIG = """\
|
| 'common_dev_configs': ['gn_debug'],
|
| 'configs': {
|
| 'gyp_rel_bot': ['gyp', 'rel', 'goma'],
|
| - 'gn_debug': ['gn', 'debug'],
|
| + 'gn_debug': ['gn', 'debug', 'goma'],
|
| + 'gyp_debug': ['gyp', 'debug'],
|
| 'gn_rel_bot': ['gn', 'rel', 'goma'],
|
| 'private': ['gyp', 'rel', 'fake_feature1'],
|
| 'unsupported': ['gn', 'fake_feature2'],
|
| @@ -92,6 +116,7 @@ TEST_CONFIG = """\
|
| 'fake_master': {
|
| 'fake_builder': 'gyp_rel_bot',
|
| 'fake_gn_builder': 'gn_rel_bot',
|
| + 'fake_gyp_builder': 'gyp_debug',
|
| },
|
| },
|
| 'mixins': {
|
| @@ -108,11 +133,10 @@ TEST_CONFIG = """\
|
| 'gn': {'type': 'gn'},
|
| 'goma': {
|
| 'gn_args': 'use_goma=true goma_dir="$(goma_dir)"',
|
| - 'gyp_defines': 'goma=1 gomadir="$(goma_dir)"',
|
| + 'gyp_defines': 'goma=1 gomadir=$(goma_dir)',
|
| },
|
| 'rel': {
|
| 'gn_args': 'is_debug=false',
|
| - 'gyp_config': 'Release',
|
| },
|
| 'debug': {
|
| 'gn_args': 'is_debug=true',
|
| @@ -125,8 +149,8 @@ TEST_CONFIG = """\
|
|
|
|
|
| class UnitTest(unittest.TestCase):
|
| - def fake_mbw(self, files=None):
|
| - mbw = FakeMBW()
|
| + def fake_mbw(self, files=None, win32=False):
|
| + mbw = FakeMBW(win32=win32)
|
| mbw.files.setdefault(mbw.default_config, TEST_CONFIG)
|
| if files:
|
| for path, contents in files.items():
|
| @@ -146,6 +170,37 @@ class UnitTest(unittest.TestCase):
|
| self.assertEqual(mbw.err, err)
|
| return mbw
|
|
|
| + def test_clobber(self):
|
| + files = {
|
| + '/fake_src/out/Debug': None,
|
| + '/fake_src/out/Debug/mb_type': None,
|
| + }
|
| + mbw = self.fake_mbw(files)
|
| +
|
| + # The first time we run this, the build dir doesn't exist, so no clobber.
|
| + self.check(['gen', '-c', 'gn_debug', '//out/Debug'], mbw=mbw, ret=0)
|
| + self.assertEqual(mbw.rmdirs, [])
|
| + self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn')
|
| +
|
| + # The second time we run this, the build dir exists and matches, so no
|
| + # clobber.
|
| + self.check(['gen', '-c', 'gn_debug', '//out/Debug'], mbw=mbw, ret=0)
|
| + self.assertEqual(mbw.rmdirs, [])
|
| + self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gn')
|
| +
|
| + # Now we switch build types; this should result in a clobber.
|
| + self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0)
|
| + self.assertEqual(mbw.rmdirs, ['/fake_src/out/Debug'])
|
| + self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp')
|
| +
|
| + # Now we delete mb_type; this checks the case where the build dir
|
| + # exists but wasn't populated by mb; this should also result in a clobber.
|
| + del mbw.files['/fake_src/out/Debug/mb_type']
|
| + self.check(['gen', '-c', 'gyp_debug', '//out/Debug'], mbw=mbw, ret=0)
|
| + self.assertEqual(mbw.rmdirs,
|
| + ['/fake_src/out/Debug', '/fake_src/out/Debug'])
|
| + self.assertEqual(mbw.files['/fake_src/out/Debug/mb_type'], 'gyp')
|
| +
|
| def test_gn_analyze(self):
|
| files = {'/tmp/in.json': """{\
|
| "files": ["foo/foo_unittest.cc"],
|
| @@ -200,8 +255,19 @@ class UnitTest(unittest.TestCase):
|
| })
|
|
|
| def test_gn_gen(self):
|
| - self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0)
|
| - self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0)
|
| + self.check(['gen', '-c', 'gn_debug', '//out/Default', '-g', '/goma'],
|
| + ret=0,
|
| + out=('/fake_src/buildtools/linux64/gn gen //out/Default '
|
| + '\'--args=is_debug=true use_goma=true goma_dir="/goma"\' '
|
| + '--check\n'))
|
| +
|
| + mbw = self.fake_mbw(win32=True)
|
| + self.check(['gen', '-c', 'gn_debug', '-g', 'c:\\goma', '//out/Debug'],
|
| + mbw=mbw, ret=0,
|
| + out=('c:\\fake_src\\buildtools\\win\\gn gen //out/Debug '
|
| + '"--args=is_debug=true use_goma=true goma_dir=\\"'
|
| + 'c:\\goma\\"" --check\n'))
|
| +
|
|
|
| def test_gn_gen_fails(self):
|
| mbw = self.fake_mbw()
|
| @@ -237,7 +303,7 @@ class UnitTest(unittest.TestCase):
|
|
|
| def test_gn_lookup_goma_dir_expansion(self):
|
| self.check(['lookup', '-c', 'gn_rel_bot', '-g', '/foo'], ret=0,
|
| - out=("/fake_src/buildtools/linux64/gn gen '<path>' "
|
| + out=("/fake_src/buildtools/linux64/gn gen _path_ "
|
| "'--args=is_debug=false use_goma=true "
|
| "goma_dir=\"/foo\"'\n" ))
|
|
|
| @@ -253,7 +319,16 @@ class UnitTest(unittest.TestCase):
|
| self.assertTrue(mbw.cross_compile)
|
|
|
| def test_gyp_gen(self):
|
| - self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0)
|
| + self.check(['gen', '-c', 'gyp_rel_bot', '-g', '/goma', '//out/Release'],
|
| + ret=0,
|
| + out=("GYP_DEFINES='goma=1 gomadir=/goma'\n"
|
| + "python build/gyp_chromium -G output_dir=out\n"))
|
| +
|
| + mbw = self.fake_mbw(win32=True)
|
| + self.check(['gen', '-c', 'gyp_rel_bot', '-g', 'c:\\goma', '//out/Release'],
|
| + mbw=mbw, ret=0,
|
| + out=("set GYP_DEFINES=goma=1 gomadir='c:\\goma'\n"
|
| + "python build\\gyp_chromium -G output_dir=out\n"))
|
|
|
| def test_gyp_gen_fails(self):
|
| mbw = self.fake_mbw()
|
| @@ -262,8 +337,8 @@ class UnitTest(unittest.TestCase):
|
|
|
| def test_gyp_lookup_goma_dir_expansion(self):
|
| self.check(['lookup', '-c', 'gyp_rel_bot', '-g', '/foo'], ret=0,
|
| - out=("python build/gyp_chromium -G 'output_dir=<path>' "
|
| - "-G config=Release -D goma=1 -D gomadir=/foo\n"))
|
| + out=("GYP_DEFINES='goma=1 gomadir=/foo'\n"
|
| + "python build/gyp_chromium -G output_dir=_path_\n"))
|
|
|
| def test_help(self):
|
| orig_stdout = sys.stdout
|
|
|