From 1d30631db4ff58e63c4ae4b7132cb136fb0c37b3 Mon Sep 17 00:00:00 2001 From: dpranke Date: Tue, 11 Aug 2015 14:17:33 -0700 Subject: [PATCH] Fix the way MB invokes the GYP analyzer. Also fix a previously broken unittest, add a new unittest, and make sure the unittests and pylint are run as part of the presubmit checks. R=sky@chromium.org BUG=481692 Review URL: https://codereview.chromium.org/1279093004 Cr-Commit-Position: refs/heads/master@{#342896} --- tools/mb/PRESUBMIT.py | 25 +++++++++++++++++++++++++ tools/mb/mb.py | 4 ++-- tools/mb/mb_unittest.py | 29 +++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 tools/mb/PRESUBMIT.py mode change 100644 => 100755 tools/mb/mb_unittest.py diff --git a/tools/mb/PRESUBMIT.py b/tools/mb/PRESUBMIT.py new file mode 100644 index 000000000000..7774b937b42b --- /dev/null +++ b/tools/mb/PRESUBMIT.py @@ -0,0 +1,25 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +def _CommonChecks(input_api, output_api): + results = [] + + # Run Pylint over the files in the directory. + pylint_checks = input_api.canned_checks.GetPylint(input_api, output_api) + results.extend(input_api.RunTests(pylint_checks)) + + # Run the MB unittests. + results.extend(input_api.canned_checks.RunUnitTestsInDirectory( + input_api, output_api, '.', [ r'^.+_unittest\.py$'])) + + return results + + +def CheckChangeOnUpload(input_api, output_api): + return _CommonChecks(input_api, output_api) + + +def CheckChangeOnCommit(input_api, output_api): + return _CommonChecks(input_api, output_api) diff --git a/tools/mb/mb.py b/tools/mb/mb.py index c38a0965a821..5e2714b98c17 100755 --- a/tools/mb/mb.py +++ b/tools/mb/mb.py @@ -24,7 +24,6 @@ import sys import subprocess import tempfile - def main(args): mbw = MetaBuildWrapper() mbw.ParseArgs(args) @@ -438,7 +437,8 @@ class MetaBuildWrapper(object): self.Print() cmd = self.GYPCmd(output_dir, vals['gyp_defines'], config=gyp_config) - cmd.extend(['-G', 'config_path=%s' % self.args.input_path[0], + cmd.extend(['-f', 'analyzer', + '-G', 'config_path=%s' % self.args.input_path[0], '-G', 'analyzer_output_path=%s' % self.args.output_path[0]]) ret, _, _ = self.Run(cmd) if not ret and self.args.verbose: diff --git a/tools/mb/mb_unittest.py b/tools/mb/mb_unittest.py old mode 100644 new mode 100755 index 6723950b96ef..2b1d5fa458e5 --- a/tools/mb/mb_unittest.py +++ b/tools/mb/mb_unittest.py @@ -1,3 +1,4 @@ +#!/usr/bin/python # Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -5,6 +6,7 @@ """Tests for mb.py.""" import json +import StringIO import sys import unittest @@ -212,8 +214,12 @@ class UnitTest(unittest.TestCase): 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/testing/buildbot/gn_isolate_map.pyl': ( + "{'base_unittests': {" + " 'label': '//base:base_unittests'," + " 'type': 'raw'," + " 'args': []," + "}}\n" ), '/fake_src/out/Default/base_unittests.runtime_deps': ( "base_unittests\n" @@ -239,9 +245,10 @@ class UnitTest(unittest.TestCase): "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) + mbw = self.check(['analyze', '-c', 'gyp_rel_bot', '//out/Release', + '/tmp/in.json', '/tmp/out.json'], + ret=0) + self.assertIn('analyzer', mbw.calls[0]) def test_gyp_gen(self): self.check(['gen', '-c', 'gyp_rel_bot', '//out/Release'], ret=0) @@ -257,9 +264,15 @@ class UnitTest(unittest.TestCase): "-G config=Release -D goma=1 -D gomadir=/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']) + orig_stdout = sys.stdout + try: + sys.stdout = StringIO.StringIO() + self.assertRaises(SystemExit, self.check, ['-h']) + self.assertRaises(SystemExit, self.check, ['help']) + self.assertRaises(SystemExit, self.check, ['help', 'gen']) + finally: + sys.stdout = orig_stdout + def test_validate(self): self.check(['validate'], ret=0) -- 2.11.4.GIT