-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
language-support/scala: add support for specifying dependency roots e…
…xplicitly (#1210) * language-support/scala: add support for specifying roots explicitly By default, code-gen will use all templates in the given package as roots, and generate code for all types used. This patch adds the ability to specify roots explicitly via a set of regex.es to match the (fully qualified) template names. This is an experiment, tests and UI need to be adjusted later. * scala codegen rootfilter: move filtering to envIFace handling * doc for --root option * scalafmt * test filterTemplatesBy * release note for --root Scala codegen option
- Loading branch information
1 parent
2b5c25f
commit b0b3e29
Showing
6 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
language-support/scala/codegen/src/test/scala/com/digitalasset/codegen/CodeGenSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.digitalasset | ||
package codegen | ||
|
||
import daml.lf.data.ImmArray.ImmArraySeq | ||
import daml.lf.data.Ref.Identifier | ||
import daml.lf.iface._ | ||
import daml.lf.value.ValueGenerators.idGen | ||
|
||
import org.scalatest.{WordSpec, Matchers} | ||
import org.scalatest.prop.GeneratorDrivenPropertyChecks | ||
|
||
class CodeGenSpec extends WordSpec with Matchers with GeneratorDrivenPropertyChecks { | ||
import CodeGen.filterTemplatesBy | ||
import CodeGenSpec._ | ||
|
||
"filterTemplatesBy" should { | ||
"be identity given empty regexes" in forAll(trivialEnvInterfaceGen) { ei => | ||
filterTemplatesBy(Seq.empty)(ei) should ===(ei) | ||
} | ||
|
||
"delete all templates given impossible regex" in forAll(trivialEnvInterfaceGen) { ei => | ||
val noTemplates = ei copy (ei.typeDecls transform { | ||
case (_, tmpl @ InterfaceType.Template(_, _)) => InterfaceType.Normal(tmpl.`type`) | ||
case (_, v) => v | ||
}) | ||
filterTemplatesBy(Seq("(?!a)a".r))(ei) should ===(noTemplates) | ||
} | ||
|
||
"match the union of regexes, not intersection" in forAll(trivialEnvInterfaceGen) { ei => | ||
filterTemplatesBy(Seq("(?s).*".r, "(?!a)a".r))(ei) should ===(ei) | ||
} | ||
} | ||
} | ||
|
||
object CodeGenSpec { | ||
import org.scalacheck.{Arbitrary, Gen} | ||
import Arbitrary.arbitrary | ||
|
||
val trivialEnvInterfaceGen: Gen[EnvironmentInterface] = { | ||
val fooRec = Record(ImmArraySeq.empty) | ||
val fooTmpl = InterfaceType.Template(fooRec, DefTemplate(Map.empty)) | ||
val fooNorm = InterfaceType.Normal(DefDataType(ImmArraySeq.empty, fooRec)) | ||
implicit val idArb: Arbitrary[Identifier] = Arbitrary(idGen) | ||
arbitrary[Map[Identifier, Boolean]] map { ids => | ||
EnvironmentInterface(ids transform { (_, isTemplate) => | ||
if (isTemplate) fooTmpl else fooNorm | ||
}) | ||
} | ||
} | ||
} |