Permalink
Browse files

[split] Update scrooge to remove date from Generated annotation so ge…

…nerated code is reproducible.

Currently Scrooge sets the "date" field of the Generated annotation for code
it generates, which leads to unique generated code. This change stops
setting the generated date as its not needed in practice and complicates
pants caching because generated code is unique.

This annotation was originally added in
#52 with the stated intent of playing
nice with IDEs. I believe this change still allows the generated code to
play well with editors, as well as now playing well with the pants cache.

RB_ID=290143
  • Loading branch information...
1 parent 8a67b91 commit 452d716c655ff4ff5f14c359fe134fd178b5e462 Travis Crawford committed with CI Feb 18, 2014
Showing with 23 additions and 42 deletions.
  1. +1 −1 scrooge-generator/src/main/resources/javagen/consts.java
  2. +1 −1 scrooge-generator/src/main/resources/javagen/enum.java
  3. +1 −1 scrooge-generator/src/main/resources/javagen/service.java
  4. +1 −1 scrooge-generator/src/main/resources/javagen/struct.java
  5. +1 −1 scrooge-generator/src/main/resources/javagen/union.java
  6. +1 −1 scrooge-generator/src/main/resources/scalagen/consts.scala
  7. +2 −2 scrooge-generator/src/main/resources/scalagen/enum.scala
  8. +1 −1 scrooge-generator/src/main/resources/scalagen/finagleClient.scala
  9. +1 −1 scrooge-generator/src/main/resources/scalagen/finagleService.scala
  10. +1 −1 scrooge-generator/src/main/resources/scalagen/service.scala
  11. +2 −2 scrooge-generator/src/main/resources/scalagen/union.scala
  12. +0 −4 scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala
  13. +1 −2 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ConstsTemplate.scala
  14. +1 −2 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/EnumTemplate.scala
  15. +1 −4 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/Generator.scala
  16. +2 −4 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/JavaGenerator.scala
  17. +1 −3 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ScalaGenerator.scala
  18. +1 −4 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ServiceTemplate.scala
  19. +1 −2 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/StructTemplate.scala
  20. +0 −1 scrooge-generator/src/main/scala/com/twitter/scrooge/java_generator/ApacheJavaGenerator.scala
  21. +2 −3 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/GeneratorFactorySpec.scala
@@ -5,7 +5,7 @@
import java.util.Map;
import java.util.Set;
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public final class Constants {
{{#constants}}
{{docstring}}
@@ -1,7 +1,7 @@
package {{package}};
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public enum {{EnumName}} {
{{#values}}
{{valuedocstring}}
@@ -34,7 +34,7 @@
{{/withFinagle}}
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public class {{ServiceName}} {
public interface Iface {{#syncParent}}extends {{syncParent}} {{/syncParent}}{
{{#syncFunctions}}
@@ -18,7 +18,7 @@
import java.util.HashSet;
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public {{/public}}{{^public}}static {{/public}}class {{StructName}}{{#isException}} extends Exception{{/isException}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
@@ -18,7 +18,7 @@
import java.util.HashSet;
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public {{/public}}{{^public}}static {{/public}}class {{StructName}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
@@ -1,6 +1,6 @@
package {{package}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
object Constants {
{{#constants}}
{{docstring}}
@@ -3,7 +3,7 @@ package {{package}}
import com.twitter.scrooge.ThriftEnum
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
case object {{EnumName}} {
{{#values}}
{{valuedocstring}}
@@ -57,5 +57,5 @@ case object {{EnumName}} {
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
sealed trait {{EnumName}} extends ThriftEnum with Serializable
@@ -13,7 +13,7 @@ import org.apache.thrift.transport.{TMemoryBuffer, TMemoryInputTransport}
import scala.collection.{Map, Set}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
class {{ServiceName}}$FinagleClient(
{{#hasParent}}override {{/hasParent}}val service: FinagleService[ThriftClientRequest, Array[Byte]],
{{#hasParent}}override {{/hasParent}}val protocolFactory: TProtocolFactory = new TBinaryProtocol.Factory,
@@ -13,7 +13,7 @@ import scala.collection.mutable.{
import scala.collection.{Map, Set}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
class {{ServiceName}}$FinagleService(
iface: {{ServiceName}}[Future],
protocolFactory: TProtocolFactory
@@ -16,7 +16,7 @@ import scala.collection.mutable.{
import scala.collection.{Map, Set}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
trait {{ServiceName}}[+MM[_]] {{#genericParent}}extends {{genericParent}} {{/genericParent}}{
{{#genericFunctions}}
{{>function}}
@@ -11,11 +11,11 @@ import scala.collection.mutable.{
import scala.collection.{Map, Set}
{{/public}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
sealed trait {{StructName}} extends {{parentType}}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
val Union = new TStruct("{{StructNameForWire}}")
{{#fields}}
@@ -20,8 +20,6 @@ import scala.collection.mutable
import java.io.{File, FileWriter}
import com.twitter.scrooge.backend.{Generator, ScalaGenerator, ServiceOption}
import com.twitter.scrooge.frontend.{TypeResolver, ThriftParser, Importer}
-import org.apache.commons.lang.time.FastDateFormat
-import java.util.Date
class Compiler {
val defaultDestFolder = "."
@@ -40,7 +38,6 @@ class Compiler {
var language: String = "scala"
var defaultNamespace: String = "thrift"
var scalaWarnOnJavaNSFallback: Boolean = false
- val now: String = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date())
def run() {
// if --gen-file-map is specified, prepare the map file.
@@ -70,7 +67,6 @@ class Compiler {
language,
resolvedDoc.resolver.includeMap,
defaultNamespace,
- now,
experimentFlags)
generator match {
@@ -19,7 +19,6 @@ trait ConstsTemplate {
"value" -> genConstant(c.value),
"docstring" -> codify(c.docstring.getOrElse(""))
)
- }),
- "date" -> codify(generationDate)
+ })
)
}
@@ -22,7 +22,6 @@ trait EnumTemplate {
"unquotedNameLowerCase" -> codify(value.sid.fullName.toLowerCase),
"value" -> codify(value.value.toString)
)
- }),
- "date" -> codify(generationDate)
+ })
)
}
@@ -54,10 +54,9 @@ object Generator {
lan: String,
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
): ThriftGenerator = Generators.get(lan) match {
- case Some(gen) => gen(includeMap, defaultNamespace, generationDate, experimentFlags)
+ case Some(gen) => gen(includeMap, defaultNamespace, experimentFlags)
case None => throw new Exception("Generator for language \"%s\" not found".format(lan))
}
}
@@ -67,7 +66,6 @@ trait GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
): ThriftGenerator
}
@@ -85,7 +83,6 @@ trait Generator
*/
val includeMap: Map[String, ResolvedDocument]
val defaultNamespace: String
- val generationDate: String
val experimentFlags: Seq[String]
/******************** helper functions ************************/
@@ -25,15 +25,13 @@ object JavaGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
- ): ThriftGenerator = new JavaGenerator(includeMap, defaultNamespace, generationDate)
+ ): ThriftGenerator = new JavaGenerator(includeMap, defaultNamespace)
}
class JavaGenerator(
val includeMap: Map[String, ResolvedDocument],
- val defaultNamespace: String,
- val generationDate: String
+ val defaultNamespace: String
) extends Generator with ThriftGenerator {
val fileExtension = ".java"
@@ -26,15 +26,13 @@ object ScalaGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
- ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, generationDate, experimentFlags)
+ ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, experimentFlags)
}
class ScalaGenerator(
val includeMap: Map[String, ResolvedDocument],
val defaultNamespace: String,
- val generationDate: String,
val experimentFlags: Seq[String]
) extends Generator with ThriftGenerator {
@@ -90,7 +90,6 @@ trait ServiceTemplate {
Dictionary(
"package" -> genID(namespace),
"ServiceName" -> genID(service.sid.toTitleCase),
- "date" -> codify(generationDate),
"docstring" -> codify(service.docstring.getOrElse("")),
"hasParent" -> v(service.parent.isDefined),
"finagleClientParent" ->
@@ -126,7 +125,6 @@ trait ServiceTemplate {
Dictionary(
"package" -> genID(namespace),
"ServiceName" -> genID(service.sid.toTitleCase),
- "date" -> codify(generationDate),
"docstring" -> codify(service.docstring.getOrElse("")),
"hasParent" -> v(service.parent.isDefined),
"finagleServiceParent" ->
@@ -205,8 +203,7 @@ trait ServiceTemplate {
"finagleServices" -> v(
if (withFinagle) Seq(finagleService(service, namespace)) else Seq()
),
- "withFinagle" -> v(withFinagle),
- "date" -> codify(generationDate)
+ "withFinagle" -> v(withFinagle)
)
}
}
@@ -281,8 +281,7 @@ trait StructTemplate {
"arity1" -> v((if (arity == 1) fieldDictionaries.take(1) else Nil)),
"arityN" -> v(arity > 1 && arity <= 22),
"withFieldGettersAndSetters" -> v(isStruct || isException),
- "withTrait" -> v(isStruct),
- "date" -> codify(generationDate)
+ "withTrait" -> v(isStruct)
)
}
}
@@ -20,7 +20,6 @@ object ApacheJavaGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
): ThriftGenerator = new ApacheJavaGenerator(includeMap, defaultNamespace)
}
@@ -8,15 +8,14 @@ class TestGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
- ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, generationDate, experimentFlags)
+ ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, experimentFlags)
}
class GeneratorFactorySpec extends Spec {
"GeneratorFactory" should {
"be loadable" in {
- val generator = Generator("test", Map.empty[String, ResolvedDocument], "", "", Seq.empty[String])
+ val generator = Generator("test", Map.empty[String, ResolvedDocument], "", Seq.empty[String])
generator.isInstanceOf[ScalaGenerator] must be(true)
}
}

0 comments on commit 452d716

Please sign in to comment.