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

Fix source context with configuration cache on AGP 8+ #725

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading