Skip to content

Commit

Permalink
Added t8115, t8116 - tests for things in variants becoming directories.
Browse files Browse the repository at this point in the history
If we have a generated file that is built in a variant directory, and
later the user creates a directory of the same name of the generated
file, we have to remove the generated file in the variant directory
before trying to parse it. Similarly, t8116 tests the case where there
is a generated directory in the variant and then becomes a real
directory.
  • Loading branch information
gittup committed Mar 18, 2024
1 parent 7a40538 commit 5b932ec
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/tup/updater.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,32 @@ static struct tup_entry *get_rel_tent(struct tup_entry *base, struct tup_entry *
if(!new)
return NULL;

if(tup_db_select_tent(new, tent->name.s, &sub) < 0)
return NULL;
if(sub) {
if(sub->type == TUP_NODE_GENERATED) {
/* If we have a generated file in the variant that is
* now a directory, we need to force deleting that
* output now so we can create the directory there
* (t8115).
*/
if(delete_file(sub) < 0)
return NULL;
if(tup_del_id_force(sub->tnode.tupid, sub->type) < 0)
return NULL;
} else if(sub->type == TUP_NODE_GENERATED_DIR) {
/* If we have a generated output dir inside the
* variant, just set its type to TUP_NODE_DIR since
* that won't happen in tup_db_create_node_srcid()
* below because of some logic to avoid changing
* generated dir types during the scanning phase
* (t8116).
*/
if(tup_db_set_type(sub, TUP_NODE_DIR) < 0)
return NULL;
}
}

sub = tup_db_create_node_srcid(new, tent->name.s, TUP_NODE_DIR, tent->tnode.tupid, &do_mkdir);
if(!sub) {
fprintf(stderr, "tup error: Unable to create tup node for variant directory: ");
Expand Down
37 changes: 37 additions & 0 deletions test/t8115-variant-output-to-directory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /bin/sh -e
# tup - A file-based build system
#
# Copyright (C) 2024 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.

# Have a variant output filename that then becomes a directory in the srcdir.
# The output should be removed in the variant location and be re-created as a
# directory.
. ./tup.sh

cat > Tupfile << HERE
: |> gcc -c hello.c -o %o |> hello
HERE
mkdir build
touch build/tup.config hello.c
update

mkdir hello
mv Tupfile hello.c hello
update

check_exist build/hello/hello

eotup
35 changes: 35 additions & 0 deletions test/t8116-variant-output-to-directory2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /bin/sh -e
# tup - A file-based build system
#
# Copyright (C) 2024 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.

# Like t8115, but we have a generated directory in the variant.
. ./tup.sh

cat > Tupfile << HERE
: |> gcc -c hello.c -o %o |> hello/out
HERE
mkdir build
touch build/tup.config hello.c
update

mkdir hello
mv Tupfile hello.c hello
update

check_exist build/hello/hello/out

eotup

0 comments on commit 5b932ec

Please sign in to comment.