Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the D %-flag for the dirname. #345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/tup/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,19 @@ static char *tup_printf(struct tupfile *tf, const char *cmd, int cmd_len,
estring_append(&e, nle->base, nle->baselen);
first = 0;
}
} else if(*next == 'D') {
int first = 1;
if(nl->num_entries == 0) {
fprintf(tf->f, "tup error: %%D used in rule pattern and no input files were specified.\n");
return NULL;
}
TAILQ_FOREACH(nle, &nl->entries, list) {
if(!first) {
estring_append(&e, " ", 1);
}
estring_append(&e, nle->path, nle->dirlen + (nle->path[nle->dirlen] == path_sep() ? 1 : 0));
first = 0;
}
} else if(*next == 'B') {
int first = 1;
if(nl->num_entries == 0) {
Expand Down
32 changes: 32 additions & 0 deletions test/t2209-dirname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /bin/sh -e
# tup - A file-based build system
#
# Copyright (C) 2016-2018 Mike Shal <marfey@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Test the %D dirname variable in an output.

. ./tup.sh
cat > Tupfile << HERE
: foreach a.txt d/b.txt d/d/c.txt |> cp %f %o |> %D%B.tst
HERE
mkdir -p d/d
touch a.txt d/b.txt d/d/c.txt
update
tup_object_exist . a.tst
tup_object_exist d b.tst
tup_object_exist d/d c.tst

eotup
3 changes: 3 additions & 0 deletions tup.1
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ The filename from the "inputs" section. This includes the path and extension. Th
.B %b
Like %f, but is just the basename of the file. The directory part is stripped off. For example, "src/foo.c" would become "foo.c"
.TP
.B %D
Like %f, but is just the dirname of the file. The basename is stripped off. For example, "src/foo.c" would become "src/"
.TP
.B %B
Like %b, but strips the extension. This is most useful in converting an input file into an output file of the same name but with a different extension, since the output file needs to be in the same directory. For example, "src/foo.c" would become "foo"
.TP
Expand Down