mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
Update Scala Codegen SBT Example (#558)
* Update scala codegen sbt example to use the latest codegen binaries Use DAR to generate Scala code, no reason to unzip DALFs. * Add support for `DA.sdkVersion` system property. To override the default sdkVersion: ``` > sbt -DDA.sdkVersion=100.12.6 compile ``` * Simplify the way examples run
This commit is contained in:
parent
91843213bc
commit
f39b7a5d3f
@ -1,5 +1,5 @@
|
|||||||
# Mock scala/codegen example (does not send any commands just prints them to STD OUT)
|
# Mock scala/codegen example (does not send any commands just prints them to STD OUT)
|
||||||
$ sbt "mock-example/runMain com.digitalasset.example.ExampleMain"
|
$ sbt -DDA.sdkVersion=100.12.6 mock-example/run
|
||||||
|
|
||||||
# Sandbox scala/codegen example (sends commands to sandbox and receives transactions)
|
# Sandbox scala/codegen example (sends commands to sandbox and receives transactions)
|
||||||
$ sbt "sandbox-example/runMain com.digitalasset.example.ExampleMain ./scala-codegen/target/repository/daml-codegen/Main.dar"
|
$ sbt -DDA.sdkVersion=100.12.6 sandbox-example/run
|
||||||
|
@ -82,7 +82,7 @@ lazy val commonSettings = Seq(
|
|||||||
|
|
||||||
lazy val sandboxDependencies = Seq(
|
lazy val sandboxDependencies = Seq(
|
||||||
"com.daml.scala" %% "bindings-akka" % sdkVersion,
|
"com.daml.scala" %% "bindings-akka" % sdkVersion,
|
||||||
"com.digitalasset.platform" % "sandbox" % sdkVersion,
|
"com.digitalasset.platform" %% "sandbox" % sdkVersion,
|
||||||
)
|
)
|
||||||
|
|
||||||
lazy val codeGenDependencies = Seq(
|
lazy val codeGenDependencies = Seq(
|
||||||
@ -145,23 +145,15 @@ def generateScalaFrom(
|
|||||||
// directory containing the dar is used as a work directory
|
// directory containing the dar is used as a work directory
|
||||||
val outDir = darFile.getParentFile
|
val outDir = darFile.getParentFile
|
||||||
|
|
||||||
// Unpack all dalf files in the dar. Note that there may be many ("fat dar"), but at least daml-prim.dalf
|
|
||||||
val dalfFiles = IO.unzip(darFile, outDir, new SimpleFilter(_ endsWith ".dalf"))
|
|
||||||
|
|
||||||
// use a FileFunction.cached on the dar
|
// use a FileFunction.cached on the dar
|
||||||
val cache = FileFunction.cached(cacheDir, FileInfo.hash) { theDalfs =>
|
val cache = FileFunction.cached(cacheDir, FileInfo.hash) { _ =>
|
||||||
val mainDalf = theDalfs
|
|
||||||
.find(_.getName endsWith mainDalfName)
|
|
||||||
.getOrElse(sys.error(s"Main dalf file ($mainDalfName) not found in $theDalfs"))
|
|
||||||
val otherDalfs = theDalfs.filterNot(_ == mainDalf).toList
|
|
||||||
|
|
||||||
if (srcManagedDir.exists) // purge output if exists
|
if (srcManagedDir.exists) // purge output if exists
|
||||||
IO.delete(srcManagedDir.listFiles)
|
IO.delete(srcManagedDir.listFiles)
|
||||||
|
|
||||||
CodeGen.generateCode(mainDalf, otherDalfs.map(_.toURI.toURL), packageName, srcManagedDir, Novel)
|
CodeGen.generateCode(List(darFile), packageName, srcManagedDir, Novel)
|
||||||
(srcManagedDir ** "*.scala").get.toSet
|
(srcManagedDir ** "*.scala").get.toSet
|
||||||
}
|
}
|
||||||
cache(dalfFiles)
|
cache(Set(darFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ##################################### end sbt-daml ##############################
|
// ##################################### end sbt-daml ##############################
|
||||||
|
@ -2,10 +2,15 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
lazy val sdkVersion: String = "100.11.25"
|
val sdkVersion: String = sdkVersionFromSysProps().getOrElse("100.12.6")
|
||||||
|
|
||||||
|
println(s"DA sdkVersion: $sdkVersion")
|
||||||
|
|
||||||
lazy val detectedOs: String = sys.props("os.name") match {
|
lazy val detectedOs: String = sys.props("os.name") match {
|
||||||
case "Mac OS X" => "osx"
|
case "Mac OS X" => "osx"
|
||||||
case _ => "linux"
|
case _ => "linux"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def sdkVersionFromSysProps(): Option[String] =
|
||||||
|
sys.props.get("DA.sdkVersion").map(_.toString)
|
||||||
}
|
}
|
||||||
|
@ -40,20 +40,16 @@ import scala.concurrent.duration._
|
|||||||
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutor, Future}
|
import scala.concurrent.{Await, ExecutionContext, ExecutionContextExecutor, Future}
|
||||||
|
|
||||||
object ExampleMain extends App {
|
object ExampleMain extends App {
|
||||||
if (args.length == 0)
|
|
||||||
throw new IllegalArgumentException(
|
private val dar = new File("./scala-codegen/target/repository/daml-codegen/Main.dar")
|
||||||
"Expected at least one DAR or DALF file passed as an argument")
|
|
||||||
|
|
||||||
private val ledgerId = "codegen-sbt-example-with-sandbox"
|
private val ledgerId = "codegen-sbt-example-with-sandbox"
|
||||||
|
|
||||||
private val port: Int = findOpenPort().fold(e => throw new IllegalStateException(e), identity)
|
private val port: Int = findOpenPort().fold(e => throw new IllegalStateException(e), identity)
|
||||||
|
|
||||||
private def archives(fileNames: List[String]): List[File] =
|
|
||||||
toFiles(args.toList).fold(e => throw new IllegalStateException(e), identity)
|
|
||||||
|
|
||||||
private val serverConfig = SandboxConfig.default.copy(
|
private val serverConfig = SandboxConfig.default.copy(
|
||||||
port = port,
|
port = port,
|
||||||
damlPackageContainer = DamlPackageContainer(archives(args.toList)),
|
damlPackageContainer = DamlPackageContainer(List(dar)),
|
||||||
timeProviderType = TimeProviderType.WallClock,
|
timeProviderType = TimeProviderType.WallClock,
|
||||||
ledgerIdMode = LedgerIdMode.HardCoded(ledgerId),
|
ledgerIdMode = LedgerIdMode.HardCoded(ledgerId),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user