Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create genrule to generate appmodules.so #41466

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (c) Meta Platforms, Inc. and 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-local
* @format
*/

'use strict';

import type {
ComponentSchema,
NativeModuleSchema,
SchemaType,
} from '../../CodegenSchema.js';

const assert = require('assert');
const fs = require('fs');
const util = require('util');

const {values: args} = util.parseArgs({
options: {
platform: {
type: 'string',
},
output: {
type: 'string',
},
['schema-query']: {
type: 'string',
},
},
});
if (!['iOS', 'android'].includes(args.platform)) {
throw new Error(`Invalid platform ${args.platform}`);
}
const platform = args.platform;
const output = args.output;
const schemaQuery: string = args['schema-query'];

if (!schemaQuery.startsWith('@')) {
throw new Error(
"The argument provided to --schema-query must be a filename that starts with '@'.",
);
}

const schemaQueryOutputFile = schemaQuery.replace(/^@/, '');
const schemaQueryOutput = fs.readFileSync(schemaQueryOutputFile, 'utf8');

const schemaFiles = schemaQueryOutput.split(' ');
const modules: {
[hasteModuleName: string]: NativeModuleSchema | ComponentSchema,
} = {};
const specNameToFile: {[hasteModuleName: string]: string} = {};

for (const file of schemaFiles) {
const schema: SchemaType = JSON.parse(fs.readFileSync(file, 'utf8'));

if (schema.modules) {
for (const specName in schema.modules) {
const module = schema.modules[specName];
if (modules[specName]) {
assert.deepEqual(
module,
modules[specName],
`App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`,
);
}

if (
module.excludedPlatforms &&
module.excludedPlatforms.indexOf(platform) >= 0
) {
continue;
}

modules[specName] = module;
specNameToFile[specName] = file;
}
}
}

fs.writeFileSync(output, JSON.stringify({modules}, null, 2));