-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow adding custom compile-time checks in distage-framework (#2133)
- Loading branch information
Showing
7 changed files
with
215 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...istage-framework/.jvm/src/test/scala/izumi/distage/roles/test/CustomCheckEntrypoint.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package izumi.distage.roles.test | ||
|
||
import cats.effect.IO | ||
import distage.DIKey | ||
import izumi.distage.framework.model.PlanCheckInput | ||
import izumi.distage.model.planning.AxisPoint | ||
import izumi.distage.planning.solver.PlanVerifier | ||
import izumi.distage.planning.solver.PlanVerifier.PlanVerifierResult | ||
import izumi.fundamentals.collections.nonempty.NESet | ||
import izumi.fundamentals.platform.strings.IzString.toRichIterable | ||
|
||
object CustomCheckEntrypoint extends TestEntrypointPatchedLeakBase { | ||
override def customCheck( | ||
planVerifier: PlanVerifier, | ||
excludedActivations: Set[NESet[AxisPoint]], | ||
checkConfig: Boolean, | ||
planCheckInput: PlanCheckInput[IO], | ||
): PlanVerifierResult = { | ||
val reachable = planVerifier.traceReachables(planCheckInput.module, planCheckInput.roots, planCheckInput.providedKeys, excludedActivations) | ||
val conflictKeys = planCheckInput.module.keys.filter { | ||
// filter out any set elements (to remove weak set elements) | ||
case _: DIKey.SetElementKey => false | ||
// make sure that all keys we are checking contain 'Conflict' in their short type name | ||
case other => other.tpe.tag.shortName.contains("Conflict") | ||
} | ||
val unused = conflictKeys -- reachable | ||
if (unused.nonEmpty) { | ||
throw new RuntimeException(s"Custom check failed, found unused bindings for following keys: ${unused.map(_.tpe.tag.repr).niceList()}") | ||
} else { | ||
PlanVerifierResult.empty | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.