Skip to content

Fix buildCodegenCLI on Windows - #58813

Open
TheSeydiCharyyev wants to merge 2 commits into
react:mainfrom
TheSeydiCharyyev:fix-windows-codegen-cli
Open

TheSeydiCharyyev wants to merge 2 commits into
react:mainfrom
TheSeydiCharyyev:fix-windows-codegen-cli

Conversation

@TheSeydiCharyyev

Copy link
Copy Markdown

Summary:

Building the react-native repo on Windows (for example RNTester) now gets past the buildCodegenCLI task without extra setup.

Today this task fails on Windows. See #52628, which was closed as a duplicate of #37770. It fails in three places, one after the other.

  1. ReactAndroid/build.gradle.kts reads react.internal.windowsBashPath with findProperty(...).toString(). If the property is not set, the result is the string "null". Gradle then tries to start a program called null:

    > A problem occurred starting process 'command 'null''
    
  2. With that fixed, the task falls back to bash. On a machine with WSL, this starts the WSL launcher in C:\Windows\System32, because Windows looks in System32 before it looks in the PATH. Also, the Git for Windows installer only adds Git\cmd to the PATH by default, so Git's bash.exe is not on the PATH:

    WSL (10 - Relay) ERROR: CreateProcessCommon:800: execvpe(/bin/bash) failed: No such file or directory
    > Process 'command 'bash'' finished with non-zero exit value 1
    

    Now, if the property is not set, the task looks for git.exe on the PATH. For <git>\cmd\git.exe it uses <git>\bin\bash.exe (new findGitBashOnWindows()). If it finds nothing, it uses bash like before. If the property is set, the property wins.

  3. Then scripts/oss/build.sh fails. On Windows it copies the codegen folder with tar, and it gives tar the path .../scripts/oss/../... The file names in the archive contain .., so tar does not extract them:

    tar: .../react-native-codegen/scripts/oss/../../: Member name contains '..'
    > Process 'command 'C:\Program Files\Git\bin\bash.exe'' finished with non-zero exit value 2
    

    The script now runs tar inside the folder (-C "$CODEGEN_DIR" .). The files end up at the root of $TMP_DIR, where yarn install runs. This is the same result as the cp -R "$CODEGEN_DIR/." "$TMP_DIR" line that macOS and Linux use.

Nothing changes on macOS and Linux:

  • findGitBashOnWindows() returns null.
  • windowsAwareBashCommandLine does not use the bash path.
  • The tar line only runs under msys/cygwin.

Apps that build React Native from source are not affected either. BuildCodegenCLITask returns early for the react-native-build-from-source project.

Changelog:

[INTERNAL] [FIXED] - Fix buildCodegenCLI on Windows when building the react-native repo

Test Plan:

My setup:

  • Windows 11, JDK 17, Node 22.17.1, Yarn 1.22.22
  • Git for Windows, only Git\cmd on the PATH
  • WSL installed
  • react.internal.windowsBashPath not set

I ran this from cmd.exe in the repo root, after yarn install:

gradlew.bat :packages:react-native:ReactAndroid:buildCodegenCLI
Code Result
main (cd2de18) A problem occurred starting process 'command 'null''
only fix 1 WSL execvpe(/bin/bash) failed, exit value 1
fix 1 and fix 2 Member name contains '..', exit value 2
this PR BUILD SUCCESSFUL, packages/react-native-codegen/lib is built

Unit tests, from packages/gradle-plugin:

gradlew.bat :shared:test --tests com.facebook.react.utils.TaskUtilsTest

The 6 new findGitBashOnWindows_* tests pass. I also broke the function on purpose in 4 ways: no Windows check, no git.exe check, no bash.exe check, and the wrong folder level. Each time, at least one of the new tests failed.

node scripts/format-kotlin.js --check passes.

Not covered:

  • No run on macOS or Linux. The new function has a @WithOs(OS.LINUX) test, and the tar change is only in the msys/cygwin branch.
  • No full RNTester build. This PR only covers the buildCodegenCLI task.
  • On a Windows host, 10 existing tests in packages/gradle-plugin fail, on main and with this PR. 9 are in react-native-gradle-plugin. 1 is TaskUtilsTest.windowsAwareCommandLine_withEmptyInput_isEmpty. They depend on the host OS (cmd /c, .exe, path separators, line endings). CI runs them on Linux.

The buildCodegenCLI task could not run on Windows:

- Without react.internal.windowsBashPath, the build passed the string "null"
  as the bash path, so Gradle tried to start a program called "null".
- The fallback `bash` starts the WSL launcher from System32 when WSL is
  installed. Now the task uses the bash.exe of the Git for Windows install
  found on the PATH.
- build.sh packed the codegen folder with a path that contains "..", and tar
  refused to extract it. Now it packs the folder content, like the cp branch
  does on macOS and Linux.
The function returns <root>\bin\bash.exe for the first <root>\<folder>\git.exe
on the PATH that has one. Say that in the doc comment instead of
"the Git for Windows installation".
@meta-cla

meta-cla Bot commented Oct 2, 2026

Copy link
Copy Markdown

Hi @TheSeydiCharyyev!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant