Skip to content

Commit

Permalink
Sort dependencies in ComponentTreeDeps manually to give consistent ou…
Browse files Browse the repository at this point in the history
…tput.

Incremental processing can change the order we receive elements in our metadata package. This CL sorts our metadata deps manually by file name before generating the @ComponentTreeDeps.

Fixes #3006

RELNOTES=Fix #3006:Sort dependencies in ComponentTreeDeps manually to give consistent output.
PiperOrigin-RevId: 411619490
  • Loading branch information
bcorso authored and Dagger Team committed Nov 22, 2021
1 parent e32f9c6 commit f2c10c3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
Expand Up @@ -425,6 +425,7 @@ class IncrementalProcessorTest(private val incapMode: String) {
@Test
fun changeActivitySource_addPublicMethod() {
runFullBuild()
val componentTreeDepsFullBuild = genComponentTreeDeps.readText(Charsets.UTF_8)

// Change Activity 1 source
searchAndReplace(
Expand Down Expand Up @@ -470,6 +471,11 @@ class IncrementalProcessorTest(private val incapMode: String) {
}
assertChangedFiles(FileType.JAVA, regeneratedSourceFiles)

val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8)
expect.withMessage("Full build")
.that(componentTreeDepsFullBuild)
.isEqualTo(componentTreeDepsIncrementalBuild)

// Check compilation outputs
// * Gen sources from activity 1 are re-compiled
val recompiledClassFiles = if (incapMode == ISOLATING_MODE) {
Expand Down Expand Up @@ -504,6 +510,7 @@ class IncrementalProcessorTest(private val incapMode: String) {
@Test
fun changeActivitySource_addPrivateMethod() {
runFullBuild()
val componentTreeDepsFullBuild = genComponentTreeDeps.readText(Charsets.UTF_8)

// Change Activity 1 source
searchAndReplace(
Expand Down Expand Up @@ -548,6 +555,11 @@ class IncrementalProcessorTest(private val incapMode: String) {
}
assertChangedFiles(FileType.JAVA, regeneratedSourceFiles)

val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8)
expect.withMessage("Full build")
.that(componentTreeDepsFullBuild)
.isEqualTo(componentTreeDepsIncrementalBuild)

// Check compilation outputs
// * Gen sources from activity 1 are re-compiled
val recompiledClassFiles = if (incapMode == ISOLATING_MODE) {
Expand Down Expand Up @@ -578,6 +590,7 @@ class IncrementalProcessorTest(private val incapMode: String) {
@Test
fun changeModuleSource() {
runFullBuild()
val componentTreeDepsFullBuild = genComponentTreeDeps.readText(Charsets.UTF_8)

// Change Module 1 source
searchAndReplace(
Expand Down Expand Up @@ -619,6 +632,11 @@ class IncrementalProcessorTest(private val incapMode: String) {
}
assertChangedFiles(FileType.JAVA, regeneratedSourceFiles)

val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8)
expect.withMessage("Full build")
.that(componentTreeDepsFullBuild)
.isEqualTo(componentTreeDepsIncrementalBuild)

// Check compilation outputs
// * Gen sources from module 1 are re-compiled
val recompiledClassFiles = if (incapMode == ISOLATING_MODE) {
Expand Down Expand Up @@ -649,6 +667,7 @@ class IncrementalProcessorTest(private val incapMode: String) {
@Test
fun changeAppSource() {
runFullBuild()
val componentTreeDepsFullBuild = genComponentTreeDeps.readText(Charsets.UTF_8)

// Change Application source
searchAndReplace(
Expand Down Expand Up @@ -690,6 +709,11 @@ class IncrementalProcessorTest(private val incapMode: String) {
}
assertChangedFiles(FileType.JAVA, regeneratedSourceFiles)

val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8)
expect.withMessage("Full build")
.that(componentTreeDepsFullBuild)
.isEqualTo(componentTreeDepsIncrementalBuild)

// Check compilation outputs
val recompiledClassFiles = if (incapMode == ISOLATING_MODE) {
listOf(
Expand Down Expand Up @@ -939,6 +963,8 @@ class IncrementalProcessorTest(private val incapMode: String) {
@Test
fun changeTestSource_addPublicMethod() {
runFullTestBuild()
val test1ComponentTreeDepsFullBuild = genTest1ComponentTreeDeps.readText(Charsets.UTF_8)
val test2ComponentTreeDepsFullBuild = genTest2ComponentTreeDeps.readText(Charsets.UTF_8)

// Change Test 1 source
searchAndReplace(
Expand Down Expand Up @@ -972,6 +998,15 @@ class IncrementalProcessorTest(private val incapMode: String) {
}
assertChangedFiles(FileType.JAVA, regeneratedSourceFiles)

val test1ComponentTreeDepsIncrementalBuild = genTest1ComponentTreeDeps.readText(Charsets.UTF_8)
val test2ComponentTreeDepsIncrementalBuild = genTest2ComponentTreeDeps.readText(Charsets.UTF_8)
expect.withMessage("Full build")
.that(test1ComponentTreeDepsFullBuild)
.isEqualTo(test1ComponentTreeDepsIncrementalBuild)
expect.withMessage("Full build")
.that(test2ComponentTreeDepsFullBuild)
.isEqualTo(test2ComponentTreeDepsIncrementalBuild)

val recompiledClassFiles = if (incapMode == ISOLATING_MODE) {
listOf(
classSrcTest1,
Expand All @@ -996,6 +1031,8 @@ class IncrementalProcessorTest(private val incapMode: String) {
@Test
fun changeTestSource_addPrivateMethod() {
runFullTestBuild()
val test1ComponentTreeDepsFullBuild = genTest1ComponentTreeDeps.readText(Charsets.UTF_8)
val test2ComponentTreeDepsFullBuild = genTest2ComponentTreeDeps.readText(Charsets.UTF_8)

// Change Test 1 source
searchAndReplace(
Expand Down Expand Up @@ -1031,6 +1068,15 @@ class IncrementalProcessorTest(private val incapMode: String) {
}
assertChangedFiles(FileType.JAVA, regeneratedSourceFiles)

val test1ComponentTreeDepsIncrementalBuild = genTest1ComponentTreeDeps.readText(Charsets.UTF_8)
val test2ComponentTreeDepsIncrementalBuild = genTest2ComponentTreeDeps.readText(Charsets.UTF_8)
expect.withMessage("Full build")
.that(test1ComponentTreeDepsFullBuild)
.isEqualTo(test1ComponentTreeDepsIncrementalBuild)
expect.withMessage("Full build")
.that(test2ComponentTreeDepsFullBuild)
.isEqualTo(test2ComponentTreeDepsIncrementalBuild)

val recompiledClassFiles = if (incapMode == ISOLATING_MODE) {
listOf(classSrcTest1)
} else {
Expand Down
Expand Up @@ -236,12 +236,12 @@ class ComponentTreeDepsIrCreator private constructor(
aggregatedEarlyEntryPointDeps: Set<AggregatedEarlyEntryPointIr>,
) = ComponentTreeDepsIrCreator(
isSharedTestComponentsEnabled,
aggregatedRoots,
defineComponentDeps,
aliasOfDeps,
aggregatedDeps,
aggregatedUninstallModulesDeps,
aggregatedEarlyEntryPointDeps
aggregatedRoots.toList().sortedBy { it.fqName.canonicalName() }.toSet(),
defineComponentDeps.toList().sortedBy { it.fqName.canonicalName() }.toSet(),
aliasOfDeps.toList().sortedBy { it.fqName.canonicalName() }.toSet(),
aggregatedDeps.toList().sortedBy { it.fqName.canonicalName() }.toSet(),
aggregatedUninstallModulesDeps.toList().sortedBy { it.fqName.canonicalName() }.toSet(),
aggregatedEarlyEntryPointDeps.toList().sortedBy { it.fqName.canonicalName() }.toSet()
).let { producer ->
if (isTest) {
producer.testComponents()
Expand Down

0 comments on commit f2c10c3

Please sign in to comment.