diff --git a/src/tup/updater.c b/src/tup/updater.c index 70049cdee..80dde8d82 100644 --- a/src/tup/updater.c +++ b/src/tup/updater.c @@ -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: "); diff --git a/test/t8115-variant-output-to-directory.sh b/test/t8115-variant-output-to-directory.sh new file mode 100755 index 000000000..63cbbdb20 --- /dev/null +++ b/test/t8115-variant-output-to-directory.sh @@ -0,0 +1,37 @@ +#! /bin/sh -e +# tup - A file-based build system +# +# Copyright (C) 2024 Mike Shal +# +# 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 diff --git a/test/t8116-variant-output-to-directory2.sh b/test/t8116-variant-output-to-directory2.sh new file mode 100755 index 000000000..f7df71915 --- /dev/null +++ b/test/t8116-variant-output-to-directory2.sh @@ -0,0 +1,35 @@ +#! /bin/sh -e +# tup - A file-based build system +# +# Copyright (C) 2024 Mike Shal +# +# 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