Skip to content

Commit

Permalink
feat: don't add a XCode prebuild action to invoke codegen anymore (#679)
Browse files Browse the repository at this point in the history
### Summary

We used to add an xcode prebuild script to invoke codegen each time the
user built their example application. However, with the latest setup,
the action just causes the build to fail immediately. This PR removes
that script. With this removal, the user has to install pods each time
they change their codegen specs.

### Test plan

1. Create a new library using `crnl` and make sure it supports the new
architecture
2. Install the pods and try building the example app using xcode
3. Make sure the build doesn't fail immediately.
  • Loading branch information
atlj authored Nov 15, 2024
1 parent 4a3d2a1 commit 8fc684a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ async function create(_argv: yargs.Arguments<any>) {
exampleCommunityCLIVersion;

if (arch !== 'legacy') {
addCodegenBuildScript(folder, options.project.name);
addCodegenBuildScript(folder);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ if (isNewArchitectureEnabled()) {
preBuild.dependsOn invokeLibraryCodegen
}`;

// This is added to the example app's xcscheme file to invoke codegen before every build
const XCODE_INVOKE_CODEGEN_ACTION = `
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Invoke Codegen"
scriptText = "cd &quot;$WORKSPACE_PATH/../../../&quot; &amp;&amp; npx bob build --target codegen&#10;">
</ActionContent>
</ExecutionAction>
</PreActions>`;

// You need to have the files before calling pod install otherwise they won't be registered in your pod.
// So we add a pre_install hook to the podfile that invokes codegen
const PODSPEC_INVOKE_CODEGEN_SCRIPT = `
Expand All @@ -40,26 +28,14 @@ const PODSPEC_INVOKE_CODEGEN_SCRIPT = `
* Codegen isn't invoked for libraries with `includesGeneratedCode` set to `true`.
* This patches the example app to invoke library codegen on every app build.
*/
export async function addCodegenBuildScript(
libraryPath: string,
projectName: string
) {
export async function addCodegenBuildScript(libraryPath: string) {
const appBuildGradlePath = path.join(
libraryPath,
'example',
'android',
'app',
'build.gradle'
);
const exampleAppBuildSchemePath = path.join(
libraryPath,
'example',
'ios',
`${projectName}Example.xcodeproj`,
'xcshareddata',
'xcschemes',
`${projectName}Example.xcscheme`
);
const podfilePath = path.join(libraryPath, 'example', 'ios', 'Podfile');

// Add a gradle task that runs before every build
Expand All @@ -68,25 +44,6 @@ export async function addCodegenBuildScript(

await fs.writeFile(appBuildGradlePath, appBuildGradle);

// Add an XCode prebuild action.
const exampleAppBuildScheme = (await fs.readFile(exampleAppBuildSchemePath))
.toString()
.split('\n');
// Used XCode and inspected the result to determine where it inserts the actions
const actionTargetLineIndex = exampleAppBuildScheme.findIndex((line) =>
line.includes('<BuildActionEntries>')
);
exampleAppBuildScheme.splice(
actionTargetLineIndex,
0,
XCODE_INVOKE_CODEGEN_ACTION
);

await fs.writeFile(
exampleAppBuildSchemePath,
exampleAppBuildScheme.join('\n')
);

// Add a preinstall action to the podfile that invokes codegen
const podfile = (await fs.readFile(podfilePath)).toString().split('\n');
const podfilePostInstallIndex = podfile.findIndex((line) =>
Expand Down

0 comments on commit 8fc684a

Please sign in to comment.