Skip to content

Commit 28aeb7b

Browse files
cortinicofacebook-github-bot
authored andcommitted
Do not .lowerCase the library name when codegenerating TurboModule Specs
Summary: The Codegen is generating a broken output if using the default library name: `Packages<GradleModuleName>Spec`. This diff is fixing the codegenerator to don't call the `.lowerCase` on the library name when generating the Makefile. Changelog: [Android] [Fixed] - Do not .lowerCase the library name when codegenerating TurboModule Specs Reviewed By: ShikaSD Differential Revision: D32597578 fbshipit-source-id: dee729a44134d7b3878074507191bb2a1c200608
1 parent a5469f9 commit 28aeb7b

9 files changed

+398
-103
lines changed

packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = {
121121
[
122122
'jni/Android.mk',
123123
AndroidMkTemplate({
124-
libraryName: `${libraryName.toLowerCase()}`,
124+
libraryName: libraryName,
125125
}),
126126
],
127127
]);

packages/react-native-codegen/src/generators/modules/__test_fixtures__/fixtures.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -1459,11 +1459,25 @@ const REAL_MODULE_EXAMPLE: SchemaType = {
14591459
},
14601460
};
14611461

1462+
const SAMPLE_WITH_UPPERCASE_NAME: SchemaType = {
1463+
modules: {
1464+
NativeSampleTurboModule: {
1465+
type: 'NativeModule',
1466+
aliases: {},
1467+
spec: {
1468+
properties: [],
1469+
},
1470+
moduleNames: ['SampleTurboModule'],
1471+
},
1472+
},
1473+
};
1474+
14621475
module.exports = {
1463-
COMPLEX_OBJECTS,
1464-
TWO_MODULES_DIFFERENT_FILES,
1465-
EMPTY_NATIVE_MODULES,
1466-
SIMPLE_NATIVE_MODULES,
1467-
NATIVE_MODULES_WITH_TYPE_ALIASES,
1468-
REAL_MODULE_EXAMPLE,
1476+
complex_objects: COMPLEX_OBJECTS,
1477+
two_modules_different_files: TWO_MODULES_DIFFERENT_FILES,
1478+
empty_native_modules: EMPTY_NATIVE_MODULES,
1479+
simple_native_modules: SIMPLE_NATIVE_MODULES,
1480+
native_modules_with_type_aliases: NATIVE_MODULES_WITH_TYPE_ALIASES,
1481+
real_module_example: REAL_MODULE_EXAMPLE,
1482+
SampleWithUppercaseName: SAMPLE_WITH_UPPERCASE_NAME,
14691483
};

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleCpp-test.js.snap

+42-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`GenerateModuleCpp can generate fixture COMPLEX_OBJECTS 1`] = `
3+
exports[`GenerateModuleCpp can generate fixture SampleWithUppercaseName 1`] = `
44
Map {
55
"NativeModules.cpp" => "/**
66
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -11,7 +11,37 @@ Map {
1111
* @generated by codegen project: GenerateModuleH.js
1212
*/
1313
14-
#include <react/modules/COMPLEX_OBJECTS/NativeModules.h>
14+
#include <react/modules/SampleWithUppercaseName/NativeModules.h>
15+
16+
namespace facebook {
17+
namespace react {
18+
19+
20+
21+
NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
22+
: TurboModule(\\"SampleTurboModule\\", jsInvoker) {
23+
24+
}
25+
26+
27+
} // namespace react
28+
} // namespace facebook
29+
",
30+
}
31+
`;
32+
33+
exports[`GenerateModuleCpp can generate fixture complex_objects 1`] = `
34+
Map {
35+
"NativeModules.cpp" => "/**
36+
* Copyright (c) Facebook, Inc. and its affiliates.
37+
*
38+
* This source code is licensed under the MIT license found in the
39+
* LICENSE file in the root directory of this source tree.
40+
*
41+
* @generated by codegen project: GenerateModuleH.js
42+
*/
43+
44+
#include <react/modules/complex_objects/NativeModules.h>
1545
1646
namespace facebook {
1747
namespace react {
@@ -47,7 +77,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
4777
}
4878
`;
4979
50-
exports[`GenerateModuleCpp can generate fixture EMPTY_NATIVE_MODULES 1`] = `
80+
exports[`GenerateModuleCpp can generate fixture empty_native_modules 1`] = `
5181
Map {
5282
"NativeModules.cpp" => "/**
5383
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -58,7 +88,7 @@ Map {
5888
* @generated by codegen project: GenerateModuleH.js
5989
*/
6090
61-
#include <react/modules/EMPTY_NATIVE_MODULES/NativeModules.h>
91+
#include <react/modules/empty_native_modules/NativeModules.h>
6292
6393
namespace facebook {
6494
namespace react {
@@ -77,7 +107,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
77107
}
78108
`;
79109
80-
exports[`GenerateModuleCpp can generate fixture NATIVE_MODULES_WITH_TYPE_ALIASES 1`] = `
110+
exports[`GenerateModuleCpp can generate fixture native_modules_with_type_aliases 1`] = `
81111
Map {
82112
"NativeModules.cpp" => "/**
83113
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -88,7 +118,7 @@ Map {
88118
* @generated by codegen project: GenerateModuleH.js
89119
*/
90120
91-
#include <react/modules/NATIVE_MODULES_WITH_TYPE_ALIASES/NativeModules.h>
121+
#include <react/modules/native_modules_with_type_aliases/NativeModules.h>
92122
93123
namespace facebook {
94124
namespace react {
@@ -114,7 +144,7 @@ AliasTurboModuleCxxSpecJSI::AliasTurboModuleCxxSpecJSI(std::shared_ptr<CallInvok
114144
}
115145
`;
116146
117-
exports[`GenerateModuleCpp can generate fixture REAL_MODULE_EXAMPLE 1`] = `
147+
exports[`GenerateModuleCpp can generate fixture real_module_example 1`] = `
118148
Map {
119149
"NativeModules.cpp" => "/**
120150
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -125,7 +155,7 @@ Map {
125155
* @generated by codegen project: GenerateModuleH.js
126156
*/
127157
128-
#include <react/modules/REAL_MODULE_EXAMPLE/NativeModules.h>
158+
#include <react/modules/real_module_example/NativeModules.h>
129159
130160
namespace facebook {
131161
namespace react {
@@ -196,7 +226,7 @@ NativeExceptionsManagerCxxSpecJSI::NativeExceptionsManagerCxxSpecJSI(std::shared
196226
}
197227
`;
198228
199-
exports[`GenerateModuleCpp can generate fixture SIMPLE_NATIVE_MODULES 1`] = `
229+
exports[`GenerateModuleCpp can generate fixture simple_native_modules 1`] = `
200230
Map {
201231
"NativeModules.cpp" => "/**
202232
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -207,7 +237,7 @@ Map {
207237
* @generated by codegen project: GenerateModuleH.js
208238
*/
209239
210-
#include <react/modules/SIMPLE_NATIVE_MODULES/NativeModules.h>
240+
#include <react/modules/simple_native_modules/NativeModules.h>
211241
212242
namespace facebook {
213243
namespace react {
@@ -270,7 +300,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
270300
}
271301
`;
272302
273-
exports[`GenerateModuleCpp can generate fixture TWO_MODULES_DIFFERENT_FILES 1`] = `
303+
exports[`GenerateModuleCpp can generate fixture two_modules_different_files 1`] = `
274304
Map {
275305
"NativeModules.cpp" => "/**
276306
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -281,7 +311,7 @@ Map {
281311
* @generated by codegen project: GenerateModuleH.js
282312
*/
283313
284-
#include <react/modules/TWO_MODULES_DIFFERENT_FILES/NativeModules.h>
314+
#include <react/modules/two_modules_different_files/NativeModules.h>
285315
286316
namespace facebook {
287317
namespace react {

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleH-test.js.snap

+38-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`GenerateModuleH can generate fixture COMPLEX_OBJECTS 1`] = `
3+
exports[`GenerateModuleH can generate fixture SampleWithUppercaseName 1`] = `
4+
Map {
5+
"NativeModules.h" => "/**
6+
* Copyright (c) Facebook, Inc. and its affiliates.
7+
*
8+
* This source code is licensed under the MIT license found in the
9+
* LICENSE file in the root directory of this source tree.
10+
*
11+
* @generated by codegen project: GenerateModuleH.js
12+
*/
13+
14+
#pragma once
15+
16+
#include <ReactCommon/TurboModule.h>
17+
18+
namespace facebook {
19+
namespace react {
20+
class JSI_EXPORT NativeSampleTurboModuleCxxSpecJSI : public TurboModule {
21+
protected:
22+
NativeSampleTurboModuleCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
23+
24+
public:
25+
26+
27+
};
28+
29+
} // namespace react
30+
} // namespace facebook
31+
",
32+
}
33+
`;
34+
35+
exports[`GenerateModuleH can generate fixture complex_objects 1`] = `
436
Map {
537
"NativeModules.h" => "/**
638
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -35,7 +67,7 @@ virtual void getArrays(jsi::Runtime &rt, const jsi::Object &options) = 0;
3567
}
3668
`;
3769
38-
exports[`GenerateModuleH can generate fixture EMPTY_NATIVE_MODULES 1`] = `
70+
exports[`GenerateModuleH can generate fixture empty_native_modules 1`] = `
3971
Map {
4072
"NativeModules.h" => "/**
4173
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -67,7 +99,7 @@ public:
6799
}
68100
`;
69101
70-
exports[`GenerateModuleH can generate fixture NATIVE_MODULES_WITH_TYPE_ALIASES 1`] = `
102+
exports[`GenerateModuleH can generate fixture native_modules_with_type_aliases 1`] = `
71103
Map {
72104
"NativeModules.h" => "/**
73105
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -100,7 +132,7 @@ virtual void cropImage(jsi::Runtime &rt, const jsi::Object &cropData) = 0;
100132
}
101133
`;
102134
103-
exports[`GenerateModuleH can generate fixture REAL_MODULE_EXAMPLE 1`] = `
135+
exports[`GenerateModuleH can generate fixture real_module_example 1`] = `
104136
Map {
105137
"NativeModules.h" => "/**
106138
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -155,7 +187,7 @@ virtual void dismissRedbox(jsi::Runtime &rt) = 0;
155187
}
156188
`;
157189
158-
exports[`GenerateModuleH can generate fixture SIMPLE_NATIVE_MODULES 1`] = `
190+
exports[`GenerateModuleH can generate fixture simple_native_modules 1`] = `
159191
Map {
160192
"NativeModules.h" => "/**
161193
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -197,7 +229,7 @@ virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0;
197229
}
198230
`;
199231
200-
exports[`GenerateModuleH can generate fixture TWO_MODULES_DIFFERENT_FILES 1`] = `
232+
exports[`GenerateModuleH can generate fixture two_modules_different_files 1`] = `
201233
Map {
202234
"NativeModules.h" => "/**
203235
* Copyright (c) Facebook, Inc. and its affiliates.

packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap

+63-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`GenerateModuleHObjCpp can generate fixture COMPLEX_OBJECTS 1`] = `
3+
exports[`GenerateModuleHObjCpp can generate fixture SampleWithUppercaseName 1`] = `
44
Map {
5-
"COMPLEX_OBJECTS.h" => "/**
5+
"SampleWithUppercaseName.h" => "/**
6+
* Copyright (c) Facebook, Inc. and its affiliates.
7+
*
8+
* This source code is licensed under the MIT license found in the
9+
* LICENSE file in the root directory of this source tree.
10+
*
11+
* @generated by codegen project: GenerateModuleObjCpp
12+
*
13+
* We create an umbrella header (and corresponding implementation) here since
14+
* Cxx compilation in BUCK has a limitation: source-code producing genrule()s
15+
* must have a single output. More files => more genrule()s => slower builds.
16+
*/
17+
18+
#ifndef __cplusplus
19+
#error This file must be compiled as Obj-C++. If you are importing it, you must change your file extension to .mm.
20+
#endif
21+
#import <Foundation/Foundation.h>
22+
#import <RCTRequired/RCTRequired.h>
23+
#import <RCTTypeSafety/RCTConvertHelpers.h>
24+
#import <RCTTypeSafety/RCTTypedModuleConstants.h>
25+
#import <React/RCTBridgeModule.h>
26+
#import <React/RCTCxxConvert.h>
27+
#import <React/RCTManagedPointer.h>
28+
#import <ReactCommon/RCTTurboModule.h>
29+
#import <folly/Optional.h>
30+
#import <vector>
31+
32+
33+
@protocol NativeSampleTurboModuleSpec <RCTBridgeModule, RCTTurboModule>
34+
35+
36+
37+
@end
38+
namespace facebook {
39+
namespace react {
40+
/**
41+
* ObjC++ class for module 'NativeSampleTurboModule'
42+
*/
43+
class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public ObjCTurboModule {
44+
public:
45+
NativeSampleTurboModuleSpecJSI(const ObjCTurboModule::InitParams &params);
46+
};
47+
} // namespace react
48+
} // namespace facebook
49+
50+
",
51+
}
52+
`;
53+
54+
exports[`GenerateModuleHObjCpp can generate fixture complex_objects 1`] = `
55+
Map {
56+
"complex_objects.h" => "/**
657
* Copyright (c) Facebook, Inc. and its affiliates.
758
*
859
* This source code is licensed under the MIT license found in the
@@ -258,9 +309,9 @@ inline facebook::react::LazyVector<JS::NativeSampleTurboModule::SpecGetArraysOpt
258309
}
259310
`;
260311
261-
exports[`GenerateModuleHObjCpp can generate fixture EMPTY_NATIVE_MODULES 1`] = `
312+
exports[`GenerateModuleHObjCpp can generate fixture empty_native_modules 1`] = `
262313
Map {
263-
"EMPTY_NATIVE_MODULES.h" => "/**
314+
"empty_native_modules.h" => "/**
264315
* Copyright (c) Facebook, Inc. and its affiliates.
265316
*
266317
* This source code is licensed under the MIT license found in the
@@ -309,9 +360,9 @@ namespace facebook {
309360
}
310361
`;
311362
312-
exports[`GenerateModuleHObjCpp can generate fixture NATIVE_MODULES_WITH_TYPE_ALIASES 1`] = `
363+
exports[`GenerateModuleHObjCpp can generate fixture native_modules_with_type_aliases 1`] = `
313364
Map {
314-
"NATIVE_MODULES_WITH_TYPE_ALIASES.h" => "/**
365+
"native_modules_with_type_aliases.h" => "/**
315366
* Copyright (c) Facebook, Inc. and its affiliates.
316367
*
317368
* This source code is licensed under the MIT license found in the
@@ -480,9 +531,9 @@ inline folly::Optional<bool> JS::AliasTurboModule::Options::allowExternalStorage
480531
}
481532
`;
482533
483-
exports[`GenerateModuleHObjCpp can generate fixture REAL_MODULE_EXAMPLE 1`] = `
534+
exports[`GenerateModuleHObjCpp can generate fixture real_module_example 1`] = `
484535
Map {
485-
"REAL_MODULE_EXAMPLE.h" => "/**
536+
"real_module_example.h" => "/**
486537
* Copyright (c) Facebook, Inc. and its affiliates.
487538
*
488539
* This source code is licensed under the MIT license found in the
@@ -770,9 +821,9 @@ inline bool JS::NativeImagePickerIOS::SpecOpenCameraDialogConfig::videoMode() co
770821
}
771822
`;
772823
773-
exports[`GenerateModuleHObjCpp can generate fixture SIMPLE_NATIVE_MODULES 1`] = `
824+
exports[`GenerateModuleHObjCpp can generate fixture simple_native_modules 1`] = `
774825
Map {
775-
"SIMPLE_NATIVE_MODULES.h" => "/**
826+
"simple_native_modules.h" => "/**
776827
* Copyright (c) Facebook, Inc. and its affiliates.
777828
*
778829
* This source code is licensed under the MIT license found in the
@@ -876,9 +927,9 @@ inline JS::NativeSampleTurboModule::Constants::Builder::Builder(Constants i) : _
876927
}
877928
`;
878929
879-
exports[`GenerateModuleHObjCpp can generate fixture TWO_MODULES_DIFFERENT_FILES 1`] = `
930+
exports[`GenerateModuleHObjCpp can generate fixture two_modules_different_files 1`] = `
880931
Map {
881-
"TWO_MODULES_DIFFERENT_FILES.h" => "/**
932+
"two_modules_different_files.h" => "/**
882933
* Copyright (c) Facebook, Inc. and its affiliates.
883934
*
884935
* This source code is licensed under the MIT license found in the

0 commit comments

Comments
 (0)