Skip to content

Commit

Permalink
Fix relative includes in component codegen (#42956)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42956

In the component codegen system, when the header prefix is an empty string, we generate includes using angle brackets, like this:

```
#include <EventEmitter.h>
```

This fails to compile in buck.

If we instead generate includes using quotations, buck compiles again.
```
#include "EventEmitter.h"
```

So, changes: if the headerPrefix is an empty string, generate includes using quotes.

This is a followup to D51811596.

Changelog: [Internal]

Reviewed By: fkgozali, dmytrorykun

Differential Revision: D53487111

fbshipit-source-id: e90a8b9fd4f8a2a93a0f4ad0ed989af26ad122c5
  • Loading branch information
RSNara authored and facebook-github-bot committed Feb 10, 2024
1 parent d0dd0e2 commit 3582f43
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,19 @@ function convertDefaultTypeToString(
}
}
const IncludeTemplate = ({
headerPrefix,
file,
}: {
headerPrefix: string,
file: string,
}): string => {
if (headerPrefix === '') {
return `#include "${file}"`;
}
return `#include <${headerPrefix}${file}>`;
};

module.exports = {
convertDefaultTypeToString,
getCppArrayTypeForAnnotation,
Expand All @@ -265,4 +278,5 @@ module.exports = {
toIntEnumValueName,
generateStructName,
generateEventStructName,
IncludeTemplate,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import type {SchemaType} from '../../CodegenSchema';

const {IncludeTemplate} = require('./CppHelpers');

// File path -> contents
type FilesOutput = Map<string, string>;

Expand All @@ -33,7 +35,7 @@ const FileTemplate = ({
#pragma once
#include <${headerPrefix}ShadowNodes.h>
${IncludeTemplate({headerPrefix, file: 'ShadowNodes.h'})}
#include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
} from '../../CodegenSchema';

const {indent} = require('../Utils');
const {generateEventStructName} = require('./CppHelpers');
const {IncludeTemplate, generateEventStructName} = require('./CppHelpers');

// File path -> contents
type FilesOutput = Map<string, string>;
Expand Down Expand Up @@ -47,7 +47,7 @@ const FileTemplate = ({
* ${'@'}generated by codegen project: GenerateEventEmitterCpp.js
*/
#include <${headerPrefix}EventEmitters.h>
${IncludeTemplate({headerPrefix, file: 'EventEmitters.h'})}
${[...extraIncludes].join('\n')}
namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

import type {ComponentShape, SchemaType} from '../../CodegenSchema';

const {convertDefaultTypeToString, getImports} = require('./CppHelpers');
const {
IncludeTemplate,
convertDefaultTypeToString,
getImports,
} = require('./CppHelpers');

// File path -> contents
type FilesOutput = Map<string, string>;
Expand All @@ -35,7 +39,7 @@ const FileTemplate = ({
* ${'@'}generated by codegen project: GeneratePropsCpp.js
*/
#include <${headerPrefix}Props.h>
${IncludeTemplate({headerPrefix, file: 'Props.h'})}
${imports}
namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import type {SchemaType} from '../../CodegenSchema';

const {IncludeTemplate} = require('./CppHelpers');

// File path -> contents
type FilesOutput = Map<string, string>;

Expand All @@ -31,7 +33,7 @@ const FileTemplate = ({
* ${'@'}generated by codegen project: GenerateShadowNodeCpp.js
*/
#include <${headerPrefix}ShadowNodes.h>
${IncludeTemplate({headerPrefix, file: 'ShadowNodes.h'})}
namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import type {SchemaType} from '../../CodegenSchema';

const {IncludeTemplate} = require('./CppHelpers');

// File path -> contents
type FilesOutput = Map<string, string>;

Expand All @@ -33,9 +35,9 @@ const FileTemplate = ({
#pragma once
#include <${headerPrefix}EventEmitters.h>
#include <${headerPrefix}Props.h>
#include <${headerPrefix}States.h>
${IncludeTemplate({headerPrefix, file: 'EventEmitters.h'})}
${IncludeTemplate({headerPrefix, file: 'Props.h'})}
${IncludeTemplate({headerPrefix, file: 'States.h'})}
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <jsi/jsi.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import type {SchemaType} from '../../CodegenSchema';

const {IncludeTemplate} = require('./CppHelpers');

// File path -> contents
type FilesOutput = Map<string, string>;

Expand All @@ -30,7 +32,7 @@ const FileTemplate = ({
*
* ${'@'}generated by codegen project: GenerateStateCpp.js
*/
#include <${headerPrefix}States.h>
${IncludeTemplate({headerPrefix, file: 'States.h'})}
namespace facebook::react {
Expand Down

0 comments on commit 3582f43

Please sign in to comment.