Skip to content

Commit 3d64fd5

Browse files
authored
Merge pull request #6595 from dotty-staging/remove-xml
Fix #5597: Remove scala-xml dependency, add it to the community-build
2 parents 2c26c17 + 1cf4190 commit 3d64fd5

File tree

17 files changed

+127
-79
lines changed

17 files changed

+127
-79
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@
3737
[submodule "community-build/community-projects/sourcecode"]
3838
path = community-build/community-projects/sourcecode
3939
url = https://github.com/dotty-staging/sourcecode
40+
[submodule "community-build/community-projects/scala-xml"]
41+
path = community-build/community-projects/scala-xml
42+
url = https://github.com/scala/scala-xml
Submodule scala-xml added at 19f53ad

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class CommunityBuildTest {
109109
updateCommand = "scalatest/update"
110110
)
111111

112+
@Test def scalaXml = test(
113+
project = "scala-xml",
114+
testCommand = "xml/test",
115+
updateCommand = "xml/update"
116+
)
117+
112118
@Test def scopt = test(
113119
project = "scopt",
114120
testCommand = "scoptJVM/compile",

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ class Definitions {
223223
lazy val Sys_errorR: TermRef = SysPackage.moduleClass.requiredMethodRef(nme.error)
224224
def Sys_error(implicit ctx: Context): Symbol = Sys_errorR.symbol
225225

226+
lazy val ScalaXmlPackageClass: Symbol = ctx.getPackageClassIfDefined("scala.xml")
227+
226228
lazy val CompiletimePackageObjectRef: TermRef = ctx.requiredModuleRef("scala.compiletime.package")
227229
lazy val CompiletimePackageObject: Symbol = CompiletimePackageObjectRef.symbol.moduleClass
228230
lazy val Compiletime_errorR: TermRef = CompiletimePackageObjectRef.symbol.requiredMethodRef(nme.error)

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ trait Symbols { this: Context =>
383383
.requiredSymbol("class", name, generateStubs = false)(_.isClass)
384384
}
385385

386+
/** Get ClassSymbol if package is either defined in current compilation run
387+
* or present on classpath.
388+
* Returns NoSymbol otherwise. */
389+
def getPackageClassIfDefined(path: PreName): Symbol = {
390+
val name = path.toTypeName
391+
base.staticRef(name, isPackage = true, generateStubs = false)
392+
.requiredSymbol("package", name, generateStubs = false)(_ is PackageClass)
393+
}
394+
386395
def requiredModule(path: PreName): TermSymbol = {
387396
val name = path.toTermName
388397
base.staticRef(name).requiredSymbol("object", name)(_ is Module).asTerm

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package parsing
55
import scala.annotation.internal.sharable
66
import scala.collection.mutable.ListBuffer
77
import scala.collection.immutable.BitSet
8-
import util.{ SourceFile, SourcePosition }
8+
import util.{ SourceFile, SourcePosition, NoSourcePosition }
99
import Tokens._
1010
import Scanners._
1111
import xml.MarkupParsers.MarkupParser
@@ -473,8 +473,21 @@ object Parsers {
473473

474474
/* -------------- XML ---------------------------------------------------- */
475475

476-
/** the markup parser */
477-
lazy val xmlp: xml.MarkupParsers.MarkupParser = new MarkupParser(this, true)
476+
/** The markup parser.
477+
* The first time this lazy val is accessed, we assume we were trying to parse an XML literal.
478+
* The current position is recorded for later error reporting if it turns out
479+
* that we don't have scala-xml on the compilation classpath.
480+
*/
481+
lazy val xmlp: xml.MarkupParsers.MarkupParser = {
482+
myFirstXmlPos = source.atSpan(Span(in.offset))
483+
new MarkupParser(this, true)
484+
}
485+
486+
/** The position of the first XML literal encountered while parsing,
487+
* NoSourcePosition if there were no XML literals.
488+
*/
489+
def firstXmlPos: SourcePosition = myFirstXmlPos
490+
private[this] var myFirstXmlPos: SourcePosition = NoSourcePosition
478491

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

compiler/src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import parsing.Parsers.Parser
1111
import config.Config
1212
import config.Printers.{typr, default}
1313
import util.Stats._
14+
import util.{ SourcePosition, NoSourcePosition }
1415
import scala.util.control.NonFatal
1516
import ast.Trees._
1617

@@ -25,6 +26,11 @@ class FrontEnd extends Phase {
2526
/** The contexts for compilation units that are parsed but not yet entered */
2627
private[this] var remaining: List[Context] = Nil
2728

29+
/** The position of the first XML literal encountered while parsing,
30+
* NoSourcePosition if there were no XML literals.
31+
*/
32+
private[this] var firstXmlPos: SourcePosition = NoSourcePosition
33+
2834
/** Does a source file ending with `<name>.scala` belong to a compilation unit
2935
* that is parsed but not yet entered?
3036
*/
@@ -41,9 +47,17 @@ class FrontEnd extends Phase {
4147

4248
def parse(implicit ctx: Context): Unit = monitor("parsing") {
4349
val unit = ctx.compilationUnit
50+
4451
unit.untpdTree =
4552
if (unit.isJava) new JavaParser(unit.source).parse()
46-
else new Parser(unit.source).parse()
53+
else {
54+
val p = new Parser(unit.source)
55+
val tree = p.parse()
56+
if (p.firstXmlPos.exists && !firstXmlPos.exists)
57+
firstXmlPos = p.firstXmlPos
58+
tree
59+
}
60+
4761
val printer = if (ctx.settings.Xprint.value.contains("parser")) default else typr
4862
printer.println("parsed:\n" + unit.untpdTree.show)
4963
if (Config.checkPositions)
@@ -86,6 +100,12 @@ class FrontEnd extends Phase {
86100
enterSyms(remaining.head)
87101
remaining = remaining.tail
88102
}
103+
104+
if (firstXmlPos.exists && !defn.ScalaXmlPackageClass.exists)
105+
ctx.error("""To support XML literals, your project must depend on scala-xml.
106+
|See https://github.com/scala/scala-xml for more information.""".stripMargin,
107+
firstXmlPos)
108+
89109
unitContexts.foreach(typeCheck(_))
90110
record("total trees after typer", ast.Trees.ntrees)
91111
unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)

compiler/test/dotty/Properties.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ object Properties {
5959
/** scala-asm jar */
6060
def scalaAsm: String = sys.props("dotty.tests.classes.scalaAsm")
6161

62-
/** scala-xml jar */
63-
def scalaXml: String = sys.props("dotty.tests.classes.scalaXml")
64-
6562
/** jline-terminal jar */
6663
def jlineTerminal: String = sys.props("dotty.tests.classes.jlineTerminal")
6764

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object TestConfiguration {
1212
)
1313

1414
val checkOptions = Array(
15-
// "-Yscala2-unpickler", s"${Properties.scalaLibrary}:${Properties.scalaXml}",
15+
// "-Yscala2-unpickler", s"${Properties.scalaLibrary}",
1616
"-Yno-deep-subtypes",
1717
"-Yno-double-bindings",
1818
"-Yforce-sbt-phases",
@@ -21,13 +21,11 @@ object TestConfiguration {
2121

2222
val basicClasspath = mkClasspath(List(
2323
Properties.scalaLibrary,
24-
Properties.scalaXml,
2524
Properties.dottyLibrary
2625
))
2726

2827
val withCompilerClasspath = mkClasspath(List(
2928
Properties.scalaLibrary,
30-
Properties.scalaXml,
3129
Properties.scalaAsm,
3230
Properties.jlineTerminal,
3331
Properties.jlineReader,

0 commit comments

Comments
 (0)