From 02fed063408bb9902dc6df79903b3cf7c82df84e Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Thu, 3 Sep 2020 16:08:00 -0700 Subject: [PATCH] Codegen: Add JNI C++ generator for TurboModule subclasses Summary: This adds the C++ classes for Android, just like checked in here: https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni The whitespace/formatting is slightly different but the functionality should be preserved. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D23489368 fbshipit-source-id: 60c112a48b6de2d2eb19f7d1bcc894048334610f --- .../src/generators/RNCodegen.js | 8 +- .../modules/GenerateModuleJniCpp.js | 333 ++++++++++++++++ .../generators/modules/GenerateModuleJniH.js | 78 ++++ .../__tests__/GenerateModuleJniCpp-test.js | 29 ++ .../__tests__/GenerateModuleJniH-test.js | 29 ++ .../GenerateModuleJniCpp-test.js.snap | 366 ++++++++++++++++++ .../GenerateModuleJniH-test.js.snap | 278 +++++++++++++ scripts/generate-native-modules-specs-cli.js | 18 +- 8 files changed, 1137 insertions(+), 2 deletions(-) create mode 100644 packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js create mode 100644 packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js create mode 100644 packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniCpp-test.js create mode 100644 packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniH-test.js create mode 100644 packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniCpp-test.js.snap create mode 100644 packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap diff --git a/packages/react-native-codegen/src/generators/RNCodegen.js b/packages/react-native-codegen/src/generators/RNCodegen.js index ce6221db60e..576d984abd8 100644 --- a/packages/react-native-codegen/src/generators/RNCodegen.js +++ b/packages/react-native-codegen/src/generators/RNCodegen.js @@ -27,6 +27,8 @@ const generateModuleH = require('./modules/GenerateModuleH.js'); const generateModuleCpp = require('./modules/GenerateModuleCpp.js'); const generateModuleHObjCpp = require('./modules/GenerateModuleHObjCpp.js'); const generateModuleJavaSpec = require('./modules/GenerateModuleJavaSpec.js'); +const GenerateModuleJniCpp = require('./modules/GenerateModuleJniCpp.js'); +const GenerateModuleJniH = require('./modules/GenerateModuleJniH.js'); const generateModuleMm = require('./modules/GenerateModuleMm.js'); const generatePropsJavaInterface = require('./components/GeneratePropsJavaInterface.js'); const generatePropsJavaDelegate = require('./components/GeneratePropsJavaDelegate.js'); @@ -74,7 +76,11 @@ const GENERATORS = { generateModuleH.generate, generateModuleHObjCpp.generate, generateModuleMm.generate, - // TODO: Java output and the C++ output need to be separated. + ], + // TODO: Refactor this to consolidate various C++ output variation instead of forking Android. + modulesAndroid: [ + GenerateModuleJniCpp.generate, + GenerateModuleJniH.generate, generateModuleJavaSpec.generate, ], tests: [generateTests.generate], diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js new file mode 100644 index 00000000000..45182b9bbc4 --- /dev/null +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js @@ -0,0 +1,333 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + */ + +'use strict'; + +import type { + FunctionTypeAnnotationParam, + FunctionTypeAnnotationReturn, + NativeModuleShape, + ObjectTypeAliasTypeShape, + SchemaType, +} from '../../CodegenSchema'; + +const {getTypeAliasTypeAnnotation} = require('./Utils'); + +type FilesOutput = Map; + +const propertyHeaderTemplate = + 'static facebook::jsi::Value __hostFunction_Native::_MODULE_NAME_::SpecJSI_::_PROPERTY_NAME_::(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {'; + +const propertyCastTemplate = + 'static_cast(turboModule).invokeJavaMethod(rt, ::_KIND_::, "::_PROPERTY_NAME_::", "::_SIGNATURE_::", args, count);'; + +const propertyTemplate = ` +${propertyHeaderTemplate} + return ${propertyCastTemplate} +}`; + +const propertyDefTemplate = + ' methodMap_["::_PROPERTY_NAME_::"] = MethodMetadata {::_ARGS_COUNT_::, __hostFunction_Native::_MODULE_NAME_::SpecJSI_::_PROPERTY_NAME_::};'; + +const moduleTemplate = ` +::_TURBOMODULE_METHOD_INVOKERS_:: + +Native::_MODULE_NAME_::SpecJSI::Native::_MODULE_NAME_::SpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { +::_PROPERTIES_MAP_:: +}`.trim(); + +const template = ` +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * ${'@'}generated by codegen project: GenerateModuleJniCpp.js + */ + +#include ::_INCLUDE_:: + +namespace facebook { +namespace react { + +::_MODULES_:: + +} // namespace react +} // namespace facebook +`; + +function translateReturnTypeToKind( + typeAnnotation: FunctionTypeAnnotationReturn, +): string { + switch (typeAnnotation.type) { + case 'ReservedFunctionValueTypeAnnotation': + switch (typeAnnotation.name) { + case 'RootTag': + return 'NumberKind'; + default: + (typeAnnotation.name: empty); + throw new Error( + `Invalid ReservedFunctionValueTypeName name, got ${typeAnnotation.name}`, + ); + } + case 'VoidTypeAnnotation': + return 'VoidKind'; + case 'StringTypeAnnotation': + return 'StringKind'; + case 'BooleanTypeAnnotation': + return 'BooleanKind'; + case 'NumberTypeAnnotation': + case 'DoubleTypeAnnotation': + case 'FloatTypeAnnotation': + case 'Int32TypeAnnotation': + return 'NumberKind'; + case 'GenericPromiseTypeAnnotation': + return 'PromiseKind'; + case 'GenericObjectTypeAnnotation': + case 'ObjectTypeAnnotation': + return 'ObjectKind'; + case 'ArrayTypeAnnotation': + return 'ArrayKind'; + default: + // TODO (T65847278): Figure out why this does not work. + // (typeAnnotation.type: empty); + throw new Error( + `Unknown prop type for returning value, found: ${typeAnnotation.type}"`, + ); + } +} + +function translateParamTypeToJniType( + param: FunctionTypeAnnotationParam, + aliases: $ReadOnly<{[aliasName: string]: ObjectTypeAliasTypeShape, ...}>, +): string { + const {nullable, typeAnnotation} = param; + + const realTypeAnnotation = + typeAnnotation.type === 'TypeAliasTypeAnnotation' + ? getTypeAliasTypeAnnotation(typeAnnotation.name, aliases) + : typeAnnotation; + + switch (realTypeAnnotation.type) { + case 'ReservedFunctionValueTypeAnnotation': + switch (realTypeAnnotation.name) { + case 'RootTag': + return 'D'; + default: + (realTypeAnnotation.name: empty); + throw new Error( + `Invalid ReservedFunctionValueTypeName name, got ${realTypeAnnotation.name}`, + ); + } + case 'VoidTypeAnnotation': + return 'V'; + case 'StringTypeAnnotation': + return 'Ljava/lang/String;'; + case 'BooleanTypeAnnotation': + return nullable ? 'Ljava/lang/Boolean' : 'Z'; + case 'NumberTypeAnnotation': + case 'DoubleTypeAnnotation': + case 'FloatTypeAnnotation': + case 'Int32TypeAnnotation': + return nullable ? 'Ljava/lang/Double;' : 'D'; + case 'GenericPromiseTypeAnnotation': + return 'Lcom/facebook/react/bridge/Promise;'; + case 'GenericObjectTypeAnnotation': + case 'ObjectTypeAnnotation': + return 'Lcom/facebook/react/bridge/ReadableMap;'; + case 'ArrayTypeAnnotation': + return 'Lcom/facebook/react/bridge/ReadableArray;'; + case 'FunctionTypeAnnotation': + return 'Lcom/facebook/react/bridge/Callback;'; + default: + throw new Error( + `Unknown prop type for method arg, found: ${realTypeAnnotation.type}"`, + ); + } +} + +function translateReturnTypeToJniType( + typeAnnotation: FunctionTypeAnnotationReturn, +): string { + const {nullable} = typeAnnotation; + + switch (typeAnnotation.type) { + case 'ReservedFunctionValueTypeAnnotation': + switch (typeAnnotation.name) { + case 'RootTag': + return 'D'; + default: + (typeAnnotation.name: empty); + throw new Error( + `Invalid ReservedFunctionValueTypeName name, got ${typeAnnotation.name}`, + ); + } + case 'VoidTypeAnnotation': + return 'V'; + case 'StringTypeAnnotation': + return 'Ljava/lang/String;'; + case 'BooleanTypeAnnotation': + return nullable ? 'Ljava/lang/Boolean' : 'Z'; + case 'NumberTypeAnnotation': + case 'DoubleTypeAnnotation': + case 'FloatTypeAnnotation': + case 'Int32TypeAnnotation': + return nullable ? 'Ljava/lang/Double;' : 'D'; + case 'GenericPromiseTypeAnnotation': + return 'Lcom/facebook/react/bridge/Promise;'; + case 'GenericObjectTypeAnnotation': + case 'ObjectTypeAnnotation': + return 'Lcom/facebook/react/bridge/WritableMap;'; + case 'ArrayTypeAnnotation': + return 'Lcom/facebook/react/bridge/WritableArray;'; + default: + throw new Error( + `Unknown prop type for method return type, found: ${typeAnnotation.type}"`, + ); + } +} + +function translateMethodTypeToJniSignature( + property, + aliases: $ReadOnly<{[aliasName: string]: ObjectTypeAliasTypeShape, ...}>, +): string { + const {name, typeAnnotation} = property; + const {returnTypeAnnotation} = typeAnnotation; + + const params = [...typeAnnotation.params]; + let processedReturnTypeAnnotation = returnTypeAnnotation; + const isPromiseReturn = + returnTypeAnnotation.type === 'GenericPromiseTypeAnnotation'; + if (isPromiseReturn) { + processedReturnTypeAnnotation = { + nullable: false, + type: 'VoidTypeAnnotation', + }; + } + + const argsSignatureParts = params.map(t => { + return translateParamTypeToJniType(t, aliases); + }); + if (isPromiseReturn) { + // Additional promise arg for this case. + argsSignatureParts.push(translateReturnTypeToJniType(returnTypeAnnotation)); + } + const argsSignature = argsSignatureParts.join(''); + const returnSignature = + name === 'getConstants' + ? 'Ljava/util/Map;' + : translateReturnTypeToJniType(processedReturnTypeAnnotation); + + return `(${argsSignature})${returnSignature}`; +} + +function translateMethodForImplementation( + property, + aliases: $ReadOnly<{[aliasName: string]: ObjectTypeAliasTypeShape, ...}>, +): string { + const {returnTypeAnnotation} = property.typeAnnotation; + + const numberOfParams = + property.typeAnnotation.params.length + + (returnTypeAnnotation.type === 'GenericPromiseTypeAnnotation' ? 1 : 0); + const translatedArguments = property.typeAnnotation.params + .map(param => param.name) + .concat( + returnTypeAnnotation.type === 'GenericPromiseTypeAnnotation' + ? ['promise'] + : [], + ) + .slice(1) + .join(':') + .concat(':'); + if ( + property.name === 'getConstants' && + returnTypeAnnotation.type === 'ObjectTypeAnnotation' && + returnTypeAnnotation.properties && + returnTypeAnnotation.properties.length === 0 + ) { + return ''; + } + return propertyTemplate + .replace(/::_KIND_::/g, translateReturnTypeToKind(returnTypeAnnotation)) + .replace(/::_PROPERTY_NAME_::/g, property.name) + .replace( + /::_ARGS_::/g, + numberOfParams === 0 + ? '' + : (numberOfParams === 1 ? '' : ':') + translatedArguments, + ) + .replace( + /::_SIGNATURE_::/g, + translateMethodTypeToJniSignature(property, aliases), + ); +} + +module.exports = { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { + const nativeModules: {[name: string]: NativeModuleShape, ...} = Object.keys( + schema.modules, + ) + .map(moduleName => { + const modules = schema.modules[moduleName].nativeModules; + if (modules == null) { + return null; + } + + return modules; + }) + .filter(Boolean) + .reduce((acc, modules) => Object.assign(acc, modules), {}); + + const modules = Object.keys(nativeModules) + .map(name => { + const {aliases, properties} = nativeModules[name]; + const translatedMethods = properties + .map(property => translateMethodForImplementation(property, aliases)) + .join('\n'); + return moduleTemplate + .replace(/::_TURBOMODULE_METHOD_INVOKERS_::/g, translatedMethods) + .replace( + '::_PROPERTIES_MAP_::', + properties + .map( + ({ + name: propertyName, + typeAnnotation: {params, returnTypeAnnotation}, + }) => + propertyName === 'getConstants' && + returnTypeAnnotation.type === 'ObjectTypeAnnotation' && + returnTypeAnnotation.properties && + returnTypeAnnotation.properties.length === 0 + ? '' + : propertyDefTemplate + .replace(/::_PROPERTY_NAME_::/g, propertyName) + .replace(/::_ARGS_COUNT_::/g, params.length.toString()), + ) + .join('\n'), + ) + .replace(/::_MODULE_NAME_::/g, name); + }) + .join('\n'); + + const fileName = `${moduleSpecName}-generated.cpp`; + const replacedTemplate = template + .replace(/::_MODULES_::/g, modules) + .replace(/::_LIBRARY_NAME_::/g, libraryName) + .replace(/::_INCLUDE_::/g, `"${moduleSpecName}.h"`); + return new Map([[fileName, replacedTemplate]]); + }, +}; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js new file mode 100644 index 00000000000..8b27ad3cb39 --- /dev/null +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js @@ -0,0 +1,78 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + */ + +'use strict'; + +import type {SchemaType} from '../../CodegenSchema'; + +type FilesOutput = Map; + +const moduleTemplate = `/** + * JNI C++ class for module '::_MODULE_NAME_::' + */ +class JSI_EXPORT Native::_MODULE_NAME_::SpecJSI : public JavaTurboModule { +public: + Native::_MODULE_NAME_::SpecJSI(const JavaTurboModule::InitParams ¶ms); +}; +`; + +const template = ` +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * ${'@'}generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +::_MODULES_:: + +} // namespace react +} // namespace facebook +`; + +module.exports = { + generate( + libraryName: string, + schema: SchemaType, + moduleSpecName: string, + ): FilesOutput { + const nativeModules = Object.keys(schema.modules) + .sort() + .map(moduleName => { + const modules = schema.modules[moduleName].nativeModules; + if (modules == null) { + return null; + } + + return modules; + }) + .filter(Boolean) + .reduce((acc, components) => Object.assign(acc, components), {}); + + const modules = Object.keys(nativeModules) + .map(name => moduleTemplate.replace(/::_MODULE_NAME_::/g, name)) + .join('\n'); + + const fileName = `${moduleSpecName}.h`; + const replacedTemplate = template.replace(/::_MODULES_::/g, modules); + + return new Map([[fileName, replacedTemplate]]); + }, +}; diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniCpp-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniCpp-test.js new file mode 100644 index 00000000000..e6030bca0fc --- /dev/null +++ b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniCpp-test.js @@ -0,0 +1,29 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @emails oncall+react_native + * @flow strict-local + * @format + */ + +'use strict'; + +const fixtures = require('../__test_fixtures__/fixtures.js'); +const generator = require('../GenerateModuleJniCpp.js'); + +describe('GenerateModuleJniCpp', () => { + Object.keys(fixtures) + .sort() + .forEach(fixtureName => { + const fixture = fixtures[fixtureName]; + + it(`can generate fixture ${fixtureName}`, () => { + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniH-test.js b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniH-test.js new file mode 100644 index 00000000000..dcbd78a42c6 --- /dev/null +++ b/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleJniH-test.js @@ -0,0 +1,29 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @emails oncall+react_native + * @flow strict-local + * @format + */ + +'use strict'; + +const fixtures = require('../__test_fixtures__/fixtures.js'); +const generator = require('../GenerateModuleJniH.js'); + +describe('GenerateModuleJniH', () => { + Object.keys(fixtures) + .sort() + .forEach(fixtureName => { + const fixture = fixtures[fixtureName]; + + it(`can generate fixture ${fixtureName}`, () => { + expect( + generator.generate(fixtureName, fixture, 'SampleSpec'), + ).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniCpp-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniCpp-test.js.snap new file mode 100644 index 00000000000..3baa888f467 --- /dev/null +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniCpp-test.js.snap @@ -0,0 +1,366 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`GenerateModuleJniCpp can generate fixture COMPLEX_OBJECTS 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_difficult(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, ObjectKind, \\"difficult\\", \\"(Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_optionals(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"optionals\\", \\"(Lcom/facebook/react/bridge/ReadableMap;)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_optionalMethod(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"optionalMethod\\", \\"(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/ReadableArray;)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getArrays(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"getArrays\\", \\"(Lcom/facebook/react/bridge/ReadableMap;)V\\", args, count); +} + +NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"difficult\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_difficult}; + methodMap_[\\"optionals\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_optionals}; + methodMap_[\\"optionalMethod\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleSpecJSI_optionalMethod}; + methodMap_[\\"getArrays\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getArrays}; +} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniCpp can generate fixture EMPTY_NATIVE_MODULES 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + + +NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + +} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniCpp can generate fixture NATIVE_MODULES_WITH_TYPE_ALIASES 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + + +static facebook::jsi::Value __hostFunction_NativeAliasTurboModuleSpecJSI_cropImage(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"cropImage\\", \\"(Lcom/facebook/react/bridge/ReadableMap;)V\\", args, count); +} + +NativeAliasTurboModuleSpecJSI::NativeAliasTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + + methodMap_[\\"cropImage\\"] = MethodMetadata {1, __hostFunction_NativeAliasTurboModuleSpecJSI_cropImage}; +} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniCpp can generate fixture REAL_MODULE_EXAMPLE 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + + +static facebook::jsi::Value __hostFunction_NativeCameraRollManagerSpecJSI_getPhotos(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, PromiseKind, \\"getPhotos\\", \\"(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeCameraRollManagerSpecJSI_saveToCameraRoll(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, PromiseKind, \\"saveToCameraRoll\\", \\"(Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/Promise;)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeCameraRollManagerSpecJSI_deletePhotos(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, PromiseKind, \\"deletePhotos\\", \\"(Lcom/facebook/react/bridge/ReadableArray;Lcom/facebook/react/bridge/Promise;)V\\", args, count); +} + +NativeCameraRollManagerSpecJSI::NativeCameraRollManagerSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + + methodMap_[\\"getPhotos\\"] = MethodMetadata {1, __hostFunction_NativeCameraRollManagerSpecJSI_getPhotos}; + methodMap_[\\"saveToCameraRoll\\"] = MethodMetadata {2, __hostFunction_NativeCameraRollManagerSpecJSI_saveToCameraRoll}; + methodMap_[\\"deletePhotos\\"] = MethodMetadata {1, __hostFunction_NativeCameraRollManagerSpecJSI_deletePhotos}; +} + +static facebook::jsi::Value __hostFunction_NativeImagePickerIOSSpecJSI_openCameraDialog(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"openCameraDialog\\", \\"(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Callback;Lcom/facebook/react/bridge/Callback;)V\\", args, count); +} + +NativeImagePickerIOSSpecJSI::NativeImagePickerIOSSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"openCameraDialog\\"] = MethodMetadata {3, __hostFunction_NativeImagePickerIOSSpecJSI_openCameraDialog}; +} + +static facebook::jsi::Value __hostFunction_NativeExceptionsManagerSpecJSI_reportFatalException(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"reportFatalException\\", \\"(Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;D)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeExceptionsManagerSpecJSI_reportSoftException(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"reportSoftException\\", \\"(Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;D)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeExceptionsManagerSpecJSI_reportException(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"reportException\\", \\"(Lcom/facebook/react/bridge/ReadableMap;)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeExceptionsManagerSpecJSI_updateExceptionMessage(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"updateExceptionMessage\\", \\"(Ljava/lang/String;Lcom/facebook/react/bridge/ReadableArray;D)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeExceptionsManagerSpecJSI_dismissRedbox(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"dismissRedbox\\", \\"()V\\", args, count); +} + +NativeExceptionsManagerSpecJSI::NativeExceptionsManagerSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"reportFatalException\\"] = MethodMetadata {3, __hostFunction_NativeExceptionsManagerSpecJSI_reportFatalException}; + methodMap_[\\"reportSoftException\\"] = MethodMetadata {3, __hostFunction_NativeExceptionsManagerSpecJSI_reportSoftException}; + methodMap_[\\"reportException\\"] = MethodMetadata {1, __hostFunction_NativeExceptionsManagerSpecJSI_reportException}; + methodMap_[\\"updateExceptionMessage\\"] = MethodMetadata {3, __hostFunction_NativeExceptionsManagerSpecJSI_updateExceptionMessage}; + methodMap_[\\"dismissRedbox\\"] = MethodMetadata {0, __hostFunction_NativeExceptionsManagerSpecJSI_dismissRedbox}; +} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniCpp can generate fixture SIMPLE_NATIVE_MODULES 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, ObjectKind, \\"getConstants\\", \\"()Ljava/util/Map;\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"voidFunc\\", \\"()V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getBool(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, BooleanKind, \\"getBool\\", \\"(Z)Z\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, NumberKind, \\"getNumber\\", \\"(D)D\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getString(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, StringKind, \\"getString\\", \\"(Ljava/lang/String;)Ljava/lang/String;\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getArray(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, ArrayKind, \\"getArray\\", \\"(Lcom/facebook/react/bridge/ReadableArray;)Lcom/facebook/react/bridge/WritableArray;\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getObject(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, ObjectKind, \\"getObject\\", \\"(Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, NumberKind, \\"getRootTag\\", \\"(D)D\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValue(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, ObjectKind, \\"getValue\\", \\"(DLjava/lang/String;Lcom/facebook/react/bridge/ReadableMap;)Lcom/facebook/react/bridge/WritableMap;\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"getValueWithCallback\\", \\"(Lcom/facebook/react/bridge/Callback;)V\\", args, count); +} + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, PromiseKind, \\"getValueWithPromise\\", \\"(ZLcom/facebook/react/bridge/Promise;)V\\", args, count); +} + +NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"getConstants\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_getConstants}; + methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc}; + methodMap_[\\"getBool\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getBool}; + methodMap_[\\"getNumber\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getNumber}; + methodMap_[\\"getString\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getString}; + methodMap_[\\"getArray\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getArray}; + methodMap_[\\"getObject\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getObject}; + methodMap_[\\"getRootTag\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getRootTag}; + methodMap_[\\"getValue\\"] = MethodMetadata {3, __hostFunction_NativeSampleTurboModuleSpecJSI_getValue}; + methodMap_[\\"getValueWithCallback\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithCallback}; + methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise}; +} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniCpp can generate fixture TWO_MODULES_DIFFERENT_FILES 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"voidFunc\\", \\"()V\\", args, count); +} + +NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc}; +} + + +static facebook::jsi::Value __hostFunction_NativeSample2TurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"voidFunc\\", \\"()V\\", args, count); +} + +NativeSample2TurboModuleSpecJSI::NativeSample2TurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + + methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSample2TurboModuleSpecJSI_voidFunc}; +} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniCpp can generate fixture TWO_MODULES_SAME_FILE 1`] = ` +Map { + "SampleSpec-generated.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniCpp.js + */ + +#include \\"SampleSpec.h\\" + +namespace facebook { +namespace react { + + +static facebook::jsi::Value __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"voidFunc\\", \\"()V\\", args, count); +} + +NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_voidFunc}; +} + +static facebook::jsi::Value __hostFunction_NativeSample2TurboModuleSpecJSI_voidFunc(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) { + return static_cast(turboModule).invokeJavaMethod(rt, VoidKind, \\"voidFunc\\", \\"()V\\", args, count); +} + +NativeSample2TurboModuleSpecJSI::NativeSample2TurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms) + : JavaTurboModule(params) { + methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSample2TurboModuleSpecJSI_voidFunc}; +} + +} // namespace react +} // namespace facebook +", +} +`; diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap new file mode 100644 index 00000000000..6308dceddc0 --- /dev/null +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap @@ -0,0 +1,278 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`GenerateModuleJniH can generate fixture COMPLEX_OBJECTS 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'SampleTurboModule' + */ +class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniH can generate fixture EMPTY_NATIVE_MODULES 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'SampleTurboModule' + */ +class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniH can generate fixture NATIVE_MODULES_WITH_TYPE_ALIASES 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'AliasTurboModule' + */ +class JSI_EXPORT NativeAliasTurboModuleSpecJSI : public JavaTurboModule { +public: + NativeAliasTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniH can generate fixture REAL_MODULE_EXAMPLE 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'CameraRollManager' + */ +class JSI_EXPORT NativeCameraRollManagerSpecJSI : public JavaTurboModule { +public: + NativeCameraRollManagerSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + +/** + * JNI C++ class for module 'ExceptionsManager' + */ +class JSI_EXPORT NativeExceptionsManagerSpecJSI : public JavaTurboModule { +public: + NativeExceptionsManagerSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + +/** + * JNI C++ class for module 'ImagePickerIOS' + */ +class JSI_EXPORT NativeImagePickerIOSSpecJSI : public JavaTurboModule { +public: + NativeImagePickerIOSSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniH can generate fixture SIMPLE_NATIVE_MODULES 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'SampleTurboModule' + */ +class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniH can generate fixture TWO_MODULES_DIFFERENT_FILES 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'SampleTurboModule' + */ +class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + +/** + * JNI C++ class for module 'Sample2TurboModule' + */ +class JSI_EXPORT NativeSample2TurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSample2TurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateModuleJniH can generate fixture TWO_MODULES_SAME_FILE 1`] = ` +Map { + "SampleSpec.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @generated by codegen project: GenerateModuleJniH.js + */ + +#import +#import +#import +#import + +namespace facebook { +namespace react { + +/** + * JNI C++ class for module 'SampleTurboModule' + */ +class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSampleTurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + +/** + * JNI C++ class for module 'Sample2TurboModule' + */ +class JSI_EXPORT NativeSample2TurboModuleSpecJSI : public JavaTurboModule { +public: + NativeSample2TurboModuleSpecJSI(const JavaTurboModule::InitParams ¶ms); +}; + + +} // namespace react +} // namespace facebook +", +} +`; diff --git a/scripts/generate-native-modules-specs-cli.js b/scripts/generate-native-modules-specs-cli.js index fe0871bb368..a86d9103577 100644 --- a/scripts/generate-native-modules-specs-cli.js +++ b/scripts/generate-native-modules-specs-cli.js @@ -38,7 +38,7 @@ function generateSpec(platform, schemaPath, outputDirectory) { RNCodegen.generate( {libraryName, schema, outputDirectory: tempOutputDirectory, moduleSpecName}, { - generators: ['modules'], + generators: platform === 'android' ? ['modulesAndroid'] : ['modules'], }, ); @@ -73,6 +73,22 @@ function generateSpec(platform, schemaPath, outputDirectory) { `${outputDirectory}/${f}`, ); }); + + // And all C++ files for JNI. + const jniOutputDirectory = `${outputDirectory}/jni`; + mkdirp.sync(jniOutputDirectory); + files + .filter( + f => + f.startsWith(moduleSpecName) && + (f.endsWith('.h') || f.endsWith('.cpp')), + ) + .forEach(f => { + fs.copyFileSync( + `${tempOutputDirectory}/${f}`, + `${jniOutputDirectory}/${f}`, + ); + }); } }