From 917fac73b0b046b774ea10fa76074d7397568f8d Mon Sep 17 00:00:00 2001 From: dpranke Date: Thu, 25 Jun 2015 14:54:17 -0700 Subject: [PATCH] Clean up mb code. This patch removes the unused RunGNIsolate function from MB, and adds unit test coverage of the --swarming-target-files options to `gn gen`. This patch also re-orders the unit tests to follow the natural sort/execution order and splits GN tests out from GYP tests. R=maruel@chromium.org BUG= Review URL: https://codereview.chromium.org/1202273003 Cr-Commit-Position: refs/heads/master@{#336269} --- tools/mb/mb.py | 48 ------------------------------------------- tools/mb/mb_unittest.py | 54 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 61 deletions(-) diff --git a/tools/mb/mb.py b/tools/mb/mb.py index 7f9aab69fa61..e7ef57b63efe 100755 --- a/tools/mb/mb.py +++ b/tools/mb/mb.py @@ -443,54 +443,6 @@ class MetaBuildWrapper(object): return ret - def RunGNIsolate(self, vals): - build_path = self.args.path[0] - inp = self.ReadInputJSON(['targets']) - if self.args.verbose: - self.Print() - self.Print('isolate input:') - self.PrintJSON(inp) - self.Print() - output_path = self.args.output_path[0] - - for target in inp['targets']: - runtime_deps_path = self.ToAbsPath(build_path, target + '.runtime_deps') - - if not self.Exists(runtime_deps_path): - self.WriteFailureAndRaise('"%s" does not exist' % runtime_deps_path, - output_path) - - command, extra_files = self.GetIsolateCommand(target, vals) - - runtime_deps = self.ReadFile(runtime_deps_path).splitlines() - - - isolate_path = self.ToAbsPath(build_path, target + '.isolate') - self.WriteFile(isolate_path, - pprint.pformat({ - 'variables': { - 'command': command, - 'files': sorted(runtime_deps + extra_files), - 'read_only': 1, - } - }) + '\n') - - self.WriteJSON( - { - 'args': [ - '--isolated', - self.ToSrcRelPath('%s/%s.isolated' % (build_path, target)), - '--isolate', - self.ToSrcRelPath('%s/%s.isolate' % (build_path, target)), - ], - 'dir': self.chromium_src_dir, - 'version': 1, - }, - isolate_path + 'd.gen.json', - ) - - return 0 - def GetIsolateCommand(self, target, vals): extra_files = [] diff --git a/tools/mb/mb_unittest.py b/tools/mb/mb_unittest.py index 2d6ae62e8e1a..6723950b96ef 100644 --- a/tools/mb/mb_unittest.py +++ b/tools/mb/mb_unittest.py @@ -172,7 +172,6 @@ class UnitTest(unittest.TestCase): }"""} mbw = self.fake_mbw(files) mbw.Call = lambda cmd: (0, 'out/Default/foo_unittests\n', '') - self.check(['analyze', '-c', 'gn_debug', '//out/Default', '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) out = json.loads(mbw.files['/tmp/out.json']) @@ -201,38 +200,67 @@ class UnitTest(unittest.TestCase): 'status': 'No dependency', }) + 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) + + def test_gn_gen_fails(self): + mbw = self.fake_mbw() + mbw.Call = lambda cmd: (1, '', '') + self.check(['gen', '-c', 'gn_debug', '//out/Default'], mbw=mbw, ret=1) + + def test_gn_gen_swarming(self): + files = { + '/tmp/swarming_targets': 'base_unittests\n', + '/fake_src/testing/buildbot/ninja_to_gn.pyl': ( + "{'base_unittests': '//base:base_unittests'}\n" + ), + '/fake_src/out/Default/base_unittests.runtime_deps': ( + "base_unittests\n" + ), + } + mbw = self.fake_mbw(files) + self.check(['gen', + '-c', 'gn_debug', + '--swarming-targets-file', '/tmp/swarming_targets', + '//out/Default'], mbw=mbw, ret=0) + self.assertIn('/fake_src/out/Default/base_unittests.isolate', + mbw.files) + self.assertIn('/fake_src/out/Default/base_unittests.isolated.gen.json', + mbw.files) + + def test_gn_lookup(self): + self.check(['lookup', '-c', 'gn_debug'], ret=0) + + 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 '' " + "'--args=is_debug=false use_goma=true " + "goma_dir=\"/foo\"'\n" )) + def test_gyp_analyze(self): self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', '/tmp/in.json', '/tmp/out.json'], ret=0) - def test_gen(self): - self.check(['gen', '-c', 'gn_debug', '//out/Default'], ret=0) + def test_gyp_gen(self): self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0) - def test_gen_fails(self): + def test_gyp_gen_fails(self): mbw = self.fake_mbw() mbw.Call = lambda cmd: (1, '', '') - self.check(['gen', '-c', 'gn_debug', '//out/Default'], mbw=mbw, ret=1) self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], mbw=mbw, ret=1) - def test_goma_dir_expansion(self): + 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=' " "-G config=Release -D goma=1 -D gomadir=/foo\n")) - self.check(['lookup', '-c', 'gn_rel_bot', '-g', '/foo'], ret=0, - out=("/fake_src/buildtools/linux64/gn gen '' " - "'--args=is_debug=false use_goma=true " - "goma_dir=\"/foo\"'\n" )) def test_help(self): self.assertRaises(SystemExit, self.check, ['-h']) self.assertRaises(SystemExit, self.check, ['help']) self.assertRaises(SystemExit, self.check, ['help', 'gen']) - def test_lookup(self): - self.check(['lookup', '-c', 'gn_debug'], ret=0) - def test_validate(self): self.check(['validate'], ret=0) -- 2.11.4.GIT