Files
Meshtastic-Android/gradle/init-scripts/flatpak-ops.init.gradle.kts
James Rich 18c547ba29 fix(flatpak-ops): capture build-logic bootstrap via init script
PR #5599's BuildOperationListener attached too late: build-logic's own
plugin resolutions (kotlin-dsl plugin marker, detekt, etc.) happen
before the root project applies meshtastic.flatpak-ops, so those URLs
never reached the manifest. Vid's flatpak-builder run then failed with
'Plugin [org.gradle.kotlin.kotlin-dsl:6.5.7] was not found' under
--offline Gradle.

Fix: move listener registration into a Gradle init script
(gradle/init-scripts/flatpak-ops.init.gradle.kts) passed via -I.
The init script fires before any project or plugin resolution, so
build-logic bootstrap downloads are captured. The flatpak-ops plugin
now reads the shared URL set from gradle.extensions; if the init
script isn't loaded, it falls back to a local listener and warns.

CI workflows + scripts/verify-flatpak/verify.sh updated to pass
-I gradle/init-scripts/flatpak-ops.init.gradle.kts.

Also expand verify.sh to optionally run a full flatpak-builder build
(not just --download-only), with macOS refusing full-build mode
because nested bwrap fails under Docker Desktop's seccomp. Adds
--download-only and --skip-regen flags.

Verified on macOS via --download-only: manifest grew to 2744 entries
and now contains org.gradle.kotlin.kotlin-dsl.gradle.plugin (the
artifact that broke vid's CI). Full-build verification pending on
Linux.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 09:53:23 -05:00

45 lines
2.0 KiB
Kotlin

/*
* Copyright (c) 2026 Meshtastic LLC
*
* Init script for meshtastic.flatpak-ops. Attaches a BuildOperationListener
* BEFORE any project or plugin resolution happens — which is necessary because
* the flatpak-ops plugin itself lives in build-logic, and any artifacts pulled
* to bootstrap build-logic (kotlin-dsl plugin marker, detekt, etc.) would be
* invisible to a listener registered later from a root-project plugin.
*
* Captured URLs are stored on `gradle.extensions` under the key below; the
* captureFlatpakSources task (registered by FlatpakOpsPlugin) reads them.
*
* Pass to Gradle via:
* ./gradlew -I gradle/init-scripts/flatpak-ops.init.gradle.kts ...
*/
import org.gradle.api.internal.GradleInternal
import org.gradle.internal.operations.BuildOperationDescriptor
import org.gradle.internal.operations.BuildOperationListener
import org.gradle.internal.operations.BuildOperationListenerManager
import org.gradle.internal.operations.OperationFinishEvent
import org.gradle.internal.operations.OperationIdentifier
import org.gradle.internal.operations.OperationProgressEvent
import org.gradle.internal.operations.OperationStartEvent
import org.gradle.internal.resource.ExternalResourceReadBuildOperationType
import java.util.concurrent.ConcurrentHashMap
val capturedUrls: MutableSet<String> = ConcurrentHashMap.newKeySet()
gradle.extensions.add("flatpakOpsCapturedUrls", capturedUrls)
val manager =
(gradle as GradleInternal).services.get(BuildOperationListenerManager::class.java)
manager.addListener(
object : BuildOperationListener {
override fun started(op: BuildOperationDescriptor, e: OperationStartEvent) = Unit
override fun progress(id: OperationIdentifier, e: OperationProgressEvent) = Unit
override fun finished(op: BuildOperationDescriptor, e: OperationFinishEvent) {
val details = op.details as? ExternalResourceReadBuildOperationType.Details ?: return
if (e.failure != null) return
capturedUrls.add(details.location)
}
},
)