Skip to content

Commit

Permalink
Bug 1444546 - Part 4: Use GENERATED_FILES for Android JNI wrapper gen…
Browse files Browse the repository at this point in the history
…eration. r=froydnj,jchen

MozReview-Commit-ID: 1IjoQdEMqr8

--HG--
extra : rebase_source : 9f2e539328d83aa15bce0357a8c7d2722d517b2a
  • Loading branch information
ncalexan committed Mar 7, 2018
1 parent 53a4852 commit bf575d4
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 12,066 deletions.
7 changes: 0 additions & 7 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ storage/test/.*
testing/gtest/.*
tools/profiler/tests/.*
uriloader/exthandler/tests/.*
# JNI code is generated
widget/android/GeneratedJNINatives.h
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/fennec/FennecJNINatives.h
widget/android/fennec/FennecJNIWrappers.cpp
widget/android/fennec/FennecJNIWrappers.h
widget/tests/.*
xpcom/glue/tests/.*
xpcom/tests/.*
Expand Down
5 changes: 5 additions & 0 deletions config/recurse.mk
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ accessible/xpcom/export: xpcom/xpidl/export
# source code in order to write the SDK bindings.
widget/android/bindings/export: mobile/android/base/export

# The widget JNI wrapper generator code needs to build the GeckoView
# and Fennec source code in order to find JNI wrapper annotations.
widget/android/fennec/export: mobile/android/base/export
widget/android/export: mobile/android/base/export

# .xpt generation needs the xpidl lex/yacc files
xpcom/xpidl/export: xpcom/idl-parser/xpidl/export

Expand Down
102 changes: 0 additions & 102 deletions mobile/android/base/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@
# find and create .mozconfig files and to generate targets.
.NOTPARALLEL:

GARBAGE += \
classes.dex \
gecko.ap_ \
GeneratedJNINatives.h \
GeneratedJNIWrappers.cpp \
GeneratedJNIWrappers.h \
FennecJNINatives.h \
FennecJNIWrappers.cpp \
FennecJNIWrappers.h \
$(NULL)

GARBAGE_DIRS += classes db jars res sync services generated

generated_resources := \
AndroidManifest.xml \
res/raw/browsersearch.json \
Expand All @@ -43,31 +30,11 @@ chrome-%::
res/raw$(AB_rCD)/browsersearch.json \
AB_CD=$*

GeneratedJNIWrappers.cpp GeneratedJNIWrappers.h GeneratedJNINatives.h : android_apks
$(REPORT_BUILD)

FennecJNIWrappers.cpp FennecJNIWrappers.h FennecJNINatives.h: android_apks
$(REPORT_BUILD)

include $(topsrcdir)/config/rules.mk

# Override the Java settings with some specific android settings
include $(topsrcdir)/config/android-common.mk

update-generated-wrappers:
@cp $(CURDIR)/GeneratedJNIWrappers.cpp \
$(CURDIR)/GeneratedJNIWrappers.h \
$(CURDIR)/GeneratedJNINatives.h $(topsrcdir)/widget/android
@echo Updated generated JNI code

update-fennec-wrappers:
@cp $(CURDIR)/FennecJNIWrappers.cpp \
$(CURDIR)/FennecJNIWrappers.h \
$(CURDIR)/FennecJNINatives.h $(topsrcdir)/widget/android/fennec
@echo Updated Fennec JNI code

.PHONY: update-generated-wrappers update-fennec-wrappers

# This target is only used by IDE integrations. It rebuilds resources
# that end up in omni.ja using the equivalent of |mach build faster|,
# does most of the packaging step, and then updates omni.ja in
Expand Down Expand Up @@ -100,73 +67,4 @@ endif

.PHONY: gradle-targets gradle-omnijar

# Neither multi-locale builds nor single-locale repacks should be
# generating JNI wrappers. In the future, generating JNI wrappers
# will be integrated into the build system closer to their use,
# avoiding these work-arounds.
ifneq (multi,$(AB_CD))
ifeq (,$(IS_LANGUAGE_REPACK))

# GeneratedJNIWrappers.cpp target also generates
# GeneratedJNIWrappers.h and GeneratedJNINatives.h
# FennecJNIWrappers.cpp target also generates
# FennecJNIWrappers.h and FennecJNINatives.h

# List of build flags used by auto-generated JNI bindings (through the
# @BuildFlag annotation in Java). For example, add a "MOZ_FOO \" line to this
# list to support @BuildFlag(MOZ_FOO).
#
# Be sure that the given BUILD_FLAG is exposed to the generated JNI
# wrapper compilation environment! This might mean adding a local
# DEFINE in /widget/android and/or /widget/android/fennec.
BINDING_BUILD_FLAGS = \
MOZ_NATIVE_DEVICES \
$(NULL)

# Preprocess a JNI binding file using the build flags defined above.
# $(1): JNI binding file to preprocess.
preprocess-binding = ($(call py_action,preprocessor, \
$(foreach flag,$(BINDING_BUILD_FLAGS),$(if $($(flag)),-D$(flag))) \
-DMOZ_PREPROCESSOR $(1)) || echo $(1))

# Preprocess and compare two versions of a JNI binding file, one in-tree
# version and one newly generated version.
# $(1): Base file name of the JNI binding file.
# $(2): Additional path to prepend to the in-tree file name. This is required
# because in-tree Fennec-specific bindings are in a separate fennec/ directory.
compare-binding = $(call preprocess-binding,$(1)) | ( \
$(call preprocess-binding,$(topsrcdir)/widget/android/$(2)$(1)) 3<&- | \
diff /dev/fd/3 - >/dev/null ) 3<&0

libs:: GeneratedJNIWrappers.cpp
@($(call compare-binding,GeneratedJNIWrappers.cpp) && \
$(call compare-binding,GeneratedJNIWrappers.h) && \
$(call compare-binding,GeneratedJNINatives.h)) || \
(echo '*****************************************************' && \
echo '*** Error: The generated JNI code has changed ***' && \
echo '* To update generated code in the tree, please run *' && \
echo && \
echo ' make -C $(CURDIR) update-generated-wrappers' && \
echo && \
echo '* Repeat the build, and check in any changes. *' && \
echo '*****************************************************' && \
exit 1)

libs:: FennecJNIWrappers.cpp
@($(call compare-binding,FennecJNIWrappers.cpp,fennec/) && \
$(call compare-binding,FennecJNIWrappers.h,fennec/) && \
$(call compare-binding,FennecJNINatives.h,fennec/)) || \
(echo '*****************************************************' && \
echo '*** Error: The Fennec JNI code has changed ***' && \
echo '* To update generated code in the tree, please run *' && \
echo && \
echo ' make -C $(CURDIR) update-fennec-wrappers' && \
echo && \
echo '* Repeat the build, and check in any changes. *' && \
echo '*****************************************************' && \
exit 1)

endif # ifneq (multi,$(AB_CD))
endif # ifeq (,$(IS_LANGUAGE_REPACK))

export:: android_apks
22 changes: 22 additions & 0 deletions mobile/android/gradle.configure
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ def gradle_android_generate_sdk_bindings_tasks():
set_config('GRADLE_ANDROID_GENERATE_SDK_BINDINGS_TASKS', gradle_android_generate_sdk_bindings_tasks)


@depends(gradle_android_build_config)
def gradle_android_generate_generated_jni_wrappers_tasks(build_config):
'''Gradle tasks run by |mach android generate-generated-jni-wrappers|.'''
return [
'geckoview:generateJNIWrappersForGenerated{geckoview.variant.name}'.format(geckoview=build_config.geckoview),
]

set_config('GRADLE_ANDROID_GENERATE_GENERATED_JNI_WRAPPERS_TASKS', gradle_android_generate_generated_jni_wrappers_tasks)


@depends(gradle_android_build_config)
def gradle_android_generate_fennec_jni_wrappers_tasks(build_config):
'''Gradle tasks run by |mach android generate-fennec-jni-wrappers|.'''
return [
'app:generateJNIWrappersForFennec{app.variant.name}'.format(app=build_config.app),
]

set_config('GRADLE_ANDROID_GENERATE_FENNEC_JNI_WRAPPERS_TASKS', gradle_android_generate_fennec_jni_wrappers_tasks)


@depends(gradle_android_build_config, check_build_environment)
@imports(_from='itertools', _import='imap')
def gradle_android_app_apks(build_config, build_env):
Expand Down Expand Up @@ -215,6 +235,8 @@ set_config('GRADLE_ANDROID_ARCHIVE_GECKOVIEW_TASKS', gradle_android_archive_geck
gradle_android_findbugs_tasks,
gradle_android_archive_geckoview_tasks,
gradle_android_generate_sdk_bindings_tasks,
gradle_android_generate_generated_jni_wrappers_tasks,
gradle_android_generate_fennec_jni_wrappers_tasks,
)
@imports(_from='itertools', _import='imap')
@imports(_from='itertools', _import='chain')
Expand Down
8 changes: 8 additions & 0 deletions mobile/android/gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ def assemble_app(dummy_output_file, *inputs):

def generate_sdk_bindings(dummy_output_file, *args):
return android('generate-sdk-bindings', *args)


def generate_generated_jni_wrappers(dummy_output_file, *args):
return android('generate-generated-jni-wrappers', *args)


def generate_fennec_jni_wrappers(dummy_output_file, *args):
return android('generate-fennec-jni-wrappers', *args)
4 changes: 2 additions & 2 deletions mobile/android/gradle/with_gecko_binaries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ext.configureLibraryVariantWithJNIWrappers = { variant, module ->
args module
args output

workingDir "${topobjdir}/mobile/android/base"
workingDir "${topobjdir}/widget/android"

dependsOn jarTask
dependsOn annotationProcessorsJarTask
Expand Down Expand Up @@ -186,7 +186,7 @@ ext.configureApplicationVariantWithJNIWrappers = { variant, module ->
args module
args output

workingDir "${topobjdir}/mobile/android/base"
workingDir "${topobjdir}/widget/android/fennec"

// This forces bundling, which isn't usually part of the assemble* process.
dependsOn jarTask
Expand Down
18 changes: 18 additions & 0 deletions mobile/android/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ def stem(input):
return ret


@SubCommand('android', 'generate-generated-jni-wrappers',
"""Generate GeckoView JNI wrappers used when building GeckoView.""")
@CommandArgument('args', nargs=argparse.REMAINDER)
def android_generate_generated_jni_wrappers(self, args):
ret = self.gradle(self.substs['GRADLE_ANDROID_GENERATE_GENERATED_JNI_WRAPPERS_TASKS'] + args, verbose=True)

return ret


@SubCommand('android', 'generate-fennec-jni-wrappers',
"""Generate Fennec-specific JNI wrappers used when building Firefox for Android.""")
@CommandArgument('args', nargs=argparse.REMAINDER)
def android_generate_fennec_jni_wrappers(self, args):
ret = self.gradle(self.substs['GRADLE_ANDROID_GENERATE_FENNEC_JNI_WRAPPERS_TASKS'] + args, verbose=True)

return ret


@SubCommand('android', 'test',
"""Run Android local unit tests.
See https://developer.mozilla.org/en-US/docs/Mozilla/Android-specific_test_suites#android-test""")
Expand Down
Loading

0 comments on commit bf575d4

Please sign in to comment.