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

Create a FlutterPluginUtils.kt, and port static methods from FlutterPlugin there #165239

Merged
merged 16 commits into from
Mar 18, 2025

Conversation

gmackall
Copy link
Member

@gmackall gmackall commented Mar 14, 2025

Creates a FlutterPluginUtils.kt object to contain static methods used by the Flutter Gradle plugin, and moves over (porting them from Groovy to Kotlin)

  1. Methods that were already static in FlutterPlugin.
  2. Methods that were not static but were only accessing the project member. These methods were made static by changing their signature to take the project as an argument.

This doesn't get all of the methods of type 2. Specifically, I'm planning on leaving functions that interact with the Android Gradle plugin for a different PR, as this PR was getting long enough and those pieces will be a lot more brittle anyways (so I'd like to be able to revert them on their own).

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels Mar 14, 2025
@gmackall gmackall marked this pull request as ready for review March 17, 2025 20:03
@gmackall gmackall requested review from ash2moon and a team March 17, 2025 20:03
// minimum version does support the replacement we can replace by changing a single line.
@JvmStatic
@Suppress("DEPRECATION")
internal fun capitalize(string: String): String = string.capitalize()
Copy link
Member Author

Choose a reason for hiding this comment

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

Open to removing this, I meant to actually make this the suggested replacement but we can't use the syntax because of our min version constraints.

* A collection of static utility functions used by the Flutter Gradle Plugin.
*/
object FlutterPluginUtils {
// Gradle properties.
Copy link
Contributor

Choose a reason for hiding this comment

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

If these are used in other files can you add a pointer to those files? If they are used only by referencing constants can you say that in the kt doc?

Copy link
Member Author

@gmackall gmackall Mar 17, 2025

Choose a reason for hiding this comment

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

Hmm intellisense should work here for finding references, so I would prefer if we instead relied on that here (it even works cross groovy boundary). Does that make sense to you?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can talk about it in person but do think that a comment is correct. This is one of the issues with using strings. Yes tooling can find the same string in many places in code. The documentation defines where we intend the strings to match.

* Kotlin (settings.gradle.kts). This is the same behavior as Gradle 8.5.
*/
@JvmStatic
internal fun settingsGradleFile(project: Project): File {
Copy link
Contributor

Choose a reason for hiding this comment

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

On this an other methods taking in a project is a large scope/object. Consider if you can reduce what is passed in to variables that are more restricted.

For example in this method I think you can pass project.projectDir and project.logger and still have full functionality.

I think a bunch of the methods that use properties will need to stay the same here are some others I think can have reduced input scope.

  • buildGradleFile
  • shouldConfigureFlutterTask
  • pluginSupportsAndroidPlatform

Copy link
Member Author

@gmackall gmackall Mar 17, 2025

Choose a reason for hiding this comment

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

Minimized the scope of buildGradleFile and settingsGradleFile, and changed the names.

I haven't minimized the scope of the others, because I feel like it starts to leak some of the implementation out of the methods themselves

e.g. shouldConfigureFlutterTask could take a taskNames: List<String> instead of a project, but I'm not sure it's immediately obvious to a caller that you get that list with project.gradle.startParameter.taskNames, or that whether a plugin project supports Android is a function of it's projectDir.

But can reconsider if you feel strongly that those methods should also have their scope minimized

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is a good reason to take a project that is fine with me. Thank you for taking a pass to see if we could reduce scope.

@gmackall gmackall added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2025
Copy link
Contributor

auto-submit bot commented Mar 17, 2025

autosubmit label was removed for flutter/flutter/165239, because - The status or check suite Windows framework_tests_libraries has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2025
@gmackall gmackall added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Mar 18, 2025
Merged via the queue into flutter:master with commit 879d80f Mar 18, 2025
133 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2025
// Gradle properties.
internal const val PROP_SHOULD_SHRINK_RESOURCES = "shrink"
internal const val PROP_SPLIT_PER_ABI = "split-per-abi"
internal const val PROP_LOCAL_ENGINE_REPO = "localEngineRepo"
Copy link
Member

Choose a reason for hiding this comment

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

This should be "local-engine-repo"

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow I'm surprised we didn't have a test that would catch this. Will revert and reland

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok looks like the autorevert is gonna be difficult due to merge conflicts, will just approve the fix forward

@gmackall
Copy link
Member Author

Reason for revert: #165239 (comment)

@gmackall gmackall added the revert Autorevert PR (with "Reason for revert:" comment) label Mar 18, 2025
Copy link
Contributor

auto-submit bot commented Mar 18, 2025

Unable to create the revert pull request due to ProcessException: Standard out
Auto-merging packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
CONFLICT (content): Merge conflict in packages/flutter_tools/gradle/src/main/groovy/flutter.groovy
CONFLICT (modify/delete): packages/flutter_tools/gradle/src/main/kotlin/FlutterPluginUtils.kt deleted in parent of 879d80f (Create a FlutterPluginUtils.kt, and port static methods from FlutterPlugin there (#165239)) and modified in HEAD. Version HEAD of packages/flutter_tools/gradle/src/main/kotlin/FlutterPluginUtils.kt left in tree.
CONFLICT (modify/delete): packages/flutter_tools/gradle/src/test/kotlin/FlutterPluginUtilsTest.kt deleted in parent of 879d80f (Create a FlutterPluginUtils.kt, and port static methods from FlutterPlugin there (#165239)) and modified in HEAD. Version HEAD of packages/flutter_tools/gradle/src/test/kotlin/FlutterPluginUtilsTest.kt left in tree.
Standard error
error: could not revert 879d80f... Create a FlutterPluginUtils.kt, and port static methods from FlutterPlugin there (#165239)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git revert --continue".
hint: You can instead skip this commit with "git revert --skip".
hint: To abort and get back to the state before "git revert",
hint: run "git revert --abort".
Command: git revert --no-edit -m 1 879d80f

@auto-submit auto-submit bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants