summaryrefslogtreecommitdiff
path: root/main/core/src/mill/define/BaseModule.scala
blob: 03bdeccc67df976ba8017a81a1fee124ef0faa13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package mill.define

import ammonite.ops.Path

object BaseModule{
  case class Implicit(value: BaseModule)
}

abstract class BaseModule(millSourcePath0: Path,
                          external0: Boolean = false,
                          foreign0 : Boolean = false)
                         (implicit millModuleEnclosing0: sourcecode.Enclosing,
                          millModuleLine0: sourcecode.Line,
                          millName0: sourcecode.Name,
                          millFile0: sourcecode.File,
                          caller: Caller)
  extends Module()(
    mill.define.Ctx.make(
      implicitly,
      implicitly,
      implicitly,
      BasePath(millSourcePath0),
      Segments(),
      mill.util.Router.Overrides(0),
      Ctx.External(external0),
      Ctx.Foreign(foreign0),
      millFile0,
      caller
    )
  ){
  // A BaseModule should provide an empty Segments list to it's children, since
  // it is the root of the module tree, and thus must not include it's own
  // sourcecode.Name as part of the list,
  override implicit def millModuleSegments: Segments = Segments()
  override def millSourcePath = millOuterCtx.millSourcePath
  override implicit def millModuleBasePath: BasePath = BasePath(millSourcePath)
  implicit def millImplicitBaseModule: BaseModule.Implicit = BaseModule.Implicit(this)
  def millDiscover: Discover[this.type]
}


abstract class ExternalModule(implicit millModuleEnclosing0: sourcecode.Enclosing,
                              millModuleLine0: sourcecode.Line,
                              millName0: sourcecode.Name)
  extends BaseModule(ammonite.ops.pwd, external0 = true, foreign0 = false)(
    implicitly, implicitly, implicitly, implicitly, Caller(())
  ){

  implicit def millDiscoverImplicit: Discover[_] = millDiscover
  assert(
    !" #".exists(millModuleEnclosing0.value.contains(_)),
    "External modules must be at a top-level static path, not " + millModuleEnclosing0.value
  )
  override implicit def millModuleSegments = {
    Segments(millModuleEnclosing0.value.split('.').map(Segment.Label):_*)
  }
}