From 62fd669dc722d16b099048f8bc9a5383070fe104 Mon Sep 17 00:00:00 2001 From: Taras Glek Date: Fri, 10 Sep 2010 12:30:07 -0400 Subject: [PATCH] Bug 589368 - Locale repacking support for jar reordering; r=ted a=blocking-betaN+ --- config/optimizejars.py | 170 ++++++++++++++++++-------- modules/libjar/nsZipArchive.cpp | 2 +- toolkit/locales/l10n.mk | 2 + toolkit/mozapps/installer/packager.mk | 7 +- 4 files changed, 124 insertions(+), 57 deletions(-) diff --git a/config/optimizejars.py b/config/optimizejars.py index 2f26637a874..234d82bf039 100644 --- a/config/optimizejars.py +++ b/config/optimizejars.py @@ -183,14 +183,24 @@ class BinaryBlob: assert_true(out_data == data, "Serialization fail %d !=%d"% (len(out_data), len(data))) return retstruct -def optimizejar(log, jar, outjar): - entries = open(log).read().rstrip().split("\n") +def optimizejar(jar, outjar, inlog = None): + if inlog is not None: + inlog = open(inlog).read().rstrip() + # in the case of an empty log still move the index forward + if len(inlog) == 0: + inlog = [] + else: + inlog = inlog.split("\n") + outlog = [] jarblob = BinaryBlob(jar) dirend = jarblob.read_struct(cdir_end, jarblob.length - size_of(cdir_end)) assert_true(dirend.signature == ENDSIG, "no signature in the end"); - cdir_offset = dirend.cdir_offset - + readahead = 0 + if inlog is None and cdir_offset == 4: + readahead = struct.unpack("= old_entry_offset + len(data): + outlog.append(entry.filename) + reordered_count += 1 + if inlog is None: + dirend.cdir_offset = out_offset + + dirend_data = dirend.pack() assert_true(size_of(cdir_end) == len(dirend_data), "Failed to serialize directory end correctly. Serialized size;%d, expected:%d"%(len(dirend_data), size_of(cdir_end))); - outfd.write(dirend_data) + outfd.seek(dirend.cdir_offset) assert_true(len(cdir_data) == dirend.cdir_size, "Failed to serialize central directory correctly. Serialized size;%d, expected:%d expected-size:%d" % (len(cdir_data), dirend.cdir_size, dirend.cdir_size - len(cdir_data))); outfd.write(cdir_data) outfd.write(dirend_data) + + # for ordered jars the central directory is written in the begining of the file, so a second central-directory + # entry has to be written in the end of the file + if inlog is not None: + outfd.seek(0) + outfd.write(struct.pack("mFileData; const PRUint8* endp = startp + mFd->mLen; - PRUint32 centralOffset = 1; + PRUint32 centralOffset = 4; if (mFd->mLen > ZIPCENTRAL_SIZE && *(PRUint32*)(startp + centralOffset) == CENTRALSIG) { // Success means optimized jar layout from bug 559961 is in effect } else { diff --git a/toolkit/locales/l10n.mk b/toolkit/locales/l10n.mk index 29625d786ff..5e43dc3e935 100644 --- a/toolkit/locales/l10n.mk +++ b/toolkit/locales/l10n.mk @@ -132,6 +132,8 @@ MOZDEPTH ?= $(DEPTH) repackage-zip: UNPACKAGE="$(ZIP_IN)" repackage-zip: +# Adjust jar logs with the new locale (can't use sed -i because of bug 373784) + -$(PERL) -pi -e "s/en-US/$(AB_CD)/g" $(_ABS_DIST)/jarlog/*.jar.log # call a hook for apps to put their uninstall helper.exe into the package $(UNINSTALLER_PACKAGE_HOOK) # copy xpi-stage over, but not install.rdf and chrome.manifest, diff --git a/toolkit/mozapps/installer/packager.mk b/toolkit/mozapps/installer/packager.mk index 01814fbcc57..e9f2ab4b42d 100644 --- a/toolkit/mozapps/installer/packager.mk +++ b/toolkit/mozapps/installer/packager.mk @@ -87,6 +87,7 @@ SDK = $(SDK_PATH)$(PKG_BASENAME).sdk$(SDK_SUFFIX) MAKE_PACKAGE = $(error What is a $(MOZ_PKG_FORMAT) package format?); MAKE_CAB = $(error Don't know how to make a CAB!); +_ABS_DIST = $(call core_abspath,$(DIST)) ifdef WINCE ifndef WINCE_WINDOWS_MOBILE @@ -184,7 +185,6 @@ endif INNER_MAKE_PACKAGE = $(_ABS_MOZSRCDIR)/build/package/mac_osx/pkg-dmg \ --source "$(PKG_DMG_SOURCE)" --target "$(PACKAGE)" \ --volname "$(MOZ_APP_DISPLAYNAME)" $(PKG_DMG_FLAGS) -_ABS_DIST = $(call core_abspath,$(DIST)) INNER_UNMAKE_PACKAGE = \ set -ex; \ rm -rf $(_ABS_DIST)/unpack.tmp; \ @@ -241,10 +241,11 @@ PACK_OMNIJAR = \ mv components.manifest components && \ find . | xargs touch -t 201001010000 && \ zip -r9mX omni.jar $(OMNIJAR_FILES) -x $(NON_OMNIJAR_FILES) && \ - $(OPTIMIZE_JARS_CMD) $(DIST)/jarlog/ ./ ./ && \ + $(OPTIMIZE_JARS_CMD) --optimize $(_ABS_DIST)/jarlog/ ./ ./ && \ mv binary.manifest components && \ printf "manifest components/binary.manifest\n" > chrome.manifest UNPACK_OMNIJAR = \ + $(OPTIMIZE_JARS_CMD) --deoptimize $(_ABS_DIST)/jarlog/ ./ ./ && \ unzip -o omni.jar && \ rm -f components/binary.manifest && \ sed -e 's/^\#binary-component/binary-component/' components/components.manifest > components.manifest && \ @@ -456,7 +457,7 @@ else endif # DMG endif # MOZ_PKG_MANIFEST endif # UNIVERSAL_BINARY - $(OPTIMIZE_JARS_CMD) $(DIST)/jarlog/ $(DIST)/bin/chrome $(DIST)/$(STAGEPATH)$(MOZ_PKG_DIR)/chrome + $(OPTIMIZE_JARS_CMD) --optimize $(DIST)/jarlog/ $(DIST)/bin/chrome $(DIST)/$(STAGEPATH)$(MOZ_PKG_DIR)/chrome ifndef PKG_SKIP_STRIP @echo "Stripping package directory..." @cd $(DIST)/$(STAGEPATH)$(MOZ_PKG_DIR); find . ! -type d \