tup icon indicating copy to clipboard operation
tup copied to clipboard

Add the D %-flag for the dirname.

Open vicencb opened this issue 7 years ago • 8 comments

%D (dirname) is the counterpart of %b (basename) It is useful for recreating the source directory structure inside the build directory.

vicencb avatar Feb 25 '18 22:02 vicencb

Thanks for adding this! I'm curious what use-case you have that needs this flag? Also, do you mind signing the CLA since this adds new functionality?

gittup avatar Feb 27 '18 17:02 gittup

Hi for the use case, consider the following Tupfile:

# There can be several files with the same basename.
SOURCES+=src/dir1/*.c
SOURCES+=src/dir2/*.c
SOURCES+=src/dir2/dir3/*.c
SOURCES+=src/*.c

# Put all autogenerated files in the obj directory.

# This will not work, because several object files with the same basename will overwrite each other.
# foreach $(SOURCES) |> cc -c %f -o %o |> obj/%B.o {obj}

# With %D the same directory structure found in src will be inside obj.
: foreach $(SOURCES) |> cc -c %f -o %o |> obj/%D%B.o {obj}

: {obj} |> cc %f -o %o |> obj/program

For the CLA, I have read https://github.com/gittup/tup/blob/master/CONTRIBUTING.md but that page is not convincing me to sign anything. Could you expand that page to try to convince potential contributors into signing it? Some information I would like to see in that page:

  1. Why do you want contributors to sign it?
  2. Why a contributor is requested all that information? (e-mail address, personal address, ...)
  3. If my contribution is placed in the public domain, do I need to sign the CLA?

Regards,   Vicenç.

vicencb avatar Feb 27 '18 18:02 vicencb

Hello, I have found http://gittup.org/tup/license.html which answers point no. 1. A link could be added in CONTRIBUTING.md. Please, can you answer 2 and 3? I am specially interested in 3.

Regards,   Vicenç.

vicencb avatar Mar 12 '18 20:03 vicencb

I'm also needing this for the same reason. I am transpiling a directory tree of files to another destination directory and want to keep the directory structure intact. The two solutions I see are

app/*.moon app/nested/*.moon |> moonc -o %o %f |> %D%B.lua

app/*.moon app/nested/*.moon |> moonc -o %o %f |> %F.lua

where %F would be the whole path with the extension stripped (like %B is to %b).

Also bump since it seems like this perhaps got lost @gittup

s-ol avatar Oct 19 '18 03:10 s-ol

It looks like this isn't going to be added? I also need this :'(

@gittup is there any chance this feature be implemented?

danielytics avatar Oct 28 '20 21:10 danielytics

It looks like this isn't going to be added? I also need this :'(

@gittup is there any chance this feature be implemented?

Hi @danielytics, can you clarify what your use-case is? The initial suggestion of using it to re-create the source hierarchy inside a build directory would already be automatically handled by variants. Can you give an example Tupfile of what you're wanting to do?

gittup avatar Oct 29 '20 20:10 gittup

I guess I'm just trying to simplify the Tupfile for the case when the sources are spread between subdirectories (which I often do to keep large sources easier to manage) and I'm trying to figure out how to keep my Tupfile small and simple. Ideally, it would support both recursive directory globbing as well as this feature to really work though... But maybe I'm missing something and there's a simpler way?

Right now, I have a Tupfile that looks something like this:

: foreach src/*.cpp |> !compile-c++  |> build/B.o
: foreach src/core/*.cpp |> !compile-c++ |> build/core_%B.o
: foreach src/utils/*.cpp |> !compile-c++ |> build/utils_%B.o
# ...
: build/*.o |> !link-exe |> ../prog

It works, but its not ideal as I have to manually enumerate all subdirectories and then either prefix the object files, or again enumerate the subdirectories in the inputs for the link step.

EDIT: Ok, I'm still learning tup, but I guess as long as I restrict it to one level of nesting, I can do this:

:foreach src/foo/*.cpp |> !compile-c++ |> build/%d_%B.o
:foreach src/bar/*.cpp |> !compile-c++ |> build/%d_%B.o

danielytics avatar Oct 29 '20 20:10 danielytics

Ah, apologies @gittup for the noise. I think I can accomplish more or less what I want, using %d to name the outputs and groups as inputs so I don't need to list directories more than once. I guess I didn't understand tup's capabilities well enough, but after rereading the docs a few times, I think I've got it.

danielytics avatar Nov 01 '20 21:11 danielytics