summaryrefslogtreecommitdiff
path: root/scalalib
diff options
context:
space:
mode:
authorandres-pipicello-olx <36170539+andres-pipicello-olx@users.noreply.github.com>2019-01-31 09:07:43 -0300
committerLi Haoyi <haoyi.sg@gmail.com>2019-01-31 04:07:43 -0800
commitf6b05534cc4af0ad78622a3a7e687dbe1e1f8a1c (patch)
treeb8fdd697f890e71ea9481ad71196e6c28f071dcf /scalalib
parent83ac3f9425a89823023be9819412a4dd88fe0a56 (diff)
downloadmill-f6b05534cc4af0ad78622a3a7e687dbe1e1f8a1c.tar.gz
mill-f6b05534cc4af0ad78622a3a7e687dbe1e1f8a1c.tar.bz2
mill-f6b05534cc4af0ad78622a3a7e687dbe1e1f8a1c.zip
Added compiler-classpath properties to generated IntelliJ xml files (#531)
Diffstat (limited to 'scalalib')
-rwxr-xr-xscalalib/src/GenIdeaImpl.scala62
-rw-r--r--scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml8
2 files changed, 59 insertions, 11 deletions
diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala
index 07b32a3e..e815ffbd 100755
--- a/scalalib/src/GenIdeaImpl.scala
+++ b/scalalib/src/GenIdeaImpl.scala
@@ -8,6 +8,7 @@ import mill.api.Ctx.{Home, Log}
import mill.api.Strict.Agg
import mill.api.{Loose, Strict}
import mill.{T, scalalib}
+import os.Path
import scala.util.Try
@@ -98,12 +99,33 @@ object GenIdeaImpl {
.filter(_.toIO.exists)
}.getOrElse(Seq())
+ case class ResolvedModule(
+ path: Segments,
+ classpath: Loose.Agg[Path],
+ module: JavaModule,
+ pluginClasspath: Loose.Agg[Path],
+ scalaOptions: Seq[String],
+ compilerClasspath: Loose.Agg[Path],
+ libraryClasspath: Loose.Agg[Path]
+ )
+
val resolved = for((path, mod) <- modules) yield {
val scalaLibraryIvyDeps = mod match{
case x: ScalaModule => x.scalaLibraryIvyDeps
- case _ => T.task{Nil}
+ case _ => T.task{Loose.Agg.empty[Dep]}
}
val allIvyDeps = T.task{mod.transitiveIvyDeps() ++ scalaLibraryIvyDeps() ++ mod.compileIvyDeps()}
+
+ val scalaCompilerClasspath = mod match{
+ case x: ScalaModule => x.scalaCompilerClasspath
+ case _ => T.task{Loose.Agg.empty[PathRef]}
+ }
+
+
+ val externalLibraryDependencies = T.task{
+ mod.resolveDeps(scalaLibraryIvyDeps)()
+ }
+
val externalDependencies = T.task{
mod.resolveDeps(allIvyDeps)() ++
Task.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten
@@ -124,19 +146,26 @@ object GenIdeaImpl {
val resolvedCp: Loose.Agg[PathRef] = evalOrElse(evaluator, externalDependencies, Loose.Agg.empty)
val resolvedSrcs: Loose.Agg[PathRef] = evalOrElse(evaluator, externalSources, Loose.Agg.empty)
val resolvedSp: Loose.Agg[PathRef] = evalOrElse(evaluator, scalacPluginDependencies, Loose.Agg.empty)
+ val resolvedCompilerCp: Loose.Agg[PathRef] = evalOrElse(evaluator, scalaCompilerClasspath, Loose.Agg.empty)
+ val resolvedLibraryCp: Loose.Agg[PathRef] = evalOrElse(evaluator, externalLibraryDependencies, Loose.Agg.empty)
val scalacOpts: Seq[String] = evalOrElse(evaluator, scalacOptions, Seq())
- (
+ ResolvedModule(
path,
resolvedCp.map(_.path).filter(_.ext == "jar") ++ resolvedSrcs.map(_.path),
mod,
resolvedSp.map(_.path).filter(_.ext == "jar"),
- scalacOpts
+ scalacOpts,
+ resolvedCompilerCp.map(_.path),
+ resolvedLibraryCp.map(_.path)
)
}
+
val moduleLabels = modules.map(_.swap).toMap
- val allResolved = resolved.flatMap(_._2) ++ buildLibraryPaths ++ buildDepsPaths
+ val allResolved = resolved.flatMap(_.classpath) ++ buildLibraryPaths ++ buildDepsPaths
+
+ val librariesProperties = resolved.flatMap(x => x.libraryClasspath.map(_ -> x.compilerClasspath)).toMap
val commonPrefix =
if (allResolved.isEmpty) 0
@@ -216,8 +245,8 @@ object GenIdeaImpl {
val compilerSettings = resolved
.foldLeft(Map[(Loose.Agg[os.Path], Seq[String]), Vector[JavaModule]]()) {
(r, q) =>
- val key = (q._4, q._5)
- r + (key -> (r.getOrElse(key, Vector()) :+ q._3))
+ val key = (q.pluginClasspath, q.scalaOptions)
+ r + (key -> (r.getOrElse(key, Vector()) :+ q.module))
}
val allBuildLibraries : Set[ResolvedLibrary] =
@@ -249,16 +278,15 @@ object GenIdeaImpl {
val libraries = resolvedLibraries(allResolved).map{ resolved =>
import resolved.path
- val url = if (path.ext == "jar") "jar://" + path + "!/" else "file://" + path
val name = libraryName(resolved)
val sources = resolved match {
case CoursierResolved(_, _, s) => s.map(p => "jar://" + p + "!/")
case OtherResolved(_) => None
}
- Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, url, sources))
+ Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, path, sources, librariesProperties.getOrElse(path, Loose.Agg.empty)))
}
- val moduleFiles = resolved.map{ case (path, resolvedDeps, mod, _, _) =>
+ val moduleFiles = resolved.map{ case ResolvedModule(path, resolvedDeps, mod, _, _, _, _) =>
val Seq(
resourcesPathRefs: Seq[PathRef],
sourcesPathRef: Seq[PathRef],
@@ -375,9 +403,21 @@ object GenIdeaImpl {
</component>
</module>
}
- def libraryXmlTemplate(name: String, url: String, sources: Option[String]) = {
+ def libraryXmlTemplate(name: String, path: os.Path, sources: Option[String], compilerClassPath: Loose.Agg[Path]) = {
+ val url = if (path.ext == "jar") "jar://" + path + "!/" else "file://" + path
+ val isScalaLibrary = compilerClassPath.nonEmpty
<component name="libraryTable">
- <library name={name} type={if(name.contains("scala-library-")) "Scala" else null}>
+ <library name={name} type={if(isScalaLibrary) "Scala" else null}>
+ { if(isScalaLibrary) {
+ <properties>
+ <compiler-classpath>
+ {
+ compilerClassPath.toList.sortBy(_.wrapped).map(p => <root url={"file://" + p}/>)
+ }
+ </compiler-classpath>
+ </properties>
+ }
+ }
<CLASSES>
<root url={url}/>
</CLASSES>
diff --git a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml
index 5f6d7263..5f7c5056 100644
--- a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml
+++ b/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml
@@ -1,5 +1,13 @@
<component name="libraryTable">
<library name="scala-library-2.12.4.jar" type="Scala">
+ <properties>
+ <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"/>
+ </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!/"/>
</CLASSES>