Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: tools/cr/cr/base/platform.py

Issue 72733002: [cr tool] Adding the concept of a target platform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cr_fix_client_path
Patch Set: Add whitespace Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/cr/cr/base/platform.py
diff --git a/tools/cr/cr/base/platform.py b/tools/cr/cr/base/platform.py
new file mode 100644
index 0000000000000000000000000000000000000000..7155d2bc7102526f27a7c143ce10b6e92df3daff
--- /dev/null
+++ b/tools/cr/cr/base/platform.py
@@ -0,0 +1,70 @@
+# Copyright (c) 2013 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.
+
+"""Module for the target platform support."""
+
+from importlib import import_module
+import os
+
+import cr
+
+DEFAULT = cr.Config.From(
+ DEPOT_TOOLS=os.path.join('{GOOGLE_CODE}', 'depot_tools'),
+)
+
+
+class Platform(cr.Plugin, cr.Plugin.Type):
+ """Base class for implementing cr platforms.
+
+ A platform is the target operating system being compiled for (linux android).
+ """
+
+ _platform_module = import_module('platform', None)
+ SELECTOR = 'CR_PLATFORM'
+
+ @classmethod
+ def AddArguments(cls, parser):
+ parser.add_argument(
+ '--platform', dest=cls.SELECTOR,
+ choices=cls.Choices(),
+ default=None,
+ help='Sets the target platform to use. Overrides ' + cls.SELECTOR
+ )
+
+ @classmethod
+ def System(cls):
+ return cls._platform_module.system()
+
+ def __init__(self):
+ super(Platform, self).__init__()
+
+ def Activate(self, context):
+ super(Platform, self).Activate(context)
+ if _PathFixup not in context.fixup_hooks:
+ context.fixup_hooks.append(_PathFixup)
+
+ @cr.Plugin.activemethod
+ def Prepare(self, context):
+ pass
+
+ @property
+ def paths(self):
+ return []
+
+
+def _PathFixup(context, key, value):
+ """A context fixup that does platform specific modifications to the PATH."""
+ if key == 'PATH':
+ paths = []
+ for entry in Platform.GetActivePlugin(context).paths:
+ entry = context.Substitute(entry)
+ if entry not in paths:
+ paths.append(entry)
+ for entry in value.split(os.path.pathsep):
+ if entry.endswith(os.path.sep + 'goma'):
+ pass
+ elif entry not in paths:
+ paths.append(entry)
+ value = os.path.pathsep.join(paths)
+ return value
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698