OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Takes the output of the build step and turns it into a compressed | 6 """Takes the output of the build step and turns it into a compressed |
7 archive ready for distribution. | 7 archive ready for distribution. |
8 | 8 |
9 This script assumes the build script has been run to compile the add-in. | 9 This script assumes the build script has been run to compile the add-in. |
10 It zips up all files required for the add-in installation and places the | 10 It zips up all files required for the add-in installation and places the |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 sys.stderr.write(msg + '\n') | 125 sys.stderr.write(msg + '\n') |
126 sys.exit(1) | 126 sys.exit(1) |
127 | 127 |
128 | 128 |
129 def WriteFileToArchive(archive, filename, archive_name): | 129 def WriteFileToArchive(archive, filename, archive_name): |
130 print 'Adding: %s' % archive_name | 130 print 'Adding: %s' % archive_name |
131 archive_name = join('vs_addin', archive_name) | 131 archive_name = join('vs_addin', archive_name) |
132 archive.add(filename, archive_name) | 132 archive.add(filename, archive_name) |
133 | 133 |
134 | 134 |
135 def CopyWithReplacement(src, dest, replacements): | |
136 if os.path.exists(dest): | |
137 shutil.rmtree(dest) | |
138 os.makedirs(dest) | |
139 src_basename = os.path.basename(src) | |
140 dest_basename = os.path.basename(dest) | |
141 for filename in os.listdir(src): | |
142 srcfile = join(src, filename) | |
143 # skip non-files, in particular .svn folders. | |
144 if not os.path.isfile(srcfile): | |
145 continue | |
146 destfile = join(dest, filename.replace(src_basename, dest_basename)) | |
147 data = open(srcfile, "rb").read() | |
148 for pat, subst in replacements.iteritems(): | |
149 data = data.replace(pat, subst) | |
150 open(destfile, "wb").write(data) | |
151 | |
152 | |
135 def main(): | 153 def main(): |
136 if not os.path.exists(BUILD_DIR): | 154 if not os.path.exists(BUILD_DIR): |
137 Error("build dir not found: %s" % BUILD_DIR) | 155 Error("build dir not found: %s" % BUILD_DIR) |
138 | 156 |
139 archive = tarfile.open(OUTPUT_NAME, 'w:gz') | 157 archive = tarfile.open(OUTPUT_NAME, 'w:gz') |
140 for source_dest in FILE_LIST: | 158 for source_dest in FILE_LIST: |
141 file_name = os.path.basename(source_dest[0]) | 159 file_name = os.path.basename(source_dest[0]) |
142 dest = join(source_dest[1], file_name) | 160 dest = join(source_dest[1], file_name) |
143 WriteFileToArchive(archive, source_dest[0], dest) | 161 WriteFileToArchive(archive, source_dest[0], dest) |
144 | 162 |
145 AddFolderToArchive(RESOURCE_DIRECTORY, archive) | 163 AddFolderToArchive(RESOURCE_DIRECTORY, archive) |
146 | 164 |
147 # Duplicate the NaCl64 platform but rename it to NaCl32 | 165 # Duplicate the NaCl64 platform but rename it to NaCl32 |
148 src64 = join(RESOURCE_DIRECTORY, 'NaCl64') | 166 src64 = join(RESOURCE_DIRECTORY, 'NaCl64') |
149 dest32 = join(BUILD_DIR, 'NaCl32') | |
150 if os.path.exists(dest32): | |
151 shutil.rmtree(dest32) | |
152 os.makedirs(dest32) | |
153 for filename in os.listdir(src64): | |
154 srcfile = join(src64, filename) | |
155 # skip non-files, in particular .svn folders. | |
156 if not os.path.isfile(srcfile): | |
157 continue | |
158 destfile = join(dest32, filename.replace('NaCl64', 'NaCl32')) | |
159 data = open(srcfile, "rb").read() | |
160 data = data.replace("x86_64", "i686") | |
161 data = data.replace("64", "32") | |
162 open(destfile, "wb").write(data) | |
163 | 167 |
164 AddFolderToArchive(join(BUILD_DIR, "NaCl32"), archive, "NaCl32") | 168 dest = join(BUILD_DIR, 'NaCl32') |
169 CopyWithReplacement(src64, dest, {'x86_64': 'i686', '64': '32'}) | |
170 AddFolderToArchive(dest, archive, "NaCl32") | |
171 | |
172 replacements = { | |
binji
2012/10/29 18:08:59
nit: probably should inline this below or rename t
| |
173 'NaCl64': 'PNaCl', | |
174 'x86_64': 'i686', | |
175 '64': '32', | |
176 '.nexe': '.pexe', | |
177 'nacl_link.xml': 'pnacl_link.xml', | |
178 r'win_x86_$(ToolchainName)\bin': r'win_x86_pnacl\newlib\bin', | |
179 r'$(TargetArchitecture)-nacl-gcc.exe': 'pnacl-clang.bat', | |
180 r'$(TargetArchitecture)-nacl-g++.exe': 'pnacl-clang++.bat', | |
181 } | |
182 | |
183 dest = join(BUILD_DIR, 'PNaCl') | |
184 CopyWithReplacement(src64, dest, replacements) | |
185 AddFolderToArchive(dest, archive, "PNaCl") | |
165 | 186 |
166 AddVersionModifiedAddinFile(archive) | 187 AddVersionModifiedAddinFile(archive) |
167 archive.close() | 188 archive.close() |
168 | 189 |
169 | 190 |
170 if __name__ == '__main__': | 191 if __name__ == '__main__': |
171 main() | 192 main() |
OLD | NEW |