|
| 1 | +//| mill-version: 1.0.0 |
| 2 | +//| mill-jvm-version: 11 |
| 3 | +//| mill-opts: ["--jobs=0.5C"] |
| 4 | +//| mvnDeps: |
| 5 | +//| - com.github.lolgab::mill-mima_mill1:0.2.0 |
| 6 | +//| - com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION |
| 7 | +package build |
| 8 | +import mill._, scalalib._, scalajslib._, scalanativelib._, publish._ |
| 9 | +import mill.util.VcsVersion |
| 10 | +import mill.contrib.buildinfo.BuildInfo |
| 11 | +import com.github.lolgab.mill.mima._ |
| 12 | + |
| 13 | +val communityBuildDottyVersion = sys.props.get("dottyVersion").toList |
| 14 | + |
| 15 | +val scalaVersions = "2.12.20" :: "2.13.16" :: "3.3.6" :: communityBuildDottyVersion |
| 16 | + |
| 17 | +val scalaReflectVersion = "1.1.3" |
| 18 | + |
| 19 | +trait MimaCheck extends Mima { |
| 20 | + def mimaPreviousVersions = VcsVersion.vcsState().lastTag.toSeq |
| 21 | +} |
| 22 | + |
| 23 | +trait UtestModule extends PublishModule with MimaCheck { |
| 24 | + def artifactName = "utest" |
| 25 | + |
| 26 | + def publishVersion = VcsVersion.vcsState().format() |
| 27 | + |
| 28 | + def pomSettings = PomSettings( |
| 29 | + description = artifactName(), |
| 30 | + organization = "com.lihaoyi", |
| 31 | + url = "https://github.com/com-lihaoyi/utest", |
| 32 | + licenses = Seq(License.MIT), |
| 33 | + versionControl = VersionControl.github(owner = "com-lihaoyi", repo = "utest"), |
| 34 | + developers = Seq( |
| 35 | + Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi") |
| 36 | + ) |
| 37 | + ) |
| 38 | +} |
| 39 | +trait UtestMainModule extends CrossScalaModule with UtestModule with PlatformScalaModule{ |
| 40 | + def resolveUnpackShade(filtered: Seq[PathRef])(implicit ctx: mill.api.TaskCtx) = { |
| 41 | + for(jar <- filtered) os.unzip(jar.path, Task.dest) |
| 42 | + |
| 43 | + for(file <- os.walk(Task.dest) if file.ext == "scala"){ |
| 44 | + val text = os.read(file) |
| 45 | + if (!text.contains("package scala")){ |
| 46 | + os.write.over( |
| 47 | + file, |
| 48 | + "package utest.shaded\n" + |
| 49 | + text.replace("assert(", "Predef.assert(") |
| 50 | + .replace("_root_.pprint", "_root_.utest.shaded.pprint") |
| 51 | + .replace("_root_.fansi", "_root_.utest.shaded.fansi") |
| 52 | + ) |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + Seq(PathRef(Task.dest)) |
| 57 | + } |
| 58 | + |
| 59 | + def generatedSources = Task{ |
| 60 | + // Locally-build and shade versions of pprint and fansi to avoid classpath |
| 61 | + // conflicts and circular dependencies between utest and those projects |
| 62 | + resolveUnpackShade( |
| 63 | + defaultResolver().classpath( |
| 64 | + Seq( |
| 65 | + mvn"com.lihaoyi::pprint:0.9.3", |
| 66 | + mvn"com.lihaoyi::fansi:0.5.1", |
| 67 | + mvn"app.tulz::stringdiff:0.3.4" |
| 68 | + ), |
| 69 | + sources = true |
| 70 | + ).filter(_.path.last match{ |
| 71 | + case s"fansi$versionSuffix.jar" => true |
| 72 | + case s"pprint$versionSuffix.jar" => true |
| 73 | + case s"stringdiff$versionSuffix.jar" => true |
| 74 | + case _ => false |
| 75 | + }) |
| 76 | + ) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +trait UtestTestModule extends BuildInfo with TestModule { |
| 82 | + def scalaVersion: T[String] |
| 83 | + def testFramework = "test.utest.CustomFramework" |
| 84 | + |
| 85 | + val buildInfoPackageName = "test.utest" |
| 86 | + |
| 87 | + def buildInfoMembers = Seq(BuildInfo.Value("scalaVersion", scalaVersion())) |
| 88 | +} |
| 89 | + |
| 90 | +object utest extends Module { |
| 91 | + object jvm extends Cross[JvmUtestModule](scalaVersions) |
| 92 | + trait JvmUtestModule |
| 93 | + extends UtestMainModule { |
| 94 | + def compileMvnDeps = |
| 95 | + if (crossScalaVersion.startsWith("2")) Seq( |
| 96 | + mvn"org.scala-lang:scala-reflect:${crossScalaVersion}", |
| 97 | + mvn"org.scala-lang:scala-compiler:${crossScalaVersion}" |
| 98 | + ) |
| 99 | + else Seq.empty[Dep] |
| 100 | + |
| 101 | + def mvnDeps = Seq( |
| 102 | + mvn"com.lihaoyi::sourcecode::0.4.3-M5", |
| 103 | + mvn"org.scala-sbt:test-interface::1.0", |
| 104 | + mvn"org.scala-lang.modules::scala-collection-compat::2.13.0", |
| 105 | + ) ++ (if (crossScalaVersion.startsWith("2")) Seq( |
| 106 | + mvn"org.portable-scala::portable-scala-reflect::$scalaReflectVersion", |
| 107 | + mvn"org.scala-lang:scala-reflect:$crossScalaVersion" |
| 108 | + ) else Seq()) |
| 109 | + object test extends ScalaTests with UtestTestModule{ |
| 110 | + def resources = super[UtestTestModule].resources() ++ super[ScalaTests].resources() |
| 111 | + def scalacOptions = Seq("-Yrangepos") |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + object js extends Cross[JsUtestModule](scalaVersions) |
| 116 | + trait JsUtestModule extends UtestMainModule with ScalaJSModule{ |
| 117 | + def compileMvnDeps = |
| 118 | + if (crossScalaVersion.startsWith("2")) Seq( |
| 119 | + mvn"org.scala-lang:scala-reflect:${crossScalaVersion}", |
| 120 | + mvn"org.scala-lang:scala-compiler:${crossScalaVersion}" |
| 121 | + ) |
| 122 | + else Seq.empty[Dep] |
| 123 | + def mvnDeps = Seq( |
| 124 | + mvn"com.lihaoyi::sourcecode::0.4.3-M5", |
| 125 | + mvn"org.scala-js::scalajs-test-interface:${scalaJSVersion()}".withDottyCompat(crossScalaVersion), |
| 126 | + mvn"org.portable-scala::portable-scala-reflect::$scalaReflectVersion".withDottyCompat(crossScalaVersion), |
| 127 | + mvn"org.scala-lang.modules::scala-collection-compat::2.13.0", |
| 128 | + ) ++ (if(crossScalaVersion.startsWith("2")) Seq( |
| 129 | + mvn"org.scala-lang:scala-reflect:$crossScalaVersion" |
| 130 | + ) else Seq()) |
| 131 | + def scalaJSVersion = "1.19.0" |
| 132 | + object test extends ScalaJSTests with UtestTestModule{ |
| 133 | + def resources = super[UtestTestModule].resources() ++ super[ScalaJSTests].resources() |
| 134 | + def scalacOptions = Seq("-Yrangepos") |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + object native extends Cross[NativeUtestModule](scalaVersions) |
| 139 | + trait NativeUtestModule extends UtestMainModule with ScalaNativeModule { |
| 140 | + def compileMvnDeps = |
| 141 | + if (crossScalaVersion.startsWith("2")) Seq( |
| 142 | + mvn"org.scala-lang:scala-reflect:${crossScalaVersion}", |
| 143 | + mvn"org.scala-lang:scala-compiler:${crossScalaVersion}" |
| 144 | + ) |
| 145 | + else Seq.empty[Dep] |
| 146 | + def mvnDeps = Seq( |
| 147 | + mvn"com.lihaoyi::sourcecode::0.4.3-M5", |
| 148 | + mvn"org.scala-native::test-interface::${scalaNativeVersion()}", |
| 149 | + mvn"org.scala-lang.modules::scala-collection-compat::2.13.0", |
| 150 | + ) |
| 151 | + |
| 152 | + def scalaNativeVersion = "0.5.8" |
| 153 | + object test extends ScalaNativeTests with UtestTestModule{ |
| 154 | + def resources = super[UtestTestModule].resources() ++ super[ScalaNativeTests].resources() |
| 155 | + def scalacOptions = Seq("-Yrangepos") |
| 156 | + } |
| 157 | + } |
| 158 | +} |
0 commit comments