Skip to content

Commit fe679c0

Browse files
muuki88jenkins
authored and
jenkins
committed
scrooge: Add setting to configure root dir importer
Problem As described in twitter/scrooge/twitter#341 a lot of warnings are generated when using scrooge in projects with sbt sub modules as a root dir importer is always added. Solution Add a new setting scroogeThriftIncludeRoot that makes this behaviour configurable. The default behaviour is as it is now. Result Users won't see a ton of warnings. Closes twitter#345 Signed-off-by: Joy Bestourous <[email protected]> Differential Revision: https://phabricator.twitter.biz/D633782
1 parent 72f5a0a commit fe679c0

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala

+14-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ package com.twitter.scrooge
1818

1919
import com.twitter.scrooge.ast.Document
2020
import com.twitter.scrooge.backend.{GeneratorFactory, ScalaGenerator}
21-
import com.twitter.scrooge.frontend.{FileParseException, TypeResolver, ThriftParser, Importer}
21+
import com.twitter.scrooge.frontend.{
22+
FileParseException,
23+
Importer,
24+
NullImporter,
25+
ThriftParser,
26+
TypeResolver
27+
}
2228
import com.twitter.scrooge.java_generator.ApacheJavaGenerator
29+
2330
import java.io.{File, FileWriter}
2431
import scala.collection.concurrent.TrieMap
2532

@@ -45,7 +52,12 @@ class Compiler(val config: ScroogeConfig) {
4552
new FileWriter(file)
4653
}
4754

48-
val importer = Importer(new File(".")) +: Importer(config.includePaths.toSeq)
55+
val importer = {
56+
val rootImporter =
57+
if (config.addRootDirImporter) Importer(new File("."))
58+
else NullImporter
59+
rootImporter +: Importer(config.includePaths.toSeq)
60+
}
4961

5062
val isJava = config.language.equals("java")
5163
val documentCache = new TrieMap[String, Document]

scrooge-generator/src/main/scala/com/twitter/scrooge/ScroogeOptionParser.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ case class ScroogeConfig(
4141
language: String = CompilerDefaults.language,
4242
defaultNamespace: String = CompilerDefaults.defaultNamespace,
4343
scalaWarnOnJavaNSFallback: Boolean = false,
44-
javaSerEnumType: Boolean = false)
44+
javaSerEnumType: Boolean = false,
45+
addRootDirImporter: Boolean = true)
4546

4647
object ScroogeOptionParser {
4748

scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ object ScroogeSBT extends AutoPlugin {
2222
flags: Set[ServiceOption],
2323
disableStrict: Boolean,
2424
scalaWarnOnJavaNSFallback: Boolean,
25-
defaultNamespace: String
25+
defaultNamespace: String,
26+
addRootDirImporter: Boolean
2627
): Unit = {
2728

2829
val originalLoader: Option[ClassLoader] =
@@ -43,7 +44,8 @@ object ScroogeSBT extends AutoPlugin {
4344
strict = !disableStrict,
4445
scalaWarnOnJavaNSFallback = scalaWarnOnJavaNSFallback,
4546
defaultNamespace = defaultNamespace,
46-
language = language.toLowerCase
47+
language = language.toLowerCase,
48+
addRootDirImporter = addRootDirImporter
4749
)
4850

4951
try {
@@ -105,6 +107,11 @@ object ScroogeSBT extends AutoPlugin {
105107
"complete list of folders to search for thrift 'include' directives"
106108
)
107109

110+
val scroogeThriftIncludeRoot = SettingKey[Boolean](
111+
"scrooge-thrift-include-root",
112+
"If true scrooge will always search the project root for script files"
113+
)
114+
108115
val scroogeThriftNamespaceMap = SettingKey[Map[String, String]](
109116
"scrooge-thrift-namespace-map",
110117
"namespace rewriting, to support generation of java/finagle/scrooge into the same jar"
@@ -187,6 +194,7 @@ object ScroogeSBT extends AutoPlugin {
187194
scroogeThriftSources := (scroogeThriftSourceFolder.value ** "*.thrift").get,
188195
// complete list of include directories
189196
scroogeThriftIncludes := scroogeThriftIncludeFolders.value ++ scroogeUnpackDeps.value,
197+
scroogeThriftIncludeRoot := true,
190198
// unpack thrift files from all dependencies in the `thrift` configuration
191199
//
192200
// returns Seq[File] - directories that include thrift files
@@ -259,6 +267,7 @@ object ScroogeSBT extends AutoPlugin {
259267
val disableStrict = scroogeDisableStrict.value
260268
val warnOnFallBack = scroogeScalaWarnOnJavaNSFallback.value
261269
val javaNamespace = scroogeDefaultJavaNamespace.value
270+
val addRootDirImporter = scroogeThriftIncludeRoot.value
262271
// for some reason, sbt sometimes calls us multiple times, often with no source files.
263272
if (scroogeIsDirty.value && thriftSources.nonEmpty) {
264273
streamValue.log.info(s"Generating scrooge thrift for ${thriftSources.mkString(", ")} ...")
@@ -273,7 +282,8 @@ object ScroogeSBT extends AutoPlugin {
273282
buildOptions.toSet,
274283
disableStrict,
275284
warnOnFallBack,
276-
javaNamespace
285+
javaNamespace,
286+
addRootDirImporter
277287
)
278288
}
279289
}

0 commit comments

Comments
 (0)