From 1efccc8bc76681c4fddb2a60e31c11a569e7eca0 Mon Sep 17 00:00:00 2001 From: "peter@chromium.org" Date: Fri, 27 Apr 2012 16:34:38 +0000 Subject: [PATCH] Add the ability to specify a target_os for gclient solutions This ability is useful for versions of Chromium (i.e. Android) which want to cross-compile to another platform that has a fixed set of custom dependencies. Review URL: http://codereview.chromium.org/10127004 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@134280 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 12 ++++++++++++ tests/gclient_test.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/gclient.py b/gclient.py index 0ebd1e9b7..14da99584 100644 --- a/gclient.py +++ b/gclient.py @@ -47,6 +47,14 @@ Hooks { "pattern": "\\.(gif|jpe?g|pr0n|png)$", "action": ["python", "image_indexer.py", "--all"]}, ] + +Specifying a target OS + An optional key named "target_os" may be added to a gclient file to specify + one or more additional operating systems that should be considered when + processing the deps_os dict of a DEPS file. + + Example: + target_os = [ "android" ] """ __version__ = "0.6.4" @@ -843,6 +851,10 @@ solutions = [ except SyntaxError, e: gclient_utils.SyntaxErrorToError('.gclient', e) + # 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)) + deps_to_add = [] for s in config_dict.get('solutions', []): try: diff --git a/tests/gclient_test.py b/tests/gclient_test.py index a1433e38b..235ca54f5 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -275,6 +275,38 @@ class GclientTest(trial_dir.TestCase): work_queue.flush({}, None, [], options=options) self.assertEqual(client.GetHooks(options), [x['action'] for x in hooks]) + def testTargetOS(self): + """Verifies that specifying a target_os pulls in all 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. The + value will be appended to the _enforced_os tuple. + """ + + write( + '.gclient', + 'solutions = [\n' + ' { "name": "foo",\n' + ' "url": "svn://example.com/foo",\n' + ' }]\n' + 'target_os = ["baz"]') + 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', 'unix'], sorted(obj.enforced_os)) + if __name__ == '__main__': sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)