|
1 | 1 | import com.android.build.api.variant.impl.VariantOutputImpl |
| 2 | +import org.gradle.api.DefaultTask |
| 3 | +import org.gradle.api.file.ConfigurableFileCollection |
| 4 | +import org.gradle.api.file.DirectoryProperty |
| 5 | +import org.gradle.api.tasks.InputFiles |
| 6 | +import org.gradle.api.tasks.Internal |
| 7 | +import org.gradle.api.tasks.OutputDirectory |
| 8 | +import org.gradle.api.tasks.PathSensitive |
| 9 | +import org.gradle.api.tasks.PathSensitivity |
| 10 | +import org.gradle.api.tasks.TaskAction |
| 11 | +import org.gradle.process.ExecOperations |
2 | 12 | import java.time.Instant |
3 | 13 | import java.time.ZoneOffset |
4 | 14 | import java.time.format.DateTimeFormatter |
5 | 15 | import java.util.Properties |
| 16 | +import javax.inject.Inject |
6 | 17 |
|
7 | 18 | val dnsjavaInetAddressResolverService = "META-INF/services/java.net.spi.InetAddressResolverProvider" |
8 | 19 | val openClawAndroidVersionFile = rootProject.file("Config/Version.properties") |
9 | 20 | val thirdPartyLicensesDir = rootProject.file("THIRD_PARTY_LICENSES") |
| 21 | +val openClawRepositoryRoot = rootProject.projectDir.resolve("../..").canonicalFile |
| 22 | +val canvasA2uiAssetsDir = layout.buildDirectory.dir("generated/canvasA2uiAssets") |
10 | 23 | val openClawAndroidVersionProperties = |
11 | 24 | Properties().apply { |
12 | 25 | if (!openClawAndroidVersionFile.isFile) { |
@@ -119,6 +132,56 @@ plugins { |
119 | 132 | alias(libs.plugins.ksp) |
120 | 133 | } |
121 | 134 |
|
| 135 | +abstract class StageCanvasA2uiTask |
| 136 | + @Inject |
| 137 | + constructor( |
| 138 | + private val execOperations: ExecOperations, |
| 139 | + ) : DefaultTask() { |
| 140 | + @get:Internal abstract val repoRoot: DirectoryProperty |
| 141 | + |
| 142 | + @get:InputFiles |
| 143 | + @get:PathSensitive(PathSensitivity.RELATIVE) |
| 144 | + abstract val sourceFiles: ConfigurableFileCollection |
| 145 | + |
| 146 | + @get:OutputDirectory abstract val outputDirectory: DirectoryProperty |
| 147 | + |
| 148 | + @TaskAction |
| 149 | + fun stage() { |
| 150 | + val root = repoRoot.get().asFile |
| 151 | + execOperations.exec { |
| 152 | + workingDir(root) |
| 153 | + commandLine( |
| 154 | + "node", |
| 155 | + "scripts/sync-native-a2ui.mjs", |
| 156 | + "--write", |
| 157 | + "--output", |
| 158 | + outputDirectory |
| 159 | + .get() |
| 160 | + .dir("CanvasA2UI") |
| 161 | + .asFile.absolutePath, |
| 162 | + ) |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | +val stageCanvasA2ui = |
| 168 | + tasks.register<StageCanvasA2uiTask>("stageCanvasA2ui") { |
| 169 | + group = "build" |
| 170 | + description = "Stages the plugin-owned Canvas A2UI renderer for native apps." |
| 171 | + repoRoot.set(openClawRepositoryRoot) |
| 172 | + sourceFiles.from( |
| 173 | + openClawRepositoryRoot.resolve("package.json"), |
| 174 | + openClawRepositoryRoot.resolve("pnpm-lock.yaml"), |
| 175 | + openClawRepositoryRoot.resolve("scripts/bundle-a2ui.mjs"), |
| 176 | + openClawRepositoryRoot.resolve("scripts/sync-native-a2ui.mjs"), |
| 177 | + openClawRepositoryRoot.resolve("extensions/canvas/package.json"), |
| 178 | + openClawRepositoryRoot.resolve("extensions/canvas/scripts/bundle-a2ui.mjs"), |
| 179 | + openClawRepositoryRoot.resolve("extensions/canvas/src/host/a2ui/index.html"), |
| 180 | + ) |
| 181 | + sourceFiles.from(openClawRepositoryRoot.resolve("extensions/canvas/src/host/a2ui-app")) |
| 182 | + outputDirectory.set(canvasA2uiAssetsDir) |
| 183 | + } |
| 184 | + |
122 | 185 | ksp { |
123 | 186 | arg("room.schemaLocation", "$projectDir/schemas") |
124 | 187 | } |
@@ -269,6 +332,10 @@ android { |
269 | 332 |
|
270 | 333 | androidComponents { |
271 | 334 | onVariants { variant -> |
| 335 | + variant.sources.assets?.addGeneratedSourceDirectory( |
| 336 | + stageCanvasA2ui, |
| 337 | + StageCanvasA2uiTask::outputDirectory, |
| 338 | + ) |
272 | 339 | variant.outputs |
273 | 340 | .filterIsInstance<VariantOutputImpl>() |
274 | 341 | .forEach { output -> |
|
0 commit comments