Skip to content

Commit 3f58fa2

Browse files
Adding ability to run commands for different situations
1 parent 1e39a6b commit 3f58fa2

File tree

8 files changed

+554
-100
lines changed

8 files changed

+554
-100
lines changed

DefaultYAMLs/DefaultScriptInfo.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ Defines:
6767
- "EXAMPLE_DEFINE" # Define without a value
6868
- "VERSION_MAJOR=1" # Define with a value
6969

70+
# (Optional) Setup commands are run once before the script is first built.
71+
# These commands are run at the script's location when no build directory exists.
72+
Setup:
73+
# Target Platform (DefaultPlatform, Windows, Linux, MacOS, or Unix)
74+
DefaultPlatform:
75+
# Profile name (e.g., "g++", "clang++", "msvc", or "DefaultProfile" for any profile)
76+
DefaultProfile:
77+
# List of setup commands
78+
- "echo Setting up script..."
79+
80+
# (Optional) PreBuild commands are run before each build.
81+
# These commands are run in the build directory before compilation starts.
82+
PreBuild:
83+
# Target Platform
84+
DefaultPlatform:
85+
# Profile name
86+
DefaultProfile:
87+
- "echo Starting build..."
88+
89+
# (Optional) PostBuild commands are run after each successful build.
90+
# These commands are run in the output directory where binaries are located.
91+
PostBuild:
92+
# Target Platform
93+
DefaultPlatform:
94+
# Profile name
95+
DefaultProfile:
96+
- "echo Build completed..."
97+
98+
# (Optional) Cleanup commands are run when using the --cleanup option.
99+
# These commands are run at the script's location before the build directory is removed.
100+
Cleanup:
101+
# Target Platform
102+
DefaultPlatform:
103+
# Profile name
104+
DefaultProfile:
105+
- "echo Cleaning up script..."
106+
70107
# (Optional) The list of dependencies needed by the script
71108
Dependencies:
72109
# Dependency name

Examples/test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,38 @@ PassScriptPath: true
2222
# Turns into `TEST_DEF=\"Test Define Working\"` in shell
2323
DefaultProfile: ["TEST_DEF=\\\"Test Define Working\\\""]
2424
25+
Setup:
26+
Unix:
27+
DefaultProfile:
28+
- "echo Setting up script... in $PWD"
29+
Windows:
30+
DefaultProfile:
31+
- "echo Setting up script... in %cd%"
32+
33+
PreBuild:
34+
Unix:
35+
DefaultProfile:
36+
- "echo Starting build... in $PWD"
37+
Windows:
38+
DefaultProfile:
39+
- "echo Starting build... in %cd%"
40+
41+
PostBuild:
42+
Unix:
43+
DefaultProfile:
44+
- "echo Build completed... in $PWD"
45+
Windows:
46+
DefaultProfile:
47+
- "echo Build completed... in %cd%"
48+
49+
Cleanup:
50+
Unix:
51+
DefaultProfile:
52+
- "echo Cleaning up script... in $PWD"
53+
Windows:
54+
DefaultProfile:
55+
- "echo Cleaning up script... in %cd%"
56+
2557
Dependencies:
2658
- Name: ssLogger
2759
Platforms: [Windows, Linux, MacOS]

Include/runcpp2/Data/ScriptInfo.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "runcpp2/Data/ParseCommon.hpp"
77
#include "runcpp2/Data/ProfilesCompilesFiles.hpp"
88
#include "runcpp2/Data/ProfilesDefines.hpp"
9+
#include "runcpp2/Data/ProfilesCommands.hpp"
910

1011
#include <string>
1112
#include <vector>
@@ -31,6 +32,11 @@ namespace runcpp2
3132

3233
std::unordered_map<PlatformName, ProfilesDefines> Defines;
3334

35+
std::unordered_map<PlatformName, ProfilesCommands> Setup;
36+
std::unordered_map<PlatformName, ProfilesCommands> PreBuild;
37+
std::unordered_map<PlatformName, ProfilesCommands> PostBuild;
38+
std::unordered_map<PlatformName, ProfilesCommands> Cleanup;
39+
3440
bool Populated = false;
3541

3642
bool ParseYAML_Node(ryml::ConstNodeRef& node);

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace runcpp2
2525
VERSION,
2626
LOG_LEVEL,
2727
CONFIG_FILE,
28+
CLEANUP,
2829
COUNT
2930
};
3031

Src/Tests/Data/ScriptInfoTest.cpp

Lines changed: 118 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,49 @@ int main(int argc, char** argv)
3737
MSVC:
3838
- src/extra.cpp
3939
- src/debug.cpp
40+
Defines:
41+
Windows:
42+
MSVC:
43+
- _DEBUG
44+
- VERSION=1.0.0
45+
GCC:
46+
- NDEBUG
47+
Setup:
48+
Windows:
49+
MSVC:
50+
- echo 1
51+
- echo 2
52+
Unix:
53+
GCC:
54+
- echo 3
55+
- echo 4
56+
PreBuild:
57+
Windows:
58+
MSVC:
59+
- echo 2
60+
- echo 3
61+
Unix:
62+
GCC:
63+
- echo 4
64+
- echo 5
65+
PostBuild:
66+
Windows:
67+
MSVC:
68+
- echo 3
69+
- echo 4
70+
Unix:
71+
GCC:
72+
- echo 5
73+
- echo 6
74+
Cleanup:
75+
Windows:
76+
MSVC:
77+
- echo 4
78+
- echo 5
79+
Unix:
80+
GCC:
81+
- echo 6
82+
- echo 7
4083
Dependencies:
4184
- Name: MyLib
4285
Platforms:
@@ -55,13 +98,6 @@ int main(int argc, char** argv)
5598
- mylib
5699
SearchDirectories:
57100
- lib/Debug
58-
Defines:
59-
Windows:
60-
MSVC:
61-
- _DEBUG
62-
- VERSION=1.0.0
63-
GCC:
64-
- NDEBUG
65101
)";
66102

67103
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
@@ -122,13 +158,6 @@ int main(int argc, char** argv)
122158
ssTEST_OUTPUT_ASSERT("MSVC files count", msvcFiles.size() == 2);
123159
ssTEST_OUTPUT_ASSERT("MSVC first file", msvcFiles.at(0) == "src/extra.cpp");
124160

125-
//Verify Dependencies
126-
ssTEST_OUTPUT_ASSERT("Dependencies count", scriptInfo.Dependencies.size(), 1);
127-
ssTEST_OUTPUT_ASSERT("Dependency name", scriptInfo.Dependencies.at(0).Name == "MyLib");
128-
ssTEST_OUTPUT_ASSERT( "Dependency type",
129-
scriptInfo.Dependencies.at(0).LibraryType ==
130-
runcpp2::Data::DependencyLibraryType::SHARED);
131-
132161
//Verify Defines
133162
ssTEST_OUTPUT_SETUP
134163
(
@@ -139,6 +168,81 @@ int main(int argc, char** argv)
139168
ssTEST_OUTPUT_ASSERT("MSVC first define", msvcDefines.at(0).Name == "_DEBUG");
140169
ssTEST_OUTPUT_ASSERT("MSVC second define name", msvcDefines.at(1).Name == "VERSION");
141170
ssTEST_OUTPUT_ASSERT("MSVC second define value", msvcDefines.at(1).Value == "1.0.0");
171+
172+
//Verify Setup
173+
ssTEST_OUTPUT_ASSERT( "Setup commands count MSVC",
174+
scriptInfo.Setup.at("Windows").CommandSteps.at("MSVC").size() == 2);
175+
ssTEST_OUTPUT_ASSERT( "Setup commands count GCC",
176+
scriptInfo.Setup.at("Unix").CommandSteps.at("GCC").size() == 2);
177+
178+
ssTEST_OUTPUT_SETUP
179+
(
180+
const std::vector<std::string>& msvcSetupCommands =
181+
scriptInfo.Setup.at("Windows").CommandSteps.at("MSVC");
182+
183+
const std::vector<std::string>& gccSetupCommands =
184+
scriptInfo.Setup.at("Unix").CommandSteps.at("GCC");
185+
);
186+
187+
ssTEST_OUTPUT_ASSERT("MSVC setup commands count", msvcSetupCommands.size() == 2);
188+
ssTEST_OUTPUT_ASSERT("MSVC setup commands", msvcSetupCommands.at(0) == "echo 1");
189+
190+
ssTEST_OUTPUT_ASSERT("GCC setup commands count", gccSetupCommands.size() == 2);
191+
ssTEST_OUTPUT_ASSERT("GCC setup commands", gccSetupCommands.at(0) == "echo 3");
192+
193+
//Verify PreBuild
194+
ssTEST_OUTPUT_ASSERT( "PreBuild commands count MSVC",
195+
scriptInfo.PreBuild.at("Windows").CommandSteps.at("MSVC").size() == 2);
196+
ssTEST_OUTPUT_ASSERT( "PreBuild commands count GCC",
197+
scriptInfo.PreBuild.at("Unix").CommandSteps.at("GCC").size() == 2);
198+
199+
ssTEST_OUTPUT_SETUP
200+
(
201+
const std::vector<std::string>& msvcPreBuildCommands =
202+
scriptInfo.PreBuild.at("Windows").CommandSteps.at("MSVC");
203+
204+
const std::vector<std::string>& gccPreBuildCommands =
205+
scriptInfo.PreBuild.at("Unix").CommandSteps.at("GCC");
206+
);
207+
208+
ssTEST_OUTPUT_ASSERT("MSVC prebuild commands count", msvcPreBuildCommands.size() == 2);
209+
ssTEST_OUTPUT_ASSERT("MSVC prebuild commands", msvcPreBuildCommands.at(0) == "echo 2");
210+
211+
ssTEST_OUTPUT_ASSERT("GCC prebuild commands count", gccPreBuildCommands.size() == 2);
212+
ssTEST_OUTPUT_ASSERT("GCC prebuild commands", gccPreBuildCommands.at(1) == "echo 5");
213+
214+
//Verify PostBuild
215+
ssTEST_OUTPUT_ASSERT( "PostBuild commands count GCC",
216+
scriptInfo.PostBuild.at("Unix").CommandSteps.at("GCC").size() == 2);
217+
218+
ssTEST_OUTPUT_SETUP
219+
(
220+
const std::vector<std::string>& gccPostBuildCommands =
221+
scriptInfo.PostBuild.at("Unix").CommandSteps.at("GCC");
222+
);
223+
224+
ssTEST_OUTPUT_ASSERT("GCC postbuild commands count", gccPostBuildCommands.size() == 2);
225+
ssTEST_OUTPUT_ASSERT("GCC postbuild commands", gccPostBuildCommands.at(1) == "echo 6");
226+
227+
//Verify Cleanup
228+
ssTEST_OUTPUT_ASSERT( "Cleanup commands count MSVC",
229+
scriptInfo.Cleanup.at("Windows").CommandSteps.at("MSVC").size() == 2);
230+
231+
ssTEST_OUTPUT_SETUP
232+
(
233+
const std::vector<std::string>& msvcCleanupCommands =
234+
scriptInfo.Cleanup.at("Windows").CommandSteps.at("MSVC");
235+
);
236+
237+
ssTEST_OUTPUT_ASSERT("MSVC cleanup commands count", msvcCleanupCommands.size() == 2);
238+
ssTEST_OUTPUT_ASSERT("MSVC cleanup commands", msvcCleanupCommands.at(0) == "echo 4");
239+
240+
//Verify Dependencies
241+
ssTEST_OUTPUT_ASSERT("Dependencies count", scriptInfo.Dependencies.size(), 1);
242+
ssTEST_OUTPUT_ASSERT("Dependency name", scriptInfo.Dependencies.at(0).Name == "MyLib");
243+
ssTEST_OUTPUT_ASSERT( "Dependency type",
244+
scriptInfo.Dependencies.at(0).LibraryType ==
245+
runcpp2::Data::DependencyLibraryType::SHARED);
142246

143247
//Test ToString() and Equals()
144248
ssTEST_OUTPUT_EXECUTION

0 commit comments

Comments
 (0)