From 308d5620948e0f82f60cd553116021a5d2bcd9e8 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Wed, 22 May 2019 20:26:37 -0300 Subject: [PATCH 01/11] Fixes https://github.com/lihaoyi/mill/issues/532 --- scalalib/src/GenIdeaImpl.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 404a0235eaf..54d66b2762b 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -1,12 +1,12 @@ package mill.scalalib import ammonite.runtime.SpecialClassLoader -import coursier.Repository -import mill.define._ -import mill.eval.{Evaluator, PathRef, Result} +import coursier.{LocalRepositories, Repositories} import mill.api.Ctx.{Home, Log} import mill.api.Strict.Agg -import mill.api.{Loose, Strict} +import mill.api.{Loose, Result, Strict} +import mill.define._ +import mill.eval.{Evaluator, PathRef} import mill.{T, scalalib} import os.Path @@ -77,7 +77,7 @@ object GenIdeaImpl { else sys.props.get("MILL_BUILD_LIBRARIES") match { case Some(found) => found.split(',').map(os.Path(_)).distinct.toList case None => - val repos = modules.foldLeft(Set.empty[Repository]) { _ ++ _._2.repositories } + val repos = Seq(LocalRepositories.ivy2Local, Repositories.central) val artifactNames = Seq("main-moduledefs", "main-api", "main-core", "scalalib", "scalajslib") val Result.Success(res) = scalalib.Lib.resolveDependencies( repos.toList, From e2b169171946eba9a3a43621f50fcd421eea443d Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Wed, 22 May 2019 20:37:49 -0300 Subject: [PATCH 02/11] Using Task.sequence instead of multiple evals --- scalalib/src/GenIdeaImpl.scala | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 54d66b2762b..84ec26fc66d 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -112,7 +112,7 @@ object GenIdeaImpl { libraryClasspath: Loose.Agg[Path] ) - val resolved = for((path, mod) <- modules) yield { + val resolved = evalOrElse(evaluator, Task.sequence(for((path, mod) <- modules) yield { val scalaLibraryIvyDeps = mod match{ case x: ScalaModule => x.scalaLibraryIvyDeps case _ => T.task{Loose.Agg.empty[Dep]} @@ -146,23 +146,25 @@ object GenIdeaImpl { 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 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, - resolvedCompilerCp.map(_.path), - resolvedLibraryCp.map(_.path) - ) - } + T.task { + val resolvedCp: Loose.Agg[PathRef] = externalDependencies() + val resolvedSrcs: Loose.Agg[PathRef] = externalSources() + val resolvedSp: Loose.Agg[PathRef] = scalacPluginDependencies() + val resolvedCompilerCp: Loose.Agg[PathRef] = scalaCompilerClasspath() + val resolvedLibraryCp: Loose.Agg[PathRef] = externalLibraryDependencies() + val scalacOpts: Seq[String] = scalacOptions() + + ResolvedModule( + path, + resolvedCp.map(_.path).filter(_.ext == "jar") ++ resolvedSrcs.map(_.path), + mod, + resolvedSp.map(_.path).filter(_.ext == "jar"), + scalacOpts, + resolvedCompilerCp.map(_.path), + resolvedLibraryCp.map(_.path) + ) + } + }), Seq()) val moduleLabels = modules.map(_.swap).toMap From ea1202f3846a998860c2d02ae6138731472b0daf Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Thu, 23 May 2019 22:43:33 -0300 Subject: [PATCH 03/11] Fixes generation of fake SBT libraries --- scalalib/src/GenIdeaImpl.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 84ec26fc66d..8c72f0bd80a 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -226,12 +226,16 @@ object GenIdeaImpl { def sbtLibraryNameFromPom(pom : os.Path) : String = { val xml = scala.xml.XML.loadFile(pom.toIO) - val groupId = (xml \ "groupId").text + val parent = xml \ "parent" val artifactId = (xml \ "artifactId").text - val version = (xml \ "version").text + val groupId = Some(xml \ "groupId").filter(_.nonEmpty).getOrElse(parent \ "groupId").text + val version = Some(xml \ "version").filter(_.nonEmpty).getOrElse(parent \ "version").text - // The scala version here is non incidental - s"SBT: $groupId:$artifactId:$version:jar" + val artifactWithScalaVersion = artifactId.substring(artifactId.length - 5) match { + case "_2.10" | "_2.11" | "_2.12" => artifactId + case _ => artifactId + "_2.12" + } + s"SBT: $groupId:$artifactWithScalaVersion:$version:jar" } def libraryName(resolvedJar: ResolvedLibrary) : String = resolvedJar match { From 3008b55602a493787f41b9b8ce7fc3430b0dbdfc Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Thu, 23 May 2019 23:10:28 -0300 Subject: [PATCH 04/11] Simple fix for https://github.com/lihaoyi/mill/issues/527 --- scalalib/src/GenIdeaImpl.scala | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 8c72f0bd80a..e483f2877a9 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -238,13 +238,13 @@ object GenIdeaImpl { s"SBT: $groupId:$artifactWithScalaVersion:$version:jar" } - def libraryName(resolvedJar: ResolvedLibrary) : String = resolvedJar match { + def libraryNames(resolvedJar: ResolvedLibrary) : Seq[String] = resolvedJar match { case CoursierResolved(path, pom, _) if buildDepsPaths.contains(path) => - sbtLibraryNameFromPom(pom) + Seq(sbtLibraryNameFromPom(pom), pathToLibName(path)) case CoursierResolved(path, _, _) => - pathToLibName(path) + Seq(pathToLibName(path)) case OtherResolved(path) => - pathToLibName(path) + Seq(pathToLibName(path)) } def resolvedLibraries(resolved : Seq[os.Path]) : Seq[ResolvedLibrary] = resolved @@ -274,9 +274,7 @@ object GenIdeaImpl { ), Tuple2( os.rel/".idea_modules"/"mill-build.iml", - rootXmlTemplate( - for(lib <- allBuildLibraries) - yield libraryName(lib) + rootXmlTemplate(allBuildLibraries.flatMap(lib => libraryNames(lib)) ) ), Tuple2( @@ -285,14 +283,14 @@ object GenIdeaImpl { ) ) - val libraries = resolvedLibraries(allResolved).map{ resolved => + val libraries = resolvedLibraries(allResolved).flatMap{ resolved => import resolved.path - val name = libraryName(resolved) + val names = libraryNames(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, path, sources, librariesProperties.getOrElse(path, Loose.Agg.empty))) + for(name <- names) yield Tuple2(os.rel/".idea"/'libraries/s"$name.xml", libraryXmlTemplate(name, path, sources, librariesProperties.getOrElse(path, Loose.Agg.empty))) } val moduleFiles = resolved.map{ case ResolvedModule(path, resolvedDeps, mod, _, _, _, _) => From 9626e43ee80dafa0795621fae842dd0c676c6240 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Fri, 24 May 2019 17:04:42 -0300 Subject: [PATCH 05/11] Fixes 'file name too long' error --- scalalib/src/GenIdeaImpl.scala | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index e483f2877a9..2db28327a6f 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -172,31 +172,15 @@ object GenIdeaImpl { val librariesProperties = resolved.flatMap(x => x.libraryClasspath.map(_ -> x.compilerClasspath)).toMap - val commonPrefix = - if (allResolved.isEmpty) 0 - else { - val minResolvedLength = allResolved.map(_.segmentCount).min - allResolved.map(_.segments.take(minResolvedLength).toList) - .transpose - .takeWhile(_.distinct.length == 1) - .length - } - - // only resort to full long path names if the jar name is a duplicate val pathShortLibNameDuplicate = allResolved .distinct - .map{p => p.last -> p} - .groupBy(_._1) + .groupBy(_.last) .filter(_._2.size > 1) - .keySet + .mapValues(_.zipWithIndex) + .flatMap(y => y._2.map(x => x._1 -> s"${y._1} (${x._2})")) val pathToLibName = allResolved - .map{p => - if (pathShortLibNameDuplicate(p.last)) - (p, p.segments.drop(commonPrefix).mkString("_")) - else - (p, p.last) - } + .map(p => p -> pathShortLibNameDuplicate.getOrElse(p, p.last)) .toMap sealed trait ResolvedLibrary { def path : os.Path } From 03e37da5b250be99fa45c9df04c91e2f1d1e0252 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Fri, 24 May 2019 22:14:57 -0300 Subject: [PATCH 06/11] Using coursier for reading poms instead of ad-hoc xml parsing --- scalalib/src/GenIdeaImpl.scala | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 2db28327a6f..a9eefc65060 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -1,6 +1,8 @@ package mill.scalalib import ammonite.runtime.SpecialClassLoader +import coursier.core.compatibility.xmlParseDom +import coursier.maven.Pom import coursier.{LocalRepositories, Repositories} import mill.api.Ctx.{Home, Log} import mill.api.Strict.Agg @@ -207,19 +209,15 @@ object GenIdeaImpl { // Hack so that Intellij does not complain about unresolved magic // imports in build.sc when in fact they are resolved - def sbtLibraryNameFromPom(pom : os.Path) : String = { - val xml = scala.xml.XML.loadFile(pom.toIO) - - val parent = xml \ "parent" - val artifactId = (xml \ "artifactId").text - val groupId = Some(xml \ "groupId").filter(_.nonEmpty).getOrElse(parent \ "groupId").text - val version = Some(xml \ "version").filter(_.nonEmpty).getOrElse(parent \ "version").text + def sbtLibraryNameFromPom(pomPath : os.Path) : String = { + val pom = xmlParseDom(os.read(pomPath)).flatMap(Pom.project).right.get + val artifactId = pom.module.name.value val artifactWithScalaVersion = artifactId.substring(artifactId.length - 5) match { case "_2.10" | "_2.11" | "_2.12" => artifactId case _ => artifactId + "_2.12" } - s"SBT: $groupId:$artifactWithScalaVersion:$version:jar" + s"SBT: ${pom.module.organization.value}:$artifactWithScalaVersion:${pom.version}:jar" } def libraryNames(resolvedJar: ResolvedLibrary) : Seq[String] = resolvedJar match { From 05d1d400be88e0a4c3676dd4418cc9d93fe9c5d6 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Sun, 26 May 2019 10:09:55 -0300 Subject: [PATCH 07/11] It seems that simply using the provided evaluator fixes https://github.com/lihaoyi/mill/issues/352 --- scalalib/src/GenIdeaImpl.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index a9eefc65060..75b8851334b 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -19,6 +19,7 @@ object GenIdea extends ExternalModule { def idea(ev: Evaluator) = T.command{ mill.scalalib.GenIdeaImpl( + ev, implicitly, ev.rootModule, ev.rootModule.millDiscover @@ -31,7 +32,8 @@ object GenIdea extends ExternalModule { object GenIdeaImpl { - def apply(ctx: Log with Home, + def apply(evaluator: Evaluator, + ctx: Log with Home, rootModule: BaseModule, discover: Discover[_]): Unit = { val pp = new scala.xml.PrettyPrinter(999, 4) @@ -42,9 +44,6 @@ object GenIdeaImpl { os.remove.all(os.pwd/".idea"/"scala_compiler.xml") os.remove.all(os.pwd/".idea_modules") - - val evaluator = new Evaluator(ctx.home, os.pwd / 'out, os.pwd / 'out, rootModule, ctx.log) - for((relPath, xml) <- xmlFileLayout(evaluator, rootModule, jdkInfo, Some(ctx))){ os.write.over(os.pwd/relPath, pp.format(xml), createFolders = true) } From 85dd96a12d4a8b995f02ea1a9f00772420c700d5 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Thu, 6 Jun 2019 18:14:01 -0300 Subject: [PATCH 08/11] Added back the usage of module-defined repos for resolving mill libraries --- scalalib/src/GenIdeaImpl.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 75b8851334b..97decd3f698 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -3,7 +3,7 @@ package mill.scalalib import ammonite.runtime.SpecialClassLoader import coursier.core.compatibility.xmlParseDom import coursier.maven.Pom -import coursier.{LocalRepositories, Repositories} +import coursier.{LocalRepositories, Repositories, Repository} import mill.api.Ctx.{Home, Log} import mill.api.Strict.Agg import mill.api.{Loose, Result, Strict} @@ -78,7 +78,7 @@ object GenIdeaImpl { else sys.props.get("MILL_BUILD_LIBRARIES") match { case Some(found) => found.split(',').map(os.Path(_)).distinct.toList case None => - val repos = Seq(LocalRepositories.ivy2Local, Repositories.central) + val repos = modules.foldLeft(Set.empty[Repository]) { _ ++ _._2.repositories } ++ Set(LocalRepositories.ivy2Local, Repositories.central) val artifactNames = Seq("main-moduledefs", "main-api", "main-core", "scalalib", "scalajslib") val Result.Success(res) = scalalib.Lib.resolveDependencies( repos.toList, From 37b4e936e529bc1c54290f38a1912e7e79b703a4 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Tue, 11 Jun 2019 14:54:37 -0300 Subject: [PATCH 09/11] Changed GenIdeaTests to use ScriptTestSuite --- .../resources/gen-idea-hello-world/build.sc | 11 ++++ .../libraries/scala-library-2.12.4.jar.xml | 0 .../idea/misc.xml | 0 .../idea/modules.xml | 4 +- .../idea_modules/helloworld.iml} | 12 ++-- .../idea_modules/helloworld.test.iml} | 14 ++--- .../idea_modules/mill-build.iml | 0 scalalib/test/src/GenIdeaTests.scala | 60 +++++++------------ 8 files changed, 47 insertions(+), 54 deletions(-) create mode 100644 scalalib/test/resources/gen-idea-hello-world/build.sc rename scalalib/test/resources/{gen-idea => gen-idea-hello-world}/idea/libraries/scala-library-2.12.4.jar.xml (100%) rename scalalib/test/resources/{gen-idea => gen-idea-hello-world}/idea/misc.xml (100%) rename scalalib/test/resources/{gen-idea => gen-idea-hello-world}/idea/modules.xml (71%) rename scalalib/test/resources/{gen-idea/idea_modules/iml => gen-idea-hello-world/idea_modules/helloworld.iml} (62%) rename scalalib/test/resources/{gen-idea/idea_modules/test.iml => gen-idea-hello-world/idea_modules/helloworld.test.iml} (61%) rename scalalib/test/resources/{gen-idea => gen-idea-hello-world}/idea_modules/mill-build.iml (100%) diff --git a/scalalib/test/resources/gen-idea-hello-world/build.sc b/scalalib/test/resources/gen-idea-hello-world/build.sc new file mode 100644 index 00000000000..53cd26a947d --- /dev/null +++ b/scalalib/test/resources/gen-idea-hello-world/build.sc @@ -0,0 +1,11 @@ +import mill.scalalib +import $ivy.`com.lihaoyi::mill-contrib-buildinfo:0.4.0` + +trait HelloWorldModule extends scalalib.ScalaModule { + def scalaVersion = "2.12.4" + object test extends super.Tests { + def testFrameworks = Seq("utest.runner.Framework") + } +} + +object HelloWorld extends HelloWorldModule diff --git a/scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml b/scalalib/test/resources/gen-idea-hello-world/idea/libraries/scala-library-2.12.4.jar.xml similarity index 100% rename from scalalib/test/resources/gen-idea/idea/libraries/scala-library-2.12.4.jar.xml rename to scalalib/test/resources/gen-idea-hello-world/idea/libraries/scala-library-2.12.4.jar.xml diff --git a/scalalib/test/resources/gen-idea/idea/misc.xml b/scalalib/test/resources/gen-idea-hello-world/idea/misc.xml similarity index 100% rename from scalalib/test/resources/gen-idea/idea/misc.xml rename to scalalib/test/resources/gen-idea-hello-world/idea/misc.xml diff --git a/scalalib/test/resources/gen-idea/idea/modules.xml b/scalalib/test/resources/gen-idea-hello-world/idea/modules.xml similarity index 71% rename from scalalib/test/resources/gen-idea/idea/modules.xml rename to scalalib/test/resources/gen-idea-hello-world/idea/modules.xml index d6334ea357d..193fa62d229 100644 --- a/scalalib/test/resources/gen-idea/idea/modules.xml +++ b/scalalib/test/resources/gen-idea-hello-world/idea/modules.xml @@ -2,8 +2,8 @@ - - + + diff --git a/scalalib/test/resources/gen-idea/idea_modules/iml b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml similarity index 62% rename from scalalib/test/resources/gen-idea/idea_modules/iml rename to scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml index 13e8daf76f0..38ea17be8c6 100644 --- a/scalalib/test/resources/gen-idea/idea_modules/iml +++ b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml @@ -1,12 +1,12 @@ - + - - - - - + + + + + diff --git a/scalalib/test/resources/gen-idea/idea_modules/test.iml b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml similarity index 61% rename from scalalib/test/resources/gen-idea/idea_modules/test.iml rename to scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml index aecae2e378b..bfe0ff3cbe5 100644 --- a/scalalib/test/resources/gen-idea/idea_modules/test.iml +++ b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml @@ -1,18 +1,18 @@ - + - - - - - + + + + + - + diff --git a/scalalib/test/resources/gen-idea/idea_modules/mill-build.iml b/scalalib/test/resources/gen-idea-hello-world/idea_modules/mill-build.iml similarity index 100% rename from scalalib/test/resources/gen-idea/idea_modules/mill-build.iml rename to scalalib/test/resources/gen-idea-hello-world/idea_modules/mill-build.iml diff --git a/scalalib/test/src/GenIdeaTests.scala b/scalalib/test/src/GenIdeaTests.scala index 60c9f9a8500..efd6381cb7e 100644 --- a/scalalib/test/src/GenIdeaTests.scala +++ b/scalalib/test/src/GenIdeaTests.scala @@ -1,50 +1,29 @@ package mill.scalalib -import mill._ -import mill.util.{TestEvaluator, TestUtil} +import mill.util.ScriptTestSuite +import os.Path import utest._ -object GenIdeaTests extends TestSuite { - - val millSourcePath = os.pwd / 'target / 'workspace / "gen-idea" - - trait HelloWorldModule extends scalalib.ScalaModule { - def scalaVersion = "2.12.4" - def millSourcePath = GenIdeaTests.millSourcePath - object test extends super.Tests { - def testFrameworks = Seq("utest.runner.Framework") - } - } - - object HelloWorld extends TestUtil.BaseModule with HelloWorldModule - - val helloWorldEvaluator = TestEvaluator.static(HelloWorld) +object GenIdeaTests extends ScriptTestSuite(false) { def tests: Tests = Tests { 'genIdeaTests - { - val pp = new scala.xml.PrettyPrinter(999, 4) - - val layout = GenIdeaImpl.xmlFileLayout( - helloWorldEvaluator.evaluator, - HelloWorld, - ("JDK_1_8", "1.8 (1)"), None, fetchMillModules = false) - for((relPath, xml) <- layout){ - os.write.over(millSourcePath/ "generated"/ relPath, pp.format(xml), createFolders = true) - } + initWorkspace() + eval("mill.scalalib.GenIdea/idea") Seq( - "gen-idea/idea_modules/iml" -> - millSourcePath / "generated" / ".idea_modules" /".iml", - "gen-idea/idea_modules/test.iml" -> - millSourcePath / "generated" / ".idea_modules" /"test.iml", - "gen-idea/idea_modules/mill-build.iml" -> - millSourcePath / "generated" / ".idea_modules" /"mill-build.iml", - "gen-idea/idea/libraries/scala-library-2.12.4.jar.xml" -> - millSourcePath / "generated" / ".idea" / "libraries" / "scala-library-2.12.4.jar.xml", - "gen-idea/idea/modules.xml" -> - millSourcePath / "generated" / ".idea" / "modules.xml", - "gen-idea/idea/misc.xml" -> - millSourcePath / "generated" / ".idea" / "misc.xml" + s"$workspaceSlug/idea_modules/helloworld.iml" -> + os.pwd / ".idea_modules" /"helloworld.iml", + s"$workspaceSlug/idea_modules/helloworld.test.iml" -> + os.pwd / ".idea_modules" /"helloworld.test.iml", +// s"$workspaceSlug/idea_modules/mill-build.iml" -> +// os.pwd / ".idea_modules" /"mill-build.iml", + s"$workspaceSlug/idea/libraries/scala-library-2.12.4.jar.xml" -> + os.pwd / ".idea" / "libraries" / "scala-library-2.12.4.jar.xml", + s"$workspaceSlug/idea/modules.xml" -> + os.pwd / ".idea" / "modules.xml", + s"$workspaceSlug/idea/misc.xml" -> + os.pwd / ".idea" / "misc.xml" ).foreach { case (resource, generated) => val resourceString = scala.io.Source.fromResource(resource).getLines().mkString("\n") val generatedString = normaliseLibraryPaths(os.read(generated)) @@ -54,8 +33,11 @@ object GenIdeaTests extends TestSuite { } } - private def normaliseLibraryPaths(in: String): String = { in.replaceAll(coursier.paths.CoursierPaths.cacheDirectory().toString, "COURSIER_HOME") } + + override def workspaceSlug: String = "gen-idea-hello-world" + + override def scriptSourcePath: Path = os.pwd / 'scalalib / 'test / 'resources / workspaceSlug } From 0c46108b91175dd7579645ddc0caf6a9a637895e Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Tue, 18 Jun 2019 15:25:16 -0300 Subject: [PATCH 10/11] Using mill source path instead of pwd --- scalalib/src/GenIdeaImpl.scala | 28 ++++++++++--------- .../resources/gen-idea-hello-world/build.sc | 1 - .../idea_modules/helloworld.iml | 12 ++++---- .../idea_modules/helloworld.test.iml | 12 ++++---- scalalib/test/src/GenIdeaTests.scala | 10 +++---- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index 97decd3f698..f27fb1dac0a 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -23,29 +23,31 @@ object GenIdea extends ExternalModule { implicitly, ev.rootModule, ev.rootModule.millDiscover - ) + ).run() } implicit def millScoptEvaluatorReads[T] = new mill.main.EvaluatorScopt[T]() lazy val millDiscover = Discover[this.type] } -object GenIdeaImpl { +case class GenIdeaImpl(evaluator: Evaluator, + ctx: Log with Home, + rootModule: BaseModule, + discover: Discover[_]) { + val cwd: Path = rootModule.millSourcePath - def apply(evaluator: Evaluator, - ctx: Log with Home, - rootModule: BaseModule, - discover: Discover[_]): Unit = { - val pp = new scala.xml.PrettyPrinter(999, 4) + def run(): Unit = { - val jdkInfo = extractCurrentJdk(os.pwd / ".idea" / "misc.xml").getOrElse(("JDK_1_8", "1.8 (1)")) - os.remove.all(os.pwd/".idea"/"libraries") - os.remove.all(os.pwd/".idea"/"scala_compiler.xml") - os.remove.all(os.pwd/".idea_modules") + val pp = new scala.xml.PrettyPrinter(999, 4) + val jdkInfo = extractCurrentJdk(cwd / ".idea" / "misc.xml").getOrElse(("JDK_1_8", "1.8 (1)")) + + os.remove.all(cwd/".idea"/"libraries") + os.remove.all(cwd/".idea"/"scala_compiler.xml") + os.remove.all(cwd/".idea_modules") for((relPath, xml) <- xmlFileLayout(evaluator, rootModule, jdkInfo, Some(ctx))){ - os.write.over(os.pwd/relPath, pp.format(xml), createFolders = true) + os.write.over(cwd/relPath, pp.format(xml), createFolders = true) } } @@ -326,7 +328,7 @@ object GenIdeaImpl { } def relify(p: os.Path) = { - val r = p.relativeTo(os.pwd/".idea_modules") + val r = p.relativeTo(cwd/".idea_modules") (Seq.fill(r.ups)("..") ++ r.segments).mkString("/") } diff --git a/scalalib/test/resources/gen-idea-hello-world/build.sc b/scalalib/test/resources/gen-idea-hello-world/build.sc index 53cd26a947d..45ec2536782 100644 --- a/scalalib/test/resources/gen-idea-hello-world/build.sc +++ b/scalalib/test/resources/gen-idea-hello-world/build.sc @@ -1,5 +1,4 @@ import mill.scalalib -import $ivy.`com.lihaoyi::mill-contrib-buildinfo:0.4.0` trait HelloWorldModule extends scalalib.ScalaModule { def scalaVersion = "2.12.4" diff --git a/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml index 38ea17be8c6..6808e515a68 100644 --- a/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml +++ b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.iml @@ -1,12 +1,12 @@ - + - - - - - + + + + + diff --git a/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml index bfe0ff3cbe5..26fac21d0af 100644 --- a/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml +++ b/scalalib/test/resources/gen-idea-hello-world/idea_modules/helloworld.test.iml @@ -1,12 +1,12 @@ - + - - - - - + + + + + diff --git a/scalalib/test/src/GenIdeaTests.scala b/scalalib/test/src/GenIdeaTests.scala index efd6381cb7e..b7d3a2577b2 100644 --- a/scalalib/test/src/GenIdeaTests.scala +++ b/scalalib/test/src/GenIdeaTests.scala @@ -13,17 +13,17 @@ object GenIdeaTests extends ScriptTestSuite(false) { Seq( s"$workspaceSlug/idea_modules/helloworld.iml" -> - os.pwd / ".idea_modules" /"helloworld.iml", + workspacePath / ".idea_modules" /"helloworld.iml", s"$workspaceSlug/idea_modules/helloworld.test.iml" -> - os.pwd / ".idea_modules" /"helloworld.test.iml", + workspacePath / ".idea_modules" /"helloworld.test.iml", // s"$workspaceSlug/idea_modules/mill-build.iml" -> // os.pwd / ".idea_modules" /"mill-build.iml", s"$workspaceSlug/idea/libraries/scala-library-2.12.4.jar.xml" -> - os.pwd / ".idea" / "libraries" / "scala-library-2.12.4.jar.xml", + workspacePath / ".idea" / "libraries" / "scala-library-2.12.4.jar.xml", s"$workspaceSlug/idea/modules.xml" -> - os.pwd / ".idea" / "modules.xml", + workspacePath / ".idea" / "modules.xml", s"$workspaceSlug/idea/misc.xml" -> - os.pwd / ".idea" / "misc.xml" + workspacePath / ".idea" / "misc.xml" ).foreach { case (resource, generated) => val resourceString = scala.io.Source.fromResource(resource).getLines().mkString("\n") val generatedString = normaliseLibraryPaths(os.read(generated)) From 6b80cfa4a13fa0c4af3ca0d08ba2ad80e6c94b59 Mon Sep 17 00:00:00 2001 From: Andres Pipicello Date: Wed, 26 Jun 2019 17:07:44 -0300 Subject: [PATCH 11/11] Update logic to check for Scala libraries when generating fake SBT libraries --- scalalib/src/GenIdeaImpl.scala | 5 +++-- scalalib/test/src/GenIdeaTests.scala | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala index f27fb1dac0a..04cd5158b23 100755 --- a/scalalib/src/GenIdeaImpl.scala +++ b/scalalib/src/GenIdeaImpl.scala @@ -84,7 +84,7 @@ case class GenIdeaImpl(evaluator: Evaluator, val artifactNames = Seq("main-moduledefs", "main-api", "main-core", "scalalib", "scalajslib") val Result.Success(res) = scalalib.Lib.resolveDependencies( repos.toList, - Lib.depToDependency(_, "2.12.4", ""), + Lib.depToDependency(_, "2.12.8", ""), for(name <- artifactNames) yield ivy"com.lihaoyi::mill-$name:${sys.props("MILL_VERSION")}", false, @@ -214,8 +214,9 @@ case class GenIdeaImpl(evaluator: Evaluator, val pom = xmlParseDom(os.read(pomPath)).flatMap(Pom.project).right.get val artifactId = pom.module.name.value + val scalaArtifactRegex = ".*_[23]\\.[0-9]{1,2}".r val artifactWithScalaVersion = artifactId.substring(artifactId.length - 5) match { - case "_2.10" | "_2.11" | "_2.12" => artifactId + case scalaArtifactRegex(_*) => artifactId case _ => artifactId + "_2.12" } s"SBT: ${pom.module.organization.value}:$artifactWithScalaVersion:${pom.version}:jar" diff --git a/scalalib/test/src/GenIdeaTests.scala b/scalalib/test/src/GenIdeaTests.scala index b7d3a2577b2..b1b71cb1d84 100644 --- a/scalalib/test/src/GenIdeaTests.scala +++ b/scalalib/test/src/GenIdeaTests.scala @@ -16,8 +16,6 @@ object GenIdeaTests extends ScriptTestSuite(false) { workspacePath / ".idea_modules" /"helloworld.iml", s"$workspaceSlug/idea_modules/helloworld.test.iml" -> workspacePath / ".idea_modules" /"helloworld.test.iml", -// s"$workspaceSlug/idea_modules/mill-build.iml" -> -// os.pwd / ".idea_modules" /"mill-build.iml", s"$workspaceSlug/idea/libraries/scala-library-2.12.4.jar.xml" -> workspacePath / ".idea" / "libraries" / "scala-library-2.12.4.jar.xml", s"$workspaceSlug/idea/modules.xml" ->