Skip to content

Commit

Permalink
Support imports in file compiler (#3921)
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot authored Dec 1, 2023
1 parent 96fbf9d commit 3b22ec3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
33 changes: 33 additions & 0 deletions lang/jvm/src/main/scala/com/wavesplatform/lang/FileCompiler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.wavesplatform.lang

import com.google.common.base.Charsets
import com.google.common.io
import com.wavesplatform.lang.v1.estimator.v3.ScriptEstimatorV3

import java.io.File

object FileCompiler extends App {
private val estimator = ScriptEstimatorV3.latest

args
.foreach { path =>
val scriptFile = new File(path).getAbsoluteFile
require(scriptFile.isFile, s"$path is not a file")
val baseDirectory = scriptFile.getParentFile
val imports = baseDirectory
.listFiles({ (pathname: File) =>
pathname.isFile && pathname.getAbsoluteFile != scriptFile
})
.map { f =>
f.getName -> io.Files.asCharSource(f, Charsets.UTF_8).read()
}
.toMap

API
.compile(io.Files.asCharSource(scriptFile, Charsets.UTF_8).read(), estimator, libraries = imports)
.fold(
error => throw new RuntimeException(s"$error while compiling $path"),
_ => println(s"successfully compiled $path")
)
}
}

This file was deleted.

0 comments on commit 3b22ec3

Please sign in to comment.