From 901898516278e0d866ce07ff7731661076810f0c Mon Sep 17 00:00:00 2001 From: Mike Shal Date: Sun, 19 May 2024 12:10:06 -0700 Subject: [PATCH] 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. --- src/tup/tup/main.c | 14 +++++++++++++- test/t8048-tup-variants.sh | 4 +++- test/t8049-tup-variants2.sh | 4 +++- test/t8050-tup-variants3.sh | 4 +++- test/t8051-tup-variants4.sh | 1 - test/t8052-tup-variants5.sh | 4 +++- test/t8053-tup-variants6.sh | 4 +++- test/t8054-variant-rmrf2.sh | 1 - test/t8055-variant-rmrf3.sh | 1 - test/t8056-move-variant-monitor.sh | 1 - test/t8057-variant-rmrf4.sh | 2 +- test/t8058-variant-rmrf5.sh | 1 - test/t8061-include-rules.sh | 1 - test/t8062-move-variant-dir.sh | 2 +- test/t8063-move-variant-dir-monitor.sh | 1 - test/t8081-generated-dir.sh | 1 - tup.1 | 4 ++-- 17 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/tup/tup/main.c b/src/tup/tup/main.c index cf5f11d84..b2e32484a 100644 --- a/src/tup/tup/main.c +++ b/src/tup/tup/main.c @@ -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] [ ... ]", "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) 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; } diff --git a/test/t8048-tup-variants.sh b/test/t8048-tup-variants.sh index f1aecd5ff..008b5ea11 100755 --- a/test/t8048-tup-variants.sh +++ b/test/t8048-tup-variants.sh @@ -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 @@ -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 diff --git a/test/t8049-tup-variants2.sh b/test/t8049-tup-variants2.sh index 2a34d20d9..f237fb5c4 100755 --- a/test/t8049-tup-variants2.sh +++ b/test/t8049-tup-variants2.sh @@ -18,7 +18,6 @@ # Use the 'tup variant' command in a sub-directory. . ./tup.sh -check_no_windows tup variant mkdir configs @@ -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 diff --git a/test/t8050-tup-variants3.sh b/test/t8050-tup-variants3.sh index 7921186a2..2cd122684 100755 --- a/test/t8050-tup-variants3.sh +++ b/test/t8050-tup-variants3.sh @@ -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 @@ -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 diff --git a/test/t8051-tup-variants4.sh b/test/t8051-tup-variants4.sh index a6bd31d81..8188bfe1f 100755 --- a/test/t8051-tup-variants4.sh +++ b/test/t8051-tup-variants4.sh @@ -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 diff --git a/test/t8052-tup-variants5.sh b/test/t8052-tup-variants5.sh index 9b604764a..e617ccea5 100755 --- a/test/t8052-tup-variants5.sh +++ b/test/t8052-tup-variants5.sh @@ -18,7 +18,6 @@ # Use the 'tup variant' command on config files without any suffix. . ./tup.sh -check_no_windows tup variant mkdir configs @@ -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 diff --git a/test/t8053-tup-variants6.sh b/test/t8053-tup-variants6.sh index f96af06b7..c8e14f4e6 100755 --- a/test/t8053-tup-variants6.sh +++ b/test/t8053-tup-variants6.sh @@ -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 @@ -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 diff --git a/test/t8054-variant-rmrf2.sh b/test/t8054-variant-rmrf2.sh index a20683089..dcec61159 100755 --- a/test/t8054-variant-rmrf2.sh +++ b/test/t8054-variant-rmrf2.sh @@ -18,7 +18,6 @@ # Try to rm -rf multiple variants. . ./tup.sh -check_no_windows tup variant mkdir sub mkdir configs diff --git a/test/t8055-variant-rmrf3.sh b/test/t8055-variant-rmrf3.sh index d41a8196d..de1a63e3c 100755 --- a/test/t8055-variant-rmrf3.sh +++ b/test/t8055-variant-rmrf3.sh @@ -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 diff --git a/test/t8056-move-variant-monitor.sh b/test/t8056-move-variant-monitor.sh index 906ef7a04..324be114d 100755 --- a/test/t8056-move-variant-monitor.sh +++ b/test/t8056-move-variant-monitor.sh @@ -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 diff --git a/test/t8057-variant-rmrf4.sh b/test/t8057-variant-rmrf4.sh index 07898b7b3..f3be0c681 100755 --- a/test/t8057-variant-rmrf4.sh +++ b/test/t8057-variant-rmrf4.sh @@ -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 diff --git a/test/t8058-variant-rmrf5.sh b/test/t8058-variant-rmrf5.sh index 459256ade..d3e9973f5 100755 --- a/test/t8058-variant-rmrf5.sh +++ b/test/t8058-variant-rmrf5.sh @@ -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 diff --git a/test/t8061-include-rules.sh b/test/t8061-include-rules.sh index c1abdc5c7..7b205eab9 100755 --- a/test/t8061-include-rules.sh +++ b/test/t8061-include-rules.sh @@ -18,7 +18,6 @@ # Use include_rules in a variant Tupfile . ./tup.sh -check_no_windows tup variant mkdir sub mkdir sub/sub2 diff --git a/test/t8062-move-variant-dir.sh b/test/t8062-move-variant-dir.sh index facfef028..6733c0d3b 100755 --- a/test/t8062-move-variant-dir.sh +++ b/test/t8062-move-variant-dir.sh @@ -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 diff --git a/test/t8063-move-variant-dir-monitor.sh b/test/t8063-move-variant-dir-monitor.sh index da414234e..9d0ed7b71 100755 --- a/test/t8063-move-variant-dir-monitor.sh +++ b/test/t8063-move-variant-dir-monitor.sh @@ -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 diff --git a/test/t8081-generated-dir.sh b/test/t8081-generated-dir.sh index 680cdcee6..c8b5104a3 100755 --- a/test/t8081-generated-dir.sh +++ b/test/t8081-generated-dir.sh @@ -18,7 +18,6 @@ # Use a variant with a generated directory. . ./tup.sh -check_no_windows tup variant touch tup.config mkdir a diff --git a/tup.1 b/tup.1 index 850f158a6..eaed9b9d8 100644 --- a/tup.1 +++ b/tup.1 @@ -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 @@ -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/