Skip to content

Commit

Permalink
Remove moduleSpecName
Browse files Browse the repository at this point in the history
Summary:
All our codegen JavaScript now simply uses libraryName instead of moduleSpecName. In our buck infra, we assign native_module_spec_name to libraryName.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25842696

fbshipit-source-id: efd3af402585f9ad4ff3b593179147eea91cc331
  • Loading branch information
RSNara authored and facebook-github-bot committed Jan 8, 2021
1 parent d5cfad5 commit 9215980
Show file tree
Hide file tree
Showing 43 changed files with 67 additions and 127 deletions.
7 changes: 3 additions & 4 deletions packages/react-native-codegen/DEFS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,10 @@ def rn_codegen_modules(
fb_native.genrule(
name = generate_fixtures_rule_name,
srcs = native.glob(["src/generators/**/*.js"]),
cmd = "$(exe {generator_script}) $(location {schema_target}) {library_name} $OUT {native_module_spec_name} {android_package_name}".format(
cmd = "$(exe {generator_script}) $(location {schema_target}) {library_name} $OUT {android_package_name}".format(
generator_script = react_native_root_target("packages/react-native-codegen:generate_all_from_schema"),
schema_target = schema_target,
library_name = name,
native_module_spec_name = native_module_spec_name,
library_name = native_module_spec_name,
android_package_name = android_package_name,
),
out = "codegenfiles-{}".format(name),
Expand Down Expand Up @@ -285,7 +284,7 @@ def rn_codegen_components(
fb_native.genrule(
name = generate_fixtures_rule_name,
srcs = native.glob(["src/generators/**/*.js"]),
cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:generate_all_from_schema"), schema_target, name, name),
cmd = "$(exe {}) $(location {}) {} $OUT".format(react_native_root_target("packages/react-native-codegen:generate_all_from_schema"), schema_target, name),
out = "codegenfiles-{}".format(name),
labels = ["codegen_rule"],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function getModules(): SchemaType {
describe('GenerateModuleObjCpp', () => {
it('can generate a header file NativeModule specs', () => {
const libName = 'RNCodegenModuleFixtures';
const output = generator.generate(libName, getModules(), libName);
const output = generator.generate(libName, getModules());
expect(output.get(libName + '.h')).toMatchSnapshot();
});

it('can generate an implementation file NativeModule specs', () => {
const libName = 'RNCodegenModuleFixtures';
const output = generator.generate(libName, getModules(), libName);
const output = generator.generate(libName, getModules());
expect(output.get(libName + '-generated.mm')).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const fs = require('fs');
const mkdirp = require('mkdirp');

const args = process.argv.slice(2);
if (args.length < 4) {
if (args.length < 3) {
throw new Error(
`Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(
', ',
Expand All @@ -30,8 +30,7 @@ if (args.length < 4) {
const schemaPath = args[0];
const libraryName = args[1];
const outputDirectory = args[2];
const moduleSpecName = args[3];
const packageName = args[4];
const packageName = args[3];

const schemaText = fs.readFileSync(schemaPath, 'utf-8');

Expand All @@ -49,7 +48,7 @@ try {
}

RNCodegen.generate(
{libraryName, schema, outputDirectory, moduleSpecName, packageName},
{libraryName, schema, outputDirectory, packageName},
{
generators: [
'descriptors',
Expand Down
13 changes: 2 additions & 11 deletions packages/react-native-codegen/src/generators/RNCodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Options = $ReadOnly<{
libraryName: string,
schema: SchemaType,
outputDirectory: string,
moduleSpecName: string,
packageName?: string, // Some platforms have a notion of package, which should be configurable.
}>;

Expand Down Expand Up @@ -153,23 +152,15 @@ function checkFilesForChanges(

module.exports = {
generate(
{
libraryName,
schema,
outputDirectory,
moduleSpecName,
packageName,
}: Options,
{libraryName, schema, outputDirectory, packageName}: Options,
{generators, test}: Config,
): boolean {
schemaValidator.validate(schema);

const generatedFiles = [];
for (const name of generators) {
for (const generator of GENERATORS[name]) {
generatedFiles.push(
...generator(libraryName, schema, moduleSpecName, packageName),
);
generatedFiles.push(...generator(libraryName, schema, packageName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'ComponentDescriptors.h';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'RCTComponentViewHelpers.h';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const moduleComponents: ComponentCollection = Object.keys(schema.modules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const moduleComponents: ComponentCollection = Object.keys(schema.modules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'Props.cpp';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'Props.h';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
// TODO: This doesn't support custom package name yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
// TODO: This doesn't support custom package name yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'ShadowNodes.cpp';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'ShadowNodes.h';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const fileName = 'Tests.cpp';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GenerateComponentDescriptorH', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GenerateComponentHObjCpp', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GenerateEventEmitterCpp', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GenerateEventEmitterH', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GeneratePropsCpp', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GeneratePropsH', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GeneratePropsJavaDelegate', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GeneratePropsJavaInterface', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GenerateShadowNodeH', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('GenerateTests', () => {
const fixture = fixtures[fixtureName];

it(`can generate fixture ${fixtureName}`, () => {
expect(
generator.generate(fixtureName, fixture, 'SampleSpec'),
).toMatchSnapshot();
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const nativeModules = getModules(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const nativeModules = getModules(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const files = new Map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const nativeModules = getModules(schema);
Expand Down Expand Up @@ -451,12 +450,12 @@ module.exports = {
},
);

const fileName = `${moduleSpecName}-generated.cpp`;
const fileName = `${libraryName}-generated.cpp`;
const replacedTemplate = FileTemplate({
modules: modules,
libraryName: libraryName.replace(/-/g, '_'),
moduleLookups,
include: `"${moduleSpecName}.h"`,
include: `"${libraryName}.h"`,
});
return new Map([[`jni/${fileName}`, replacedTemplate]]);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const nativeModules = getModules(schema);
Expand All @@ -113,7 +112,7 @@ module.exports = {
.map(hasteModuleName => ModuleClassDeclarationTemplate({hasteModuleName}))
.join('\n');

const fileName = `${moduleSpecName}.h`;
const fileName = `${libraryName}.h`;
const replacedTemplate = HeaderFileTemplate({
modules: modules,
libraryName: libraryName.replace(/-/g, '_'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ module.exports = {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
packageName?: string,
): FilesOutput {
const nativeModules = getModules(schema);
Expand Down Expand Up @@ -191,13 +190,13 @@ module.exports = {
);
}

const headerFileName = `${moduleSpecName}.h`;
const headerFileName = `${libraryName}.h`;
const headerFile = HeaderFileTemplate({
moduleDeclarations: moduleDeclarations.join('\n'),
structInlineMethods: structInlineMethods.join('\n'),
});
const sourceFileName = `${moduleSpecName}-generated.mm`;
const sourceFileName = `${libraryName}-generated.mm`;
const sourceFile = SourceFileTemplate({
headerFileName,
moduleImplementations: moduleImplementations.join('\n'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('GenerateModuleCpp', () => {
generator.generate(
fixtureName,
fixture,
'SampleSpec',
'com.facebook.fbreact.specs',
),
).toMatchSnapshot();
Expand Down
Loading

0 comments on commit 9215980

Please sign in to comment.