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

chore: add variant support #1138

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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: 5 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ if(DEBUG)
add_compile_definitions(ALLOW_ALL_CORS)
endif()

if(NOT DEFINED CORTEX_VARIANT)
set(CORTEX_VARIANT "prod")
endif()

if(NOT DEFINED CORTEX_CONFIG_FILE_PATH)
set(CORTEX_CONFIG_FILE_PATH "user_home")
endif()
Expand All @@ -83,6 +87,7 @@ if(DEFINED CMAKE_JS_INC)
add_compile_definitions(NAPI_VERSION=8)
endif()

add_compile_definitions(CORTEX_VARIANT="${CORTEX_VARIANT}")
add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}")
add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}")

Expand Down
48 changes: 43 additions & 5 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
namespace file_manager_utils {
constexpr std::string_view kCortexConfigurationFileName = ".cortexrc";
constexpr std::string_view kDefaultConfigurationPath = "user_home";
constexpr std::string_view kProdVariant = "prod";
constexpr std::string_view kBetaVariant = "beta";
constexpr std::string_view kNightlyVariant = "nightly";

inline std::filesystem::path GetExecutableFolderContainerPath() {
#if defined(__APPLE__) && defined(__MACH__)
Expand Down Expand Up @@ -75,13 +78,34 @@ inline std::filesystem::path GetHomeDirectoryPath() {
}

inline std::filesystem::path GetConfigurationPath() {
#ifndef CORTEX_CONFIG_FILE_PATH
#define CORTEX_CONFIG_FILE_PATH kDefaultConfigurationPath
#endif

#ifndef CORTEX_VARIANT
#define CORTEX_VARIANT kProdVariant
#endif
std::string config_file_path{CORTEX_CONFIG_FILE_PATH};

if (config_file_path != kDefaultConfigurationPath) {
CTL_INF("Config file path: " + config_file_path);
return std::filesystem::path(config_file_path);
}

std::string variant{CORTEX_VARIANT};
std::string env_postfix{""};
if (variant == kBetaVariant) {
env_postfix.append("-").append(kBetaVariant);
} else if (variant == kNightlyVariant) {
env_postfix.append("-").append(kNightlyVariant);
}

std::string config_file_name{kCortexConfigurationFileName};
config_file_name.append(env_postfix);
CTL_INF("Config file name: " + config_file_name);

auto home_path = GetHomeDirectoryPath();
auto configuration_path = home_path / kCortexConfigurationFileName;
auto configuration_path = home_path / config_file_name;
return configuration_path;
}

Expand All @@ -91,15 +115,30 @@ inline void CreateConfigFileIfNotExist() {
// already exists
return;
}
#ifndef CORTEX_VARIANT
#define CORTEX_VARIANT "prod"
#endif
std::string default_data_folder_name{config_yaml_utils::kCortexFolderName};

std::string variant{CORTEX_VARIANT};
std::string env_postfix{""};
if (variant == kBetaVariant) {
env_postfix.append("-").append(kBetaVariant);
} else if (variant == kNightlyVariant) {
env_postfix.append("-").append(kNightlyVariant);
}
default_data_folder_name.append(env_postfix);

CLI_LOG("Config file not found. Creating one at " + config_path.string());
auto defaultDataFolderPath =
file_manager_utils::GetHomeDirectoryPath() / config_yaml_utils::kCortexFolderName;
file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name;
CTL_INF("Default data folder path: " + defaultDataFolderPath.string());

auto config = config_yaml_utils::CortexConfig{
.dataFolderPath = defaultDataFolderPath.string(),
.host = config_yaml_utils::kDefaultHost,
.port = config_yaml_utils::kDefaultPort,
};
std::cout << "config: " << config.dataFolderPath << "\n";
DumpYamlConfig(config, config_path.string());
}

Expand All @@ -116,8 +155,7 @@ inline std::filesystem::path GetCortexDataPath() {
auto config = GetCortexConfig();
std::filesystem::path data_folder_path;
if (!config.dataFolderPath.empty()) {
data_folder_path =
std::filesystem::path(config.dataFolderPath);
data_folder_path = std::filesystem::path(config.dataFolderPath);
} else {
auto home_path = GetHomeDirectoryPath();
data_folder_path = home_path / config_yaml_utils::kCortexFolderName;
Expand Down
Loading