From 18a4f6a798201616cd616261143d44dcd6fe9ad8 Mon Sep 17 00:00:00 2001 From: "stuartmorgan@chromium.org" Date: Fri, 2 Nov 2012 13:37:24 +0000 Subject: [PATCH] Allow specificying that only target_os should be used in a gclient file This allows specificying that a target OS list should override the base list instead of adding to it. This is useful for iOS builds, where the desired behavior is to pull only the iOS deps, not the union of the Mac and iOS deps. Review URL: https://chromiumcodereview.appspot.com/11363036 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@165671 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 16 ++++++++++- tests/gclient_test.py | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index a91c61b32..40a5e0d76 100644 --- a/gclient.py +++ b/gclient.py @@ -55,6 +55,13 @@ Specifying a target OS Example: target_os = [ "android" ] + + If the "target_os_only" key is also present and true, then *only* the + operating systems listed in "target_os" will be used. + + Example: + target_os = [ "ios" ] + target_os_only = True """ __version__ = "0.6.4" @@ -886,7 +893,14 @@ solutions = [ # Append any target OS that is not already being enforced to the tuple. target_os = config_dict.get('target_os', []) - self._enforced_os = tuple(set(self._enforced_os).union(target_os)) + if config_dict.get('target_os_only', False): + self._enforced_os = tuple(set(target_os)) + else: + self._enforced_os = tuple(set(self._enforced_os).union(target_os)) + + if not target_os and config_dict.get('target_os_only', False): + raise gclient_utils.Error('Can\'t use target_os_only if target_os is ' + 'not specified') deps_to_add = [] for s in config_dict.get('solutions', []): diff --git a/tests/gclient_test.py b/tests/gclient_test.py index 20c9ca627..449a49169 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -307,6 +307,73 @@ class GclientTest(trial_dir.TestCase): obj = gclient.GClient.LoadCurrentConfig(options) self.assertEqual(['baz', 'unix'], sorted(obj.enforced_os)) + def testTargetOsWithTargetOsOnly(self): + """Verifies that specifying a target_os and target_os_only pulls in only + the relevant dependencies. + + The target_os variable allows specifying the name of an additional OS which + should be considered when selecting dependencies from a DEPS' deps_os. With + target_os_only also set, the _enforced_os tuple will be set to only the + target_os value. + """ + + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo",\n' + ' "url": "svn://example.com/foo",\n' + ' }]\n' + 'target_os = ["baz"]\n' + 'target_os_only = True') + write( + os.path.join('foo', 'DEPS'), + 'deps = {\n' + ' "foo/dir1": "/dir1",' + '}\n' + 'deps_os = {\n' + ' "unix": { "foo/dir2": "/dir2", },\n' + ' "baz": { "foo/dir3": "/dir3", },\n' + '}') + + parser = gclient.Parser() + options, _ = parser.parse_args(['--jobs', '1']) + options.deps_os = "unix" + + obj = gclient.GClient.LoadCurrentConfig(options) + self.assertEqual(['baz'], sorted(obj.enforced_os)) + + def testTargetOsOnlyWithoutTargetOs(self): + """Verifies that specifying a target_os_only without target_os_only raises + an exception. + """ + + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo",\n' + ' "url": "svn://example.com/foo",\n' + ' }]\n' + 'target_os_only = True') + write( + os.path.join('foo', 'DEPS'), + 'deps = {\n' + ' "foo/dir1": "/dir1",' + '}\n' + 'deps_os = {\n' + ' "unix": { "foo/dir2": "/dir2", },\n' + '}') + + parser = gclient.Parser() + options, _ = parser.parse_args(['--jobs', '1']) + options.deps_os = "unix" + + exception_raised = False + try: + gclient.GClient.LoadCurrentConfig(options) + except gclient_utils.Error: + exception_raised = True + self.assertTrue(exception_raised) + def testTargetOsInDepsFile(self): """Verifies that specifying a target_os value in a DEPS file pulls in all relevant dependencies.