From a70f0ceb443da270aad31f5ed478e95df7962849 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Wed, 9 Sep 2020 13:49:18 -0700 Subject: Make StageOption Unserializable (#1891) These options are generally specific to a stage and thus should not be propagating across serialization--- .../scala/firrtl/options/StageAnnotations.scala | 2 +- .../phases/WriteOutputAnnotationsSpec.scala | 23 ++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src') 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) -- cgit v1.2.3