16#define pharos_artifact_emit_strdup _strdup
18#define pharos_artifact_emit_strdup strdup
23 const char *cursor = text;
24 size_t needle_len = strlen(needle);
25 if (text == NULL || needle == NULL || needle_len == 0) {
28 while ((cursor = strstr(cursor, needle)) != NULL) {
37 const unsigned char *cursor;
43 for (cursor = (
const unsigned char *)(value != NULL ? value :
""); *cursor !=
'\0'; cursor++) {
45 if (*cursor ==
'\\' || *cursor ==
'"') {
47 escaped[1] = (char)*cursor;
53 }
else if (*cursor ==
'\n') {
58 }
else if (*cursor ==
'\r') {
63 }
else if (*cursor ==
'\t') {
69 char single = (char)*cursor;
84 return path_join(build_dir != NULL ? build_dir :
"dist", target_id);
88 char *reports_dir =
path_join(build_dir != NULL ? build_dir :
"dist",
"reports");
91 if (reports_dir == NULL) {
94 snprintf(buffer,
sizeof(buffer),
"%s-website-%s.json", verb, target_id);
101 char *report_json = (
char *)malloc(strlen(report_id != NULL ? report_id :
"") + strlen(verb != NULL ? verb :
"") + strlen(target_id != NULL ? target_id :
"") + strlen(artifact_dir != NULL ? artifact_dir :
"") + 256);
102 if (report_json == NULL) {
105 snprintf(report_json, strlen(report_id != NULL ? report_id :
"") + strlen(verb != NULL ? verb :
"") + strlen(target_id != NULL ? target_id :
"") + strlen(artifact_dir != NULL ? artifact_dir :
"") + 256,
106 "{\"report_id\":\"%s\",\"verb\":\"%s\",\"target_kind\":\"website\",\"target_id\":\"%s\",\"status\":\"ok\",\"artifact_dir\":\"%s\",\"runtime_launcher\":true,\"host_target\":\"native-host\"}\n",
107 report_id != NULL ? report_id :
"",
108 verb != NULL ? verb :
"",
109 target_id != NULL ? target_id :
"",
110 artifact_dir != NULL ? artifact_dir :
""
116 size_t needed = strlen(app_id != NULL ? app_id :
"") + 512;
117 char *index_html = (
char *)malloc(needed);
118 if (index_html == NULL) {
121 snprintf(index_html, needed,
"<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>%s</title></head><body><main><h1>%s</h1><p>Pharos native app artifact built from app-owned JSON/HTML/assets.</p></main></body></html>\n", app_id != NULL ? app_id :
"", app_id != NULL ? app_id :
"");
126 const char *manifest_text,
127 const char *artifact_generated_by,
128 const char *state_path,
129 const char *base_path,
130 const char *log_path,
131 const char *log_format,
132 const char *error_report_path,
134 const char *compiled_entrypoint,
146 if (manifest_text == NULL || manifest_text[0] ==
'\0') {
184 || !
yyjson_mut_obj_add_strcpy(mut_doc, runtime,
"compiled_entrypoint", compiled_entrypoint != NULL ? compiled_entrypoint :
"")) {
200 if (artifact == NULL) {
232 || !
yyjson_mut_obj_add_strcpy(mut_doc, artifact,
"generated_by", artifact_generated_by != NULL ? artifact_generated_by :
"pharos-native-runtime")) {
245 const char *artifact_dir,
247 const char *state_path,
248 const char *base_path,
249 const char *log_path,
250 const char *log_format,
251 const char *error_report_path,
253 const char *host_profile,
254 const char *compiled_entrypoint
262 char *error_report_path_json =
json_string_dup_native(error_report_path != NULL ? error_report_path :
"");
265 char *compiled_entrypoint_json =
json_string_dup_native(compiled_entrypoint != NULL ? compiled_entrypoint :
"");
267 if (artifact_dir_json == NULL || app_id_json == NULL || state_path_json == NULL || base_path_json == NULL || log_path_json == NULL || log_format_json == NULL || error_report_path_json == NULL || debug_json == NULL || host_profile_json == NULL || compiled_entrypoint_json == NULL) {
268 free(artifact_dir_json);
270 free(state_path_json);
271 free(base_path_json);
273 free(log_format_json);
274 free(error_report_path_json);
276 free(host_profile_json);
277 free(compiled_entrypoint_json);
280 report_json = (
char *)malloc(strlen(artifact_dir_json) + strlen(app_id_json) + strlen(state_path_json) + strlen(base_path_json) + strlen(log_path_json) + strlen(log_format_json) + strlen(error_report_path_json) + strlen(debug_json) + strlen(host_profile_json) + strlen(compiled_entrypoint_json) + 512);
281 if (report_json != NULL) {
282 snprintf(report_json, strlen(artifact_dir_json) + strlen(app_id_json) + strlen(state_path_json) + strlen(base_path_json) + strlen(log_path_json) + strlen(log_format_json) + strlen(error_report_path_json) + strlen(debug_json) + strlen(host_profile_json) + strlen(compiled_entrypoint_json) + 512,
283 "{\"report_id\":\"pharos-local-app-build-v1\",\"target_kind\":\"app\",\"target_id\":%s,\"status\":\"built\",\"artifact_dir\":%s,\"state_path\":%s,\"base_path\":%s,\"log_path\":%s,\"log_format\":%s,\"error_report_path\":%s,\"debug\":%s,\"host_profile\":%s,\"compiled_entrypoint\":%s,\"generated_by\":\"pharos-native-runtime\"}\n",
284 app_id_json, artifact_dir_json, state_path_json, base_path_json, log_path_json, log_format_json, error_report_path_json, debug_json, host_profile_json, compiled_entrypoint_json);
286 free(artifact_dir_json);
288 free(state_path_json);
289 free(base_path_json);
291 free(log_format_json);
292 free(error_report_path_json);
294 free(host_profile_json);
295 free(compiled_entrypoint_json);
char * build_native_app_index_html(const char *app_id)
Builds the default index.html payload for a native app artifact.
char * native_website_artifact_dir(const char *build_dir, const char *target_id)
Builds the artifact directory path for a generated website target.
char * json_string_dup_native(const char *value)
Duplicates a string while escaping it for JSON string output.
char * native_website_report_path(const char *build_dir, const char *verb, const char *target_id)
Builds the report file path for a website build or status operation.
int count_substring_occurrences(const char *text, const char *needle)
Counts how many times a substring occurs in a string.
char * build_native_app_build_report_json(const char *artifact_dir, const char *app_id, const char *state_path, const char *base_path, const char *log_path, const char *log_format, const char *error_report_path, const char *debug, const char *host_profile, const char *compiled_entrypoint)
Builds a JSON report describing a native app build result.
char * build_artifact_local_app_manifest_json(const char *manifest_text, const char *artifact_generated_by, const char *state_path, const char *base_path, const char *log_path, const char *log_format, const char *error_report_path, const char *debug, const char *compiled_entrypoint, int route_count, int surface_count, int workflow_count)
Builds an artifact-localized copy of the app-owned manifest.
char * build_native_website_status_report_json(const char *report_id, const char *verb, const char *target_id, const char *artifact_dir)
Builds a JSON status report for a native website artifact.
Declares helpers that build native artifact and report payload strings.
void buffer_init(Buffer *buffer)
Initializes a growable buffer to an empty state.
char * path_join(const char *left, const char *right)
Joins two path segments using the native path separator.
void buffer_free(Buffer *buffer)
Releases memory owned by a growable buffer.
int buffer_append(Buffer *buffer, const void *data, size_t len)
Appends bytes to a growable buffer and maintains a trailing NUL byte.
Declares shared low-level support helpers used across the Pharos native runtime.
void native_json_doc_free(yyjson_doc *doc)
Releases a document returned by the native yyjson helpers.
yyjson_doc * native_json_doc_load_text(const char *text)
Parses JSON text into an owned yyjson document.
Declares shared helper wrappers around vendored yyjson parsing and serialization APIs.
Growable byte buffer used by parsing and string assembly helpers.
void yyjson_mut_doc_free(yyjson_mut_doc *doc)
yyjson_mut_doc * yyjson_doc_mut_copy(const yyjson_doc *doc, const yyjson_alc *alc)
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_remove_key(yyjson_mut_val *obj, const char *key)
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj_get(const yyjson_mut_val *obj, const char *key)
yyjson_api_inline bool yyjson_mut_obj_add_int(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, int64_t val)
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj(yyjson_mut_doc *doc)
yyjson_api_inline char * yyjson_mut_write(const yyjson_mut_doc *doc, yyjson_write_flag flg, size_t *len)
yyjson_api_inline yyjson_mut_val * yyjson_mut_strcpy(yyjson_mut_doc *doc, const char *str)
yyjson_api_inline bool yyjson_mut_is_obj(const yyjson_mut_val *val)
yyjson_api_inline yyjson_mut_val * yyjson_mut_doc_get_root(yyjson_mut_doc *doc)
yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val)
static const yyjson_write_flag YYJSON_WRITE_ESCAPE_UNICODE
yyjson_api_inline bool yyjson_mut_obj_put(yyjson_mut_val *obj, yyjson_mut_val *key, yyjson_mut_val *val)
static const yyjson_write_flag YYJSON_WRITE_PRETTY