OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import contextlib | 5 import contextlib |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
(...skipping 29 matching lines...) Expand all Loading... |
40 'platform': 'android_linux2', | 40 'platform': 'android_linux2', |
41 }, | 41 }, |
42 'ANDROID_SDK_ROOT': { | 42 'ANDROID_SDK_ROOT': { |
43 'dependency_name': 'android_sdk', | 43 'dependency_name': 'android_sdk', |
44 'platform': 'android_linux2', | 44 'platform': 'android_linux2', |
45 }, | 45 }, |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 def _GetEnvironmentVariableConfig(): | 49 def _GetEnvironmentVariableConfig(): |
50 env_var_config = {} | 50 path_config = ( |
51 for k, v in _LEGACY_ENVIRONMENT_VARIABLES.iteritems(): | 51 (os.environ.get(k), v) |
52 path = os.environ.get(k) | 52 for k, v in _LEGACY_ENVIRONMENT_VARIABLES.iteritems()) |
53 if path: | 53 return { |
54 env_var_config[v['dependency_name']] = { | 54 'config_type': 'BaseConfig', |
| 55 'dependencies': { |
| 56 c['dependency_name']: { |
55 'file_info': { | 57 'file_info': { |
56 v['platform']: { | 58 c['platform']: { |
57 'local_paths': [path] | 59 'local_paths': [p], |
58 } | 60 }, |
59 } | 61 }, |
60 } | 62 } for p, c in path_config if p |
61 return env_var_config | 63 }, |
| 64 } |
62 | 65 |
63 | 66 |
64 class _Environment(object): | 67 class _Environment(object): |
65 | 68 |
66 def __init__(self): | 69 def __init__(self): |
67 self._dm_init_lock = threading.Lock() | 70 self._dm_init_lock = threading.Lock() |
68 self._dm = None | 71 self._dm = None |
69 | 72 |
70 def Initialize(self, configs=None, config_files=None): | 73 def Initialize(self, configs=None, config_files=None): |
71 """Initialize devil's environment from configuration files. | 74 """Initialize devil's environment from configuration files. |
(...skipping 21 matching lines...) Expand all Loading... |
93 configs=configs, | 96 configs=configs, |
94 config_files=config_files) | 97 config_files=config_files) |
95 assert self._dm is not None, 'Failed to create dependency manager.' | 98 assert self._dm is not None, 'Failed to create dependency manager.' |
96 | 99 |
97 def _InitializeRecursive(self, configs=None, config_files=None): | 100 def _InitializeRecursive(self, configs=None, config_files=None): |
98 # This recurses through configs to create temporary files for each and | 101 # This recurses through configs to create temporary files for each and |
99 # take advantage of context managers to appropriately close those files. | 102 # take advantage of context managers to appropriately close those files. |
100 # TODO(jbudorick): Remove this recursion if/when dependency_manager | 103 # TODO(jbudorick): Remove this recursion if/when dependency_manager |
101 # supports loading configurations directly from a dict. | 104 # supports loading configurations directly from a dict. |
102 if configs: | 105 if configs: |
103 with tempfile.NamedTemporaryFile() as next_config_file: | 106 with tempfile.NamedTemporaryFile(delete=False) as next_config_file: |
104 next_config_file.write(json.dumps(configs[0])) | 107 try: |
105 next_config_file.flush() | 108 next_config_file.write(json.dumps(configs[0])) |
106 self._InitializeRecursive( | 109 next_config_file.close() |
107 configs=configs[1:], | 110 self._InitializeRecursive( |
108 config_files=[next_config_file.name] + (config_files or [])) | 111 configs=configs[1:], |
| 112 config_files=[next_config_file.name] + (config_files or [])) |
| 113 finally: |
| 114 if os.path.exists(next_config_file.name): |
| 115 os.remove(next_config_file.name) |
109 else: | 116 else: |
110 config_files = config_files or [] | 117 config_files = config_files or [] |
111 if 'DEVIL_ENV_CONFIG' in os.environ: | 118 if 'DEVIL_ENV_CONFIG' in os.environ: |
112 config_files.append(os.environ.get('DEVIL_ENV_CONFIG')) | 119 config_files.append(os.environ.get('DEVIL_ENV_CONFIG')) |
113 config_files.append(_DEVIL_DEFAULT_CONFIG) | 120 config_files.append(_DEVIL_DEFAULT_CONFIG) |
114 | 121 |
115 self._dm = dependency_manager.DependencyManager( | 122 self._dm = dependency_manager.DependencyManager( |
116 [dependency_manager.BaseConfig(c) for c in config_files]) | 123 [dependency_manager.BaseConfig(c) for c in config_files]) |
117 | 124 |
118 def FetchPath(self, dependency, arch=None, device=None): | 125 def FetchPath(self, dependency, arch=None, device=None): |
(...skipping 10 matching lines...) Expand all Loading... |
129 | 136 |
130 | 137 |
131 def GetPlatform(arch=None, device=None): | 138 def GetPlatform(arch=None, device=None): |
132 if not arch: | 139 if not arch: |
133 arch = device.product_cpu_abi if device else sys.platform | 140 arch = device.product_cpu_abi if device else sys.platform |
134 return 'android_%s' % arch | 141 return 'android_%s' % arch |
135 | 142 |
136 | 143 |
137 config = _Environment() | 144 config = _Environment() |
138 | 145 |
OLD | NEW |