Skip to content

How to modify source files? #2750

Answered by lefou
jatcwang asked this question in Q&A
Sep 18, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

As Mill is all about caching and avoiding unnecessary work, you will likely want to implement it as a target, not as command. I you want to edit your sources, you need to depend on the sources target.

def updateHeaders1: T[Seq[PathRef]] = T {
  val changed = for {
    file <- Lib.findSourceFiles(sources(), Seq("scala"))
  } yield editFile(file)
  changed.map(PathRef(_))
}

As we changed the files, a next invokation of updateHeaders1 will re-run. To avoid that, we could use a persistent target, remember the checksums of the edited files and only act on changed files.

def updateHeaders2: T[Seq[PathRef]] = T.persistent {
  val previous: Map[os.Path, PathRef] = 
    upickle.default.read[Seq[Pa…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lefou
Comment options

@jatcwang
Comment options

Answer selected by jatcwang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants