-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
fix(android): Append .exe
to hermesc binary path for Windows users
#34151
Conversation
Hi @JoseLion! 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 [email protected]. Thanks! |
.gitignore
Outdated
@@ -122,6 +122,7 @@ package-lock.json | |||
# Visual studio | |||
.vscode | |||
.vs | |||
bin/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this line because vscode-java extension creates this folder on Java projects 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same problem. Still I won't add bin/
here (I added it in my global .gitignore
).
The problem is on VS Code's end, as they used a folder name which is too generic and potentially used in production. This has the risk of accidentally make us skip artifacts during NPM packaging or git commits.
Base commit: c37f719 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for doing this @JoseLion
.gitignore
Outdated
@@ -122,6 +122,7 @@ package-lock.json | |||
# Visual studio | |||
.vscode | |||
.vs | |||
bin/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same problem. Still I won't add bin/
here (I added it in my global .gitignore
).
The problem is on VS Code's end, as they used a folder name which is too generic and potentially used in production. This has the risk of accidentally make us skip artifacts during NPM packaging or git commits.
@@ -102,20 +102,22 @@ def getHermesCommand = { | |||
} | |||
} | |||
|
|||
def hermescBin = Os.isFamily(Os.FAMILY_WINDOWS) ? 'hermesc.exe' : 'hermesc' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. Can I ask you to do the same logic here:
Lines 125 to 161 in c37f719
internal fun detectOSAwareHermesCommand(projectRoot: File, hermesCommand: String): String { | |
// 1. If the project specifies a Hermes command, don't second guess it. | |
if (hermesCommand.isNotBlank()) { | |
val osSpecificHermesCommand = | |
if ("%OS-BIN%" in hermesCommand) { | |
hermesCommand.replace("%OS-BIN%", getHermesOSBin()) | |
} else { | |
hermesCommand | |
} | |
return osSpecificHermesCommand | |
// Execution on Windows fails with / as separator | |
.replace('/', File.separatorChar) | |
} | |
// 2. If the project is building hermes-engine from source, use hermesc from there | |
val builtHermesc = | |
getBuiltHermescFile(projectRoot, System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")) | |
if (builtHermesc.exists()) { | |
return builtHermesc.absolutePath | |
} | |
// 3. If the react-native contains a pre-built hermesc, use it. | |
val prebuiltHermesPath = | |
HERMESC_IN_REACT_NATIVE_PATH.replace("%OS-BIN%", getHermesOSBin()) | |
// Execution on Windows fails with / as separator | |
.replace('/', File.separatorChar) | |
val prebuiltHermes = File(projectRoot, prebuiltHermesPath) | |
if (prebuiltHermes.exists()) { | |
return prebuiltHermes.absolutePath | |
} | |
error( | |
"Couldn't determine Hermesc location. " + | |
"Please set `react.hermesCommand` to the path of the hermesc binary file. " + | |
"node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc") | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Thanks for the review BTW 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I took a slightly different approach since the Kotlin was a bit different, but it's still the same concept 😁
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Base commit: c37f719 |
@philIip has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this took longer. This can be merged 👍
I've also added tests which will appear in the final commit
This pull request was successfully merged by @JoseLion in 7fcdb9d. When will my fix make it into a release? | Upcoming Releases |
…34151) Summary: Resolves #34116. In a nutshell, the problem was a missing `.exe` extension on the `hermesc` binary path when running on Windows OS. The missing extension causes the method `.exists()` of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users Pull Request resolved: #34151 Test Plan: ### Reproduce Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can: 1. Create or reuse a React Native application with version `v0.69.1` on a Windows machine 2. Enable Hermes on Android following the steps on the [documentation](https://reactnative.dev/docs/hermes#enabling-hermes) 3. Clean the build folder: `cd android && ./gradlew clean` 4. Bundle the JS and assets for a release version: `./gradlew bundleReleaseJsAndAssets` 5. The build fails with the following error: ```shell Execution failed for task ':app:bundleReleaseJsAndAssets'. > java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc ``` ### Test the changes Follow the same steps above using the fix on this PR and the error should disappear 🙂 Reviewed By: NickGerleman Differential Revision: D37755468 Pulled By: cortinico fbshipit-source-id: 2ad0ced583555b907259df116f64a45da6d153f3
…acebook#34151) Summary: Resolves facebook#34116. In a nutshell, the problem was a missing `.exe` extension on the `hermesc` binary path when running on Windows OS. The missing extension causes the method `.exists()` of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users Pull Request resolved: facebook#34151 Test Plan: ### Reproduce Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can: 1. Create or reuse a React Native application with version `v0.69.1` on a Windows machine 2. Enable Hermes on Android following the steps on the [documentation](https://reactnative.dev/docs/hermes#enabling-hermes) 3. Clean the build folder: `cd android && ./gradlew clean` 4. Bundle the JS and assets for a release version: `./gradlew bundleReleaseJsAndAssets` 5. The build fails with the following error: ```shell Execution failed for task ':app:bundleReleaseJsAndAssets'. > java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc ``` ### Test the changes Follow the same steps above using the fix on this PR and the error should disappear 🙂 Reviewed By: NickGerleman Differential Revision: D37755468 Pulled By: cortinico fbshipit-source-id: 2ad0ced583555b907259df116f64a45da6d153f3
…acebook#34151) Summary: Resolves facebook#34116. In a nutshell, the problem was a missing `.exe` extension on the `hermesc` binary path when running on Windows OS. The missing extension causes the method `.exists()` of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users Pull Request resolved: facebook#34151 Test Plan: ### Reproduce Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can: 1. Create or reuse a React Native application with version `v0.69.1` on a Windows machine 2. Enable Hermes on Android following the steps on the [documentation](https://reactnative.dev/docs/hermes#enabling-hermes) 3. Clean the build folder: `cd android && ./gradlew clean` 4. Bundle the JS and assets for a release version: `./gradlew bundleReleaseJsAndAssets` 5. The build fails with the following error: ```shell Execution failed for task ':app:bundleReleaseJsAndAssets'. > java.lang.Exception: Couldn't determine Hermesc location. Please set `project.ext.react.hermesCommand` to the path of the hermesc binary file. node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc ``` ### Test the changes Follow the same steps above using the fix on this PR and the error should disappear 🙂 Reviewed By: NickGerleman Differential Revision: D37755468 Pulled By: cortinico fbshipit-source-id: 2ad0ced583555b907259df116f64a45da6d153f3
Summary
Resolves #34116.
In a nutshell, the problem was a missing
.exe
extension on thehermesc
binary path when running on Windows OS. The missing extension causes the method.exists()
of the File instance to always return false, so none of the conditions ever met and an error was thrown whenever a release build with Hermes enabled was run on Windows. More details can be found in the comments on the above issues.Changelog
[Android] [Fixed] - Fix error of release builds with Hermes enabled for Windows users
Test Plan
Reproduce
Changes on Gradle scrips are better tested on an actual application. To reproduce the issue you can:
v0.69.1
on a Windows machinecd android && ./gradlew clean
./gradlew bundleReleaseJsAndAssets
Test the changes
Follow the same steps above using the fix on this PR and the error should disappear 🙂