Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 9a9c132

Browse files
committed
chore: add variant support
1 parent 8c06f78 commit 9a9c132

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

engine/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ if(DEBUG)
5959
add_compile_definitions(ALLOW_ALL_CORS)
6060
endif()
6161

62+
if(NOT DEFINED CORTEX_VARIANT)
63+
set(CORTEX_VARIANT "prod")
64+
endif()
65+
6266
if(NOT DEFINED CORTEX_CONFIG_FILE_PATH)
6367
set(CORTEX_CONFIG_FILE_PATH "user_home")
6468
endif()
@@ -83,6 +87,7 @@ if(DEFINED CMAKE_JS_INC)
8387
add_compile_definitions(NAPI_VERSION=8)
8488
endif()
8589

90+
add_compile_definitions(CORTEX_VARIANT="${CORTEX_VARIANT}")
8691
add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}")
8792
add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}")
8893

engine/utils/file_manager_utils.h

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace file_manager_utils {
1818
constexpr std::string_view kCortexConfigurationFileName = ".cortexrc";
1919
constexpr std::string_view kDefaultConfigurationPath = "user_home";
20+
constexpr std::string_view kBetaVariant = "beta";
21+
constexpr std::string_view kNightlyVariant = "nightly";
2022

2123
inline std::filesystem::path GetExecutableFolderContainerPath() {
2224
#if defined(__APPLE__) && defined(__MACH__)
@@ -75,13 +77,34 @@ inline std::filesystem::path GetHomeDirectoryPath() {
7577
}
7678

7779
inline std::filesystem::path GetConfigurationPath() {
80+
#ifndef CORTEX_CONFIG_FILE_PATH
81+
#define CORTEX_CONFIG_FILE_PATH "user_home"
82+
#endif
83+
84+
#ifndef CORTEX_VARIANT
85+
#define CORTEX_VARIANT "prod"
86+
#endif
7887
std::string config_file_path{CORTEX_CONFIG_FILE_PATH};
7988

8089
if (config_file_path != kDefaultConfigurationPath) {
90+
CTL_INF("Config file path: " + config_file_path);
8191
return std::filesystem::path(config_file_path);
8292
}
93+
94+
std::string variant{CORTEX_VARIANT};
95+
std::string env_postfix{""};
96+
if (variant == kBetaVariant) {
97+
env_postfix.append("-").append(kBetaVariant);
98+
} else if (variant == kNightlyVariant) {
99+
env_postfix.append("-").append(kNightlyVariant);
100+
}
101+
102+
std::string config_file_name{kCortexConfigurationFileName};
103+
config_file_name.append(env_postfix);
104+
CTL_INF("Config file name: " + config_file_name);
105+
83106
auto home_path = GetHomeDirectoryPath();
84-
auto configuration_path = home_path / kCortexConfigurationFileName;
107+
auto configuration_path = home_path / config_file_name;
85108
return configuration_path;
86109
}
87110

@@ -91,15 +114,30 @@ inline void CreateConfigFileIfNotExist() {
91114
// already exists
92115
return;
93116
}
117+
#ifndef CORTEX_VARIANT
118+
#define CORTEX_VARIANT "prod"
119+
#endif
120+
std::string default_data_folder_name{config_yaml_utils::kCortexFolderName};
121+
122+
std::string variant{CORTEX_VARIANT};
123+
std::string env_postfix{""};
124+
if (variant == kBetaVariant) {
125+
env_postfix.append("-").append(kBetaVariant);
126+
} else if (variant == kNightlyVariant) {
127+
env_postfix.append("-").append(kNightlyVariant);
128+
}
129+
default_data_folder_name.append(env_postfix);
130+
94131
CLI_LOG("Config file not found. Creating one at " + config_path.string());
95132
auto defaultDataFolderPath =
96-
file_manager_utils::GetHomeDirectoryPath() / config_yaml_utils::kCortexFolderName;
133+
file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name;
134+
CTL_INF("Default data folder path: " + defaultDataFolderPath.string());
135+
97136
auto config = config_yaml_utils::CortexConfig{
98137
.dataFolderPath = defaultDataFolderPath.string(),
99138
.host = config_yaml_utils::kDefaultHost,
100139
.port = config_yaml_utils::kDefaultPort,
101140
};
102-
std::cout << "config: " << config.dataFolderPath << "\n";
103141
DumpYamlConfig(config, config_path.string());
104142
}
105143

@@ -116,8 +154,7 @@ inline std::filesystem::path GetCortexDataPath() {
116154
auto config = GetCortexConfig();
117155
std::filesystem::path data_folder_path;
118156
if (!config.dataFolderPath.empty()) {
119-
data_folder_path =
120-
std::filesystem::path(config.dataFolderPath);
157+
data_folder_path = std::filesystem::path(config.dataFolderPath);
121158
} else {
122159
auto home_path = GetHomeDirectoryPath();
123160
data_folder_path = home_path / config_yaml_utils::kCortexFolderName;

0 commit comments

Comments
 (0)