Bug 1448428 - Part 1d: Change naming scheme for generated source files; r=snorp,nalexander,geckoview-reviewers

We update the name generation code to dump the files into:
```
OBJDIR/widget/android/jni/GeneratedJNI{Natives, Wrappers}
```

which are then exported to `mozilla/jni/natives` and `mozilla/jni/wrappers`

Differential Revision: https://phabricator.services.mozilla.com/D74720
This commit is contained in:
Aaron Klotz 2020-05-12 23:04:59 +00:00
parent 1332cb4147
commit 2b93310c1b
2 changed files with 43 additions and 20 deletions

View File

@ -22,6 +22,10 @@ import java.util.Iterator;
import java.util.TreeSet;
public class AnnotationProcessor {
private static final String NATIVES_NAME = "Natives";
private static final String WRAPPERS_NAME = "Wrappers";
private static final String EXPORT_PREFIX = "mozilla/java/";
public static final String GENERATED_COMMENT =
"// GENERATED CODE\n" +
"// Generated by the Java program at /build/annotationProcessors at compile time\n" +
@ -38,6 +42,9 @@ public class AnnotationProcessor {
}
final String OUTPUT_PREFIX = args[0];
final String QUALIFIER = OUTPUT_PREFIX + "JNI";
(new File(QUALIFIER)).mkdir();
System.out.println("Processing annotations...");
@ -51,8 +58,8 @@ public class AnnotationProcessor {
int ret = 0;
final String unifiedHeaderFileName = OUTPUT_PREFIX + "JNIWrappers.h";
final String unifiedNativesFileName = OUTPUT_PREFIX + "JNINatives.h";
final String unifiedHeaderFileName = QUALIFIER + WRAPPERS_NAME + ".h";
final String unifiedNativesFileName = QUALIFIER + NATIVES_NAME + ".h";
final StringBuilder unifiedHeaderFile = new StringBuilder(GENERATED_COMMENT);
final StringBuilder unifiedNativesFile = new StringBuilder(GENERATED_COMMENT);
@ -126,13 +133,15 @@ public class AnnotationProcessor {
continue;
}
final String sourceFileName = OUTPUT_PREFIX + annotatedClass.generatedName + "JNIWrappers.cpp";
final String headerFileName = OUTPUT_PREFIX + annotatedClass.generatedName + "JNIWrappers.h";
final String nativesFileName = OUTPUT_PREFIX + annotatedClass.generatedName + "JNINatives.h";
final String sourceFileName = QUALIFIER + annotatedClass.generatedName + WRAPPERS_NAME + ".cpp";
final String headerFileName = QUALIFIER + File.separator + annotatedClass.generatedName + WRAPPERS_NAME + ".h";
final String headerExportedFileName = EXPORT_PREFIX + annotatedClass.generatedName + WRAPPERS_NAME + ".h";
final String nativesFileName = QUALIFIER + File.separator + annotatedClass.generatedName + NATIVES_NAME + ".h";
final String nativesExportedFileName = EXPORT_PREFIX + annotatedClass.generatedName + NATIVES_NAME + ".h";
if (generatedNamesToUnify.contains(annotatedClass.generatedName)) {
unifiedHeaderFile.append("#include \"" + headerFileName + "\"\n");
unifiedNativesFile.append("#include \"" + nativesFileName + "\"\n");
unifiedHeaderFile.append("#include \"" + headerExportedFileName + "\"\n");
unifiedNativesFile.append("#include \"" + nativesExportedFileName + "\"\n");
}
generatedNamesToUnify.remove(annotatedClass.generatedName);
@ -141,8 +150,8 @@ public class AnnotationProcessor {
final StringBuilder nativesFile = new StringBuilder(GENERATED_COMMENT);
headerFile.append(
"#ifndef " + getHeaderGuardName(headerFileName) + "\n" +
"#define " + getHeaderGuardName(headerFileName) + "\n" +
"#ifndef " + getHeaderGuardName(headerExportedFileName) + "\n" +
"#define " + getHeaderGuardName(headerExportedFileName) + "\n" +
"\n" +
"#ifndef MOZ_PREPROCESSOR\n" +
"#include \"mozilla/jni/Refs.h\"\n" +
@ -154,7 +163,7 @@ public class AnnotationProcessor {
implementationFile.append(
"#ifndef MOZ_PREPROCESSOR\n" +
"#include \"" + headerFileName + "\"\n" +
"#include \"" + headerExportedFileName + "\"\n" +
"#include \"mozilla/jni/Accessors.h\"\n" +
"#endif\n" +
"\n" +
@ -163,11 +172,11 @@ public class AnnotationProcessor {
"\n");
nativesFile.append(
"#ifndef " + getHeaderGuardName(nativesFileName) + "\n" +
"#define " + getHeaderGuardName(nativesFileName) + "\n" +
"#ifndef " + getHeaderGuardName(nativesExportedFileName) + "\n" +
"#define " + getHeaderGuardName(nativesExportedFileName) + "\n" +
"\n" +
"#ifndef MOZ_PREPROCESSOR\n" +
"#include \"" + headerFileName + "\"\n" +
"#include \"" + headerExportedFileName + "\"\n" +
"#include \"mozilla/jni/Natives.h\"\n" +
"#endif\n" +
"\n" +

View File

@ -85,13 +85,14 @@ classes_with_WrapForJNI = [
'XPCOMEventTarget',
]
headers_from_WrapForJNI = sorted(
['GeneratedJNINatives.h', 'GeneratedJNIWrappers.h'] +
['Generated{}JNINatives.h'.format(c) for c in classes_with_WrapForJNI] +
['Generated{}JNIWrappers.h'.format(c) for c in classes_with_WrapForJNI])
natives_from_WrapForJNI = sorted(
['GeneratedJNI/{}Natives.h'.format(c) for c in classes_with_WrapForJNI])
wrappers_from_WrapForJNI = sorted(
['GeneratedJNI/{}Wrappers.h'.format(c) for c in classes_with_WrapForJNI])
sources_from_WrapForJNI = sorted(
'Generated{}JNIWrappers.cpp'.format(c) for c in classes_with_WrapForJNI)
'GeneratedJNI{}Wrappers.cpp'.format(c) for c in classes_with_WrapForJNI)
EXPORTS.mozilla.widget += [
'AndroidCompositorWidget.h',
@ -100,7 +101,18 @@ EXPORTS.mozilla.widget += [
'nsWindow.h',
]
EXPORTS += ['!{}'.format(c) for c in headers_from_WrapForJNI]
EXPORTS.mozilla.java += [
'!{}'.format(c) for c in natives_from_WrapForJNI
]
EXPORTS.mozilla.java += [
'!{}'.format(c) for c in wrappers_from_WrapForJNI
]
EXPORTS += [
'!GeneratedJNINatives.h',
'!GeneratedJNIWrappers.h',
]
SOURCES += ['!{}'.format(c) for c in sources_from_WrapForJNI]
@ -145,7 +157,9 @@ include('/ipc/chromium/chromium-config.mozbuild')
# the Gradle task that generates all of the outputs, so we add a dummy first
# output.
t = tuple(['generated_jni_wrappers'] + headers_from_WrapForJNI + sources_from_WrapForJNI)
t = tuple(['generated_jni_wrappers', 'GeneratedJNINatives.h',
'GeneratedJNIWrappers.h'] + natives_from_WrapForJNI +
sources_from_WrapForJNI + wrappers_from_WrapForJNI)
GeneratedFile(*t,
script='/mobile/android/gradle.py',