Skip to content

Commit

Permalink
Daml export: make paths relative to daml.yaml (#10388)
Browse files Browse the repository at this point in the history
Previously data-dependencies in the generated daml.yaml file had a path
including the output-dir path itself. E.g.

```
data-dependencies:
- /some/out/path/deps/some.dalf
```

This worked fine so long as the output path was absolute. However, if
the output path is a relative path, then it might lead to "no such file"
errors during daml build.

This change always makes the generated data-dependencies paths relative
to the daml.yaml file.

changelog_begin
- [Daml export] The generated paths to data-dependencies DALFs are now
  relative to the generated daml.yaml. Fixes
  #10378.
changelog_end

Co-authored-by: Andreas Herrmann <[email protected]>
  • Loading branch information
aherrmann-da and aherrmann authored Jul 23, 2021
1 parent 90c3582 commit 7df9758
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

package com.daml.script.export

import java.io.{File, PrintWriter}
import java.io.File
import java.nio.file.{Files, Path, Paths, StandardCopyOption}
import java.time.Duration

import com.daml.fs.Utils.deleteRecursively
import com.daml.ledger.api.tls.TlsConfiguration
import com.daml.lf.engine.script.{RunnerConfig, RunnerMain}

import scala.io.Source

case class ExampleClientConfig(
darPath: File,
targetPort: Int,
Expand Down Expand Up @@ -115,29 +113,12 @@ object ExampleClient {
),
)
)
normalizeDataDependencies(outputPath, outputPath.resolve("daml.yaml"))
moveFile(outputPath.resolve("Export.daml").toFile, clientConfig.outputExportDaml.toFile)
moveFile(outputPath.resolve("args.json").toFile, clientConfig.outputArgsJson.toFile)
moveFile(outputPath.resolve("daml.yaml").toFile, clientConfig.outputDamlYaml.toFile)
}
}

private def normalizeDataDependencies(outputPath: Path, damlYaml: Path): Unit = {
val tmpFile = damlYaml.resolveSibling("daml.yaml.new").toFile
val reader = Source.fromFile(damlYaml.toFile)
val writer = new PrintWriter(tmpFile)
try {
reader
.getLines()
.map { x => x.replace(outputPath.toString, "EXPORT_OUT") }
.foreach(x => writer.println(x))
} finally {
reader.close()
writer.close()
}
moveFile(tmpFile, damlYaml.toFile)
}

private def moveFile(src: File, dst: File): Unit = {
if (!dst.getParentFile.exists()) {
if (!dst.getParentFile.mkdirs())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object Export {
val prefix = pkg.metadata.map(md => s"${md.name}-${md.version}-").getOrElse("")
val file = deps.resolve(s"$prefix$pkgId.dalf")
Dependencies.writeDalf(file, pkgId, bs)
file
dir.relativize(file)
}
val lfTarget = Dependencies.targetLfVersion(pkgs.values.map(_._2.languageVersion))
val targetFlag = lfTarget.fold("")(Dependencies.targetFlag(_))
Expand Down
42 changes: 21 additions & 21 deletions docs/source/tools/export/output-root/daml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ dependencies:
- daml-prim
- daml-script
data-dependencies:
- EXPORT_OUT/deps/057eed1fd48c238491b8ea06b9b5bf85a5d4c9275dd3f6183e0e6b01730cc2ba.dalf
- EXPORT_OUT/deps/40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7.dalf
- EXPORT_OUT/deps/518032f41fd0175461b35ae0c9691e08b4aea55e62915f8360af2cc7a1f2ba6c.dalf
- EXPORT_OUT/deps/6839a6d3d430c569b2425e9391717b44ca324b88ba621d597778811b2d05031d.dalf
- EXPORT_OUT/deps/6c2c0667393c5f92f1885163068cd31800d2264eb088eb6fc740e11241b2bf06.dalf
- EXPORT_OUT/deps/733e38d36a2759688a4b2c4cec69d48e7b55ecc8dedc8067b815926c917a182a.dalf
- EXPORT_OUT/deps/76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f.dalf
- EXPORT_OUT/deps/8a7806365bbd98d88b4c13832ebfa305f6abaeaf32cfa2b7dd25c4fa489b79fb.dalf
- EXPORT_OUT/deps/99a2705ed38c1c26cbb8fe7acf36bbf626668e167a33335de932599219e0a235.dalf
- EXPORT_OUT/deps/bfcd37bd6b84768e86e432f5f6c33e25d9e7724a9d42e33875ff74f6348e733f.dalf
- EXPORT_OUT/deps/c1f1f00558799eec139fb4f4c76f95fb52fa1837a5dd29600baa1c8ed1bdccfd.dalf
- EXPORT_OUT/deps/cc348d369011362a5190fe96dd1f0dfbc697fdfd10e382b9e9666f0da05961b7.dalf
- EXPORT_OUT/deps/d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662.dalf
- EXPORT_OUT/deps/d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97.dalf
- EXPORT_OUT/deps/e22bce619ae24ca3b8e6519281cb5a33b64b3190cc763248b4c3f9ad5087a92c.dalf
- EXPORT_OUT/deps/e491352788e56ca4603acc411ffe1a49fefd76ed8b163af86cf5ee5f4c38645b.dalf
- EXPORT_OUT/deps/daml-prim-0.0.0-b76d13799ea5488f281440b63072ad3e3d48d72936144e7d19209c9cf115aa9d.dalf
- EXPORT_OUT/deps/daml-script-0.0.0-024f7a831e04595b36c668121dce9209d63e5a6a46f01a4533fca5e4c521e7e4.dalf
- EXPORT_OUT/deps/daml-stdlib-0.0.0-68a8ef91f10c283e1a5fc914bbf0addd41a089ad3625641966df2415e6010e2e.dalf
- EXPORT_OUT/deps/daml-stdlib-DA-Set-Types-1.0.0-97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657.dalf
- EXPORT_OUT/deps/script-test-0.0.1-87967f7d2b53db9652bd343a24db7cbe371c4b105005d57eed853bd309bac477.dalf
- deps/057eed1fd48c238491b8ea06b9b5bf85a5d4c9275dd3f6183e0e6b01730cc2ba.dalf
- deps/40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7.dalf
- deps/518032f41fd0175461b35ae0c9691e08b4aea55e62915f8360af2cc7a1f2ba6c.dalf
- deps/6839a6d3d430c569b2425e9391717b44ca324b88ba621d597778811b2d05031d.dalf
- deps/6c2c0667393c5f92f1885163068cd31800d2264eb088eb6fc740e11241b2bf06.dalf
- deps/733e38d36a2759688a4b2c4cec69d48e7b55ecc8dedc8067b815926c917a182a.dalf
- deps/76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f.dalf
- deps/8a7806365bbd98d88b4c13832ebfa305f6abaeaf32cfa2b7dd25c4fa489b79fb.dalf
- deps/99a2705ed38c1c26cbb8fe7acf36bbf626668e167a33335de932599219e0a235.dalf
- deps/bfcd37bd6b84768e86e432f5f6c33e25d9e7724a9d42e33875ff74f6348e733f.dalf
- deps/c1f1f00558799eec139fb4f4c76f95fb52fa1837a5dd29600baa1c8ed1bdccfd.dalf
- deps/cc348d369011362a5190fe96dd1f0dfbc697fdfd10e382b9e9666f0da05961b7.dalf
- deps/d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662.dalf
- deps/d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97.dalf
- deps/e22bce619ae24ca3b8e6519281cb5a33b64b3190cc763248b4c3f9ad5087a92c.dalf
- deps/e491352788e56ca4603acc411ffe1a49fefd76ed8b163af86cf5ee5f4c38645b.dalf
- deps/daml-prim-0.0.0-b76d13799ea5488f281440b63072ad3e3d48d72936144e7d19209c9cf115aa9d.dalf
- deps/daml-script-0.0.0-024f7a831e04595b36c668121dce9209d63e5a6a46f01a4533fca5e4c521e7e4.dalf
- deps/daml-stdlib-0.0.0-68a8ef91f10c283e1a5fc914bbf0addd41a089ad3625641966df2415e6010e2e.dalf
- deps/daml-stdlib-DA-Set-Types-1.0.0-97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657.dalf
- deps/script-test-0.0.1-87967f7d2b53db9652bd343a24db7cbe371c4b105005d57eed853bd309bac477.dalf
build-options:
- --target=1.13
- --package=script-test-0.0.1

0 comments on commit 7df9758

Please sign in to comment.