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

Refactor gradle plugin #263

Merged
merged 9 commits into from
Sep 8, 2021
Merged

Refactor gradle plugin #263

merged 9 commits into from
Sep 8, 2021

Conversation

chippmann
Copy link
Contributor

@chippmann chippmann commented Aug 21, 2021

Resolves #259 by introducing a task registry with which the individual tasks are properly grouped and accessible and configurable in a typesafe way. by splitting the task registration/creation into individual extension functions residing in their own files.

It also splits some functions up into individual parts and removes some parameter passing by introducing extension functions/properties for gradles Project class so we can access extensions directly for example.

This could further be improved though by using sealed classes or interfaces for the tasks and use them inside the TaskRegistry as in it's current state, the TaskRegistry could become unreadable if even more tasks would be added in the future. But to keep this more simple until we actually need it, i opted to just keep them in an enum for now.

Edit: updated implementation after: #263 (review)

@piiertho
Copy link
Member

I see you did not touch bindings logic but we have a failure on test_array_any_not_null_append test. Do you have it locally ? Or maybe we have a deeper problem ?

@chippmann chippmann force-pushed the feature/cleanup_gradle_plugin branch from 2b0e1a9 to df84299 Compare August 25, 2021 11:10
Copy link
Member

@piiertho piiertho left a comment

Choose a reason for hiding this comment

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

Great !

Copy link
Contributor

@raniejade raniejade left a comment

Choose a reason for hiding this comment

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

It's a bit of an anti-pattern for a task to declare its own dependencies. Normally it's the responsibility of the plugin to setup that. If a task requires some input from another task then it can be passed to the task as an input property. https://docs.gradle.org/current/userguide/custom_tasks.html

open class TaskA: AbstractTask() {

	@Output
	public val output = objects.stringProperty()
	
}

open class TaskB: AbstractTask() {
    @Input
	val input = objects.stringProperty()
}

// somewhere in the plugin
taskB.input.set(taskA.output)

The advantage of doing it this way is we can leverage gradle incremental build support. So if taskB's output didn't change then taskA will not be executed.

So a task should only do one thing, it doesn't know anything about the other tasks.

Copy link
Contributor

@raniejade raniejade left a comment

Choose a reason for hiding this comment

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

This looks good, but I have a couple of questions.

)

// START: android specific tasks
val checkD8ToolAccessibleTask = checkD8ToolAccessibleTask()
Copy link
Contributor

Choose a reason for hiding this comment

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

I was expecting an if (isAndroidExportConfigured()) statement here, what happens if the user doesnt' want to build for android?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is currently taking care of in the setup of the build task:

if (godotJvmExtension.isAndroidExportEnabled.get()) {
    finalizedBy(packageBootstrapDexJarTask, packageMainDexJarTask)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, weird way of doing it - we don't really need to configure the android/native image tasks when they are disabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, not a big issue. This will change once I'm done with the refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

// END: android specific tasks

// START: graal native image specific tasks
val checkNativeImageToolAccessibleTask = checkNativeImageToolAccessibleTask()
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same

import org.gradle.api.Task

fun Project.checkAndroidJarAccessibleTask(): Task {
return with(tasks.create("checkAndroidJarAccessible")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big issue, but have you tried using register instead of create? With register a task is only configured/resolved when it will participate in the execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice to know. I'll change them

@chippmann chippmann requested a review from raniejade September 4, 2021 08:37
@chippmann chippmann merged commit e6fc5e7 into master Sep 8, 2021
@chippmann chippmann deleted the feature/cleanup_gradle_plugin branch September 8, 2021 04:05
@chippmann chippmann mentioned this pull request Sep 8, 2021
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.

Refactor setupConfigurationsAndCompilations.kt
3 participants