diff --git a/src/bsys.c b/src/bsys.c index 8b7ffe46..0fccc9eb 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -39,7 +39,7 @@ int bsys_dep_tree(bsys_t const* bsys) { char* const STR_CLEANUP serialized = dep_node_serialize(tree); - printf("%s", serialized); + printf(DEP_TAG_START "%s" DEP_TAG_END, serialized); return 0; } diff --git a/src/dep_serialization.c b/src/dep_serialization.c index 0385c55c..95bd39f2 100644 --- a/src/dep_serialization.c +++ b/src/dep_serialization.c @@ -63,6 +63,8 @@ char* dep_node_serialize(dep_node_t* node) { } int dep_node_deserialize(dep_node_t* root, char* serialized) { + // Do all the necessary set up for the root node and the stack. + root->is_root = true; root->path = NULL; @@ -74,9 +76,34 @@ int dep_node_deserialize(dep_node_t* root, char* serialized) { assert(stack != NULL); stack[0] = root; + // Figure out if we're using dependency tree tags or not. + // If we are, jump to after that point in the string passed. + // If we are not, assume the whole string is the meat of the dependency tree. + + char* const dep_tag_start = strstr(serialized, DEP_TAG_START); + bool const use_tags = dep_tag_start != NULL; + + if (use_tags) { + serialized = dep_tag_start + strlen(DEP_TAG_START); + } + + // We need to keep a copy of the original backing string to free it later. + // If using tags, remove all that is after the closing tag. + char* const STR_CLEANUP orig_backing = strdup(serialized); assert(orig_backing != NULL); + if (use_tags) { + char* const dep_tag_end = strstr(orig_backing, DEP_TAG_END); + + if (dep_tag_end == NULL) { + LOG_FATAL("Using dependency tree tags, but no closing dependency tree tag found." PLZ_REPORT); + return -1; + } + + dep_tag_end[0] = '\0'; + } + char* backing = orig_backing; char* tok; diff --git a/src/deps.c b/src/deps.c index 4492bf09..be8b6369 100644 --- a/src/deps.c +++ b/src/deps.c @@ -258,7 +258,7 @@ dep_node_t* deps_tree(flamingo_val_t* deps_vec) { FILE* const hash_f = fopen(hash_path, "r"); if (hash_f == NULL) { - // LOG_INFO("No cached dependency tree found, building it."); + LOG_INFO("No cached dependency tree found, building it."); goto build_tree; } @@ -267,14 +267,14 @@ dep_node_t* deps_tree(flamingo_val_t* deps_vec) { fclose(hash_f); if (read_hash != hash) { - // LOG_INFO("Dependency vector changed, rebuilding dependency tree."); + LOG_INFO("Dependency vector changed, rebuilding dependency tree."); goto build_tree; } FILE* const tree_f = fopen(tree_path, "r"); if (tree_f == NULL) { - // LOG_WARN("Could not open dependency tree file '%s', rebuilding it.", tree_path); + LOG_WARN("Could not open dependency tree file '%s', rebuilding it.", tree_path); goto build_tree; } diff --git a/src/deps.h b/src/deps.h index f821b476..e18f82e0 100644 --- a/src/deps.h +++ b/src/deps.h @@ -5,6 +5,9 @@ #include +#define DEP_TAG_START "\n" +#define DEP_TAG_END "\n" + typedef struct dep_node_t dep_node_t; struct dep_node_t {