Skip to content

Commit 4e66cd0

Browse files
Merge pull request #30 from Neko-Box-Coder/ScriptSteps
Adding ability to run commands for different situations
2 parents 03d7398 + 0558898 commit 4e66cd0

19 files changed

+621
-142
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ add_library(runcpp2 STATIC
123123
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/Profile.cpp"
124124
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyInfo.cpp"
125125
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyLinkProperty.cpp"
126-
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencyCommands.cpp"
127126
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/DependencySource.cpp"
128127
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/FileProperties.cpp"
129128
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/FlagsOverrideInfo.cpp"
129+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ProfilesCommands.cpp"
130130
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ProfilesFlagsOverride.cpp"
131131
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ScriptInfo.cpp"
132132
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/Data/ProfilesCompilesFiles.cpp"

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]

External/ssTest

Include/runcpp2/Data/DependencyInfo.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "runcpp2/Data/DependencyLibraryType.hpp"
55
#include "runcpp2/Data/DependencySource.hpp"
66
#include "runcpp2/Data/DependencyLinkProperty.hpp"
7-
#include "runcpp2/Data/DependencyCommands.hpp"
7+
#include "runcpp2/Data/ProfilesCommands.hpp"
88
#include "runcpp2/Data/ParseCommon.hpp"
99
#include "runcpp2/Data/FilesToCopyInfo.hpp"
1010
#include "runcpp2/YamlLib.hpp"
@@ -26,9 +26,9 @@ namespace runcpp2
2626
std::vector<std::string> IncludePaths;
2727
std::vector<std::string> AbsoluteIncludePaths;
2828
std::unordered_map<PlatformName, DependencyLinkProperty> LinkProperties;
29-
std::unordered_map<PlatformName, DependencyCommands> Setup;
30-
std::unordered_map<PlatformName, DependencyCommands> Cleanup;
31-
std::unordered_map<PlatformName, DependencyCommands> Build;
29+
std::unordered_map<PlatformName, ProfilesCommands> Setup;
30+
std::unordered_map<PlatformName, ProfilesCommands> Cleanup;
31+
std::unordered_map<PlatformName, ProfilesCommands> Build;
3232
std::unordered_map<PlatformName, FilesToCopyInfo> FilesToCopy;
3333

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

Include/runcpp2/Data/DependencyCommands.hpp renamed to Include/runcpp2/Data/ProfilesCommands.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef RUNCPP2_DATA_DEPENDENCY_COMMANDS_HPP
2-
#define RUNCPP2_DATA_DEPENDENCY_COMMANDS_HPP
1+
#ifndef RUNCPP2_DATA_PROFILES_COMMANDS_HPP
2+
#define RUNCPP2_DATA_PROFILES_COMMANDS_HPP
33

44
#include "runcpp2/Data/ParseCommon.hpp"
55
#include "runcpp2/YamlLib.hpp"
@@ -12,15 +12,15 @@ namespace runcpp2
1212
{
1313
namespace Data
1414
{
15-
class DependencyCommands
15+
class ProfilesCommands
1616
{
1717
public:
1818
//TODO: Allow specifying command can fail
1919
std::unordered_map<ProfileName, std::vector<std::string>> CommandSteps;
2020

2121
bool ParseYAML_Node(ryml::ConstNodeRef& node);
2222
std::string ToString(std::string indentation) const;
23-
bool Equals(const DependencyCommands& other) const;
23+
bool Equals(const ProfilesCommands& other) const;
2424
};
2525
}
2626
}

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/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ endfunction()
2121
create_data_test(FilePropertiesTest)
2222
create_data_test(FlagsOverrideInfoTest)
2323
create_data_test(DependencySourceTest)
24-
create_data_test(DependencyCommandsTest)
2524
create_data_test(FilesToCopyInfoTest)
25+
create_data_test(ProfilesCommandsTest)
2626
create_data_test(ProfilesCompilesFilesTest)
2727
create_data_test(ProfilesDefinesTest)
2828
create_data_test(DependencyLinkPropertyTest)
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "runcpp2/Data/DependencyCommands.hpp"
1+
#include "runcpp2/Data/ProfilesCommands.hpp"
22
#include "ssTest.hpp"
33
#include "runcpp2/YamlLib.hpp"
44
#include "runcpp2/runcpp2.hpp"
@@ -9,7 +9,7 @@ int main(int argc, char** argv)
99

1010
ssTEST_INIT_TEST_GROUP();
1111

12-
ssTEST("DependencyCommands Should Parse Valid YAML")
12+
ssTEST("ProfilesCommands Should Parse Valid YAML")
1313
{
1414
ssTEST_OUTPUT_SETUP
1515
(
@@ -27,40 +27,40 @@ int main(int argc, char** argv)
2727
ryml::Tree tree = ryml::parse_in_arena(c4::to_csubstr(yamlStr));
2828
ryml::ConstNodeRef root = tree.rootref();
2929

30-
runcpp2::Data::DependencyCommands dependencyCommands;
30+
runcpp2::Data::ProfilesCommands profilesCommands;
3131
);
3232

3333
ssTEST_OUTPUT_EXECUTION
3434
(
3535
ryml::ConstNodeRef nodeRef = root;
36-
bool parseResult = dependencyCommands.ParseYAML_Node(nodeRef);
36+
bool parseResult = profilesCommands.ParseYAML_Node(nodeRef);
3737
);
3838

3939
ssTEST_OUTPUT_ASSERT("ParseYAML_Node should succeed", parseResult);
4040

4141
//Verify parsed values
4242
ssTEST_OUTPUT_ASSERT( "MSVC commands count",
43-
dependencyCommands.CommandSteps.at("MSVC").size() == 3);
43+
profilesCommands.CommandSteps.at("MSVC").size() == 3);
4444
ssTEST_OUTPUT_ASSERT( "GCC commands count",
45-
dependencyCommands.CommandSteps.at("GCC").size() == 3);
45+
profilesCommands.CommandSteps.at("GCC").size() == 3);
4646
ssTEST_OUTPUT_ASSERT( "MSVC first command",
47-
dependencyCommands.CommandSteps.at("MSVC").at(0) == "mkdir build");
47+
profilesCommands.CommandSteps.at("MSVC").at(0) == "mkdir build");
4848
ssTEST_OUTPUT_ASSERT( "GCC last command",
49-
dependencyCommands.CommandSteps.at("GCC").at(2) == "make install");
49+
profilesCommands.CommandSteps.at("GCC").at(2) == "make install");
5050

5151
//Test ToString() and Equals()
5252
ssTEST_OUTPUT_EXECUTION
5353
(
54-
std::string yamlOutput = dependencyCommands.ToString("");
54+
std::string yamlOutput = profilesCommands.ToString("");
5555
ryml::Tree outputTree = ryml::parse_in_arena(ryml::to_csubstr(yamlOutput));
5656

57-
runcpp2::Data::DependencyCommands parsedOutput;
57+
runcpp2::Data::ProfilesCommands parsedOutput;
5858
nodeRef = outputTree.rootref();
5959
parsedOutput.ParseYAML_Node(nodeRef);
6060
);
6161

6262
ssTEST_OUTPUT_ASSERT( "Parsed output should equal original",
63-
dependencyCommands.Equals(parsedOutput));
63+
profilesCommands.Equals(parsedOutput));
6464
};
6565

6666
ssTEST_END_TEST_GROUP();

0 commit comments

Comments
 (0)