tup icon indicating copy to clipboard operation
tup copied to clipboard

Feature: Provide named targets with variables (aka functions)

Open DarkTrick opened this issue 3 years ago • 2 comments

Allow for targets like in make, but also allow usage of variables

I imagine something like this:

copy_files (build_level):
   foreach src/* |> cp %f %o |> $(build_level)/%b

release:
  copy_files(release)

debug:
  copy_files(debug)

Benefits

Allows more flexible build scripts and better support for DRY within the build scripts

DarkTrick avatar Feb 17 '22 02:02 DarkTrick

Although it's not a function, you might be able to do what you want here with !macros (see the man page under TUPFILES, !macro). In a Tuprules.tup file you could define the macro like so:

build_level = ...
!copy_files = |> cp %f %o |> $(build_level)/%b

And in a Tupfile:

include_rules
: foreach *.txt |> !copy_files |>

You might also be interested in using the Tupfile.lua parser, since with lua you can use actual functions.

gittup avatar Feb 19 '22 19:02 gittup

Thank you for the reply!

  • Nice idea! But this doesn't work for more complex examples and variables that are changing for each call.
  • I will take a look at at Tupfile.lua. Maybe it solves the problem.

DarkTrick avatar Feb 20 '22 00:02 DarkTrick