From 61a6ae674ea38ce05c2562ccd388f4464cdfb1fd Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Wed, 12 Aug 2015 11:04:03 -0700 Subject: [PATCH] Bug 1160563 - Part 2: Make ANDROID_ASSETS_DIRS a moz.build variable. r=gps We have had singular ANDROID_ASSETS_DIR in Makefile.in for a while. Fennec itself does not use the existing Makefile.in Android code, for complicated historical reasons. This makes the existing variable moz.build-only; generalizes the existing variable to an ordered list; and adds the equivalent use of the new list to the Fennec build, with a simple example asset. This patch also updates the packager to include assets packed into the gecko.ap_. Without the packager change, the assets/ directory in the ap_ gets left out of the final apk. This whole approach is totally non-standard but is more or less required to support our single-locale repack scheme. --HG-- extra : commitid : 4EAh1UNGNWT extra : rebase_source : 5e5b4c4a120c3b4cc776c9f9380ddd2f9b63587e extra : source : 0ddce3eb833e6d6180a19928a9b45d5d12f1d7fa --- build/mobile/robocop/Makefile.in | 2 -- build/mobile/robocop/moz.build | 3 +++ config/makefiles/java-build.mk | 4 ++-- mobile/android/app/assets/example_asset.txt | 1 + mobile/android/base/Makefile.in | 1 + mobile/android/base/moz.build | 4 ++++ mobile/android/mach_commands.py | 1 + python/mozbuild/mozbuild/backend/recursivemake.py | 6 ++++++ python/mozbuild/mozbuild/frontend/context.py | 8 ++++++++ python/mozbuild/mozbuild/frontend/data.py | 11 +++++++++++ python/mozbuild/mozbuild/frontend/emitter.py | 15 ++++++++++----- toolkit/mozapps/installer/upload-files.mk | 1 + 12 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 mobile/android/app/assets/example_asset.txt diff --git a/build/mobile/robocop/Makefile.in b/build/mobile/robocop/Makefile.in index 20f820fdaebb..c0c4d089b2d0 100644 --- a/build/mobile/robocop/Makefile.in +++ b/build/mobile/robocop/Makefile.in @@ -11,8 +11,6 @@ ANDROID_EXTRA_JARS += \ $(srcdir)/robotium-solo-4.3.1.jar \ $(NULL) -ANDROID_ASSETS_DIR := $(TESTPATH)/assets - _JAVA_HARNESS := \ Actions.java \ Assert.java \ diff --git a/build/mobile/robocop/moz.build b/build/mobile/robocop/moz.build index 5145e1219a45..75bf630534fb 100644 --- a/build/mobile/robocop/moz.build +++ b/build/mobile/robocop/moz.build @@ -7,6 +7,9 @@ DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME'] base = '/mobile/android/tests/browser/robocop/' + +ANDROID_ASSETS_DIRS += [base + 'assets'] + TEST_HARNESS_FILES.testing.mochitest += [ base + 'robocop.ini', base + 'robocop_autophone.ini', diff --git a/config/makefiles/java-build.mk b/config/makefiles/java-build.mk index 06b11249d966..019745db58b6 100644 --- a/config/makefiles/java-build.mk +++ b/config/makefiles/java-build.mk @@ -18,7 +18,7 @@ endif #} JAVAFILES ifdef ANDROID_APK_NAME #{ android_res_dirs := $(or $(ANDROID_RES_DIRS),$(srcdir)/res) _ANDROID_RES_FLAG := $(addprefix -S ,$(android_res_dirs)) -_ANDROID_ASSETS_FLAG := $(addprefix -A ,$(ANDROID_ASSETS_DIR)) +_ANDROID_ASSETS_FLAG := $(if $(ANDROID_ASSETS_DIRS),$(addprefix -A ,$(ANDROID_ASSETS_DIRS))) android_manifest := $(or $(ANDROID_MANIFEST_FILE),AndroidManifest.xml) GENERATED_DIRS += classes @@ -45,7 +45,7 @@ $(ANDROID_APK_NAME).ap_: .aapt.deps ; # resource files one subdirectory below the parent resource directory. android_res_files := $(wildcard $(addsuffix /*,$(wildcard $(addsuffix /*,$(android_res_dirs))))) -.aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIR)) +.aapt.deps: $(android_manifest) $(android_res_files) $(wildcard $(ANDROID_ASSETS_DIRS)) @$(TOUCH) $@ $(AAPT) package -f -M $< -I $(ANDROID_SDK)/android.jar $(_ANDROID_RES_FLAG) $(_ANDROID_ASSETS_FLAG) \ -J ${@D} \ diff --git a/mobile/android/app/assets/example_asset.txt b/mobile/android/app/assets/example_asset.txt new file mode 100644 index 000000000000..34338f983eae --- /dev/null +++ b/mobile/android/app/assets/example_asset.txt @@ -0,0 +1 @@ +This is an example asset. diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index 1826e129cdf8..ce79d0af068e 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -420,6 +420,7 @@ $(1): $$(call mkdir_deps,$(filter-out ./,$(dir $(3) $(4) $(5)))) $(2) $(if $(MOZ_ANDROID_MAX_SDK_VERSION),--max-res-version $(MOZ_ANDROID_MAX_SDK_VERSION),) \ --auto-add-overlay \ $$(addprefix -S ,$$(ANDROID_RES_DIRS)) \ + $$(addprefix -A ,$$(ANDROID_ASSETS_DIRS)) \ $(if $(extra_res_dirs),$$(addprefix -S ,$$(extra_res_dirs)),) \ $(if $(extra_packages),--extra-packages $$(extra_packages),) \ --custom-package org.mozilla.gecko \ diff --git a/mobile/android/base/moz.build b/mobile/android/base/moz.build index 60d1e4dd2c30..eff6bb5266f8 100644 --- a/mobile/android/base/moz.build +++ b/mobile/android/base/moz.build @@ -764,6 +764,10 @@ ANDROID_GENERATED_RESFILES += [ 'res/values/strings.xml', ] +ANDROID_ASSETS_DIRS += [ + '/mobile/android/app/assets', +] + # We do not expose MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN here because that # would leak the value to build logs. Instead we expose the token quietly where # appropriate in Makefile.in. diff --git a/mobile/android/mach_commands.py b/mobile/android/mach_commands.py index d7a5b1fba5fe..1a400328c1cb 100644 --- a/mobile/android/mach_commands.py +++ b/mobile/android/mach_commands.py @@ -142,6 +142,7 @@ class MachCommands(MachCommandBase): srcdir('base/src/webrtc_video_capture/java', 'media/webrtc/trunk/webrtc/modules/video_capture/android/java/src') srcdir('base/src/webrtc_video_render/java', 'media/webrtc/trunk/webrtc/modules/video_render/android/java/src') srcdir('base/src/main/res', 'mobile/android/base/resources') + srcdir('base/src/main/assets', 'mobile/android/app/assets') srcdir('base/src/crashreporter/res', 'mobile/android/base/crashreporter/res') manifest_path = os.path.join(self.topobjdir, 'mobile', 'android', 'gradle.manifest') diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index 7ec4e6b68a62..86de6351b353 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -26,6 +26,7 @@ import mozpack.path as mozpath from .common import CommonBackend from ..frontend.data import ( + AndroidAssetsDirs, AndroidResDirs, AndroidEclipseProjectData, BrandingFiles, @@ -71,6 +72,7 @@ from ..util import ( from ..makeutil import Makefile MOZBUILD_VARIABLES = [ + b'ANDROID_ASSETS_DIRS', b'ANDROID_GENERATED_RESFILES', b'ANDROID_RES_DIRS', b'ASFLAGS', @@ -603,6 +605,10 @@ class RecursiveMakeBackend(CommonBackend): for p in obj.paths: backend_file.write('ANDROID_RES_DIRS += %s\n' % p.full_path) + elif isinstance(obj, AndroidAssetsDirs): + for p in obj.paths: + backend_file.write('ANDROID_ASSETS_DIRS += %s\n' % p.full_path) + else: return obj.ack() diff --git a/python/mozbuild/mozbuild/frontend/context.py b/python/mozbuild/mozbuild/frontend/context.py index ab7a5c61dde5..906f075e21c2 100644 --- a/python/mozbuild/mozbuild/frontend/context.py +++ b/python/mozbuild/mozbuild/frontend/context.py @@ -699,6 +699,14 @@ VARIABLES = { file. """, 'export'), + 'ANDROID_ASSETS_DIRS': (ContextDerivedTypedListWithItems(Path, List), list, + """Android assets directories. + + This variable contains a list of directories containing static + files to package into an 'assets' directory and merge into an + APK file. + """, 'export'), + 'ANDROID_ECLIPSE_PROJECT_TARGETS': (dict, dict, """Defines Android Eclipse project targets. diff --git a/python/mozbuild/mozbuild/frontend/data.py b/python/mozbuild/mozbuild/frontend/data.py index 63150bffe434..c08c85233e54 100644 --- a/python/mozbuild/mozbuild/frontend/data.py +++ b/python/mozbuild/mozbuild/frontend/data.py @@ -975,3 +975,14 @@ class AndroidResDirs(ContextDerived): def __init__(self, context, paths): ContextDerived.__init__(self, context) self.paths = paths + +class AndroidAssetsDirs(ContextDerived): + """Represents Android assets directories.""" + + __slots__ = ( + 'paths', + ) + + def __init__(self, context, paths): + ContextDerived.__init__(self, context) + self.paths = paths diff --git a/python/mozbuild/mozbuild/frontend/emitter.py b/python/mozbuild/mozbuild/frontend/emitter.py index ddc0d28e7836..f8ccf02ca205 100644 --- a/python/mozbuild/mozbuild/frontend/emitter.py +++ b/python/mozbuild/mozbuild/frontend/emitter.py @@ -24,6 +24,7 @@ import reftest import mozinfo from .data import ( + AndroidAssetsDirs, AndroidResDirs, BrandingFiles, ConfigFileSubstitution, @@ -700,14 +701,18 @@ class TreeMetadataEmitter(LoggingMixin): for name, data in context.get('ANDROID_ECLIPSE_PROJECT_TARGETS', {}).items(): yield ContextWrapped(context, data) - paths = context.get('ANDROID_RES_DIRS') - if paths: + for (symbol, cls) in [ + ('ANDROID_RES_DIRS', AndroidResDirs), + ('ANDROID_ASSETS_DIRS', AndroidAssetsDirs)]: + paths = context.get(symbol) + if not paths: + continue for p in paths: if isinstance(p, SourcePath) and not os.path.isdir(p.full_path): raise SandboxValidationError('Directory listed in ' - 'ANDROID_RES_DIRS is not a directory: \'%s\'' % - p.full_path, context) - yield AndroidResDirs(context, paths) + '%s is not a directory: \'%s\'' % + (symbol, p.full_path), context) + yield cls(context, paths) if passthru.variables: yield passthru diff --git a/toolkit/mozapps/installer/upload-files.mk b/toolkit/mozapps/installer/upload-files.mk index 34402f501aa9..1804f9b07955 100644 --- a/toolkit/mozapps/installer/upload-files.mk +++ b/toolkit/mozapps/installer/upload-files.mk @@ -470,6 +470,7 @@ INNER_MAKE_PACKAGE = \ ( cd $(STAGEPATH)$(MOZ_PKG_DIR)$(_BINPATH) && \ unzip -o $(_ABS_DIST)/gecko.ap_ && \ rm $(_ABS_DIST)/gecko.ap_ && \ + $(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ assets && \ $(ZIP) $(if $(ALREADY_SZIPPED),-0 ,$(if $(MOZ_ENABLE_SZIP),-0 ))$(_ABS_DIST)/gecko.ap_ $(ASSET_SO_LIBRARIES) && \ $(ZIP) -r9D $(_ABS_DIST)/gecko.ap_ $(DIST_FILES) -x $(NON_DIST_FILES) $(SZIP_LIBRARIES) && \ $(if $(filter-out ./,$(OMNIJAR_DIR)), \