Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Strict Mode #37

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 4 additions & 1 deletion .github/workflows/linux-clang-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
sudo add-apt-repository ppa:trebelnik-stefina/launchpad-getkeys \
&& sudo apt-get update \
&& sudo apt-get install launchpad-getkeys \
&& sudo sudo apt-get update \
&& sudo apt-get update \
&& sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main' \
&& sudo launchpad-getkeys \
&& sudo apt-get update -y \
Expand All @@ -34,6 +34,9 @@ jobs:
- name: Initialize submodules
run: git submodule update --init --recursive

- name: Set up Clang environment
run: echo "/usr/bin/clang++-16" > $GITHUB_ENV

- name: Configure CMake
run: |
cmake -B ${{github.workspace}}/build \
Expand Down
40 changes: 34 additions & 6 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "ConfigValue.h"
#include "environment/ConfigProvider.h"
#include "JsonConfigLoader.h"
#include "YamlConfigLoader.h"
#include "XmlConfigLoader.h"
#include "YamlConfigLoader.h"

namespace config
{
Expand Down Expand Up @@ -176,20 +176,32 @@ void Config::initialize()

// Check if the configuration directory is empty
bool isEmpty = true;
for (const auto& entry : std::filesystem::directory_iterator(configDirectory)) {
if (entry.is_regular_file()) {
for (const auto& entry : std::filesystem::directory_iterator(configDirectory))
{
if (entry.is_regular_file())
{
isEmpty = false;
break;
}
}

// If the configuration directory is empty, log a message and return
if (isEmpty && suppressWarning != nullptr) {
if (isEmpty && suppressWarning != nullptr)
{
std::cout << "WARNING: No configurations found in configuration directory." << std::endl;
return;
}

const auto strictMode = std::getenv("CXX_CONFIG_STRICT_MODE");
bool foundCxxEnvFile = false;

const auto cxxEnv = environment::ConfigProvider::getCxxEnv();

if (strictMode != nullptr && (cxxEnv == "local" || cxxEnv == "default"))
{
throw std::runtime_error("ERROR: CXX_ENV must not be 'default' or 'local' under strict mode");
}

std::cout << "Config directory: " << configDirectory << " loaded." << std::endl;

std::vector<std::string> order = {"default", cxxEnv, "local", "local-" + cxxEnv, "custom-environment-variables"};
Expand Down Expand Up @@ -243,6 +255,10 @@ void Config::initialize()
if (filePath.string().find("environment") != std::string::npos)
{
JsonConfigLoader::loadConfigEnvFile(filePath, values);
if (filePath.stem().string() == cxxEnv)
{
foundCxxEnvFile = true;
}
}
else
{
Expand All @@ -254,17 +270,25 @@ void Config::initialize()
if (filePath.string().find("environment") != std::string::npos)
{
YamlConfigLoader::loadConfigEnvFile(filePath, values);
if (filePath.stem().string() == cxxEnv)
{
foundCxxEnvFile = true;
}
}
else
{
YamlConfigLoader::loadConfigFile(filePath, values);
}
}
}
else if (filePath.extension() == ".xml")
{
if (filePath.string().find("environment") != std::string::npos)
if (filePath.string().find("environment") != std::string::npos)
{
XmlConfigLoader::loadConfigEnvFile(filePath, values);
if (filePath.stem().string() == cxxEnv)
{
foundCxxEnvFile = true;
}
}
else
{
Expand All @@ -273,6 +297,10 @@ void Config::initialize()
}
}

if (!foundCxxEnvFile && !cxxEnv.empty() && strictMode != nullptr)
{
throw std::runtime_error("ERROR: No configuration file matching CXX_ENV");
}
if (values.empty())
{
throw std::runtime_error("Config values are empty.");
Expand Down
Loading