Skip to content
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

Add hermesFlagsForVariant and deleteDebugFilesForVariant #32281

Conversation

geraintwhite
Copy link
Contributor

@geraintwhite geraintwhite commented Sep 28, 2021

Ref #25601 (comment).

From #31040.

Summary

The hermesFlagsRelease option only works with the release build type, but not with other build types.

This PR allows hermes flags on a per variant basis to be specified using the hermesFlagsForVariant lambda.

It also allows the hermes debugger cleanup to be run on a per variant basis using the deleteDebugFilesForVariant lambda.

Changelog

[Android] [Fixed] - Fix hermesFlags not working with multiple variants

Test Plan

Set the following options in android/app/build.gradle and ensure warnings are hidden when running ./gradlew assembleRelease and ./gradlew assembleLive.

    hermesFlagsForVariant: {
        def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('live') ? ['-w'] : []
    },
    deleteDebugFilesForVariant: {
        def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('live')
    },

@analysis-bot
Copy link

analysis-bot commented Sep 28, 2021

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 4790146

@analysis-bot
Copy link

analysis-bot commented Sep 28, 2021

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,717,943 +3
android hermes armeabi-v7a 7,246,009 +5
android hermes x86 8,137,528 -2
android hermes x86_64 8,103,016 +8
android jsc arm64-v8a 9,637,133 +28
android jsc armeabi-v7a 8,552,715 +23
android jsc x86 9,650,997 +29
android jsc x86_64 10,260,163 +16

Base commit: 4790146

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Sep 28, 2021
@facebook-github-bot
Copy link
Contributor

@ShikaSD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ShikaSD
Copy link
Contributor

ShikaSD commented Sep 28, 2021

Hey, thanks for submitting this change!
From internal discussion with @cortinico:

  1. The preferred way of doing the per-variant setup is to use configuration lambdas, so that we could have more flexibility from the client side and not rely on concatenating strings with variant name and desired configuration. The good example of this idea is enableHermesForVariant parameter, which allows you to select variants to use Hermes at configuration time.
    Could you please convert the parameters you introduced to similar lambda parameters? It would also be great to document new parameters in react.gradle 🙂
  2. We are working on a Gradle plugin for the React Native and try to match all functionality from react.gradle there. Could you also apply the same changes to the task setup? You can expose new parameters in the extension similar to the enableHermesForVariant.

@ShikaSD ShikaSD self-requested a review September 28, 2021 17:21
@geraintwhite
Copy link
Contributor Author

Since hermesFlagsRelease and hermesFlagsDebug were already used, how would the lambda replace them without breaking existing usages?

@ShikaSD
Copy link
Contributor

ShikaSD commented Sep 30, 2021

Since hermesFlagsRelease and hermesFlagsDebug were already used, how would the lambda replace them without breaking existing usages?

Yep, good point. We are thinking about deprecating these flags, so maybe lambda can just override it? Something like:

if (config.hermesFlagsForVariant != null) /* new logic */ else /* old logic */

We don't have a proper variant aware API at the moment, but it is a step into right direction

@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels Oct 1, 2021
@geraintwhite geraintwhite force-pushed the fix-hermes-flags-product-flavors branch 2 times, most recently from a658dbd to 6bbc781 Compare October 11, 2021 17:25
@geraintwhite geraintwhite changed the title Fix hermesFlagsRelease not working with multiple productFlavors Add hermesFlagsForVariant and deleteDebugFilesForVariant Oct 11, 2021
@geraintwhite geraintwhite force-pushed the fix-hermes-flags-product-flavors branch from 6bbc781 to 5e07992 Compare October 11, 2021 17:31
@geraintwhite
Copy link
Contributor Author

@ShikaSD Sorry for the delay, but I found some time yesterday to convert the parameters into lambdas.

@facebook-github-bot
Copy link
Contributor

@ShikaSD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up on this. Overall looks good on my end, just left a couple of comments.

* return [hermesFlagsRelease] for Release variants and [hermesFlagsDebug] for Debug variants.
*/
var hermesFlagsForVariant: (BaseVariant) -> List<String> = {
variant -> if (variant.name.toLowerCase().contains("release")) hermesFlagsRelease.get() else hermesFlagsDebug.get()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variant -> if (variant.name.toLowerCase().contains("release")) hermesFlagsRelease.get() else hermesFlagsDebug.get()
variant -> if (variant.isRelease) hermesFlagsRelease.get() else hermesFlagsDebug.get()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After making that change the build is failing with Cannot access 'isRelease': it is private in file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the other comment 👍

* return True for Release variants and False for Debug variants.
*/
var deleteDebugFilesForVariant: (BaseVariant) -> Boolean = {
variant -> variant.name.toLowerCase().contains("release")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variant -> variant.name.toLowerCase().contains("release")
variant -> variant.isRelease

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After making that change the build is failing with Cannot access 'isRelease': it is private in file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to make it internal to expose this functionality :)
@cortinico we should consider moving it to some common utils

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup basically what @ShikaSD mentioned. If you want to export it to a VariantUtil.kt file as well, that would be fine. As long as it's internal all is good 👌

Copy link
Contributor Author

@geraintwhite geraintwhite Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's passing now after making it internal (the failing check is a connection timeout to jitpack)

react.gradle Outdated
@@ -151,6 +173,7 @@ afterEvaluate {

// Set up dev mode
def devEnabled = !(config."devDisabledIn${targetName}"
|| config."devDisabledIn${variant.buildType.name.capitalize()}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it from this PR, but it is added in another PR to fix an issue with devDisabledIn${buildType} not working for productFlavors.

@geraintwhite geraintwhite force-pushed the fix-hermes-flags-product-flavors branch 2 times, most recently from 5e07992 to 48958d8 Compare October 12, 2021 14:27
Copy link
Contributor

@ShikaSD ShikaSD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks almost good for me, the only thing left is the Variant.isRelease function. Could you make it internal to allow access to it in extension and then use it instead?
Thanks!

@geraintwhite geraintwhite force-pushed the fix-hermes-flags-product-flavors branch from 747ac5c to f79026c Compare October 13, 2021 07:09
@pull-bot
Copy link

PR build artifact for f79026c is ready.
To use, download tarball from this CircleCI job then run yarn add <path to tarball> in your React Native project.

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks for the follow up

@facebook-github-bot
Copy link
Contributor

@ShikaSD has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @grit96 in 91adb76.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 13, 2021
@geraintwhite
Copy link
Contributor Author

LGTM 👍 Thanks for the follow up

Thanks for merging. Is there any possibility of having a look at the other related PR I mentioned (fixing devDisabledIn for variants)?

@ShikaSD
Copy link
Contributor

ShikaSD commented Oct 14, 2021

@grit96 sure, it seems like it will require similar updates though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants