forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gyp_chromium: Better parsing of -G command line flag.
Handle -G output_dir=foo as well as -Goutput_dir=foo. I'm not sure how common this case is but we have NaCl SDK bot that do this. Getting this wrong results in windows toolchain being installed in 'out/' (which doesn't necessarily exist) rather than the output_dir tree and gyp uses. Add unittests for the affected parts of gyp_chromium. BUG=454594 Review URL: https://codereview.chromium.org/896663002 Cr-Commit-Position: refs/heads/master@{#314381}
- Loading branch information
Showing
3 changed files
with
99 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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. | ||
|
||
WHITELIST = [ r'.+_test.py$' ] | ||
|
||
|
||
def _RunTests(input_api, output_api): | ||
return (input_api.canned_checks.RunUnitTestsInDirectory( | ||
input_api, output_api, '.', whitelist=[r'.+_test.py$'])) | ||
|
||
|
||
def CheckChangeOnUpload(input_api, output_api): | ||
return _RunTests(input_api, output_api) | ||
|
||
|
||
def CheckChangeOnCommit(input_api, output_api): | ||
return _RunTests(input_api, output_api) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env 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. | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
SRC_DIR = os.path.dirname(SCRIPT_DIR) | ||
|
||
sys.path.append(os.path.join(SRC_DIR, 'third_party', 'pymock')) | ||
|
||
import mock | ||
|
||
# TODO(sbc): Make gyp_chromium more testable by putting the code in | ||
# a .py file. | ||
gyp_chromium = __import__('gyp_chromium') | ||
|
||
|
||
class TestGetOutputDirectory(unittest.TestCase): | ||
@mock.patch('os.environ', {}) | ||
@mock.patch('sys.argv', [__file__]) | ||
def testDefaultValue(self): | ||
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'out') | ||
|
||
@mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'}) | ||
@mock.patch('sys.argv', [__file__]) | ||
def testEnvironment(self): | ||
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'envfoo') | ||
|
||
@mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'}) | ||
@mock.patch('sys.argv', [__file__, '-Goutput_dir=cmdfoo']) | ||
def testGFlagOverridesEnv(self): | ||
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'cmdfoo') | ||
|
||
@mock.patch('os.environ', {}) | ||
@mock.patch('sys.argv', [__file__, '-G', 'output_dir=foo']) | ||
def testGFlagWithSpace(self): | ||
self.assertEqual(gyp_chromium.GetOutputDirectory(), 'foo') | ||
|
||
|
||
class TestGetGypVars(unittest.TestCase): | ||
@mock.patch('os.environ', {}) | ||
def testDefault(self): | ||
self.assertEqual(gyp_chromium.GetGypVars([]), {}) | ||
|
||
@mock.patch('os.environ', {}) | ||
@mock.patch('sys.argv', [__file__, '-D', 'foo=bar']) | ||
def testDFlags(self): | ||
self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar'}) | ||
|
||
@mock.patch('os.environ', {}) | ||
@mock.patch('sys.argv', [__file__, '-D', 'foo']) | ||
def testDFlagsNoValue(self): | ||
self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': '1'}) | ||
|
||
@mock.patch('os.environ', {}) | ||
@mock.patch('sys.argv', [__file__, '-D', 'foo=bar', '-Dbaz']) | ||
def testDFlagMulti(self): | ||
self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar', 'baz': '1'}) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |