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

Unified Diff: packagerEdge.py

Issue 29825555: Issue 6291 - add ManifoldJS packaging for Edge (Closed) Base URL: https://hg.adblockplus.org/buildtools/file/9a56d76cd951
Patch Set: Created July 9, 2018, 7:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packager.py ('k') | templates/edge/AppxManifest.xml.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerEdge.py
diff --git a/packagerEdge.py b/packagerEdge.py
index a86ffc45d44c532a24319eb809530a4f956f644d..ac671b64dccfbb280afa71bf428898d9db3c96c6 100644
--- a/packagerEdge.py
+++ b/packagerEdge.py
@@ -2,18 +2,17 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-import base64
-import hashlib
+import datetime
import json
-import mimetypes
import os
-import zipfile
+import shutil
+import subprocess
import packager
import packagerChrome
# Files and directories expected inside of the .APPX archive.
-MANIFEST = 'AppxManifest.xml'
+MANIFEST = 'appxmanifest.xml'
CONTENT_TYPES = '[Content_Types].xml'
BLOCKMAP = 'AppxBlockMap.xml'
EXTENSION_DIR = 'Extension'
@@ -29,41 +28,6 @@ def _get_template_for(filename):
return packager.getTemplate('edge/{}.tmpl'.format(filename))
-def _lfh_size(filename):
- """Compute the size of zip local file header for `filename`."""
- try:
- filename = filename.encode('utf-8')
- except UnicodeDecodeError:
- pass # filename is already a byte string.
- return zipfile.sizeFileHeader + len(filename)
-
-
-def _make_blockmap_entry(filename, data):
- blocks = [data[i:i + BLOCKSIZE] for i in range(0, len(data), BLOCKSIZE)]
- return {
- 'name': filename.replace('/', '\\'),
- 'size': len(data),
- 'lfh_size': _lfh_size(filename),
- 'blocks': [
- {'hash': base64.b64encode(hashlib.sha256(block).digest())}
- for block in blocks
- ],
- }
-
-
-def create_appx_blockmap(files):
- """Create APPX blockmap for the list of files."""
- # We don't support AppxBlockmap.xml generation for compressed zip files at
- # the moment. The only way to reliably calculate the compressed size of
- # each 64k chunk in the zip file is to override the relevant parts of
- # `zipfile` library. We have chosen to not do it so we produce an
- # uncompressed zip file that is later repackaged by Windows Store with
- # compression.
- template = _get_template_for(BLOCKMAP)
- files = [_make_blockmap_entry(n, d) for n, d in files.items()]
- return template.render(files=files).encode('utf-8')
-
-
def load_translation(files, locale):
"""Load translation strings for locale from files."""
path = '{}/_locales/{}/messages.json'.format(EXTENSION_DIR, locale)
@@ -126,27 +90,6 @@ def move_files_to_extension(files):
files['{}/{}'.format(EXTENSION_DIR, filename)] = files.pop(filename)
-def create_content_types_map(filenames):
- """Create [Content_Types].xml -- a mime type map."""
- params = {'defaults': {}, 'overrides': {}}
- overrides = {
- BLOCKMAP: 'application/vnd.ms-appx.blockmap+xml',
- MANIFEST: 'application/vnd.ms-appx.manifest+xml',
- }
- types = mimetypes.MimeTypes()
- types.add_type('application/octet-stream', '.otf')
- for filename in filenames:
- ext = os.path.splitext(filename)[1]
- if ext:
- content_type = types.guess_type(filename, strict=False)[0]
- if content_type is not None:
- params['defaults'][ext[1:]] = content_type
- if filename in overrides:
- params['overrides']['/' + filename] = overrides[filename]
- content_types_template = _get_template_for(CONTENT_TYPES)
- return content_types_template.render(params).encode('utf-8')
-
-
def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API.
buildNum=None, releaseBuild=False, keyFile=None,
devenv=False):
@@ -200,7 +143,30 @@ def createBuild(baseDir, type='edge', outFile=None, # noqa: preserve API.
files[MANIFEST] = create_appx_manifest(params, files,
buildNum, releaseBuild)
- files[BLOCKMAP] = create_appx_blockmap(files)
- files[CONTENT_TYPES] = create_content_types_map(files.keys() + [BLOCKMAP])
-
- files.zip(outfile, compression=zipfile.ZIP_STORED)
+ tmp_dir = files.to_tmp_folder('edgeextension/manifest')
+ try:
+ # mock a generationInfo.json, as i would be created by manifoldjs
+ generation_info = packager.getTemplate('generationInfo.json.tmpl')
+ with open(os.path.join(tmp_dir, 'edgeextension',
+ 'generationInfo.json'),
+ 'w') as fp:
+ fp.write(generation_info.render(
+ {'generation_time': datetime.datetime.now()}))
+
+ # package app with manifoldjs
+ cmd = ['npm', 'run', '--silent', 'package-edge']
+
+ cmd_env = os.environ.copy()
+ cmd_env['SRC_FOLDER'] = tmp_dir
+ subprocess.check_call(cmd, env=cmd_env, cwd=os.path.dirname(__file__))
+
+ package = os.path.join(tmp_dir, 'edgeextension', 'package',
+ 'edgeExtension.appx')
+
+ if isinstance(outfile, basestring):
+ shutil.copyfile(package, outfile)
+ else:
+ with open(package, 'rb') as fp:
+ outfile.write(fp.read())
+ finally:
+ shutil.rmtree(tmp_dir, ignore_errors=True)
« no previous file with comments | « packager.py ('k') | templates/edge/AppxManifest.xml.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld