-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Restrict library and reflect to compact1 profile #6164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
6047d9b to
e8d03d9
Compare
The `@remote` annotation will be removed in 2.13. It was deprecated in 2.12, and will be gone entirely in 2.13.0-M4, but first we must release a milestone that no longer refers to it (so that the compiler can bootstrap without a definition for `@remote`). This cuts tie 1 of 3 to the Java profiles beyond compact1.
The `BeanInfo` generation was deprecated in 2.12 and will be removed in 2.13.
First, we cut ties from the compiler in M3, so that we can remove the
classes `scala.beans.{BeanInfo, ScalaBeanInfo}` entirely in M4, along with
`scala.beans.{BeanInfoSkip, BeanDescription, BeanDisplayName}`, which
were part of the deprecated feature. (Note: for good measure, we should
deprecate all of them in 2.12.5, instead of just the entry point).
This cuts tie 2 of 3 to the Java profiles beyond compact1.
scala-{library,reflect} now depend only on the compact1 profile.
e8d03d9 to
07ff7ac
Compare
lrytz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @nilskp for the removal of BeanInfo, since you recently voiced your interest in that feature (https://users.scala-lang.org/t/beaninfo-alternative/1301). I guess the same functionality could be implemented with a compiler plugin.
@adriaanm how did you identify implementations that use classes outside the compact1 profile? How can we prevent new references from sneaking in?
| def javaVmArguments: List[String] = { | ||
| import scala.collection.JavaConverters._ | ||
|
|
||
| java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method is not deprecated in 2.12, we could do a reflective implementation
scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._
scala> val mxb = Class.forName("java.lang.management.ManagementFactory").getMethod("getRuntimeMXBean").invoke(null)
mxb: Object = sun.management.RuntimeImpl@4447c594
scala> Class.forName("java.lang.management.RuntimeMXBean").getMethod("getInputArguments").invoke(mxb).asInstanceOf[java.util.List[String]].asScala.toList
res19: List[String] = List(-Xmx1536m, -Xms1536m, -Xss5m, -XX:+UseCompressedOops, -XX:+UseParallelGC, -Xbootclasspath/a:/Users/luc/scala/scala-2.12.3/lib/jline-2.14.4.jar:/Users/luc/scala/scala-2.12.3/lib/scala-compiler.jar:/Users/luc/scala/scala-2.12.3/lib/scala-library.jar:/Users/luc/scala/scala-2.12.3/lib/scala-parser-combinators_2.12-1.0.6.jar:/Users/luc/scala/scala-2.12.3/lib/scala-reflect.jar:/Users/luc/scala/scala-2.12.3/lib/scala-swing_2.12-2.0.0.jar:/Users/luc/scala/scala-2.12.3/lib/scala-xml_2.12-1.0.6.jar:/Users/luc/scala/scala-2.12.3/lib/scalap-2.12.3.jar, -Dscala.boot.class.path=/Users/luc/scala/scala-2.12.3/lib/jline-2.14.4.jar:/Users/luc/scala/scala-2.12.3/lib/scala-compiler.jar:/Users/luc/scala/scala-2.12.3/lib/scala-library.jar:/Users/luc/scala/...
This would fail with java.lang.ClassNotFoundException if the classes are not available, which is probably comparable to what currently happens.
We can deprecate the method at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you're deprecating it for 2.12.5; I guess either way is fine.
|
Ah, |
👍 |
|
I can't figure out how to add a test to our build that checks that So far, I have something like: lazy val jdeps = taskKey[Unit]("Run jdeps to check dependencies")
lazy val restrictDeps = project
.dependsOn(library, reflect)
.settings(commonSettings)
.settings(disableDocs)
.settings(disablePublishing)
.settings(
Keys.test in Test := (Keys.test in Test).dependsOn(jdeps).value,
jdeps := {
import Process._
val profilePart = ".*\\((.*)\\)$".r
val jdepsOut = s"jdeps -s -P ${(packageBin in library in Compile).value.getPath} ${(packageBin in reflect in Compile).value.getPath}".lines_!
val profiles = jdepsOut.flatMap(line => line.split(" -> ", 2) match { case Array(_, profilePart(profile)) => Some(profile) case s => None }).toSet
if (profiles != Set("compact1")) streams.value.log.error("Detected dependency outside of compact1:\n"+jdepsOut.mkString("\n")) // TODO how to report error?
}
)Not sure how to run this as a test and report the error |
|
Task failure is reported by throwing an exception. |
|
I suggest the following: jdeps := {
val profilePart = ".*\\((.*)\\)$".r
val jdepsOut = Process("jdeps", Seq("-s", "-P", (packageBin in library in Compile).value.getPath, (packageBin in reflect in Compile).value.getPath)).lines_!
val profiles = jdepsOut.flatMap(line => line.split(" -> ", 2) match { case Array(_, profilePart(profile)) => Some(profile) case s => None }).toSet
if (profiles != Set("compact1"))
throw new RuntimeException("Detected dependency outside of compact1:\n"+jdepsOut.mkString("\n"))
},Errors are reported as Exceptions. I've also changed the I don't see any reason for the special @dwijnand Does sbt have any code for localizing |
|
By default it uses what it finds on the PATH, with support for a custom |
This mirror similar changes done by Adriaan Moors in scala#6164
This was already partially done in 31f9681. This mirror similar changes done by Adriaan Moors in scala#6164
As verify by running `jdep -s -P` on the dotty-compiler jar. See scala/bug#10559 for why this is useful and scala/scala#6164 for how this was implemented in scalac.
As verify by running `jdep -s -P` on the dotty-compiler jar. See scala/bug#10559 for why this is useful and scala/scala#6164 for how this was implemented in scalac.
As verify by running `jdep -s -P` on the dotty-compiler jar. See scala/bug#10559 for why this is useful and scala/scala#6164 for how this was implemented in scalac.
As verify by running `jdep -s -P` on the dotty-compiler jar. See scala/bug#10559 for why this is useful and scala/scala#6164 for how this was implemented in scalac.
|
I won't have time to implement the test for this. Tracking as scala/scala-dev#460 |
See scala/scala#6164 Ref scala/scala-dev#461 (still need to release partest & upgrade)
See scala/scala#6164 Ref scala/scala-dev#461 (still need to release partest & upgrade)
See scala/scala#6164 Ref scala/scala-dev#461 (still need to release partest & upgrade)
See scala#6164 Ref scala/scala-dev#461 (still need to release partest & upgrade)
See scala#6164 Ref scala/scala-dev#461 (still need to release partest & upgrade)
Enforcement of scala#6164 Tested manually by reverting the sys.process.javaVmArguments change 07ff7ac and then running testJDepsImpl: > testJDeps [info] Compiling 1 Scala source to /d/scala/build/quick/classes/library... [info] Packaging /d/scala/build/pack/lib/scala-library.jar ... [info] Packaging /d/scala/build/pack/lib/scala-reflect.jar ... [info] Done packaging. [info] Done packaging. [trace] Stack trace suppressed: run last root/*:testJDeps for the full output. [error] (root/*:testJDeps) Detected dependency outside of compact1: [error] scala-library.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact3) [error] scala-reflect.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact1) [error] scala-reflect.jar -> /d/scala/build/pack/lib/scala-library.jar [error] Total time: 4 s, completed 14-Jun-2018 14:20:02 Fixes scala/scala-dev#437 Fixes scala/bug#10559
Enforcement of scala#6164 Tested manually by reverting the sys.process.javaVmArguments change 07ff7ac and then running testJDepsImpl: > testJDeps [info] Compiling 1 Scala source to /d/scala/build/quick/classes/library... [info] Packaging /d/scala/build/pack/lib/scala-library.jar ... [info] Packaging /d/scala/build/pack/lib/scala-reflect.jar ... [info] Done packaging. [info] Done packaging. [trace] Stack trace suppressed: run last root/*:testJDeps for the full output. [error] (root/*:testJDeps) Detected dependency outside of compact1: [error] scala-library.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact3) [error] scala-reflect.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact1) [error] scala-reflect.jar -> /d/scala/build/pack/lib/scala-library.jar [error] Total time: 4 s, completed 14-Jun-2018 14:20:02 Fixes scala/scala-dev#437 Fixes scala/bug#10559
The scala library (core and reflect) now depends only on the compact1 profile.
See scala/bug#10559