summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2022-08-31 13:41:42 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2022-08-31 14:13:32 (GMT)
commit215b9148eb0841224496e55f993b9ad7da55101e (patch)
treef9ecb25dbbfb75912017c2ea29e39ac4f2710218
parent8bcc84283edff63d65a4f7364be0da927b8b8987 (diff)
downloadCMake-215b9148eb0841224496e55f993b9ad7da55101e.zip
CMake-215b9148eb0841224496e55f993b9ad7da55101e.tar.gz
CMake-215b9148eb0841224496e55f993b9ad7da55101e.tar.bz2
CMakePresets.json: Fix formatting of --list-presets=all
Only print an extra newline after a section if that section was actually printed.
-rw-r--r--Source/cmCMakePresetsGraph.cxx37
-rw-r--r--Source/cmCMakePresetsGraph.h17
-rw-r--r--Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild-stdout.txt8
-rw-r--r--Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild.json.in14
-rw-r--r--Tests/RunCMake/CMakePresets/ListAllPresetsNoTest-stdout.txt8
-rw-r--r--Tests/RunCMake/CMakePresets/ListAllPresetsNoTest.json.in14
-rw-r--r--Tests/RunCMake/CMakePresets/RunCMakeTest.cmake6
7 files changed, 90 insertions, 14 deletions
diff --git a/Source/cmCMakePresetsGraph.cxx b/Source/cmCMakePresetsGraph.cxx
index dba79d5..c64c633 100644
--- a/Source/cmCMakePresetsGraph.cxx
+++ b/Source/cmCMakePresetsGraph.cxx
@@ -1067,6 +1067,16 @@ void cmCMakePresetsGraph::ClearPresets()
this->Files.clear();
}
+void cmCMakePresetsGraph::printPrecedingNewline(PrintPrecedingNewline* newline)
+{
+ if (newline) {
+ if (*newline == PrintPrecedingNewline::True) {
+ std::cout << std::endl;
+ }
+ *newline = PrintPrecedingNewline::True;
+ }
+}
+
void cmCMakePresetsGraph::PrintPresets(
const std::vector<const cmCMakePresetsGraph::Preset*>& presets)
{
@@ -1095,13 +1105,16 @@ void cmCMakePresetsGraph::PrintPresets(
}
}
-void cmCMakePresetsGraph::PrintConfigurePresetList() const
+void cmCMakePresetsGraph::PrintConfigurePresetList(
+ PrintPrecedingNewline* newline) const
{
- PrintConfigurePresetList([](const ConfigurePreset&) { return true; });
+ PrintConfigurePresetList([](const ConfigurePreset&) { return true; },
+ newline);
}
void cmCMakePresetsGraph::PrintConfigurePresetList(
- const std::function<bool(const ConfigurePreset&)>& filter) const
+ const std::function<bool(const ConfigurePreset&)>& filter,
+ PrintPrecedingNewline* newline) const
{
std::vector<const cmCMakePresetsGraph::Preset*> presets;
for (auto const& p : this->ConfigurePresetOrder) {
@@ -1114,12 +1127,14 @@ void cmCMakePresetsGraph::PrintConfigurePresetList(
}
if (!presets.empty()) {
+ printPrecedingNewline(newline);
std::cout << "Available configure presets:\n\n";
cmCMakePresetsGraph::PrintPresets(presets);
}
}
-void cmCMakePresetsGraph::PrintBuildPresetList() const
+void cmCMakePresetsGraph::PrintBuildPresetList(
+ PrintPrecedingNewline* newline) const
{
std::vector<const cmCMakePresetsGraph::Preset*> presets;
for (auto const& p : this->BuildPresetOrder) {
@@ -1132,12 +1147,14 @@ void cmCMakePresetsGraph::PrintBuildPresetList() const
}
if (!presets.empty()) {
+ printPrecedingNewline(newline);
std::cout << "Available build presets:\n\n";
cmCMakePresetsGraph::PrintPresets(presets);
}
}
-void cmCMakePresetsGraph::PrintTestPresetList() const
+void cmCMakePresetsGraph::PrintTestPresetList(
+ PrintPrecedingNewline* newline) const
{
std::vector<const cmCMakePresetsGraph::Preset*> presets;
for (auto const& p : this->TestPresetOrder) {
@@ -1150,6 +1167,7 @@ void cmCMakePresetsGraph::PrintTestPresetList() const
}
if (!presets.empty()) {
+ printPrecedingNewline(newline);
std::cout << "Available test presets:\n\n";
cmCMakePresetsGraph::PrintPresets(presets);
}
@@ -1157,9 +1175,8 @@ void cmCMakePresetsGraph::PrintTestPresetList() const
void cmCMakePresetsGraph::PrintAllPresets() const
{
- this->PrintConfigurePresetList();
- std::cout << std::endl;
- this->PrintBuildPresetList();
- std::cout << std::endl;
- this->PrintTestPresetList();
+ PrintPrecedingNewline newline = PrintPrecedingNewline::False;
+ this->PrintConfigurePresetList(&newline);
+ this->PrintBuildPresetList(&newline);
+ this->PrintTestPresetList(&newline);
}
diff --git a/Source/cmCMakePresetsGraph.h b/Source/cmCMakePresetsGraph.h
index 4f3e108..efedc5b4 100644
--- a/Source/cmCMakePresetsGraph.h
+++ b/Source/cmCMakePresetsGraph.h
@@ -383,13 +383,22 @@ public:
return "";
}
+ enum class PrintPrecedingNewline
+ {
+ False,
+ True,
+ };
+ static void printPrecedingNewline(PrintPrecedingNewline* p);
+
static void PrintPresets(
const std::vector<const cmCMakePresetsGraph::Preset*>& presets);
- void PrintConfigurePresetList() const;
void PrintConfigurePresetList(
- const std::function<bool(const ConfigurePreset&)>& filter) const;
- void PrintBuildPresetList() const;
- void PrintTestPresetList() const;
+ PrintPrecedingNewline* newline = nullptr) const;
+ void PrintConfigurePresetList(
+ const std::function<bool(const ConfigurePreset&)>& filter,
+ PrintPrecedingNewline* newline = nullptr) const;
+ void PrintBuildPresetList(PrintPrecedingNewline* newline = nullptr) const;
+ void PrintTestPresetList(PrintPrecedingNewline* newline = nullptr) const;
void PrintAllPresets() const;
private:
diff --git a/Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild-stdout.txt b/Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild-stdout.txt
new file mode 100644
index 0000000..38f52aa
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild-stdout.txt
@@ -0,0 +1,8 @@
+^Not searching for unused variables given on the command line.
+Available configure presets:
+
+ "default"
+
+Available test presets:
+
+ "default"$
diff --git a/Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild.json.in b/Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild.json.in
new file mode 100644
index 0000000..9259477
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/ListAllPresetsNoBuild.json.in
@@ -0,0 +1,14 @@
+{
+ "version": 3,
+ "configurePresets": [
+ {
+ "name": "default"
+ }
+ ],
+ "testPresets": [
+ {
+ "name": "default",
+ "configurePreset": "default"
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/ListAllPresetsNoTest-stdout.txt b/Tests/RunCMake/CMakePresets/ListAllPresetsNoTest-stdout.txt
new file mode 100644
index 0000000..8cac0a8
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/ListAllPresetsNoTest-stdout.txt
@@ -0,0 +1,8 @@
+^Not searching for unused variables given on the command line.
+Available configure presets:
+
+ "default"
+
+Available build presets:
+
+ "default"$
diff --git a/Tests/RunCMake/CMakePresets/ListAllPresetsNoTest.json.in b/Tests/RunCMake/CMakePresets/ListAllPresetsNoTest.json.in
new file mode 100644
index 0000000..33fd036
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/ListAllPresetsNoTest.json.in
@@ -0,0 +1,14 @@
+{
+ "version": 3,
+ "configurePresets": [
+ {
+ "name": "default"
+ }
+ ],
+ "buildPresets": [
+ {
+ "name": "default",
+ "configurePreset": "default"
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
index d097086..c511b34 100644
--- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
@@ -304,6 +304,12 @@ unset(RunCMake_TEST_BINARY_DIR)
run_cmake_presets(ListPresetsNoSuchPreset)
run_cmake_presets(ListPresetsHidden)
+set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/ListAllPresetsNoBuild.json.in")
+run_cmake_presets(ListAllPresetsNoBuild --list-presets=all)
+
+set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/ListAllPresetsNoTest.json.in")
+run_cmake_presets(ListAllPresetsNoTest --list-presets=all)
+
# Test warning and error flags
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Warnings.json.in")
set(CMakePresets_WARN_UNUSED_CLI 1)