From 7b462e5f0b854f5d60887c8548b539902bca9060 Mon Sep 17 00:00:00 2001 From: Robby Date: Sun, 25 Feb 2018 02:14:25 -0600 Subject: GenIdea: added generation of .idea/scala_compiler.xml (#151) * Added generation of .idea/scala_compiler.xml (Scalac compiler plugins and options). * More robust evaluation of tasks because results may be empty, which causes a match error. --- scalalib/src/mill/scalalib/GenIdea.scala | 62 ++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'scalalib') diff --git a/scalalib/src/mill/scalalib/GenIdea.scala b/scalalib/src/mill/scalalib/GenIdea.scala index b7a4ec12..6cedf606 100644 --- a/scalalib/src/mill/scalalib/GenIdea.scala +++ b/scalalib/src/mill/scalalib/GenIdea.scala @@ -90,16 +90,24 @@ object GenIdea { val externalSources = T.task{ mod.resolveDeps(allIvyDeps, sources = true)() } - val Seq(resolvedCp: Loose.Agg[PathRef], resolvedSrcs: Loose.Agg[PathRef]) = - evaluator.evaluate(Agg(externalDependencies, externalSources)) - .values - (path, resolvedCp.map(_.path).filter(_.ext == "jar") ++ resolvedSrcs.map(_.path), mod) + val scalacPluginsIvyDeps = T.task{mod.scalacPluginIvyDeps()} + val scalacOptions = T.task{mod.scalacOptions()} + val scalacPluginDependencies = T.task{ + mod.resolveDeps(scalacPluginsIvyDeps)() + } + + 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 scalacOpts: Seq[String] = evalOrElse(evaluator, scalacOptions, Seq()) + + (path, resolvedCp.map(_.path).filter(_.ext == "jar") ++ resolvedSrcs.map(_.path), mod, + resolvedSp.map(_.path).filter(_.ext == "jar"), scalacOpts) } val moduleLabels = modules.map(_.swap).toMap - val allResolved = resolved.flatMap(_._2) ++ buildLibraryPaths val minResolvedLength = allResolved.map(_.segments.length).min val commonPrefix = allResolved.map(_.segments.take(minResolvedLength)) @@ -124,6 +132,13 @@ object GenIdea { } .toMap + val compilerSettings = resolved + .foldLeft(Map[(Loose.Agg[Path], Seq[String]), Vector[ScalaModule]]()) { + (r, q) => + val key = (q._4, q._5) + r + (key -> (r.getOrElse(key, Vector()) :+ q._3)) + } + val fixedFiles = Seq( Tuple2(".idea"/"misc.xml", miscXmlTemplate(jdkInfo)), Tuple2(".idea"/"scala_settings.xml", scalaSettingsTemplate()), @@ -140,6 +155,10 @@ object GenIdea { for(path <- buildLibraryPaths) yield pathToLibName(path) ) + ), + Tuple2( + ".idea"/"scala_compiler.xml", + scalaCompilerTemplate(compilerSettings) ) ) @@ -155,7 +174,7 @@ object GenIdea { Tuple2(".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, url)) } - val moduleFiles = resolved.map{ case (path, resolvedDeps, mod) => + val moduleFiles = resolved.map{ case (path, resolvedDeps, mod, _, _) => val Seq( resourcesPathRefs: Seq[PathRef], sourcesPathRef: Seq[PathRef], @@ -188,6 +207,12 @@ object GenIdea { fixedFiles ++ libraries ++ moduleFiles ++ buildLibraries } + def evalOrElse[T](evaluator: Evaluator[_], e: Task[T], default: => T): T = { + evaluator.evaluate(Agg(e)).values match { + case Seq() => default + case Seq(e: T) => e + } + } def relify(p: Path) = { val r = p.relativeTo(pwd/".idea_modules") @@ -307,4 +332,29 @@ object GenIdea { } + def scalaCompilerTemplate(settings: Map[(Loose.Agg[Path], Seq[String]), Seq[ScalaModule]]) = { + + + + { + for((((plugins, params), mods), i) <- settings.toSeq.zip(1 to settings.size)) + yield + moduleName(m.millModuleSegments)).mkString(",")}> + + { + for(param <- params) + yield + } + + + { + for(plugin <- plugins.toSeq) + yield + } + + + } + + + } } -- cgit v1.2.3