Skip to content

Commit

Permalink
Move scope-related tasks together in JavaModule (#4076)
Browse files Browse the repository at this point in the history
With the main task first, the compile-only one second, and the runtime
one third

This makes it easier to change these methods, add related ones, etc.

This is already part of #4068.
Opening the PR here to make it easier to review the changes here, and
those of #4068 if the one here
gets merged
  • Loading branch information
alexarchambault authored Dec 6, 2024
1 parent c369cb7 commit 30deaa5
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ trait JavaModule
*/
def moduleDeps: Seq[JavaModule] = Seq.empty

/**
* The compile-only direct dependencies of this module. These are *not*
* transitive, and only take effect in the module that they are declared in.
*/
def compileModuleDeps: Seq[JavaModule] = Seq.empty

/**
* The runtime-only direct dependencies of this module. These *are* transitive,
* and so get propagated to downstream modules automatically
*/
def runModuleDeps: Seq[JavaModule] = Seq.empty

/**
* Same as [[moduleDeps]] but checked to not contain cycles.
* Prefer this over using [[moduleDeps]] directly.
Expand All @@ -327,6 +339,13 @@ trait JavaModule
moduleDeps
}

/** Same as [[compileModuleDeps]] but checked to not contain cycles. */
final def compileModuleDepsChecked: Seq[JavaModule] = {
// trigger initialization to check for cycles
recCompileModuleDeps
compileModuleDeps
}

/**
* Same as [[moduleDeps]] but checked to not contain cycles.
* Prefer this over using [[moduleDeps]] directly.
Expand All @@ -345,33 +364,6 @@ trait JavaModule
_.moduleDeps
)

/** Should only be called from [[runModuleDepsChecked]] */
private lazy val recRunModuleDeps: Seq[JavaModule] =
ModuleUtils.recursive[JavaModule](
(millModuleSegments ++ Seq(Segment.Label("runModuleDeps"))).render,
this,
m => m.runModuleDeps ++ m.moduleDeps
)

/**
* The compile-only direct dependencies of this module. These are *not*
* transitive, and only take effect in the module that they are declared in.
*/
def compileModuleDeps: Seq[JavaModule] = Seq.empty

/**
* The runtime-only direct dependencies of this module. These *are* transitive,
* and so get propagated to downstream modules automatically
*/
def runModuleDeps: Seq[JavaModule] = Seq.empty

/** Same as [[compileModuleDeps]] but checked to not contain cycles. */
final def compileModuleDepsChecked: Seq[JavaModule] = {
// trigger initialization to check for cycles
recCompileModuleDeps
compileModuleDeps
}

/** Should only be called from [[compileModuleDeps]] */
private lazy val recCompileModuleDeps: Seq[JavaModule] =
ModuleUtils.recursive[JavaModule](
Expand All @@ -380,6 +372,14 @@ trait JavaModule
_.compileModuleDeps
)

/** Should only be called from [[runModuleDepsChecked]] */
private lazy val recRunModuleDeps: Seq[JavaModule] =
ModuleUtils.recursive[JavaModule](
(millModuleSegments ++ Seq(Segment.Label("runModuleDeps"))).render,
this,
m => m.runModuleDeps ++ m.moduleDeps
)

/** The direct and indirect dependencies of this module */
def recursiveModuleDeps: Seq[JavaModule] = { recModuleDeps }

Expand Down Expand Up @@ -421,13 +421,6 @@ trait JavaModule
(runModuleDepsChecked ++ moduleDepsChecked).flatMap(_.transitiveRunModuleDeps).distinct
}

/** The compile-only transitive ivy dependencies of this module and all it's upstream compile-only modules. */
def transitiveCompileIvyDeps: T[Agg[BoundDep]] = Task {
// We never include compile-only dependencies transitively, but we must include normal transitive dependencies!
compileIvyDeps().map(bindDependency()) ++
T.traverse(compileModuleDepsChecked)(_.transitiveIvyDeps)().flatten
}

/**
* Show the module dependencies.
* @param recursive If `true` include all recursive module dependencies, else only show direct dependencies.
Expand Down Expand Up @@ -498,6 +491,13 @@ trait JavaModule
}
}

/** The compile-only transitive ivy dependencies of this module and all it's upstream compile-only modules. */
def transitiveCompileIvyDeps: T[Agg[BoundDep]] = Task {
// We never include compile-only dependencies transitively, but we must include normal transitive dependencies!
compileIvyDeps().map(bindDependency()) ++
T.traverse(compileModuleDepsChecked)(_.transitiveIvyDeps)().flatten
}

/**
* The transitive run ivy dependencies of this module and all it's upstream modules.
* This is calculated from [[runIvyDeps]], [[mandatoryIvyDeps]] and recursively from [[moduleDeps]].
Expand Down

0 comments on commit 30deaa5

Please sign in to comment.