Source code formatting - how to update input files?

48 views
Skip to first unread message

Peter Moore

unread,
Jul 9, 2021, 6:25:01 PM7/9/21
to tup-users

Hi folks,

Is there an idiomatic way to implement a source formatting step in tup? I'm aware that the following type of construction is illegal since a file cannot be both a generated node and a normal file:

: foreach *.s |> asm-format %f |> %f

I see that I could have a wrapper script that moves files before or after tup is called, but that feels suboptimal, so I was wondering if there is a better approach.

Many thanks in advance!
Pete

Mike Shal

unread,
Jul 11, 2021, 5:33:36 PM7/11/21
to tup-...@googlegroups.com
Hi Pete,

I don't think this workflow will work well in tup. I think it would also be fairly confusing even if it did work -- consider if there was an un-formatted file checked into your repo, and someone checks it out and does a build. They would then find files modified in 'git diff' and the like, even though they didn't change anything themselves.

One thing you can do in the build system is to use it as a linter, so it's more of a format-checker rather than a format-rewriter. So you could do something like this:

: foreach *.s |> asm-format --check %f |>

(Assuming asm-format accepts a --check argument and exits with 0 for success and 1 for bad formatting). Note that you don't actually need an output file for this; the command will re-run if any of the inputs change.

The actual re-formatting is likely much better suited for one or both of your editor and/or a version control hook (so all files could be formatted on commit or something).

Hope that helps,
-Mike

Peter Moore

unread,
Jul 11, 2021, 10:53:52 PM7/11/21
to tup-...@googlegroups.com
That makes perfect sense, many thanks Mike!

Reply all
Reply to author
Forward
0 new messages