Skip to content

Commit

Permalink
Implement language-level property for scala library in IJ
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Sep 21, 2021
1 parent bf86a6f commit de51e9b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 30 deletions.
4 changes: 2 additions & 2 deletions main/core/src/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -664,10 +664,10 @@ object Evaluator {
rawValues: Seq[Result[Any]],
evaluated: Agg[Task[_]],
transitive: Agg[Task[_]],
failing: MultiBiMap[Either[Task[_], Labelled[_]], Result.Failing[_]],
failing: MultiBiMap[Either[Task[_], Labelled[_]], mill.api.Result.Failing[_]],
results: collection.Map[Task[_], Result[Any]]
) {
def values = rawValues.collect { case Result.Success(v) => v }
def values = rawValues.collect { case mill.api.Result.Success(v) => v }
}

def plan(rootModule: BaseModule, goals: Agg[Task[_]]) = {
Expand Down
53 changes: 36 additions & 17 deletions scalalib/src/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ case class GenIdeaImpl(
case mod: ScalaModule => (
T.task(mod.scalacPluginIvyDeps()),
T.task(mod.allScalacOptions()),
T.task(mod.scalaVersion())
T.task(Option(mod.scalaVersion()))
)
case _ => (T.task { Agg[Dep]() }, T.task { Seq() }, T.task { None })
}
Expand Down Expand Up @@ -220,6 +220,7 @@ case class GenIdeaImpl(
val resolvedConfigFileContributions: Seq[IdeaConfigFile] =
configFileContributions()
val resolvedCompilerOutput = compilerOutput()
val resolvedScalaVersion = scalaVersion()

ResolvedModule(
path = path,
Expand All @@ -234,14 +235,29 @@ case class GenIdeaImpl(
facets = resolvedFacets,
configFileContributions = resolvedConfigFileContributions,
compilerOutput = resolvedCompilerOutput.path,
scalaVersion = None
scalaVersion = resolvedScalaVersion
)
}
}
}

val resolvedModules: Seq[ResolvedModule] =
evalOrElse(evaluator, T.sequence(resolveTasks), Seq())
val resolvedModules: Seq[ResolvedModule] = {
// evalOrElse(evaluator, T.sequence(resolveTasks), throw new RuntimeException("Could not evaluate "))
val results: Evaluator.Results = evaluator.evaluate(resolveTasks)
if (results.failing.items().nonEmpty) {
def mapFailing(f: mill.api.Result.Failing[_]): String = f match {
case mill.api.Result.Exception(e, _) => s"$e\n ${e.getStackTrace.toSeq.map("" + _).mkString("\n ")}"
case f => s"$f"
}
val failing = results.failing.items().map {
case (t, es) => s"${t} => ${es.map(mapFailing(_))}"
}
throw new RuntimeException(
s"Some tasks failed: ${failing.mkString("\n")}"
)
}
results.values.map(_.asInstanceOf[ResolvedModule])
}

val moduleLabels = modules.map(_.swap).toMap

Expand All @@ -250,8 +266,8 @@ case class GenIdeaImpl(
buildLibraryPaths ++
buildDepsPaths).distinct

val librariesProperties = resolvedModules
.flatMap(x => x.libraryClasspath.map(_ -> x.compilerClasspath))
val librariesProperties: Map[Path, (Agg[Path], Option[String])] = resolvedModules
.flatMap(x => x.libraryClasspath.map(_ -> (x.compilerClasspath, x.scalaVersion)))
.toMap

val (wholeFileConfigs, configFileContributions) =
Expand Down Expand Up @@ -451,24 +467,27 @@ case class GenIdeaImpl(

val libraries: Seq[(SubPath, Elem)] =
resolvedLibraries(allResolved).flatMap { resolved =>
import resolved.path
val names = libraryNames(resolved)
val sources = resolved match {
case CoursierResolved(_, _, s) => s
case WithSourcesResolved(_, s) => s
case OtherResolved(_) => None
}
for (name <- names)
yield Tuple2(
os.sub / "libraries" / s"${ideaifyLibraryName(name)}.xml",
libraryXmlTemplate(
name = name,
path = path,
sources = sources,
scalaCompilerClassPath = librariesProperties.getOrElse(path, Agg.empty),
scalaVersion = None
yield {
val (compilerCp, scalaVersion) =
librariesProperties.getOrElse(resolved.path, (Agg.empty, None))
Tuple2(
os.sub / "libraries" / s"${ideaifyLibraryName(name)}.xml",
libraryXmlTemplate(
name = name,
path = resolved.path,
sources = sources,
scalaCompilerClassPath = compilerCp,
scalaVersion = scalaVersion
)
)
)
}
}

val moduleFiles: Seq[(SubPath, Elem)] = resolvedModules.map {
Expand Down Expand Up @@ -725,7 +744,7 @@ case class GenIdeaImpl(
{
if (scalaVersion.isDefined) {
<language-level>Scala_{
mill.scalalib.api.Util.scalaBinaryVersion(scalaVersion.get).replace("[.]", "_")
mill.scalalib.api.Util.scalaBinaryVersion(scalaVersion.get).replace(".", "_")
}</language-level>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill.scalalib.GenIdeaModule._
import mill.scalalib.TestModule

trait HelloWorldModule extends scalalib.ScalaModule {
def scalaVersion = "2.12.4"
def scalaVersion = "2.13.6"
object test extends super.Tests with TestModule.Utest

def generatedSources = T {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<component name="libraryTable">
<library name="scala-library-2.12.4.jar" type="Scala">
<library name="scala-library-2.13.6.jar" type="Scala">
<properties>
<language-level>Scala_2_13</language-level>
<compiler-classpath>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.12/1.0.6/scala-xml_2.12-1.0.6.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.12.4/scala-compiler-2.12.4.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.12.4/scala-reflect-2.12.4.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/jline/jline/3.19.0/jline-3.19.0.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.6/scala-compiler-2.13.6.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.6/scala-reflect-2.13.6.jar"/>
</compiler-classpath>
</properties>
<CLASSES>
<root url="jar://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4.jar!/"/>
<root url="jar://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6.jar!/"/>
</CLASSES>
<SOURCES>
<root url="jar://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4-sources.jar!/"/>
<root url="jar://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.6/scala-library-2.13.6-sources.jar!/"/>
</SOURCES>
</library>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</content>
<orderEntry type="inheritedJdk"/>
<orderEntry type="sourceFolder" forTests="false"/>
<orderEntry type="library" name="scala-library-2.12.4.jar" level="project"/>
<orderEntry type="library" name="scala-library-2.13.6.jar" level="project"/>
</component>
<component name="FacetManager">
<facet type="AspectJ" name="AspectJ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</content>
<orderEntry type="inheritedJdk"/>
<orderEntry type="sourceFolder" forTests="false"/>
<orderEntry type="library" name="scala-library-2.12.4.jar" level="project"/>
<orderEntry type="library" name="scala-library-2.13.6.jar" level="project"/>
<orderEntry type="module" module-name="helloworld" exported=""/>
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<component name="libraryTable">
<library name="scala-library-2.12.4.jar" type="Scala">
<properties>
<language-level>Scala_2_12</language-level>
<compiler-classpath>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.12/1.0.6/scala-xml_2.12-1.0.6.jar"/>
<root url="file://COURSIER_HOME/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.12.4/scala-compiler-2.12.4.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion scalalib/test/src/GenIdeaExtendedTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object GenIdeaExtendedTests extends ScriptTestSuite(false) {
os.sub / "mill_modules" / "helloworld.iml",
os.sub / "mill_modules" / "helloworld.test.iml",
os.sub / "mill_modules" / "mill-build.iml",
os.sub / "libraries" / "scala_library_2_12_4_jar.xml",
os.sub / "libraries" / "scala_library_2_13_6_jar.xml",
os.sub / "modules.xml",
os.sub / "misc.xml",
os.sub / "compiler.xml"
Expand Down

0 comments on commit de51e9b

Please sign in to comment.