diff --git a/scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala b/scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala index 11bfd01a7..a713a27b6 100644 --- a/scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala +++ b/scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala @@ -18,8 +18,9 @@ package com.twitter.scrooge import com.twitter.scrooge.ast.Document import com.twitter.scrooge.backend.{GeneratorFactory, ScalaGenerator} -import com.twitter.scrooge.frontend.{FileParseException, TypeResolver, ThriftParser, Importer} +import com.twitter.scrooge.frontend.{FileParseException, Importer, NullImporter, ThriftParser, TypeResolver} import com.twitter.scrooge.java_generator.ApacheJavaGenerator + import java.io.{File, FileWriter} import scala.collection.concurrent.TrieMap @@ -45,7 +46,7 @@ class Compiler(val config: ScroogeConfig) { new FileWriter(file) } - val importer = Importer(new File(".")) +: Importer(config.includePaths.toSeq) + val importer = (if(config.addRootDirImporter) Importer(new File(".")) else NullImporter) +: Importer(config.includePaths.toSeq) val isJava = config.language.equals("java") val documentCache = new TrieMap[String, Document] diff --git a/scrooge-generator/src/main/scala/com/twitter/scrooge/ScroogeOptionParser.scala b/scrooge-generator/src/main/scala/com/twitter/scrooge/ScroogeOptionParser.scala index 63c90ba2c..cd2deb42a 100644 --- a/scrooge-generator/src/main/scala/com/twitter/scrooge/ScroogeOptionParser.scala +++ b/scrooge-generator/src/main/scala/com/twitter/scrooge/ScroogeOptionParser.scala @@ -41,7 +41,9 @@ case class ScroogeConfig( language: String = CompilerDefaults.language, defaultNamespace: String = CompilerDefaults.defaultNamespace, scalaWarnOnJavaNSFallback: Boolean = false, - javaSerEnumType: Boolean = false) + javaSerEnumType: Boolean = false, + addRootDirImporter: Boolean = true +) object ScroogeOptionParser { diff --git a/scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala b/scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala index 18598e6c6..dc9d84d85 100644 --- a/scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala +++ b/scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala @@ -13,7 +13,6 @@ object ScroogeSBT extends AutoPlugin { if (language.endsWith("java")) "*.java" else "*.scala" private[this] def compile( - log: Logger, outputDir: File, thriftFiles: Set[File], thriftIncludes: Set[File], @@ -22,7 +21,8 @@ object ScroogeSBT extends AutoPlugin { flags: Set[ServiceOption], disableStrict: Boolean, scalaWarnOnJavaNSFallback: Boolean, - defaultNamespace: String + defaultNamespace: String, + addRootDirImporter: Boolean ): Unit = { val originalLoader: Option[ClassLoader] = @@ -43,7 +43,8 @@ object ScroogeSBT extends AutoPlugin { strict = !disableStrict, scalaWarnOnJavaNSFallback = scalaWarnOnJavaNSFallback, defaultNamespace = defaultNamespace, - language = language.toLowerCase + language = language.toLowerCase, + addRootDirImporter = addRootDirImporter ) try { @@ -105,6 +106,11 @@ object ScroogeSBT extends AutoPlugin { "complete list of folders to search for thrift 'include' directives" ) + val scroogeThriftIncludeRoot = SettingKey[Boolean]( + "scrooge-thrift-include-root", + "If true scrooge will always search the project root for script files" + ) + val scroogeThriftNamespaceMap = SettingKey[Map[String, String]]( "scrooge-thrift-namespace-map", "namespace rewriting, to support generation of java/finagle/scrooge into the same jar" @@ -187,6 +193,7 @@ object ScroogeSBT extends AutoPlugin { scroogeThriftSources := (scroogeThriftSourceFolder.value ** "*.thrift").get, // complete list of include directories scroogeThriftIncludes := scroogeThriftIncludeFolders.value ++ scroogeUnpackDeps.value, + scroogeThriftIncludeRoot := true, // unpack thrift files from all dependencies in the `thrift` configuration // // returns Seq[File] - directories that include thrift files @@ -259,12 +266,12 @@ object ScroogeSBT extends AutoPlugin { val disableStrict = scroogeDisableStrict.value val warnOnFallBack = scroogeScalaWarnOnJavaNSFallback.value val javaNamespace = scroogeDefaultJavaNamespace.value + val addRootDirImporter = scroogeThriftIncludeRoot.value // for some reason, sbt sometimes calls us multiple times, often with no source files. if (scroogeIsDirty.value && thriftSources.nonEmpty) { streamValue.log.info(s"Generating scrooge thrift for ${thriftSources.mkString(", ")} ...") scroogeLangs.foreach { language => compile( - streamValue.log, outputFolder, thriftSources.toSet, thriftIncludes.toSet, @@ -273,7 +280,8 @@ object ScroogeSBT extends AutoPlugin { buildOptions.toSet, disableStrict, warnOnFallBack, - javaNamespace + javaNamespace, + addRootDirImporter ) } }