Skip to content

Commit

Permalink
Fix source context with configuration cache on AGP 8+ (#725)
Browse files Browse the repository at this point in the history
* Fix source context with configuration cache on AGP 8+

* Changelog

* ktlint
  • Loading branch information
romtsn committed Jun 21, 2024
1 parent 7889641 commit bf1acca
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix source bundles with configuration cache on AGP 8+ ([#725](https://github.com/getsentry/sentry-android-gradle-plugin/pull/725))

## 4.8.0

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class JavaVariant(
projectDir.dir(javaDir.absolutePath)
}
}
javaDirs.filterBuildConfig().toSet()
}.zip(additionalSources) { javaKotlin, other -> javaKotlin + other }
(javaDirs + additionalSources.get()).filterBuildConfig().toSet()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface SentryVariant {
): Provider<out Collection<Directory>>
}

fun List<Directory>.filterBuildConfig(): List<Directory> =
fun Collection<Directory>.filterBuildConfig(): Collection<Directory> =
filterNot {
// consider also AGP buildConfig folder as well as community plugins:
// https://github.com/yshrsmz/BuildKonfig/blob/727f4f9e79e6726ab9489499ec6d92b6f6d56266/buildkonfig-gradle-plugin/src/main/kotlin/com/codingfeline/buildkonfig/gradle/BuildKonfigPlugin.kt#L47
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ data class AndroidVariant70(
val kotlinDirs = variant.sourceSets.flatMap {
it.kotlinDirectories.map { kotlinDir -> projectDir.dir(kotlinDir.absolutePath) }
}
(kotlinDirs + javaDirs).filterBuildConfig().toSet()
}.zip(additionalSources) { javaKotlin, other -> javaKotlin + other }
(kotlinDirs + javaDirs + additionalSources.get()).filterBuildConfig().toSet()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,24 @@ data class AndroidVariant74(
): Provider<out Collection<Directory>> {
val javaProvider = variant.sources.java?.all
val kotlinProvider = variant.sources.kotlin?.all

// we cannot use .zip to combine the sources, because of possibly variation of this bug:
// https://github.com/gradle/gradle/issues/23014, but using .map works just fine, so we just
// call .get() inside the .map, and the providers will be lazily evaluated this way.
return when {
javaProvider == null && kotlinProvider == null -> additionalSources
javaProvider == null -> kotlinProvider!!.zip(additionalSources) { kotlin, other ->
(kotlin + other).toSet()
javaProvider == null -> kotlinProvider!!.map { kotlin ->
(kotlin + additionalSources.get()).filterBuildConfig().toSet()
}
kotlinProvider == null -> javaProvider.zip(additionalSources) { java, other ->
(java + other).toSet()
kotlinProvider == null -> javaProvider.map { java ->
(java + additionalSources.get()).filterBuildConfig().toSet()
}
else ->
javaProvider
.zip(kotlinProvider) { java, kotlin ->
(java + kotlin).filterBuildConfig().toSet()
}
.zip(additionalSources) { javaKotlin, other -> (javaKotlin + other).toSet() }
javaProvider.map { java ->
(java + kotlinProvider.get() + additionalSources.get())
.filterBuildConfig()
.toSet()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class SentryPluginSourceContextTest :
namespace 'com.example'
buildFeatures {
buildConfig false
buildConfig true
}
}
Expand Down Expand Up @@ -298,6 +298,12 @@ class SentryPluginSourceContextTest :
"files/_/_/com/example/Example.jvm",
ktContents
)
// do not bundle build config
verifySourceBundleContents(
testProjectDir.root,
"files/_/_/com/example/BuildConfig.jvm",
""
)
}

@Test
Expand Down

0 comments on commit bf1acca

Please sign in to comment.