Last active
July 20, 2022 13:21
-
-
Save DamianReeves/6d621e4a0703e3a7ea24bf2fb59bf4a5 to your computer and use it in GitHub Desktop.
Generate morphir-ir
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
scala-cli package . -o dist/morphirIRGen -f |
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
//> using scala "3.1.3" | |
//> using lib "com.lihaoyi::os-lib::0.8.1" | |
//> using lib "com.lihaoyi::upickle::2.0.0" | |
//> using packaging.packageType "graalvm" | |
// //> using platform "scala-native" | |
@main def generateMorphirIR() = | |
val message = "Hello from Scala script" | |
println(s"isWin: ${scala.util.Properties.isWin}") | |
println(s"GitExe: ${GitOps.gitExe}") | |
object morphir { | |
object elm { | |
def clone(url: String, dest: String): Unit = { | |
// val cmd = s"git clone $url $dest" | |
// println(cmd) | |
// os.proc(cmd).! | |
} | |
} | |
} |
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
import upickle.default._ | |
object GitOps { | |
lazy val gitExe = if (scala.util.Properties.isWin) "git.exe" else "git" | |
implicit val GivenOsPathReader: ReadWriter[os.Path] = | |
readwriter[String].bimap(_.toString, os.Path(_)) | |
final case class GitCloneOptions( | |
repository: String, | |
depth: Option[Int] = None, | |
additionalArgs: Seq[String] = Seq.empty | |
) { | |
def toArgs: Seq[String] = Seq("clone") ++ depth | |
.map(d => s"--depth=$d") | |
.toSeq ++ additionalArgs ++ Seq(repository) | |
} | |
object GitCloneOptions { | |
implicit lazy val jsonify: upickle.default.ReadWriter[GitCloneOptions] = | |
upickle.default.macroRW | |
} | |
final case class GitCloneResults(repositoryPath: os.Path, hash: String) | |
object GitCloneResults { | |
implicit lazy val jsonify: upickle.default.ReadWriter[GitCloneResults] = | |
upickle.default.macroRW | |
} | |
def clone( | |
wd: os.Path, | |
options: GitCloneOptions, | |
envArgs: Map[String, String] = Map.empty | |
) = { | |
os.makeDir.all(wd) | |
val command = Vector(gitExe) ++ options.toArgs | |
val res = os.proc(command).call(cwd = wd, env = envArgs) | |
val repositoryPath = os.list(wd).head | |
val hash = getHash(repositoryPath) | |
GitCloneResults(repositoryPath, hash) | |
} | |
def getHash(repositoryPath: os.Path) = { | |
val lsFilesCommand = | |
Vector(gitExe, "ls-files", "-s", repositoryPath.toString()) | |
val lsFiles = os.proc(lsFilesCommand).spawn(stderr = os.Inherit) | |
val hashObjectCommand = Vector(gitExe, "hash-object", "--stdin") | |
val hashObject = os.proc(hashObjectCommand).call(stdin = lsFiles.stdout) | |
// val command = Vector(gitExe, "rev-parse", "HEAD") | |
// val res = os.proc(command).call(cwd = repositoryPath) | |
hashObject.out.trim() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment