From c6093cbcd4f2eb8acd44f3b9d4e7146448de172f Mon Sep 17 00:00:00 2001 From: Chick Markley Date: Fri, 12 Nov 2021 12:29:48 -0800 Subject: Let firrtl based applications run despite loading unknown annotations (#2387) An application like barstools may contain a main that loads an annotations file containing annotation classes that are not on it's classpath. This change allows unknown annotations to be preserved by wrapping them in a UnrecognizedAnnotation. If annotations are then output to a file, they will be unwrapped during serialization This feature can be enabled via an AllowUnrecognizedAnnotations annotation Co-authored-by: chick Co-authored-by: Jack Koenig --- src/test/scala/firrtlTests/AnnotationTests.scala | 35 +++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/test/scala/firrtlTests/AnnotationTests.scala') diff --git a/src/test/scala/firrtlTests/AnnotationTests.scala b/src/test/scala/firrtlTests/AnnotationTests.scala index 6ee63856..a8ff0aa0 100644 --- a/src/test/scala/firrtlTests/AnnotationTests.scala +++ b/src/test/scala/firrtlTests/AnnotationTests.scala @@ -564,7 +564,7 @@ class JsonAnnotationTests extends AnnotationTests { val manager = setupManager(Some(anno)) the[Exception] thrownBy Driver.execute(manager) should matchPattern { - case InvalidAnnotationFileException(_, _: AnnotationClassNotFoundException) => + case InvalidAnnotationFileException(_, _: UnrecogizedAnnotationsException) => } } @@ -614,4 +614,37 @@ class JsonAnnotationTests extends AnnotationTests { val cr = DoNothingTransform.runTransform(CircuitState(parse(input), ChirrtlForm, annos)) cr.annotations.toSeq shouldEqual annos } + + "fully qualified class name that is undeserializable" should "give an invalid json exception" in { + val anno = """ + |[ + | { + | "class":"firrtlTests.MyUnserAnno", + | "box":"7" + | } + |] """.stripMargin + + val manager = setupManager(Some(anno)) + the[Exception] thrownBy Driver.execute(manager) should matchPattern { + case InvalidAnnotationFileException(_, _: InvalidAnnotationJSONException) => + } + } + + "unqualified class name" should "give an unrecognized annotation exception" in { + val anno = """ + |[ + | { + | "class":"MyUnserAnno" + | "box":"7" + | } + |] """.stripMargin + val manager = setupManager(Some(anno)) + the[Exception] thrownBy Driver.execute(manager) should matchPattern { + case InvalidAnnotationFileException(_, _: UnrecogizedAnnotationsException) => + } + } } + +/* These are used by the last two tests. It is outside the main test to keep the qualified name simpler*/ +class UnserBox(val x: Int) +case class MyUnserAnno(box: UnserBox) extends NoTargetAnnotation -- cgit v1.2.3