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

Support Gradle instant execution #854

Open
SUPERCILEX opened this issue Sep 4, 2020 · 3 comments
Open

Support Gradle instant execution #854

SUPERCILEX opened this issue Sep 4, 2020 · 3 comments
Labels
enhancement Indicates new feature requests feature:other Involves a feature that doesn't fit in existing categories
Milestone

Comments

@SUPERCILEX
Copy link
Collaborator

No description provided.

@SUPERCILEX SUPERCILEX added enhancement Indicates new feature requests feature:other Involves a feature that doesn't fit in existing categories labels Sep 4, 2020
@SUPERCILEX SUPERCILEX added this to the 3.2.0 milestone Dec 2, 2020
@SUPERCILEX SUPERCILEX modified the milestones: 3.5.0, Backlog Jun 21, 2021
SUPERCILEX added a commit that referenced this issue Jun 27, 2021
SUPERCILEX added a commit that referenced this issue Jun 27, 2021
Signed-off-by: Alex Saveau <[email protected]>
(cherry picked from commit ae69e86)
@SUPERCILEX
Copy link
Collaborator Author

Remove this use of project:

if (project.gradle.taskGraph.allTasks.any { it.state.failure != null }) {

@SUPERCILEX
Copy link
Collaborator Author

SUPERCILEX commented Nov 7, 2021

Waiting on a response to gradle/gradle#16775 (comment). Otherwise we can create some hack tasks for the orElses.

SUPERCILEX added a commit that referenced this issue Nov 24, 2021
Signed-off-by: Alex Saveau <[email protected]>
(cherry picked from commit 47f649a)
@SUPERCILEX
Copy link
Collaborator Author

SUPERCILEX commented Nov 24, 2021

Tried and failed. The issue is that we need Gradle to switch configurations when dependencies change without tracking those dependencies. I think the solution might have to be splitting tasks into a version that always builds from source and one that uses artifactDir. Maybe it could be called publishPrebuiltBundle.

Index: play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt b/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt
--- a/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt	(revision dabf845a76b96b7e4c0b81dff6ddbd85f5d49373)
+++ b/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt	(date 1637719411302)
@@ -4,6 +4,7 @@
 import com.android.build.api.variant.ApplicationAndroidComponentsExtension
 import com.android.build.gradle.AppPlugin
 import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
+import com.android.tools.r8.internal.it
 import com.github.triplet.gradle.androidpublisher.ResolutionStrategy
 import com.github.triplet.gradle.common.utils.safeMkdirs
 import com.github.triplet.gradle.common.validation.validateRuntime
@@ -44,12 +45,18 @@
 import com.github.triplet.gradle.play.tasks.internal.PublishableTrackLifecycleTask
 import com.github.triplet.gradle.play.tasks.internal.UpdatableTrackLifecycleTask
 import com.github.triplet.gradle.play.tasks.internal.WriteTrackLifecycleTask
+import org.gradle.api.DefaultTask
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.Task
+import org.gradle.api.file.DirectoryProperty
+import org.gradle.api.file.RegularFileProperty
 import org.gradle.api.plugins.ExtensionAware
 import org.gradle.api.provider.Provider
 import org.gradle.api.services.BuildServiceRegistration
+import org.gradle.api.tasks.Internal
+import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.TaskAction
 import org.gradle.kotlin.dsl.container
 import org.gradle.kotlin.dsl.create
 import org.gradle.kotlin.dsl.findPlugin
@@ -60,6 +67,7 @@
 import org.gradle.kotlin.dsl.registerIfAbsent
 import org.gradle.kotlin.dsl.the
 import org.gradle.kotlin.dsl.withType
+import org.gradle.work.DisableCachingByDefault
 
 @Suppress("unused") // Used by Gradle
 internal class PlayPublisherPlugin : Plugin<Project> {
@@ -196,6 +204,13 @@
                 return@v
             }
 
+            @Suppress("UNCHECKED_CAST") // Needed for overload ambiguity
+            fun getArtifactDependenciesHack(
+                    artifact: SingleArtifact<*>,
+            ): Provider<*> = extension.artifactDir.map<String> {
+                ""
+            }.orElse(variant.artifacts.get(artifact) as Provider<String>)
+
             fun findApkFiles(): Provider<List<String>> = extension.artifactDir.map {
                 val customDir = it.asFile
                 if (customDir.isFile && customDir.extension == "apk") {
@@ -210,25 +225,50 @@
                         ?.elements?.map { it.outputFile }.sneakyNull()
             })
 
-            fun findBundleFiles(): Provider<List<String>> = extension.artifactDir.map {
-                val customDir = it.asFile
-                if (customDir.isFile && customDir.extension == "aab") {
-                    listOf(it.asFile.absolutePath)
-                } else {
-                    it.asFileTree.matching {
-                        include("*.aab")
-                    }.map { it.absolutePath }
-                }
-            }.orElse(variant.artifacts.get(SingleArtifact.BUNDLE).map {
-                listOf(it.asFile.absolutePath)
-            })
+            @DisableCachingByDefault
+            abstract class BundleFilesConfigCacheHack : DefaultTask() {
+                @get:Internal
+                abstract val artifactDir: DirectoryProperty
+
+                @get:Internal
+                abstract val bundleArtifact: RegularFileProperty
+
+                @get:OutputFile
+                abstract val files: RegularFileProperty
+
+                init {
+                    outputs.upToDateWhen { false }
+                }
+
+                @TaskAction
+                fun writePaths() {
+                    val bundleFiles = artifactDir.map {
+                        val customDir = it.asFile
+                        if (customDir.isFile && customDir.extension == "aab") {
+                            listOf(it.asFile.absolutePath)
+                        } else {
+                            it.asFileTree.matching {
+                                include("*.aab")
+                            }.map { it.absolutePath }
+                        }
+                    }.orElse(bundleArtifact.map {
+                        listOf(it.asFile.absolutePath)
+                    })
 
-            @Suppress("UNCHECKED_CAST") // Needed for overload ambiguity
-            fun getArtifactDependenciesHack(
-                    artifact: SingleArtifact<*>,
-            ): Provider<*> = extension.artifactDir.map<String> {
-                ""
-            }.orElse(variant.artifacts.get(artifact) as Provider<String>)
+                    files.get().asFile.writeText(bundleFiles.get().joinToString("\n"))
+                }
+            }
+
+            val bundleFilesHackTask = project.newTask<BundleFilesConfigCacheHack>(
+                    "bundleFilesConfigCacheHack${taskVariantName}",
+            ) {
+                dependsOn(getArtifactDependenciesHack(SingleArtifact.BUNDLE))
+                files.set(project.layout.buildDirectory.file(
+                        "$INTERMEDIATES_OUTPUT_PATH/${variant.name}/bundle-files-hack.txt"))
+
+                artifactDir.set(extension.artifactDir)
+                bundleArtifact.set(variant.artifacts.get(SingleArtifact.BUNDLE))
+            }
 
             val appId = variant.applicationId.get()
             val api = project.gradle.sharedServices.registerIfAbsent(
@@ -277,11 +317,10 @@
                     arrayOf(extension, executionDir),
             ) {
                 apiService.set(api)
-                bundles.from(findBundleFiles())
+                bundles.from(bundleFilesHackTask.forUseAtConfigurationTime().map { it.files.get().asFile.readLines() })
                 outputDirectory.set(project.layout.buildDirectory.dir(
                         "outputs/internal-sharing/bundle/${variant.name}"))
 
-                dependsOn(getArtifactDependenciesHack(SingleArtifact.BUNDLE))
                 configure3pDeps(extension, taskVariantName)
             }
             publishInternalSharingBundleAllTask { dependsOn(publishInternalSharingBundleTask) }
@@ -459,9 +498,8 @@
                     arrayOf(extension, executionDir),
             ) {
                 configureInputs()
-                bundles.from(findBundleFiles())
+                bundles.from(bundleFilesHackTask.forUseAtConfigurationTime().map { it.files.get().asFile.readLines() })
 
-                dependsOn(getArtifactDependenciesHack(SingleArtifact.BUNDLE))
                 finalizedBy(commitEditTask)
                 configure3pDeps(extension, taskVariantName)
             }

@SUPERCILEX SUPERCILEX modified the milestones: 3.7.0, 3.8.0 Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests feature:other Involves a feature that doesn't fit in existing categories
Projects
None yet
Development

No branches or pull requests

1 participant