Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions TASKS.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions UPDATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion include/core/kma_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
83 changes: 62 additions & 21 deletions src/core/kma_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand All @@ -220,7 +221,7 @@ static void CleanEverything()
foundVersion = false;
foundReferences = false;
foundGlobal = false;

foundAnyUserProfile = false;
globalData = GlobalData{};
}

Expand Down Expand Up @@ -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<string>& lines) -> void
const vector<string>& lines,
StartType type) -> void
{
Log::Print(
"Starting to parse the kalamake file '" + filePath.string() + "'"
Expand All @@ -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(
Expand All @@ -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())
{
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -790,6 +815,11 @@ namespace KalaMake::Core

break;
}
case StartType::S_VALIDATE:
{
first_parse(filePath, content, type);
break;
}
case StartType::S_CLEAN:
{
vector<path> buildPaths{};
Expand Down Expand Up @@ -1729,6 +1759,17 @@ void FirstParse(const vector<string>& 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<string>
Expand Down
45 changes: 45 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,41 @@ static void AddExternalCommands()

KalaMakeCore::OpenFile(StartType::S_LIST_PROFILES, params);
};
auto command_validate = [](const vector<string>& 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(
{
Expand Down Expand Up @@ -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[])
Expand Down