Skip to content

Commit 79b530b

Browse files
committed
Merge branch 'main' into AndroidManifest_per_SourceSet
* main: support multiple android base packages fixes #372 fixes #402 # Conflicts: # modulecheck-core/src/main/kotlin/modulecheck/core/rule/DisableViewBindingRule.kt # modulecheck-core/src/main/kotlin/modulecheck/core/rule/InheritedDependencyRule.kt # modulecheck-parsing/gradle/src/main/kotlin/modulecheck/parsing/gradle/SourceSet.kt
2 parents 47893de + 4826c29 commit 79b530b

File tree

11 files changed

+312
-56
lines changed

11 files changed

+312
-56
lines changed

modulecheck-api/src/main/kotlin/modulecheck/api/context/ClasspathDependencies.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data class ClasspathDependencies(
4949
): Set<ConfigurationName> = setOfNotNull(
5050
sourceSetName.apiConfig(),
5151
ConfigurationName.api,
52-
SourceSetName.TEST_FIXTURES.apiConfig().takeIf { isTestFixtures }
52+
if (isTestFixtures) SourceSetName.TEST_FIXTURES.apiConfig() else null
5353
)
5454

5555
val directDependencies = projectDependencies[sourceSetName]

modulecheck-api/src/main/kotlin/modulecheck/api/context/Declarations.kt

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ suspend fun ConfiguredProjectDependency.declarations(): LazySet<DeclarationName>
8686
project.declarations().get(SourceSetName.TEST_FIXTURES)
8787
} else {
8888
configurationName.toSourceSetName().withUpstream(project)
89+
.filterNot { it == SourceSetName.TEST_FIXTURES }
8990
.map { project.declarations().get(it) }
9091
.let { lazySet(it, emptyDataSource()) }
9192
}

modulecheck-core/src/main/kotlin/modulecheck/core/context/OverShotDependencies.kt

+50-11
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,71 @@ data class OverShotDependencies(
3434
suspend fun get(configurationName: ConfigurationName): List<OverShotDependencyFinding> {
3535
return delegate.getOrPut(configurationName) {
3636

37+
fun log(msg: String) {
38+
if (project.path == ":lib2") {
39+
println(msg)
40+
}
41+
}
42+
3743
project.unusedDependencies()
3844
.get(configurationName)
3945
.flatMap { unused ->
4046

47+
log(
48+
"unused\n\n$unused\n" +
49+
"~~cpd~~" +
50+
"${unused.cpd()}\n" +
51+
"_____________"
52+
)
53+
4154
val configSuffix = unused.configurationName
42-
.nameWithoutSourceSet()
43-
.takeIf { !it.equals(ConfigurationName.api.value, ignoreCase = true) }
55+
.takeIf { !it.isApi() }
56+
?.nameWithoutSourceSet()
4457
?: ConfigurationName.implementation.value
4558

46-
val allUsedByConfigName = project.sourceSets
47-
.keys
48-
.filterNot { it == unused.configurationName.toSourceSetName() }
59+
log("suffix --> $configSuffix")
60+
61+
val allUsedByConfigName = unused.configurationName
62+
.toSourceSetName()
63+
.withDownStream(project)
4964
.mapNotNull { sourceSetName ->
5065

5166
sourceSetName.javaConfigurationNames()
52-
.filterNot { it == unused.configurationName }
67+
.asSequence()
5368
// check the same config as the unused configuration first.
54-
// for instance, if `api` is unused, check `debugApi`, `testApi`, etc.
69+
// for instance, if `api` is unused, check `debugApi`, `releaseApi`, etc.
5570
.sortedByDescending {
5671
it.nameWithoutSourceSet().equals(configSuffix, ignoreCase = true)
5772
}
58-
.firstNotNullOfOrNull { configName ->
73+
.flatMap { configName ->
74+
setOf(
75+
configName to unused.cpd().isTestFixture,
76+
configName to false
77+
)
78+
}
79+
.map { (configName, isTestFixture) ->
80+
5981
ConfiguredProjectDependency(
6082
configurationName = configName,
6183
project = unused.dependencyProject,
62-
isTestFixture = unused.cpd().isTestFixture
84+
isTestFixture = isTestFixture
6385
)
64-
.takeIf { project.uses(it) }
86+
}
87+
.filterNot {
88+
it.isTestFixture == unused.cpd().isTestFixture &&
89+
it.configurationName
90+
.toSourceSetName() == unused.cpd()
91+
.configurationName
92+
.toSourceSetName()
93+
}
94+
.firstNotNullOfOrNull { cpd ->
95+
96+
cpd.takeIf {
97+
98+
log("~~~~ checking cpd --> $it ============= ${project.uses(it)}")
99+
100+
project.uses(it)
101+
}
65102
}
66103
}
67104
.groupBy { it.configurationName }
@@ -91,7 +128,9 @@ data class OverShotDependencies(
91128
newDependency = cpp,
92129
oldDependency = cpp.copy(configurationName = originalConfigurationName),
93130
configurationName = cpp.configurationName
94-
)
131+
).also {
132+
log("** final overshot **\n$it\n++++++++++++++++++")
133+
}
95134
}
96135
.sortedBy { it.dependencyProject }
97136
.distinctBy { it.dependencyProject }

modulecheck-core/src/main/kotlin/modulecheck/core/internal/uses.kt

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package modulecheck.core.internal
1717

18+
import kotlinx.coroutines.flow.toList
1819
import modulecheck.api.context.anvilGraph
1920
import modulecheck.api.context.anvilScopeContributionsForSourceSetName
2021
import modulecheck.api.context.declarations
@@ -59,10 +60,27 @@ suspend fun McProject.uses(dependency: TransitiveProjectDependency): Boolean {
5960

6061
suspend fun McProject.uses(dependency: ConfiguredProjectDependency): Boolean {
6162

63+
64+
fun log(msg: String) {
65+
if (path == ":lib2") {
66+
println(msg)
67+
}
68+
}
69+
70+
6271
val sourceSetName = dependency.configurationName.toSourceSetName()
6372

6473
val dependencyDeclarations = dependency.declarations()
6574

75+
log("""
76+
77+
dependency ==? $dependency
78+
79+
${dependencyDeclarations.toList() .joinToString("\n")}
80+
81+
=============
82+
""".trimIndent())
83+
6684
val refs = referencesForSourceSetName(sourceSetName)
6785

6886
// Check whether human-written code references the dependency first.

modulecheck-core/src/main/kotlin/modulecheck/core/rule/DisableViewBindingRule.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DisableViewBindingRule : ModuleCheckRule<DisableViewBindingGenerationFindi
6363
"$basePackage.databinding.$simpleBindingName".asExplicitReference()
6464
}
6565

66-
val usedInProject = sourceSetName.downStream(project, true)
66+
val usedInProject = sourceSetName.withDownStream(project)
6767
.any { sourceSetNameOrDownstream ->
6868

6969
generatedBindings.any { generated ->

modulecheck-core/src/main/kotlin/modulecheck/core/rule/InheritedDependencyRule.kt

+2-10
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class InheritedDependencyRule : ModuleCheckRule<InheritedDependencyFinding> {
4242
val dependencyPathCache = mutableMapOf<SourceSetName, Set<Pair<String, Boolean>>>()
4343

4444
// Returns true if the dependency is already declared in this exact configuration, **or** if
45-
// it's declared in an withUpstream configuration.
45+
// it's declared in an upstream configuration.
4646
//
4747
// For example, this function will return true for a `testImplementation` configured dependency
4848
// which is already declared in the main source set (such as with `api` or `implementation`).
@@ -57,7 +57,7 @@ class InheritedDependencyRule : ModuleCheckRule<InheritedDependencyFinding> {
5757

5858
return configurationName.toSourceSetName()
5959
// Check the receiver's configuration first, but if the dependency isn't used there, also
60-
// check the withUpstream configurations.
60+
// check the upstream configurations.
6161
.withUpstream(project)
6262
.any { sourceSet ->
6363
dependencyPathsForSourceSet(sourceSet)
@@ -128,14 +128,6 @@ class InheritedDependencyRule : ModuleCheckRule<InheritedDependencyFinding> {
128128
inherited.configurationName.implementationVariant()
129129
}
130130

131-
println("""
132-
|-----------
133-
|project --> ${project.path}
134-
|inherited --> ${inherited.copy(newConfig)}
135-
|source --> ${source}
136-
|
137-
|=====""".trimMargin())
138-
139131
InheritedDependencyFinding(
140132
dependentProject = project,
141133
newDependency = inherited.copy(newConfig),

0 commit comments

Comments
 (0)