From 8bd438bf84c1b221bcc122b3abe5d4ec37495071 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 9 Apr 2018 18:49:14 -0700 Subject: share com.sun.jna.platform.win32.Kernel32 class between all classloaders, because initializing it more than once within a single process causes crashes --- build.sc | 13 +++++++++---- core/src/mill/util/ClassLoader.scala | 10 ++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build.sc b/build.sc index b48a41a8..5cc31efc 100755 --- a/build.sc +++ b/build.sc @@ -66,7 +66,10 @@ trait MillModule extends MillPublishModule with ScalaModule{ outer => object client extends MillPublishModule{ def ivyDeps = Agg( - ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0" + ivy"org.scala-sbt.ipcsocket:ipcsocket:1.0.0".exclude( + "net.java.dev.jna" -> "jna", + "net.java.dev.jna" -> "jna-platform" + ) ) } @@ -86,8 +89,10 @@ object core extends MillModule { ) def ivyDeps = Agg( - ivy"com.lihaoyi::sourcecode:0.1.4", ivy"com.lihaoyi:::ammonite:1.1.0-14-037b8eb", + // Necessary so we can share the JNA classes throughout the build process + ivy"net.java.dev.jna:jna:4.5.0", + ivy"net.java.dev.jna:jna-platform:4.5.0" ) def generatedSources = T { @@ -149,7 +154,7 @@ object scalalib extends MillModule { genTask(scalajslib)() scalaworker.testArgs() ++ - Seq("-DMILL_BUILD_LIBRARIES=" + genIdeaArgs.map(_.path).mkString(",")) + Seq("-Djna.nosys=true") ++ Seq("-DMILL_BUILD_LIBRARIES=" + genIdeaArgs.map(_.path).mkString(",")) } } @@ -163,7 +168,7 @@ object scalajslib extends MillModule { "MILL_SCALAJS_BRIDGE_0_6" -> jsbridges("0.6").compile().classes.path, "MILL_SCALAJS_BRIDGE_1_0" -> jsbridges("1.0").compile().classes.path ) - scalaworker.testArgs() ++ (for((k, v) <- mapping.toSeq) yield s"-D$k=$v") + Seq("-Djna.nosys=true") ++ scalaworker.testArgs() ++ (for((k, v) <- mapping.toSeq) yield s"-D$k=$v") } object jsbridges extends Cross[JsBridgeModule]("0.6", "1.0") diff --git a/core/src/mill/util/ClassLoader.scala b/core/src/mill/util/ClassLoader.scala index 9678989e..c0421a7b 100644 --- a/core/src/mill/util/ClassLoader.scala +++ b/core/src/mill/util/ClassLoader.scala @@ -12,7 +12,12 @@ object ClassLoader { new URLClassLoader( makeUrls(urls).toArray, refinePlatformParent(parent) - ) + ) { + override def findClass(name: String): Class[_] = { + if (name.startsWith("com.sun.jna")) getClass.getClassLoader.loadClass(name) + else super.findClass(name) + } + } } def create(urls: Seq[URL], @@ -24,7 +29,8 @@ object ClassLoader { refinePlatformParent(parent) ) { override def findClass(name: String): Class[_] = { - customFindClass(name).getOrElse(super.findClass(name)) + if (name.startsWith("com.sun.jna")) getClass.getClassLoader.loadClass(name) + else customFindClass(name).getOrElse(super.findClass(name)) } } } -- cgit v1.2.3