First toolflow version

This commit is contained in:
2025-09-30 18:20:38 +02:00
parent b1bbd48d19
commit 2d48221e45
15 changed files with 305 additions and 0 deletions

144
toolflow/.gitignore vendored Normal file
View File

@@ -0,0 +1,144 @@
# Created by https://www.toptal.com/developers/gitignore/api/scala,intellij,sbt
# Edit at https://www.toptal.com/developers/gitignore?templates=scala,intellij,sbt
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/
# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml
### SBT ###
# Simple Build Tool
# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control
dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
.history
.cache
.lib/
### SBT Patch ###
.bsp/
### Scala ###
*.class
*.log
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# End of https://www.toptal.com/developers/gitignore/api/scala,intellij,sbt
.idea/

8
toolflow/README.md Normal file
View File

@@ -0,0 +1,8 @@
## sbt project compiled with Scala 3
### Usage
This is a normal sbt project. You can compile code with `sbt compile`, run it with `sbt run`, and `sbt console` will start a Scala 3 REPL.
For more information on the sbt-dotty plugin, see the
[scala3-example-project](https://github.com/scala/scala3-example-project/blob/main/README.md).

15
toolflow/build.sbt Normal file
View File

@@ -0,0 +1,15 @@
val scala3Version = "3.7.3"
lazy val root = project
.in(file("."))
.enablePlugins(JavaAppPackaging)
.settings(
name := "tgc-hammer",
version := "0.1.0-SNAPSHOT",
scalaVersion := scala3Version,
libraryDependencies += "org.rogach" %% "scallop" % "5.2.0",
libraryDependencies += "com.lihaoyi" %% "os-lib" % "0.11.5",
libraryDependencies += "org.scalameta" %% "munit" % "1.2.0" % Test
)

View File

@@ -0,0 +1 @@
sbt.version=1.11.6

View File

@@ -0,0 +1 @@
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.1")

View File

@@ -0,0 +1,10 @@
package com.minres.tgc.hammer
import os.Path
object Global {
def pathFromEnv(env: String): Option[Path] = sys.env.get("string").map { rawPath => Path(rawPath, os.pwd) }
lazy val HAMMER: Path = pathFromEnv("TGC_HAMMER_HOME").get
lazy val WORKDIR: Path = pathFromEnv("TGC_HAMMER_WORKDIR").get
lazy val TREENAIL: Path = HAMMER / "deps" / "treenail"
}

View File

@@ -0,0 +1,17 @@
package com.minres.tgc.hammer
import com.minres.tgc.hammer.cli.{HammerConf, MySubcommand}
object Main {
def main(args: Array[String]): Unit = {
val conf = new HammerConf(args.toIndexedSeq)
conf.subcommand match {
case Some(c: MySubcommand) =>
val tasks = c.getRequiredTasks
tasks.foreach(_.validate())
tasks.foreach(_.execute())
case _ =>
}
}
}

View File

@@ -0,0 +1,9 @@
package com.minres.tgc.hammer.cli
import org.rogach.scallop.ScallopConf
class HammerConf(arguments: Seq[String]) extends ScallopConf(arguments) {
addSubcommand(new TreenailCommand)
verify()
}

View File

@@ -0,0 +1,8 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.tasks.Task
import org.rogach.scallop.Subcommand
abstract class MySubcommand(name: String) extends Subcommand(name) {
def getRequiredTasks: Seq[Task]
}

View File

@@ -0,0 +1,19 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
import org.rogach.scallop.*
import java.io.File
import os.Path
class TreenailCommand extends MySubcommand("parseCoreDSL") {
val coreDSL: ScallopOption[File] = trailArg[File]("coreDSL")
val output: ScallopOption[File] = opt[File](short = 'o', default = Some(new File("isax.mlir")))
validateFileExists(coreDSL)
validateFileIsFile(coreDSL)
override def getRequiredTasks: Seq[Task] = Seq(
new TreenailTask(Path(coreDSL(), os.pwd), Path(output(), os.pwd))
)
}

View File

@@ -0,0 +1,12 @@
package com.minres.tgc.hammer.tasks
import os.{Path, Shellable}
trait Task {
def validate(): Unit
def execute(): Unit
def runExecutable(execPath: Path, args: Shellable*): os.CommandResult = {
os.proc(execPath, args).call()
}
}

View File

@@ -0,0 +1,16 @@
package com.minres.tgc.hammer.tasks
import com.minres.tgc.hammer.Global
import os.*
class TreenailTask(coreDSLInput: Path, output: Path) extends Task {
private val EXECUTABLE = Global.TREENAIL / "app" / "build" / "install" / "app" / "bin" / "app"
override def validate(): Unit = {
assert(isFile(EXECUTABLE), "Treenail Executable is missing, build Treenail")
}
override def execute(): Unit = {
runExecutable(EXECUTABLE, "-o", output, coreDSLInput)
}
}

View File

@@ -0,0 +1,9 @@
// For more information on writing tests, see
// https://scalameta.org/munit/docs/getting-started.html
class MySuite extends munit.FunSuite {
test("example test that succeeds") {
val obtained = 42
val expected = 42
assertEquals(obtained, expected)
}
}