Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packagerEdge.py

Issue 29931564: Issue 7080 - Don't tranlsate product name in builds for Microsoft Edge (Closed)
Patch Set: Created Oct. 30, 2018, 11:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « package.json ('k') | tests/expecteddata/AppxManifest_edge_development_build.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import os 5 import os
6 import shutil 6 import shutil
7 import json
8 import re
7 from StringIO import StringIO 9 from StringIO import StringIO
10 from glob import glob
8 import subprocess 11 import subprocess
9 import tempfile 12 import tempfile
10 from xml.etree import ElementTree 13 from xml.etree import ElementTree
11 from zipfile import ZipFile 14 from zipfile import ZipFile
12 15
13 import packager 16 import packager
14 import packagerChrome 17 import packagerChrome
15 18
16 MANIFEST = 'appxmanifest.xml' 19 MANIFEST = 'appxmanifest.xml'
17 ASSETS_DIR = 'Assets' 20 ASSETS_DIR = 'Assets'
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 if metadata.has_section('bundles'): 121 if metadata.has_section('bundles'):
119 bundle_tests = devenv and metadata.has_option('general', 'testScripts') 122 bundle_tests = devenv and metadata.has_option('general', 'testScripts')
120 packagerChrome.create_bundles(params, files, bundle_tests) 123 packagerChrome.create_bundles(params, files, bundle_tests)
121 124
122 if metadata.has_section('preprocess'): 125 if metadata.has_section('preprocess'):
123 files.preprocess(metadata.options('preprocess'), {'needsExt': True}) 126 files.preprocess(metadata.options('preprocess'), {'needsExt': True})
124 127
125 if metadata.has_section('import_locales'): 128 if metadata.has_section('import_locales'):
126 packagerChrome.import_locales(params, files) 129 packagerChrome.import_locales(params, files)
127 130
128 # For some mysterious reasons manifoldjs fails with a server error 131 # The Windows Store will reject the build unless every translation of the
129 # when building the development build and there is any translation 132 # product name has been reserved. This is hard till impossible to manage
130 # in az/messages.json for "name_devbuild", however, it works fine 133 # with community translations, so we don't translate the product name for
131 # if we use the more specific language code az-latn. 134 # Microsoft Edge. Furthermore, manifoldjs fails with a server error if the
132 az_translation = files.pop('_locales/az/messages.json', None) 135 # product name is tranlated into Azerbajani.
133 if az_translation is not None: 136 data = json.loads(files['_locales/{}/messages.json'.format(defaultLocale)])
134 files['_locales/az-latn/messages.json'] = az_translation 137 files['manifest.json'] = re.sub(
135 138 r'__MSG_(name(?:_devbuild)?)__',
136 files['manifest.json'] = packagerChrome.createManifest(params, files) 139 lambda m: data[m.group(1)]['message'],
140 packagerChrome.createManifest(params, files),
141 )
137 142
138 if devenv: 143 if devenv:
139 packagerChrome.add_devenv_requirements(files, metadata, params) 144 packagerChrome.add_devenv_requirements(files, metadata, params)
140 145
141 zipped = StringIO() 146 zipped = StringIO()
142 files.zip(zipped) 147 files.zip(zipped)
143 148
144 zipped.seek(0) 149 zipped.seek(0)
145 150
146 if devenv: 151 if devenv:
147 shutil.copyfileobj(zipped, outfile) 152 shutil.copyfileobj(zipped, outfile)
148 return 153 return
149 154
150 tmp_dir = tempfile.mkdtemp('adblockplus_package') 155 tmp_dir = tempfile.mkdtemp('adblockplus_package')
151 try: 156 try:
152 src_dir = os.path.join(tmp_dir, 'src') 157 src_dir = os.path.join(tmp_dir, 'src')
153 ext_dir = os.path.join(tmp_dir, 'ext') 158 ext_dir = os.path.join(tmp_dir, 'ext')
154 159
155 with ZipFile(zipped, 'r') as zip_file: 160 with ZipFile(zipped, 'r') as zip_file:
156 zip_file.extractall(src_dir) 161 zip_file.extractall(src_dir)
157 162
158 cmd_env = os.environ.copy() 163 cmd_env = os.environ.copy()
159 cmd_env['SRC_FOLDER'] = src_dir 164 cmd_env['SRC_FOLDER'] = src_dir
160 cmd_env['EXT_FOLDER'] = ext_dir 165 cmd_env['EXT_FOLDER'] = ext_dir
161 166
162 manifold_folder = os.path.join(ext_dir, 'MSGname', 'edgeextension')
163 manifest_folder = os.path.join(manifold_folder, 'manifest')
164 asset_folder = os.path.join(manifest_folder, ASSETS_DIR)
165
166 # prepare the extension with manifoldjs 167 # prepare the extension with manifoldjs
167 cmd = ['npm', 'run', '--silent', 'build-edge'] 168 cmd = ['npm', 'run', '--silent', 'build-edge']
168 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) 169 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__))
169 170
171 manifold_folder = glob(os.path.join(ext_dir, '*', 'edgeextension'))[0]
172 manifest_folder = os.path.join(manifold_folder, 'manifest')
173 asset_folder = os.path.join(manifest_folder, ASSETS_DIR)
174
170 # update incomplete appxmanifest 175 # update incomplete appxmanifest
171 intermediate_manifest = os.path.join(manifest_folder, MANIFEST) 176 intermediate_manifest = os.path.join(manifest_folder, MANIFEST)
172 update_appx_manifest(intermediate_manifest, baseDir, files, metadata, 177 update_appx_manifest(intermediate_manifest, baseDir, files, metadata,
173 releaseBuild) 178 releaseBuild)
174 179
175 # cleanup placeholders, copy actual images 180 # cleanup placeholders, copy actual images
176 shutil.rmtree(asset_folder) 181 shutil.rmtree(asset_folder)
177 os.mkdir(asset_folder) 182 os.mkdir(asset_folder)
178 if metadata.has_section('appx_assets'): 183 if metadata.has_section('appx_assets'):
179 for name, path in metadata.items('appx_assets'): 184 for name, path in metadata.items('appx_assets'):
180 path = os.path.join(baseDir, path) 185 path = os.path.join(baseDir, path)
181 target = os.path.join(asset_folder, name) 186 target = os.path.join(asset_folder, name)
182 shutil.copyfile(path, target) 187 shutil.copyfile(path, target)
183 188
184 # package app with manifoldjs 189 # package app with manifoldjs
185 cmd = ['npm', 'run', '--silent', 'package-edge'] 190 cmd = ['npm', 'run', '--silent', 'package-edge']
186 191
187 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__)) 192 subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__))
188 193
189 package = os.path.join(manifold_folder, 'package', 194 package = os.path.join(manifold_folder, 'package',
190 'edgeExtension.appx') 195 'edgeExtension.appx')
191 196
192 shutil.copyfile(package, outfile) 197 shutil.copyfile(package, outfile)
193 finally: 198 finally:
194 shutil.rmtree(tmp_dir, ignore_errors=True) 199 shutil.rmtree(tmp_dir, ignore_errors=True)
OLDNEW
« no previous file with comments | « package.json ('k') | tests/expecteddata/AppxManifest_edge_development_build.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld