17#define pharos_app_runtime_paths_strdup _strdup
20#define pharos_app_runtime_paths_strdup strdup
24 char *manifest_path = NULL;
25 char *manifest_text = NULL;
26 char *manifest_id = NULL;
32 if (base_dir == NULL || target_id == NULL || base_dir[0] ==
'\0') {
35 manifest_path =
path_join(base_dir,
"pharos.app.json");
36 if (manifest_path != NULL &&
path_exists(manifest_path)) {
38 if (manifest_text != NULL) {
40 if (manifest_id != NULL &&
streq(manifest_id, target_id)) {
42 if (matched == NULL) {
51 if (matched != NULL) {
55 dir = opendir(base_dir);
59 while ((entry = readdir(dir)) != NULL) {
61 if (
streq(entry->d_name,
".") ||
streq(entry->d_name,
"..")) {
64 child_root =
path_join(base_dir, entry->d_name);
65 if (child_root == NULL) {
69 manifest_path =
path_join(child_root,
"pharos.app.json");
70 if (manifest_path != NULL &&
path_exists(manifest_path)) {
72 if (manifest_text != NULL) {
74 if (manifest_id != NULL &&
streq(manifest_id, target_id)) {
76 if (matched == NULL) {
88 if (matched != NULL) {
102 if (app_dir_hint != NULL && app_dir_hint[0] !=
'\0') {
104 if (matched != NULL) {
108 if (repo_root != NULL && repo_root[0] !=
'\0') {
109 char *apps_dir =
path_join(repo_root,
"apps");
112 if (matched != NULL) {
116 if (binary_dir != NULL && binary_dir[0] !=
'\0') {
117 char *apps_adj =
path_join(binary_dir,
"apps");
120 if (matched != NULL) {
125 if (binary_parent != NULL) {
126 char *apps_near =
path_join(binary_parent,
"apps");
130 if (matched != NULL) {
151 if (artifact_parent != NULL) {
154 free(artifact_parent);
159 if (value != NULL && value[0] !=
'\0') {
164 if (result != NULL && result[0] !=
'\0') {
172 if (build_dir_override != NULL && build_dir_override[0] !=
'\0') {
179 char *apps_root = NULL;
180 char *artifact_dir = NULL;
182 if (build_dir == NULL || app_id == NULL) {
185 len = strlen(build_dir);
186 if ((
len >= 5 &&
streq(build_dir +
len - 5,
"/apps")) ||
streq(build_dir,
"apps")
188 || (
len >= 5 &&
streq(build_dir +
len - 5,
"\\apps"))
193 apps_root =
path_join(build_dir,
"apps");
194 if (apps_root == NULL) {
197 artifact_dir =
path_join(apps_root, app_id);
204 char *artifact_dir = NULL;
213 }
else if (build_dir != NULL && build_dir[0] !=
'\0') {
219 }
else if (build_dir != NULL && build_dir[0] !=
'\0') {
227 if (artifact_dir != NULL) {
235 char *resolved = NULL;
245 if (resolved == NULL) {
249 char *tmp =
path_join(resolved,
"runtime-state.json");
271 if (resolved == NULL) {
275 char *tmp =
path_join(resolved,
"runtime-state.json");
281char *
effective_app_state_path_native(
const char *app_root,
const char *build_dir,
const char *app_id,
const char *state_path_override,
const char *state_dir_override) {
282 char *resolved = NULL;
283 if (state_path_override != NULL && state_path_override[0] !=
'\0') {
286 if (state_dir_override != NULL && state_dir_override[0] !=
'\0') {
287 resolved =
path_join(state_dir_override, app_id);
288 if (resolved == NULL) {
292 char *tmp =
path_join(resolved,
"runtime-state.json");
321 if (base_path_override != NULL && base_path_override[0] !=
'\0') {
336 if (value != NULL && value[0] !=
'\0') {
341 size_t needed = strlen(
"/var/log/pharos/.log") + strlen(app_id) + 1;
342 char *log_path = (
char *)malloc(needed);
343 if (log_path != NULL) {
344 snprintf(log_path, needed,
"/var/log/pharos/%s.log", app_id);
351 if (log_path_override != NULL && log_path_override[0] !=
'\0') {
375 if (value != NULL && value[0] !=
'\0') {
384 if (value != NULL && value[0] !=
'\0') {
389 size_t needed = strlen(
"/var/log/pharos/.error.jsonl") + strlen(app_id != NULL ? app_id :
"app") + 1;
390 char *path = (
char *)malloc(needed);
392 snprintf(path, needed,
"/var/log/pharos/%s.error.jsonl", app_id != NULL && app_id[0] !=
'\0' ? app_id :
"app");
402 if (config.
debug != NULL && config.
debug[0] !=
'\0') {
407 if (value != NULL && value[0] !=
'\0') {
415 if (debug_override != NULL && debug_override[0] !=
'\0') {
void free_app_local_config_native(AppLocalConfigNative *config)
Releases heap-owned fields in an app-local configuration record.
char * normalize_base_path_native(const char *raw_value)
Normalizes a configured app base path into Pharos runtime form.
int load_app_local_config_native(const char *app_root, AppLocalConfigNative *config)
Loads app-local configuration and manifest-derived path hints into a config record.
Declares app-local runtime configuration helpers and the app-local configuration record.
char * app_build_dir_local_native(const char *app_root)
Builds the default local build directory path for an app.
char * effective_app_build_dir_native(const char *app_root, const char *build_dir_override)
Resolves the effective build directory for an app.
char * effective_app_log_path_native(const char *app_root, const char *app_id, const char *log_path_override)
Resolves the effective log file path for an app.
char * effective_app_log_format_native(const char *app_root)
Resolves the effective log format for an app.
char * app_artifact_dir_from_build_dir_native(const char *build_dir, const char *app_id)
Resolves the artifact directory for one app from a build root or deployed app parent.
char * effective_app_debug_native(const char *app_root, const char *debug_override)
Resolves the effective debug setting for an app.
char * app_debug_local_native(const char *app_root)
Builds the default local debug setting for an app.
char * find_app_root_for_target(const char *target_id, const char *app_dir_hint, const char *repo_root, const char *binary_dir)
Locates an app root for a target using explicit app-dir hints and canonical apps directories.
char * app_error_report_path_local_native(const char *app_root)
Builds the default local error report path for an app.
char * app_state_path_local_native(const char *app_root, const char *build_dir, const char *app_id)
Builds the default local state file path for an app.
char * effective_app_error_report_path_native(const char *app_root, const char *app_id)
Resolves the effective error report path for an app.
char * effective_app_state_path_native(const char *app_root, const char *build_dir, const char *app_id, const char *state_path_override, const char *state_dir_override)
Resolves the effective state file path for an app.
char * effective_app_artifact_dir_native(const char *app_root, const char *build_dir, const char *app_id)
Resolves the effective artifact directory for an app from framework build root plus app-owned contrac...
char * app_log_format_local_native(const char *app_root)
Builds the default local log format setting for an app.
char * effective_app_base_path_native(const char *app_root, const char *base_path_override)
Resolves the effective URL base path for an app.
#define pharos_app_runtime_paths_strdup
char * app_base_path_local_native(const char *app_root)
Builds the default local URL base path for an app.
char * match_app_root_in_directory(const char *base_dir, const char *target_id)
Searches one directory for an app root matching a target identifier.
char * app_log_path_local_native(const char *app_root, const char *app_id)
Builds the default local log file path for an app.
Declares helpers for locating app roots and deriving runtime paths.
char * json_find_string(const char *text, const char *key)
Finds the first JSON string value associated with a key.
Declares lightweight JSON and conf value lookup helpers.
char * path_join(const char *left, const char *right)
Joins two path segments using the native path separator.
char * path_canonicalize(const char *path)
Normalizes a path by collapsing redundant separators and dot segments.
int streq(const char *a, const char *b)
Tests whether two strings are exactly equal.
int path_is_directory(const char *path)
Tests whether a filesystem path refers to a directory.
char * path_dirname(const char *path)
Returns the parent directory component of a path.
char * read_file_text(const char *path)
Reads an entire file into a newly allocated text buffer.
int path_exists(const char *path)
Tests whether a filesystem path currently exists.
Declares shared low-level support helpers used across the Pharos native runtime.
App-local configuration values loaded from app-local config and manifest authority fields.
char * manifest_base_path
char * manifest_state_path
char * manifest_build_artifact_dir