Fix buildCodegenCLI on Windows - #58813
TheSeydiCharyyev wants to merge 2 commits into
Conversation
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".
|
Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary:
Building the react-native repo on Windows (for example RNTester) now gets past the
buildCodegenCLItask 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.
ReactAndroid/build.gradle.ktsreadsreact.internal.windowsBashPathwithfindProperty(...).toString(). If the property is not set, the result is the string"null". Gradle then tries to start a program callednull:With that fixed, the task falls back to
bash. On a machine with WSL, this starts the WSL launcher inC:\Windows\System32, because Windows looks in System32 before it looks in the PATH. Also, the Git for Windows installer only addsGit\cmdto the PATH by default, so Git'sbash.exeis not on the PATH:Now, if the property is not set, the task looks for
git.exeon the PATH. For<git>\cmd\git.exeit uses<git>\bin\bash.exe(newfindGitBashOnWindows()). If it finds nothing, it usesbashlike before. If the property is set, the property wins.Then
scripts/oss/build.shfails. On Windows it copies the codegen folder withtar, and it gives tar the path.../scripts/oss/../... The file names in the archive contain.., so tar does not extract them:The script now runs tar inside the folder (
-C "$CODEGEN_DIR" .). The files end up at the root of$TMP_DIR, whereyarn installruns. This is the same result as thecp -R "$CODEGEN_DIR/." "$TMP_DIR"line that macOS and Linux use.Nothing changes on macOS and Linux:
findGitBashOnWindows()returns null.windowsAwareBashCommandLinedoes not use the bash path.tarline only runs under msys/cygwin.Apps that build React Native from source are not affected either.
BuildCodegenCLITaskreturns early for thereact-native-build-from-sourceproject.Changelog:
[INTERNAL] [FIXED] - Fix
buildCodegenCLIon Windows when building the react-native repoTest Plan:
My setup:
Git\cmdon the PATHreact.internal.windowsBashPathnot setI ran this from
cmd.exein the repo root, afteryarn install:main(cd2de18)A problem occurred starting process 'command 'null''execvpe(/bin/bash) failed, exit value 1Member name contains '..', exit value 2BUILD SUCCESSFUL,packages/react-native-codegen/libis builtUnit tests, from
packages/gradle-plugin:The 6 new
findGitBashOnWindows_*tests pass. I also broke the function on purpose in 4 ways: no Windows check, nogit.execheck, nobash.execheck, and the wrong folder level. Each time, at least one of the new tests failed.node scripts/format-kotlin.js --checkpasses.Not covered:
@WithOs(OS.LINUX)test, and thetarchange is only in the msys/cygwin branch.buildCodegenCLItask.packages/gradle-pluginfail, onmainand with this PR. 9 are inreact-native-gradle-plugin. 1 isTaskUtilsTest.windowsAwareCommandLine_withEmptyInput_isEmpty. They depend on the host OS (cmd /c,.exe, path separators, line endings). CI runs them on Linux.