1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""Module for the target platform support.""" 6 7from importlib import import_module 8import os 9 10import cr 11 12DEFAULT = cr.Config.From( 13 DEPOT_TOOLS=os.path.join('{GOOGLE_CODE}', 'depot_tools'), 14) 15 16 17class Platform(cr.Plugin, cr.Plugin.Type): 18 """Base class for implementing cr platforms. 19 20 A platform is the target operating system being compiled for (linux android). 21 """ 22 23 _platform_module = import_module('platform', None) 24 SELECTOR = 'CR_PLATFORM' 25 26 @classmethod 27 def AddArguments(cls, parser): 28 parser.add_argument( 29 '--platform', dest=cls.SELECTOR, 30 choices=cls.Choices(), 31 default=None, 32 help='Sets the target platform to use. Overrides ' + cls.SELECTOR 33 ) 34 35 @classmethod 36 def System(cls): 37 return cls._platform_module.system() 38 39 def __init__(self): 40 super(Platform, self).__init__() 41 42 def Activate(self, context): 43 super(Platform, self).Activate(context) 44 if _PathFixup not in context.fixup_hooks: 45 context.fixup_hooks.append(_PathFixup) 46 47 @cr.Plugin.activemethod 48 def Prepare(self, context): 49 pass 50 51 @property 52 def paths(self): 53 return [] 54 55 56def _PathFixup(context, key, value): 57 """A context fixup that does platform specific modifications to the PATH.""" 58 if key == 'PATH': 59 paths = [] 60 for entry in Platform.GetActivePlugin(context).paths: 61 entry = context.Substitute(entry) 62 if entry not in paths: 63 paths.append(entry) 64 for entry in value.split(os.path.pathsep): 65 if entry.endswith(os.path.sep + 'goma'): 66 pass 67 elif entry not in paths: 68 paths.append(entry) 69 value = os.path.pathsep.join(paths) 70 return value 71