diff --git a/TASKS.md b/TASKS.md new file mode 100644 index 0000000..abe0638 --- /dev/null +++ b/TASKS.md @@ -0,0 +1,7 @@ +# KalaMake Tasks or Upcoming Features + +## Version 1.4 + +- [x] `--list-profiles` command - lists all available profiles in a `.kmake` file +- [ ] `--force` argument only for compile command - skips incremental building and recompiles everything +- [ ] `--validate` command - checks if a `.kmake` file is valid without compiling \ No newline at end of file diff --git a/UPDATES.md b/UPDATES.md index cabe3cf..09c1976 100644 --- a/UPDATES.md +++ b/UPDATES.md @@ -44,6 +44,8 @@ - fixed zig using c instead of correct cc for compiling C - fixed gcc and g++ compilers not creating .lib file in shared mode on Windows -## 1.4 +## 1.4 --- added list-profiles (by jake) +- list-profiles command - lists all available profiles in a .kmake file (by jake) +- force argument only for compile command - skips incremental building and recompiles everything +- validate command - checks if a .kmake file is valid without compiling (by jake) \ No newline at end of file diff --git a/include/core/kma_core.hpp b/include/core/kma_core.hpp index 7efe373..ad5c55e 100644 --- a/include/core/kma_core.hpp +++ b/include/core/kma_core.hpp @@ -30,7 +30,8 @@ namespace KalaMake::Core S_INVALID = 0u, S_COMPILE = 1u, S_CLEAN = 2u, - S_LIST_PROFILES = 3u + S_LIST_PROFILES = 3u, + S_VALIDATE = 4u }; enum class Version : u8 diff --git a/src/core/kma_core.cpp b/src/core/kma_core.cpp index bf1dad5..7599830 100644 --- a/src/core/kma_core.cpp +++ b/src/core/kma_core.cpp @@ -202,6 +202,7 @@ static bool foundVersion{}; static bool foundReferences{}; static bool foundGlobal{}; static bool foundTargetProfile{}; +static bool foundAnyUserProfile{}; static GlobalData globalData{}; static path projectFile{}; @@ -220,7 +221,7 @@ static void CleanEverything() foundVersion = false; foundReferences = false; foundGlobal = false; - + foundAnyUserProfile = false; globalData = GlobalData{}; } @@ -532,14 +533,16 @@ namespace KalaMake::Core Log::Print(details.str()); projectFile = params[1]; - if (type == StartType::S_COMPILE) targetProfile = params[2]; + if (type == StartType::S_COMPILE + || type == StartType::S_VALIDATE) targetProfile = params[2]; string& currentDir = KalaCLI::Core::GetCurrentDir(); if (currentDir.empty()) currentDir = current_path().string(); auto first_parse = []( const path& filePath, - const vector& lines) -> void + const vector& lines, + StartType type) -> void { Log::Print( "Starting to parse the kalamake file '" + filePath.string() + "'" @@ -555,13 +558,26 @@ namespace KalaMake::Core "KALAMAKE", "No binary type was passed!"); } - if (globalData.targetProfile.compiler == CompilerType::C_INVALID) + + //assume global profile if none was set + if (globalData.targetProfile.profileName.empty()) { - KalaMakeCore::CloseOnError( - "KALAMAKE", - "No compiler was passed!"); + globalData.targetProfile.profileName = "global"; + } + + //always check for a compiler unless global profile is used and a user profile is found. + if (type == StartType::S_COMPILE + || globalData.targetProfile.profileName != "global" + || !foundAnyUserProfile) + { + if (globalData.targetProfile.compiler == CompilerType::C_INVALID) + { + KalaMakeCore::CloseOnError( + "KALAMAKE", + "No compiler was passed!"); + } + } - if (globalData.targetProfile.binaryName.empty()) { KalaMakeCore::CloseOnError( @@ -574,11 +590,17 @@ namespace KalaMake::Core "KALAMAKE", "Passed binary name is too long!"); } - if (globalData.targetProfile.buildPath.empty()) + //always check for a build path unless global profile is used and a user profile is found. + if (type == StartType::S_COMPILE + || globalData.targetProfile.profileName != "global" + || !foundAnyUserProfile) { - KalaMakeCore::CloseOnError( - "KALAMAKE", - "No build path was passed!"); + if (globalData.targetProfile.buildPath.empty()) + { + KalaMakeCore::CloseOnError( + "KALAMAKE", + "No build path was passed!"); + } } if (globalData.targetProfile.sources.empty()) { @@ -607,12 +629,6 @@ namespace KalaMake::Core globalData.projectFile = weakly_canonical(projectFile); - //assume global profile if none was set - if (globalData.targetProfile.profileName.empty()) - { - globalData.targetProfile.profileName = "global"; - } - Log::Print( "Finished first parse!\n", "KALAMAKE", @@ -621,6 +637,17 @@ namespace KalaMake::Core Log::Print("===========================================================================\n"); CompilerType c = globalData.targetProfile.compiler; + + if (type == StartType::S_VALIDATE) + { + Log::Print( + "Finished validating, kalamake file is valid!", + "KALAMAKE", + LogType::LOG_SUCCESS); + + return; + } + if (c == CompilerType::C_ZIG || c == CompilerType::C_CL || c == CompilerType::C_CLANG_CL @@ -762,9 +789,7 @@ namespace KalaMake::Core } case StartType::S_COMPILE: { - first_parse( - filePath, - content); + first_parse(filePath, content, type); break; } case StartType::S_LIST_PROFILES: @@ -790,6 +815,11 @@ namespace KalaMake::Core break; } + case StartType::S_VALIDATE: + { + first_parse(filePath, content, type); + break; + } case StartType::S_CLEAN: { vector buildPaths{}; @@ -1729,6 +1759,17 @@ void FirstParse(const vector& lines) //always a fresh build CleanEverything(); + //look for any user profiles before continuing + for (const string& l : lines) + { + if (l.starts_with("#profile ")) + { + foundAnyUserProfile = true; + break; + } + + } + auto get_all_category_content = [&lines]( string_view categoryName, string_view categoryValue = {}) -> vector diff --git a/src/main.cpp b/src/main.cpp index e65802b..e8a8f97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -124,6 +124,41 @@ static void AddExternalCommands() KalaMakeCore::OpenFile(StartType::S_LIST_PROFILES, params); }; + auto command_validate = [](const vector& params) + { + if (params.size() == 1) + { + Log::Print( + "Command 'validate' got no arguments! You must pass a .kmake path and target profile!", + "PARSE", + LogType::LOG_ERROR, + 2); + + return; + } + if (params.size() == 2) + { + Log::Print( + "Command 'validate' requires two arguments! You must pass a .kmake path and target profile!", + "PARSE", + LogType::LOG_ERROR, + 2); + + return; + } + if (params.size() > 3) + { + Log::Print( + "Command 'validate' only allows two arguments! You must pass a .kmake path and target profile!", + "PARSE", + LogType::LOG_ERROR, + 2); + + return; + } + + KalaMakeCore::OpenFile(StartType::S_VALIDATE, params); + }; CommandManager::AddCommand( { @@ -157,6 +192,16 @@ static void AddExternalCommands() "second parameter must be valid path to a .kmake file.", .targetFunction = command_list_profiles }); + + CommandManager::AddCommand( + { + .primaryParam = "validate", + .description = + "Validates a kalamake file, " + "second parameter must be valid path to a .kmake file, " + "third parameter must be a valid profile in the .kmake file.", + .targetFunction = command_validate + }); } int main(int argc, char* argv[])