All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mill.scalalib.PlatformScalaModule.scala Maven / Gradle / Ivy

There is a newer version: 0.12.0-RC2-17-07e173
Show newest version
package mill.scalalib

import mill._
import os.Path

/**
 * A [[ScalaModule]] intended for defining `.jvm`/`.js`/`.native` submodules
 * It supports additional source directories per platform, e.g. `src-jvm/` or
 * `src-js/` and can be used inside a [[CrossScalaModule.Base]], to get one
 * source folder per platform per version e.g. `src-2.12-jvm/`.
 *
 * Adjusts the [[millSourcePath]] and [[artifactNameParts]] to ignore the last
 * path segment, which is assumed to be the name of the platform the module is
 * built against and not something that should affect the filesystem path or
 * artifact name
 */
trait PlatformScalaModule extends ScalaModule {
  override def millSourcePath: Path = super.millSourcePath / os.up

  /**
   * The platform suffix of this [[PlatformScalaModule]]. Useful if you want to
   * further customize the source paths or artifact names.
   */
  def platformScalaSuffix: String = millModuleSegments
    .value
    .collect { case l: mill.define.Segment.Label => l.value }
    .last

  override def sources: T[Seq[PathRef]] = T.sources {
    super.sources().flatMap { source =>
      val platformPath =
        PathRef(source.path / _root_.os.up / s"${source.path.last}-${platformScalaSuffix}")
      Seq(source, platformPath)
    }
  }

  override def artifactNameParts: T[Seq[String]] = super.artifactNameParts().dropRight(1)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy