aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Koenig2020-09-09 13:49:18 -0700
committerGitHub2020-09-09 20:49:18 +0000
commita70f0ceb443da270aad31f5ed478e95df7962849 (patch)
treee80b2739d7c8d7b585273df9c7605fbcfca36d48
parentbc7ac7013ecdf956b7cd61f0f0a60c7272d49cd6 (diff)
Make StageOption Unserializable (#1891)
These options are generally specific to a stage and thus should not be propagating across serialization
-rw-r--r--src/main/scala/firrtl/options/StageAnnotations.scala2
-rw-r--r--src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala23
2 files changed, 16 insertions, 9 deletions
diff --git a/src/main/scala/firrtl/options/StageAnnotations.scala b/src/main/scala/firrtl/options/StageAnnotations.scala
index 84168975..e2835e16 100644
--- a/src/main/scala/firrtl/options/StageAnnotations.scala
+++ b/src/main/scala/firrtl/options/StageAnnotations.scala
@@ -10,7 +10,7 @@ import java.io.File
import scopt.OptionParser
-sealed trait StageOption { this: Annotation => }
+sealed trait StageOption extends Unserializable { this: Annotation => }
/** An annotation that should not be serialized automatically [[phases.WriteOutputAnnotations WriteOutputAnnotations]].
* This usually means that this is an annotation that is used only internally to a [[Stage]].
diff --git a/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala b/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala
index 9e58585c..5fa9d9ef 100644
--- a/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala
+++ b/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala
@@ -12,6 +12,7 @@ import firrtl.options.{
OutputAnnotationFileAnnotation,
Phase,
PhaseException,
+ StageOption,
StageOptions,
TargetDirAnnotation,
WriteDeletedAnnotation
@@ -60,7 +61,7 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t
behavior.of(classOf[WriteOutputAnnotations].toString)
- it should "write annotations to a file (excluding DeletedAnnotations)" in new Fixture {
+ it should "write annotations to a file (excluding DeletedAnnotations and StageOptions)" in new Fixture {
val file = new File(dir + "/should-write-annotations-to-a-file.anno.json")
val annotations = Seq(
OutputAnnotationFileAnnotation(file.toString),
@@ -70,12 +71,13 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t
DeletedAnnotation("foo", WriteOutputAnnotationsSpec.FooAnnotation)
)
val expected = annotations.filter {
- case a: DeletedAnnotation => false
- case a => true
+ case _: DeletedAnnotation => false
+ case _: StageOption => false
+ case _ => true
}
val out = phase.transform(annotations)
- info("annotations are unmodified")
+ info("annotations should be as expected")
out.toSeq should be(annotations)
fileContainsAnnotations(file, expected)
@@ -96,7 +98,11 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t
info("annotations are unmodified")
out.toSeq should be(annotations)
- fileContainsAnnotations(file, annotations)
+ val expected = annotations.filter {
+ case _: StageOption => false
+ case _ => true
+ }
+ fileContainsAnnotations(file, expected)
}
it should "do nothing if no output annotation file is specified" in new Fixture {
@@ -126,9 +132,10 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t
WriteOutputAnnotationsSpec.Custom("hello!")
)
val serializedFileName = view[StageOptions](annotations).getBuildFileName("Custom", Some(".Emission"))
- val expected = annotations.map {
- case _: WriteOutputAnnotationsSpec.Custom => WriteOutputAnnotationsSpec.Replacement(serializedFileName)
- case a => a
+ val expected = annotations.flatMap {
+ case _: WriteOutputAnnotationsSpec.Custom => Some(WriteOutputAnnotationsSpec.Replacement(serializedFileName))
+ case _: StageOption => None
+ case a => Some(a)
}
val out = phase.transform(annotations)