Skip to content

Commit

Permalink
Add initial support for the 'tup variant' command on Windows.
Browse files Browse the repository at this point in the history
On other OSes, the 'tup variant' command creates a symlink to the config
files, but since that doesn't work easily on Windows we just copy the
file instead. We have to calculate a slightly different path to make
that work, and adjust the test cases to account for the fact that the
variant won't be updated when the source config file is modified.
  • Loading branch information
gittup committed May 19, 2024
1 parent 9d76ded commit 9018985
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 18 deletions.
14 changes: 13 additions & 1 deletion src/tup/tup/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static struct help {
{"refactor", "ref", "", "The refactor command can be used to help refactor Tupfiles. This will cause tup to run through the parsing phase, but not execute any commands. If any Tupfiles that are parsed result in changes to the database, these are reported as errors."},
{"monitor", NULL, "", "*LINUX ONLY* Starts the inotify-based file monitor. The monitor must scan the filesystem once and initialize watches on each directory. Then when you make changes to the files, the monitor will see them and write them directly into the database. With the monitor running, 'tup' does not need to do the initial scan, and can start constructing the build graph immediately."},
{"stop", NULL, "", "Kills the monitor if it is running."},
{"variant", NULL, "foo.config [bar.config] [...]", "For each argument, this command creates a variant directory with tup.config symlinked to the specified config file."},
{"variant", NULL, "foo.config [bar.config] [...]", "For each argument, this command creates a variant directory with tup.config symlinked (Windows: copied) to the specified config file."},
{"dbconfig", NULL, "", "Displays the current tup database configuration. These are internal values used by tup."},
{"options", NULL, "", "Displays all of the current tup options, as well as where they originated."},
{"graph", NULL, "[--dirs] [--ghosts] [--env] [--combine] [--stickies] [<output_1> ... <output_n>]", "Prints out a graphviz .dot format graph of the tup database to stdout. By default it only displays the parts of the graph that have changes. If you provide additional arguments, they are assumed to be files that you want to graph."},
Expand Down Expand Up @@ -847,11 +847,23 @@ static int create_variant(const char *config_path)
fprintf(stderr, "tup error: linkdest is too small to fit the tup.config symlink destination.\n");
return -1;
}
#ifdef _WIN32
char srcpath[PATH_MAX];
if(snprintf(srcpath, sizeof(srcpath), "%s/%s", get_sub_dir(), config_path) >= (signed)sizeof(srcpath)) {
fprintf(stderr, "tup error: srcpath is too small to fit the tup.config source path.\n");
return -1;
}
if(CopyFileA(srcpath, linkdest, TRUE) == 0) {
fprintf(stderr, "tup error: Unable to copy the config file %s to destination: %s\n", srcpath, linkdest);
return -1;
}
#else
if(symlink(linkpath, linkdest) < 0) {
perror(linkdest);
fprintf(stderr, "tup error: Unable to create tup.config symlink for config file: %s\n", config_path);
return -1;
}
#endif
printf("tup: Added variant '%s' using config file '%s'\n", dirname, config_path);
return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion test/t8048-tup-variants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Use the 'tup variant' command to create variants from existing config files.
. ./tup.sh
check_no_windows tup variant

mkdir configs

Expand All @@ -43,6 +42,9 @@ tup_object_no_exist build-default build-debug
tup_object_no_exist build-debug build-default

echo "" > configs/debug.config
if [ "$in_windows" = "1" ]; then
cp configs/debug.config build-debug/tup.config
fi
update

check_exist build-default/bar
Expand Down
4 changes: 3 additions & 1 deletion test/t8049-tup-variants2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Use the 'tup variant' command in a sub-directory.
. ./tup.sh
check_no_windows tup variant

mkdir configs

Expand All @@ -45,6 +44,9 @@ tup_object_no_exist build-default build-debug
tup_object_no_exist build-debug build-default

echo "" > configs/debug.config
if [ "$in_windows" = "1" ]; then
cp configs/debug.config build-debug/tup.config
fi
update

check_exist build-default/bar
Expand Down
4 changes: 3 additions & 1 deletion test/t8050-tup-variants3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Use the 'tup variant' command when a variant directory already exists.
. ./tup.sh
check_no_windows tup variant

mkdir build-debug
mkdir configs
Expand All @@ -44,6 +43,9 @@ tup_object_no_exist build-default build-debug
tup_object_no_exist build-debug build-default

echo "" > configs/debug.config
if [ "$in_windows" = "1" ]; then
cp configs/debug.config build-debug/tup.config
fi
update

check_exist build-default/bar
Expand Down
1 change: 0 additions & 1 deletion test/t8051-tup-variants4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Use the 'tup variant' command when a variant directory already exists and
# is not empty..
. ./tup.sh
check_no_windows tup variant

mkdir build-debug
mkdir configs
Expand Down
4 changes: 3 additions & 1 deletion test/t8052-tup-variants5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Use the 'tup variant' command on config files without any suffix.
. ./tup.sh
check_no_windows tup variant

mkdir configs

Expand All @@ -43,6 +42,9 @@ tup_object_no_exist build-default build-debug
tup_object_no_exist build-debug build-default

echo "" > configs/debug
if [ "$in_windows" = "1" ]; then
cp configs/debug build-debug/tup.config
fi
update

check_exist build-default/bar
Expand Down
4 changes: 3 additions & 1 deletion test/t8053-tup-variants6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Use the 'tup variant' command on config files further down in the
# directory structure.
. ./tup.sh
check_no_windows tup variant

mkdir sub
mkdir sub/foo
Expand Down Expand Up @@ -48,6 +47,9 @@ tup_object_no_exist build-default build-debug
tup_object_no_exist build-debug build-default

echo "" > sub/foo/configs/debug
if [ "$in_windows" = "1" ]; then
cp sub/foo/configs/debug build-debug/tup.config
fi
update

check_exist build-default/bar
Expand Down
1 change: 0 additions & 1 deletion test/t8054-variant-rmrf2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Try to rm -rf multiple variants.
. ./tup.sh
check_no_windows tup variant

mkdir sub
mkdir configs
Expand Down
1 change: 0 additions & 1 deletion test/t8055-variant-rmrf3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Make sure that if we just scan the removal of a variant and re-create it, things
# still work.
. ./tup.sh
check_no_windows tup variant

mkdir sub
mkdir configs
Expand Down
1 change: 0 additions & 1 deletion test/t8056-move-variant-monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Move a variant directory outside of the tup hierarchy with the monitor watching.
. ./tup.sh
check_no_windows tup variant
check_monitor_supported

mkdir tuptest
Expand Down
2 changes: 1 addition & 1 deletion test/t8057-variant-rmrf4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Make sure that if we just scan the removal of a variant and re-create it with
# a different symlink.
. ./tup.sh
check_no_windows tup variant
check_no_windows symlink

mkdir sub
mkdir configs
Expand Down
1 change: 0 additions & 1 deletion test/t8058-variant-rmrf5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Make sure that if we just scan the removal of a variant, re-create it and
# scan, then remove it again and update, we go back to an in-tree build.
. ./tup.sh
check_no_windows tup variant

mkdir sub
mkdir configs
Expand Down
1 change: 0 additions & 1 deletion test/t8061-include-rules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Use include_rules in a variant Tupfile
. ./tup.sh
check_no_windows tup variant

mkdir sub
mkdir sub/sub2
Expand Down
2 changes: 1 addition & 1 deletion test/t8062-move-variant-dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

# Move a variant directory to the src tree.
. ./tup.sh
check_no_windows tup variant
check_no_windows tup.config not a symlink

mkdir sub
mkdir configs
Expand Down
1 change: 0 additions & 1 deletion test/t8063-move-variant-dir-monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Move a variant directory to the src tree with the monitor running.
. ./tup.sh
check_no_windows tup variant
check_monitor_supported

monitor
Expand Down
1 change: 0 additions & 1 deletion test/t8081-generated-dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

# Use a variant with a generated directory.
. ./tup.sh
check_no_windows tup variant

touch tup.config
mkdir a
Expand Down
4 changes: 2 additions & 2 deletions tup.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "tup" "1" "2024/05/18" "http://gittup.org/tup" "tup manual"
.TH "tup" "1" "2024/05/19" "http://gittup.org/tup" "tup manual"
.\" disable hyphenation/justification
.nh
.ad l
Expand Down Expand Up @@ -142,7 +142,7 @@ Temporarily override the monitor.autoparse option to 0. This will prevent the mo
Kills the monitor if it is running. Basically it saves you the trouble of looking up the PID and killing it that way.
.TP
.B variant foo.config [bar.config] [...]
For each argument, this command creates a variant directory with tup.config symlinked to the specified config file. For example, if a directory contained several variant configurations, one could easily create a variant for each config file:
For each argument, this command creates a variant directory with tup.config symlinked (Windows: copied) to the specified config file. For example, if a directory contained several variant configurations, one could easily create a variant for each config file:

.nf
$ ls configs/
Expand Down

0 comments on commit 9018985

Please sign in to comment.