From 5db26e5136c635af062801218fc7edec280e63ff Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 2 Oct 2013 16:39:13 +0200 Subject: 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. --- .../scala/reflect/macros/compiler/Resolvers.scala | 2 +- src/compiler/scala/tools/nsc/Global.scala | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') 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 -- cgit v1.2.3