Skip to content

Remove compiler dependency on scala-xml #4394

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

Merged
merged 2 commits into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.collection.immutable.BitSet
import util.{ SourceFile, SourcePosition }
import Tokens._
import Scanners._
import MarkupParsers._
import xml.MarkupParsers.MarkupParser
import core._
import Flags._
import Contexts._
Expand Down Expand Up @@ -397,7 +397,7 @@ object Parsers {
/** the markup parser */
lazy val xmlp = new MarkupParser(this, true)

object symbXMLBuilder extends SymbolicXMLBuilder(this, true) // DEBUG choices
object symbXMLBuilder extends xml.SymbolicXMLBuilder(this, true) // DEBUG choices

def xmlLiteral() : Tree = xmlp.xLiteral
def xmlLiteralPattern() : Tree = xmlp.xLiteralPattern
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import scala.annotation.{ switch, tailrec }
import scala.collection.mutable
import scala.collection.immutable.SortedMap
import mutable.ListBuffer
import Utility.isNameStart
import rewrite.Rewrites.patch

object Scanners {
Expand Down Expand Up @@ -424,7 +423,7 @@ object Scanners {
val last = if (charOffset >= 2) buf(charOffset - 2) else ' '
nextChar()
last match {
case ' ' | '\t' | '\n' | '{' | '(' | '>' if isNameStart(ch) || ch == '!' || ch == '?' =>
case ' ' | '\t' | '\n' | '{' | '(' | '>' if xml.Utility.isNameStart(ch) || ch == '!' || ch == '?' =>
token = XMLSTART
case _ =>
// Console.println("found '<', but last is '" + in.last +"'"); // DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
\* */
package dotty.tools.dotc
package parsing
package xml

import Utility._
import util.Chars.SU
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dotty.tools
package dotc
package parsing
package xml

import scala.collection.mutable
import mutable.{ Buffer, ArrayBuffer, ListBuffer }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dotty.tools
package dotc
package parsing
package xml

import scala.collection.mutable
import scala.xml.{ EntityRef, Text }
import core._
import Decorators._
import Flags.Mutable
Expand Down Expand Up @@ -146,14 +146,11 @@ class SymbolicXMLBuilder(parser: Parser, preserveWS: Boolean)(implicit ctx: Cont
(buf map convertToTextPat).toList

def parseAttribute(pos: Position, s: String): Tree = {
val ts = scala.xml.Utility.parseAttributeValue(s) map {
case Text(s) => text(pos, s)
case EntityRef(s) => entityRef(pos, s)
}
ts.length match {
case 0 => TypedSplice(tpd.ref(defn.NilModule) withPos pos)
case 1 => ts.head
case _ => makeXMLseq(pos, ts.toList)
val ts = Utility.parseAttributeValue(s, text(pos, _), entityRef(pos, _))
ts match {
case Nil => TypedSplice(tpd.ref(defn.NilModule) withPos pos)
case t :: Nil => t
case _ => makeXMLseq(pos, ts)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dotty.tools.dotc
package parsing
package xml

import scala.collection.mutable

Expand Down
39 changes: 24 additions & 15 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ object Build {
// - publishes its own empty artifact "dotty" that depends on "dotty-library" and "dotty-compiler",
// this is only necessary for compatibility with sbt which currently hardcodes the "dotty" artifact name
lazy val dotty = project.in(file(".")).asDottyRoot(NonBootstrapped)
lazy val `dotty-bootstrapped` = project.asDottyRoot(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dotty-optimised` = project.asDottyRoot(BootstrappedOptimised).disablePlugins(ScriptedPlugin)
lazy val `dotty-bootstrapped` = project.asDottyRoot(Bootstrapped)
lazy val `dotty-optimised` = project.asDottyRoot(BootstrappedOptimised)

lazy val `dotty-interfaces` = project.in(file("interfaces")).
disablePlugins(ScriptedPlugin).
settings(commonScala2Settings). // Java-only project, so this is fine
settings(
// Do not append Scala versions to the generated artifacts
Expand Down Expand Up @@ -420,8 +421,8 @@ object Build {
)

lazy val `dotty-doc` = project.in(file("doc-tool")).asDottyDoc(NonBootstrapped)
lazy val `dotty-doc-bootstrapped` = project.in(file("doc-tool")).asDottyDoc(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dotty-doc-optimised` = project.in(file("doc-tool")).asDottyDoc(BootstrappedOptimised).disablePlugins(ScriptedPlugin)
lazy val `dotty-doc-bootstrapped` = project.in(file("doc-tool")).asDottyDoc(Bootstrapped)
lazy val `dotty-doc-optimised` = project.in(file("doc-tool")).asDottyDoc(BootstrappedOptimised)

def dottyDoc(implicit mode: Mode): Project = mode match {
case NonBootstrapped => `dotty-doc`
Expand Down Expand Up @@ -501,7 +502,8 @@ object Build {
// get libraries onboard
libraryDependencies ++= Seq(
"org.scala-lang.modules" % "scala-asm" % "6.0.0-scala-1", // used by the backend
("org.scala-lang.modules" %% "scala-xml" % "1.0.6").withDottyCompat(scalaVersion.value),
// FIXME: Not needed, but should be on the compiler CP
("org.scala-lang.modules" %% "scala-xml" % "1.1.0").withDottyCompat(scalaVersion.value),
"org.scala-lang" % "scala-library" % scalacVersion % "test",
Dependencies.compilerInterface(sbtVersion.value),
),
Expand Down Expand Up @@ -542,7 +544,7 @@ object Build {
if path.contains("scala-library") ||
// FIXME: currently needed for tests referencing scalac internals
path.contains("scala-reflect") ||
// FIXME: should go away when xml literal parsing is removed
// used for tests that compile xml
path.contains("scala-xml") ||
// used for tests that compile dotty
path.contains("scala-asm") ||
Expand Down Expand Up @@ -706,8 +708,8 @@ object Build {
if (mode == NonBootstrapped) nonBootstrapedDottyCompilerSettings else bootstrapedDottyCompilerSettings

lazy val `dotty-compiler` = project.in(file("compiler")).asDottyCompiler(NonBootstrapped)
lazy val `dotty-compiler-bootstrapped` = project.in(file("compiler")).asDottyCompiler(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dotty-compiler-optimised` = project.in(file("compiler")).asDottyCompiler(BootstrappedOptimised).disablePlugins(ScriptedPlugin)
lazy val `dotty-compiler-bootstrapped` = project.in(file("compiler")).asDottyCompiler(Bootstrapped)
lazy val `dotty-compiler-optimised` = project.in(file("compiler")).asDottyCompiler(BootstrappedOptimised)

def dottyCompiler(implicit mode: Mode): Project = mode match {
case NonBootstrapped => `dotty-compiler`
Expand All @@ -721,8 +723,8 @@ object Build {
)

lazy val `dotty-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped)
lazy val `dotty-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dotty-library-optimised`: Project = project.in(file("library")).asDottyLibrary(BootstrappedOptimised).disablePlugins(ScriptedPlugin)
lazy val `dotty-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped)
lazy val `dotty-library-optimised`: Project = project.in(file("library")).asDottyLibrary(BootstrappedOptimised)

def dottyLibrary(implicit mode: Mode): Project = mode match {
case NonBootstrapped => `dotty-library`
Expand Down Expand Up @@ -763,7 +765,7 @@ object Build {
)

lazy val `dotty-sbt-bridge` = project.in(file("sbt-bridge")).asDottySbtBridge(NonBootstrapped)
lazy val `dotty-sbt-bridge-bootstrapped` = project.in(file("sbt-bridge")).asDottySbtBridge(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dotty-sbt-bridge-bootstrapped` = project.in(file("sbt-bridge")).asDottySbtBridge(Bootstrapped)

lazy val `dotty-language-server` = project.in(file("language-server")).
dependsOn(dottyCompiler(Bootstrapped)).
Expand Down Expand Up @@ -828,8 +830,8 @@ object Build {
).disablePlugins(ScriptedPlugin)

lazy val `dotty-bench` = project.in(file("bench")).asDottyBench(NonBootstrapped)
lazy val `dotty-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dotty-bench-optimised` = project.in(file("bench")).asDottyBench(BootstrappedOptimised).disablePlugins(ScriptedPlugin)
lazy val `dotty-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped)
lazy val `dotty-bench-optimised` = project.in(file("bench")).asDottyBench(BootstrappedOptimised)

// Depend on dotty-library so that sbt projects using dotty automatically
// depend on the dotty-library
Expand Down Expand Up @@ -1132,8 +1134,8 @@ object Build {
)

lazy val dist = project.asDist(NonBootstrapped)
lazy val `dist-bootstrapped` = project.asDist(Bootstrapped).disablePlugins(ScriptedPlugin)
lazy val `dist-optimised` = project.asDist(BootstrappedOptimised).disablePlugins(ScriptedPlugin)
lazy val `dist-bootstrapped` = project.asDist(Bootstrapped)
lazy val `dist-optimised` = project.asDist(BootstrappedOptimised)

// /** A sandbox to play with the Scala.js back-end of dotty.
// *
Expand Down Expand Up @@ -1181,6 +1183,7 @@ object Build {

// FIXME: we do not aggregate `bin` because its tests delete jars, thus breaking other tests
def asDottyRoot(implicit mode: Mode): Project = project.withCommonSettings.
disablePlugins(ScriptedPlugin).
aggregate(`dotty-interfaces`, dottyLibrary, dottyCompiler, dottyDoc, dottySbtBridgeReference).
bootstrappedAggregate(`scala-library`, `scala-compiler`, `scala-reflect`, scalap, `dotty-language-server`).
dependsOn(dottyCompiler).
Expand All @@ -1190,31 +1193,37 @@ object Build {
)

def asDottyCompiler(implicit mode: Mode): Project = project.withCommonSettings.
disablePlugins(ScriptedPlugin).
dependsOn(`dotty-interfaces`).
dependsOn(dottyLibrary).
settings(dottyCompilerSettings)

def asDottyLibrary(implicit mode: Mode): Project = project.withCommonSettings.
disablePlugins(ScriptedPlugin).
settings(dottyLibrarySettings).
bootstrappedSettings(
// Needed so that the library sources are visible when `dotty.tools.dotc.core.Definitions#init` is called.
scalacOptions in Compile ++= Seq("-sourcepath", (scalaSource in Compile).value.getAbsolutePath)
)

def asDottyDoc(implicit mode: Mode): Project = project.withCommonSettings.
disablePlugins(ScriptedPlugin).
dependsOn(dottyCompiler, dottyCompiler % "test->test").
settings(dottyDocSettings)

def asDottySbtBridge(implicit mode: Mode): Project = project.withCommonSettings.
disablePlugins(ScriptedPlugin).
dependsOn(dottyCompiler % Provided).
settings(dottySbtBridgeSettings)

def asDottyBench(implicit mode: Mode): Project = project.withCommonSettings.
disablePlugins(ScriptedPlugin).
dependsOn(dottyCompiler).
settings(commonBenchmarkSettings).
enablePlugins(JmhPlugin)

def asDist(implicit mode: Mode): Project = project.
disablePlugins(ScriptedPlugin).
enablePlugins(PackPlugin).
withCommonSettings.
dependsOn(`dotty-interfaces`, dottyCompiler, dottyLibrary, dottyDoc).
Expand Down