Mill/ , register a function f: *.a > *.b

In mill/, what is the simplest way to register a function f: String → String with the following property:

  1. some file matching regex src/.*\.a is modified, say src/blah-blah.a
  2. then we do src/blah-blah.b = f(src/blah-blah.a)

So basically we want to register function so that any file of the form *.a is updated, it auto runs and it’s output is put in *.b

I suggest you ask this in Mill’s gitter channel or GitHub’s discussion forum.

Sadly Mill doesn’t have yet something built in to do this.
Implemented something similar in this video where I use a Map in memory to store the file -> hash relationship. If you want to make it persist between different runs of Mill you need to use a file inside the T.dest.ctx to store those informations.

1 Like

I am not convinced we have the same problem in mind. I am not looking for an in memory cache. I need watch to trigger a function to be called whenever a file of *.a extension is written.

Did you watch the video? It is about running a command whenever some files change. Seems to fit your case pretty good. Start the video at 6:30, this is where it gets interesting.

1 Like

Yes, I learned how to do it while doing the video, that’s why the solution came so late.
Sorry for that :smiley:

@zeroexcuses We’re solving the same problem. The Map thing I wrote in the previous message is a detail you can ignore at first.

I am sure you guys are right. But I thought one of the key points in Mill’s design was to only recompute tasks when their inputs have changed. So that sounds like—in theory at least—it should actually fit this use case really well.

1 Like

This is correct. Mill creates a hash for all output. When the input of any path within the dependency graph changes, all nodes are processed as required.

Some time ago I did this when working on code that generated Scala code based on Ploty’s JSON specs (that was a flop). So I know this is possible, but I cannot find the code nor the references (?@#$!!). So I believe Gitter channel or Github’s discussion will help.

@cbley @lolgab : I stand corrected. Thanks for sharing the informative link!