Skip to content

Commit

Permalink
dep-tree: Add tags at beginning and end of dependency tree content
Browse files Browse the repository at this point in the history
This is so that extra info logs or stuff printed to stderr doesn't end up in the dependency tree.
  • Loading branch information
obiwac committed Dec 7, 2024
1 parent 0603523 commit e31fd2a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/bsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
27 changes: 27 additions & 0 deletions src/dep_serialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/deps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/deps.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include <flamingo/flamingo.h>

#define DEP_TAG_START "<bob-dep-tree>\n"
#define DEP_TAG_END "</bob-dep-tree>\n"

typedef struct dep_node_t dep_node_t;

struct dep_node_t {
Expand Down

0 comments on commit e31fd2a

Please sign in to comment.