From 9bafb3f2d727e90230f1880090022f19adb627c8 Mon Sep 17 00:00:00 2001 From: hoangmaihuy Date: Tue, 19 Dec 2023 15:22:44 +0700 Subject: [PATCH 1/2] fix: make missinglink configurations target --- .../missinglink/MissinglinkCheckModule.scala | 34 ++++++++++--------- .../hoangmaihuy/missinglink/package.scala | 8 +++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala b/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala index ac54b04..a64c965 100644 --- a/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala +++ b/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala @@ -13,42 +13,42 @@ import mill.scalalib._ trait MissinglinkCheckModule extends JavaModule { /** Fail the build if any conflicts are found */ - def missinglinkFailOnConflicts: Boolean = true + def missinglinkFailOnConflicts: T[Boolean] = T { true } /** Also scan all dependencies */ - def missinglinkScanDependencies: Boolean = false + def missinglinkScanDependencies: T[Boolean] = T { false } /** Optional list of packages to ignore conflicts where the source of the conflict is in one of the specified * packages. */ - def missinglinkIgnoreSourcePackages: Seq[IgnoredPackage] = Seq.empty + def missinglinkIgnoreSourcePackages: T[Seq[IgnoredPackage]] = T { Seq.empty[IgnoredPackage] } /** Optional list of source packages to specifically target conflicts in. Cannot be used with * missinglinkIgnoreSourcePackages. */ - def missinglinkTargetSourcePackages: Seq[TargetedPackage] = Seq.empty + def missinglinkTargetSourcePackages: T[Seq[TargetedPackage]] = T { Seq.empty[TargetedPackage] } /** Optional list of packages to ignore conflicts where the destination/called-side of the conflict is in one of the * specified packages. */ - def missinglinkIgnoreDestinationPackages: Seq[IgnoredPackage] = Seq.empty + def missinglinkIgnoreDestinationPackages: T[Seq[IgnoredPackage]] = T { Seq.empty[IgnoredPackage] } /** Optional list of source packages to specifically target conflicts in. Cannot be used with * missinglinkIgnoreDestinationPackages. */ - def missinglinkTargetDestinationPackages: Seq[TargetedPackage] = Seq.empty + def missinglinkTargetDestinationPackages: T[Seq[TargetedPackage]] = T { Seq.empty[TargetedPackage] } /** Dependencies that are excluded from analysis */ - def missinglinkExcludedDependencies: Seq[DependencyFilter] = Seq.empty + def missinglinkExcludedDependencies: T[Seq[DependencyFilter]] = T { Seq.empty[DependencyFilter] } def missinglinkCheck(): Command[Unit] = T.command { assert( - missinglinkIgnoreSourcePackages.isEmpty || missinglinkTargetSourcePackages.isEmpty, + missinglinkIgnoreSourcePackages().isEmpty || missinglinkTargetSourcePackages().isEmpty, "ignoreSourcePackages and targetSourcePackages cannot be defined in the same project." ) assert( - missinglinkIgnoreDestinationPackages.isEmpty || missinglinkTargetDestinationPackages.isEmpty, + missinglinkIgnoreDestinationPackages().isEmpty || missinglinkTargetDestinationPackages().isEmpty, "ignoreDestinationPackages and targetDestinationPackages cannot be defined in the same project." ) @@ -59,30 +59,31 @@ trait MissinglinkCheckModule extends JavaModule { loadArtifactsAndCheckConflicts( runCp, classDirectory, - missinglinkScanDependencies, + missinglinkScanDependencies(), + missinglinkExcludedDependencies(), T.log ) val conflictFilters = filterConflicts( - missinglinkIgnoreSourcePackages, + missinglinkIgnoreSourcePackages(), "missinglinkIgnoreSourcePackages", T.log, "source", _.fromClass ) andThen filterConflicts( - missinglinkTargetSourcePackages, + missinglinkTargetSourcePackages(), "missinglinkTargetSourcePackages", T.log, "source", _.fromClass ) andThen filterConflicts( - missinglinkIgnoreDestinationPackages, + missinglinkIgnoreDestinationPackages(), "missinglinkIgnoreDestinationPackages", T.log, "destination", _.targetClass ) andThen filterConflicts( - missinglinkTargetDestinationPackages, + missinglinkTargetDestinationPackages(), "missinglinkTargetDestinationPackages", T.log, "destination", @@ -105,7 +106,7 @@ trait MissinglinkCheckModule extends JavaModule { outputConflicts(filteredConflicts, T.log) - if (missinglinkFailOnConflicts) { + if (missinglinkFailOnConflicts()) { throw new Exception(s"There were $filteredTotal conflicts") } } else { @@ -117,6 +118,7 @@ trait MissinglinkCheckModule extends JavaModule { cp: Seq[os.Path], classDirectory: os.Path, scanDependencies: Boolean, + excludedDependencies: Seq[DependencyFilter], log: Logger ): Seq[Conflict] = { @@ -125,7 +127,7 @@ trait MissinglinkCheckModule extends JavaModule { val runtimeArtifactsAfterExclusions = runtimeArtifacts .filterNot { artifact => artifact.path.fold(true) { path => - missinglinkExcludedDependencies.exists(_.check(path)) + excludedDependencies.exists(_.check(path)) } } .map(_.artifact) diff --git a/mill-missinglink/src/io/github/hoangmaihuy/missinglink/package.scala b/mill-missinglink/src/io/github/hoangmaihuy/missinglink/package.scala index e8721a8..e4f6b19 100644 --- a/mill-missinglink/src/io/github/hoangmaihuy/missinglink/package.scala +++ b/mill-missinglink/src/io/github/hoangmaihuy/missinglink/package.scala @@ -11,7 +11,11 @@ package object missinglink { } + implicit val ignoredPackageRw: upickle.default.ReadWriter[IgnoredPackage] = upickle.default.macroRW + private[missinglink] implicit object IgnoredPackages extends PackageFilters[IgnoredPackage] { + + def apply(name: String)(filters: Seq[IgnoredPackage]): Boolean = filters.forall(_.apply(name)) } @@ -22,6 +26,8 @@ package object missinglink { } + implicit val targetedPackageRw: upickle.default.ReadWriter[TargetedPackage] = upickle.default.macroRW + private[missinglink] implicit object TargetedPackages extends PackageFilters[TargetedPackage] { def apply(name: String)(filters: Seq[TargetedPackage]): Boolean = @@ -48,4 +54,6 @@ package object missinglink { } + implicit val dependencyFilterRw: upickle.default.ReadWriter[DependencyFilter] = upickle.default.macroRW + } From 5abd6a0008ecc5225d7a2be277e372435cf8b1d2 Mon Sep 17 00:00:00 2001 From: hoangmaihuy Date: Tue, 19 Dec 2023 15:24:24 +0700 Subject: [PATCH 2/2] feat: missinglinkCheckCached --- .../hoangmaihuy/missinglink/MissinglinkCheckModule.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala b/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala index a64c965..cf2c77a 100644 --- a/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala +++ b/mill-missinglink/src/io/github/hoangmaihuy/missinglink/MissinglinkCheckModule.scala @@ -41,6 +41,10 @@ trait MissinglinkCheckModule extends JavaModule { /** Dependencies that are excluded from analysis */ def missinglinkExcludedDependencies: T[Seq[DependencyFilter]] = T { Seq.empty[DependencyFilter] } + def missinglinkCheckCached = T { + missinglinkCheck() + } + def missinglinkCheck(): Command[Unit] = T.command { assert( missinglinkIgnoreSourcePackages().isEmpty || missinglinkTargetSourcePackages().isEmpty,