Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
refactor a lil.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 18, 2024
1 parent 1419fbe commit d88b5d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/main/scala/ee/hrzn/chryse/tasks/BaseTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.nio.file.Files
import java.nio.file.Paths
import java.security.MessageDigest
import java.util.HexFormat
import scala.jdk.CollectionConverters._
import scala.sys.process._

abstract class BaseTask {
Expand Down Expand Up @@ -60,6 +61,14 @@ abstract class BaseTask {
run.foreach(_.markUpToDate())
}

protected def filesInDirWithExt(dir: String, ext: String): Iterator[String] =
Files
.walk(Paths.get(dir), 1)
.iterator
.asScala
.map(_.toString)
.filter(_.endsWith(ext))

case class CompilationUnit(
val primaryInPath: Option[String],
val otherInPaths: Seq[String],
Expand Down
34 changes: 13 additions & 21 deletions src/main/scala/ee/hrzn/chryse/tasks/CxxsimTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.io.PrintWriter
import java.nio.file.Files
import java.nio.file.Paths
import scala.collection.mutable
import scala.jdk.CollectionConverters._
import scala.sys.process._

object CxxsimTask extends BaseTask {
Expand Down Expand Up @@ -116,10 +115,7 @@ object CxxsimTask extends BaseTask {

val cwd = System.getProperty("user.dir")
writePath(s"$buildDir/compile_commands.json") { wr =>
upickle.default.writeTo(
cus.map(cu => ClangdEntry(cwd, cu.primaryInPath.get, cu.cmd)),
wr,
)
upickle.default.writeTo(cus.map(ClangdEntry(_)), wr)
}

runCus("compilation", cus)
Expand Down Expand Up @@ -152,21 +148,17 @@ object CxxsimTask extends BaseTask {
}
}

private def filesInDirWithExt(dir: String, ext: String): Iterator[String] =
Files
.walk(Paths.get(dir), 1)
.iterator
.asScala
.map(_.toString)
.filter(_.endsWith(ext))
}
private case class ClangdEntry(
directory: String,
file: String,
arguments: Seq[String],
)

private case class ClangdEntry(
directory: String,
file: String,
arguments: Seq[String],
)
private object ClangdEntry {
implicit val rw: upickle.default.ReadWriter[ClangdEntry] =
upickle.default.macroRW
private object ClangdEntry {
def apply(cu: CompilationUnit): ClangdEntry =
ClangdEntry(System.getProperty("user.dir"), cu.primaryInPath.get, cu.cmd)

implicit val rw: upickle.default.ReadWriter[ClangdEntry] =
upickle.default.macroRW
}
}

0 comments on commit d88b5d4

Please sign in to comment.