OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Set of common operations/utilities for build archiving.""" | 5 """Set of common operations/utilities for build archiving.""" |
6 | 6 |
7 import glob | 7 import glob |
8 import os | 8 import os |
9 import platform | 9 import platform |
10 import re | 10 import re |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 symbol_staging_url = 'http://clients2.google.com/cr/staging_symbol' | 71 symbol_staging_url = 'http://clients2.google.com/cr/staging_symbol' |
72 | 72 |
73 | 73 |
74 class FilesCfgParser(object): | 74 class FilesCfgParser(object): |
75 """Class to process a FILES.cfg style listing of build files.""" | 75 """Class to process a FILES.cfg style listing of build files.""" |
76 | 76 |
77 def __init__(self, files_file, buildtype, arch): | 77 def __init__(self, files_file, buildtype, arch): |
78 self._buildtype = buildtype | 78 self._buildtype = buildtype |
79 self._arch = arch | 79 self._arch = arch |
80 self._files_cfg = self._ParseFilesCfg(files_file) | 80 self._files_cfg = self._ParseFilesCfg(files_file) |
81 self._files_list = self._FilterFilesCfg() | 81 self.files_dict = self._FilterFilesCfg() |
82 | 82 |
83 def _SetArch(self, value): | 83 def _SetArch(self, value): |
84 """Set build arch and reset files_list to reflect new build criteria.""" | 84 """Set build arch and reset files_dict to reflect new build criteria.""" |
85 self._arch = value | 85 self._arch = value |
86 del self._files_list[:] | 86 self.files_dict.clear() |
87 self._files_list.extend(self._FilterFilesCfg()) | 87 self.files_dict.update(self._FilterFilesCfg()) |
88 | 88 |
89 arch = property(fset=_SetArch) | 89 arch = property(fset=_SetArch) |
90 | 90 |
91 def _SetBuildType(self, value): | 91 def _SetBuildType(self, value): |
92 """Set build type and reset files_list to reflect new build criteria.""" | 92 """Set build type and reset files_dict to reflect new build criteria.""" |
93 self._buildtype = value | 93 self._buildtype = value |
94 del self._files_list[:] | 94 self.files_dict.clear() |
95 self._files_list.extend(self._FilterFilesCfg()) | 95 self.files_dict.update(self._FilterFilesCfg()) |
96 | 96 |
97 buildtype = property(fset=_SetBuildType) | 97 buildtype = property(fset=_SetBuildType) |
98 | 98 |
99 def _FilterFilesCfg(self): | 99 def _FilterFilesCfg(self): |
100 """Return a list of file items that match the current build criteria.""" | 100 """Return a dict of file items that match the current build criteria.""" |
101 files_list = [] | 101 files_dict = {} |
102 for fileobj in self._files_cfg: | 102 for fileobj in self._files_cfg: |
103 if self._buildtype not in fileobj['buildtype']: | 103 if self._buildtype not in fileobj['buildtype']: |
104 continue | 104 continue |
105 if not fileobj.get('arch') or self._arch in fileobj['arch']: | 105 if not fileobj.get('arch') or self._arch in fileobj['arch']: |
106 files_list.append(fileobj) | 106 files_dict[fileobj['filename']] = fileobj |
107 return files_list | 107 return files_dict |
108 | 108 |
109 @staticmethod | 109 @staticmethod |
110 def _ParseFilesCfg(files_file): | 110 def _ParseFilesCfg(files_file): |
111 """Return the dictionary of archive file info read from the given file.""" | 111 """Return the dictionary of archive file info read from the given file.""" |
112 if not os.path.exists(files_file): | 112 if not os.path.exists(files_file): |
113 raise StagingError('Files list does not exist (%s).' % files_file) | 113 raise StagingError('Files list does not exist (%s).' % files_file) |
114 exec_globals = {'__builtins__': None} | 114 exec_globals = {'__builtins__': None} |
115 | 115 |
116 execfile(files_file, exec_globals) | 116 execfile(files_file, exec_globals) |
117 return exec_globals['FILES'] | 117 return exec_globals['FILES'] |
118 | 118 |
119 @classmethod | 119 @classmethod |
120 def IsDirectArchive(cls, archive_list): | 120 def IsDirectArchive(cls, archive_list): |
121 """Determine if the given archive list should be archived as-is. | 121 """Determine if the given archive list should be archived as-is. |
122 | 122 |
123 An archive list (from ParseArchiveLists) is archived as-is (not added to | 123 An archive list (from ParseArchiveLists) is archived as-is (not added to |
124 another archive file) iff: | 124 another archive file) iff: |
125 - There list contains a single file, and | 125 - There list contains a single file, and |
126 - That file has the 'direct_archive' flag or its 'archive' name matches | 126 - That file has the 'direct_archive' flag or its 'archive' name matches |
127 its 'filename' (an implied 'direct_archive'). | 127 its 'filename' (an implied 'direct_archive'). |
128 """ | 128 """ |
129 fileobj = archive_list[0] | 129 fileobj = archive_list[0] |
130 return (len(archive_list) == 1 and | 130 return (len(archive_list) == 1 and |
131 (fileobj['filename'] == fileobj['archive'] or | 131 (fileobj['filename'] == fileobj['archive'] or |
132 fileobj.get('direct_archive'))) | 132 fileobj.get('direct_archive'))) |
133 | 133 |
134 def IsOptional(self, filename): | 134 def IsOptional(self, filename): |
135 """Determine if the given filename is marked optional for this config.""" | 135 """Determine if the given filename is marked optional for this config.""" |
136 found_optional = False | 136 return (self.files_dict.get(filename) and self._buildtype in |
137 for fileobj in self._files_list: | 137 self.files_dict[filename].get('optional', [])) |
138 if fileobj['filename'] == filename: | |
139 found_optional = True | |
140 if self._buildtype not in fileobj['optional']: | |
141 return False | |
142 return found_optional | |
143 | 138 |
144 def ParseGroup(self, filegroup): | 139 def ParseGroup(self, filegroup): |
145 """Return the list of filenames in the given group (e.g. "symbols").""" | 140 """Return the list of filenames in the given group (e.g. "symbols").""" |
146 return [fileobj['filename'] for fileobj in self._files_list | 141 return [fileobj['filename'] for fileobj in self.files_dict.itervalues() |
147 if (fileobj.get('filegroup') and filegroup in fileobj.get('filegroup')) | 142 if (fileobj.get('filegroup') and filegroup in fileobj.get('filegroup')) |
148 ] | 143 ] |
149 | 144 |
150 def ParseArchiveLists(self): | 145 def ParseArchiveLists(self): |
151 """Generate a dict of all the file items in all archives.""" | 146 """Generate a dict of all the file items in all archives.""" |
152 archive_lists = {} | 147 archive_lists = {} |
153 for fileobj in self._files_list: | 148 for fileobj in self.files_dict.itervalues(): |
154 if fileobj.get('archive'): | 149 if fileobj.get('archive'): |
155 archive_lists.setdefault(fileobj['archive'], []).append(fileobj) | 150 archive_lists.setdefault(fileobj['archive'], []).append(fileobj) |
156 return archive_lists | 151 return archive_lists |
157 | 152 |
158 def ParseLegacyList(self): | 153 def ParseLegacyList(self): |
159 """Return the list of 'default' filenames. | 154 """Return the list of 'default' filenames. |
160 | 155 |
161 Default files are either tagged as "default" filegroup or they have no | 156 Default files are either tagged as "default" filegroup or they have no |
162 filegroup (i.e. legacy entries from before the filegroup field was added.) | 157 filegroup (i.e. legacy entries from before the filegroup field was added.) |
163 """ | 158 """ |
164 files_list = [ | 159 files_list = [ |
165 fileobj['filename'] for fileobj in self._files_list | 160 fileobj['filename'] for fileobj in self.files_dict.itervalues() |
166 if (not fileobj.get('archive') and | 161 if (not fileobj.get('archive') and |
167 (not fileobj.get('filegroup') or 'default' in | 162 (not fileobj.get('filegroup') or 'default' in |
168 fileobj.get('filegroup'))) | 163 fileobj.get('filegroup'))) |
169 ] | 164 ] |
170 return files_list | 165 return files_list |
171 | 166 |
172 | 167 |
173 def ParseFilesList(files_file, buildtype, arch): | 168 def ParseFilesList(files_file, buildtype, arch): |
174 """DEPRECATED: Determine the list of archive files for a given release. | 169 """DEPRECATED: Determine the list of archive files for a given release. |
175 | 170 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 raise_error=not allow_missing) | 320 raise_error=not allow_missing) |
326 if not os.path.exists(zip_file): | 321 if not os.path.exists(zip_file): |
327 raise StagingError('Failed to make zip package %s' % zip_file) | 322 raise StagingError('Failed to make zip package %s' % zip_file) |
328 | 323 |
329 if os.path.basename(zip_file) != archive_name: | 324 if os.path.basename(zip_file) != archive_name: |
330 orig_zip = zip_file | 325 orig_zip = zip_file |
331 zip_file = os.path.join(os.path.dirname(orig_zip), archive_name) | 326 zip_file = os.path.join(os.path.dirname(orig_zip), archive_name) |
332 print 'Renaming archive: "%s" -> "%s"' % (orig_zip, zip_file) | 327 print 'Renaming archive: "%s" -> "%s"' % (orig_zip, zip_file) |
333 chromium_utils.MoveFile(orig_zip, zip_file) | 328 chromium_utils.MoveFile(orig_zip, zip_file) |
334 return (zip_dir, zip_file) | 329 return (zip_dir, zip_file) |
OLD | NEW |