Skip to content

Commit 9018985

Browse files
committed
Add initial support for the 'tup variant' command on Windows.
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.
1 parent 9d76ded commit 9018985

17 files changed

+32
-18
lines changed

src/tup/tup/main.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static struct help {
6565
{"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."},
6666
{"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."},
6767
{"stop", NULL, "", "Kills the monitor if it is running."},
68-
{"variant", NULL, "foo.config [bar.config] [...]", "For each argument, this command creates a variant directory with tup.config symlinked to the specified config file."},
68+
{"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."},
6969
{"dbconfig", NULL, "", "Displays the current tup database configuration. These are internal values used by tup."},
7070
{"options", NULL, "", "Displays all of the current tup options, as well as where they originated."},
7171
{"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."},
@@ -847,11 +847,23 @@ static int create_variant(const char *config_path)
847847
fprintf(stderr, "tup error: linkdest is too small to fit the tup.config symlink destination.\n");
848848
return -1;
849849
}
850+
#ifdef _WIN32
851+
char srcpath[PATH_MAX];
852+
if(snprintf(srcpath, sizeof(srcpath), "%s/%s", get_sub_dir(), config_path) >= (signed)sizeof(srcpath)) {
853+
fprintf(stderr, "tup error: srcpath is too small to fit the tup.config source path.\n");
854+
return -1;
855+
}
856+
if(CopyFileA(srcpath, linkdest, TRUE) == 0) {
857+
fprintf(stderr, "tup error: Unable to copy the config file %s to destination: %s\n", srcpath, linkdest);
858+
return -1;
859+
}
860+
#else
850861
if(symlink(linkpath, linkdest) < 0) {
851862
perror(linkdest);
852863
fprintf(stderr, "tup error: Unable to create tup.config symlink for config file: %s\n", config_path);
853864
return -1;
854865
}
866+
#endif
855867
printf("tup: Added variant '%s' using config file '%s'\n", dirname, config_path);
856868
return 0;
857869
}

test/t8048-tup-variants.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# Use the 'tup variant' command to create variants from existing config files.
2020
. ./tup.sh
21-
check_no_windows tup variant
2221

2322
mkdir configs
2423

@@ -43,6 +42,9 @@ tup_object_no_exist build-default build-debug
4342
tup_object_no_exist build-debug build-default
4443

4544
echo "" > configs/debug.config
45+
if [ "$in_windows" = "1" ]; then
46+
cp configs/debug.config build-debug/tup.config
47+
fi
4648
update
4749

4850
check_exist build-default/bar

test/t8049-tup-variants2.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

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

2322
mkdir configs
2423

@@ -45,6 +44,9 @@ tup_object_no_exist build-default build-debug
4544
tup_object_no_exist build-debug build-default
4645

4746
echo "" > configs/debug.config
47+
if [ "$in_windows" = "1" ]; then
48+
cp configs/debug.config build-debug/tup.config
49+
fi
4850
update
4951

5052
check_exist build-default/bar

test/t8050-tup-variants3.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# Use the 'tup variant' command when a variant directory already exists.
2020
. ./tup.sh
21-
check_no_windows tup variant
2221

2322
mkdir build-debug
2423
mkdir configs
@@ -44,6 +43,9 @@ tup_object_no_exist build-default build-debug
4443
tup_object_no_exist build-debug build-default
4544

4645
echo "" > configs/debug.config
46+
if [ "$in_windows" = "1" ]; then
47+
cp configs/debug.config build-debug/tup.config
48+
fi
4749
update
4850

4951
check_exist build-default/bar

test/t8051-tup-variants4.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# Use the 'tup variant' command when a variant directory already exists and
2020
# is not empty..
2121
. ./tup.sh
22-
check_no_windows tup variant
2322

2423
mkdir build-debug
2524
mkdir configs

test/t8052-tup-variants5.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# Use the 'tup variant' command on config files without any suffix.
2020
. ./tup.sh
21-
check_no_windows tup variant
2221

2322
mkdir configs
2423

@@ -43,6 +42,9 @@ tup_object_no_exist build-default build-debug
4342
tup_object_no_exist build-debug build-default
4443

4544
echo "" > configs/debug
45+
if [ "$in_windows" = "1" ]; then
46+
cp configs/debug build-debug/tup.config
47+
fi
4648
update
4749

4850
check_exist build-default/bar

test/t8053-tup-variants6.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# Use the 'tup variant' command on config files further down in the
2020
# directory structure.
2121
. ./tup.sh
22-
check_no_windows tup variant
2322

2423
mkdir sub
2524
mkdir sub/foo
@@ -48,6 +47,9 @@ tup_object_no_exist build-default build-debug
4847
tup_object_no_exist build-debug build-default
4948

5049
echo "" > sub/foo/configs/debug
50+
if [ "$in_windows" = "1" ]; then
51+
cp sub/foo/configs/debug build-debug/tup.config
52+
fi
5153
update
5254

5355
check_exist build-default/bar

test/t8054-variant-rmrf2.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# Try to rm -rf multiple variants.
2020
. ./tup.sh
21-
check_no_windows tup variant
2221

2322
mkdir sub
2423
mkdir configs

test/t8055-variant-rmrf3.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# Make sure that if we just scan the removal of a variant and re-create it, things
2020
# still work.
2121
. ./tup.sh
22-
check_no_windows tup variant
2322

2423
mkdir sub
2524
mkdir configs

test/t8056-move-variant-monitor.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# Move a variant directory outside of the tup hierarchy with the monitor watching.
2020
. ./tup.sh
21-
check_no_windows tup variant
2221
check_monitor_supported
2322

2423
mkdir tuptest

0 commit comments

Comments
 (0)