summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-10-02 16:39:13 +0200
committerEugene Burmako <xeno.by@gmail.com>2013-10-02 22:46:00 +0200
commit5db26e5136c635af062801218fc7edec280e63ff (patch)
tree163599ea267035e15cd923948c3763003e97608b /src
parentd627672ec4a10861a659bfaacfaf86aa4b5b4e6e (diff)
downloadscala-5db26e5136c635af062801218fc7edec280e63ff.tar.gz
scala-5db26e5136c635af062801218fc7edec280e63ff.tar.bz2
scala-5db26e5136c635af062801218fc7edec280e63ff.zip
gets rid of randomness in virtual filenames for bundles
Bundles are emitted in compilation units that wrap virtual source files. Previously we had those virtual files named randomly to ensure freshness, but that led to infinite compilation loops in SBT (see the commit message for more details and a link to a scala-user discussion). Now the names are generated deterministically from full names of bundles, which fixes the problems with SBT.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/macros/compiler/Resolvers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala20
2 files changed, 11 insertions, 11 deletions
diff --git a/src/compiler/scala/reflect/macros/compiler/Resolvers.scala b/src/compiler/scala/reflect/macros/compiler/Resolvers.scala
index f950059be4..49a5c01ad7 100644
--- a/src/compiler/scala/reflect/macros/compiler/Resolvers.scala
+++ b/src/compiler/scala/reflect/macros/compiler/Resolvers.scala
@@ -64,7 +64,7 @@ trait Resolvers {
val bundleParent = gen.mkAppliedTypeTree(Ident(bundleProto), bundleProto.typeParams.map(sym => Ident(sym.name)))
val bundleTemplate = Template(List(bundleParent), noSelfType, List(contextField, bundleCtor))
val bundle = atPos(bundleProto.pos)(ClassDef(NoMods, bundleName, bundleProto.typeParams.map(TypeDef(_)), bundleTemplate))
- currentRun.compileLate(PackageDef(bundlePid, List(bundle)))
+ currentRun.compileLate(bundleName + ".scala", PackageDef(bundlePid, List(bundle)))
}
// synthesize the macro impl reference, which is going to look like:
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index ef9d8a310e..92bfe6e0fe 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -1692,19 +1692,19 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
}
- // TODO: provide a way to specify a pretty name for debugging purposes
- private def randomFileName() = (
- "compileLateSynthetic-" + randomUUID().toString.replace("-", "") + ".scala"
- )
-
- def compileLate(code: PackageDef) {
+ /** Create and compile a synthetic compilation unit from the provided tree.
+ *
+ * This needs to create a virtual file underlying the compilation unit in order to appease SBT.
+ * However this file cannot have a randomly generated name, because then SBT 0.13 goes into a vicious loop
+ * as described on the mailing list: https://groups.google.com/forum/#!msg/scala-user/r1SgSoVfs0U/Wv4av0LOKukJ
+ * Therefore I have introduced an additional parameter that makes everyone specify meaningful file names.
+ */
+ def compileLate(virtualFileName: String, code: PackageDef) {
// compatibility with SBT
// on the one hand, we need to specify some jfile here, otherwise sbt crashes with an NPE (SI-6870)
// on the other hand, we can't specify the obvious enclosingUnit, because then sbt somehow fails to run tests using type macros
- // okay, now let's specify a guaranteedly non-existent file in an existing directory (so that we don't run into permission problems)
- val syntheticFileName = randomFileName()
- val fakeJfile = new java.io.File(syntheticFileName)
- val virtualFile = new VirtualFile(syntheticFileName) { override def file = fakeJfile }
+ val fakeJfile = new java.io.File(virtualFileName)
+ val virtualFile = new VirtualFile(virtualFileName) { override def file = fakeJfile }
val sourceFile = new BatchSourceFile(virtualFile, code.toString)
val unit = new CompilationUnit(sourceFile)
unit.body = code