Skip to content

Commit

Permalink
bsys: Output empty dependency tree if bsys doesn't have dep_tree fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
obiwac committed Jan 6, 2025
1 parent 84366ed commit 54b577f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/bsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ bsys_t const* bsys_identify(void) {
}

int bsys_dep_tree(bsys_t const* bsys, int argc, char* argv[]) {
dep_node_t* tree = NULL;

if (bsys->dep_tree == NULL) {
return 0;
goto no_tree;
}

// Parse the arguments as a list of hashes.
Expand All @@ -43,23 +45,21 @@ int bsys_dep_tree(bsys_t const* bsys, int argc, char* argv[]) {
// Create dependency tree.

bool circular;
dep_node_t* const tree = bsys->dep_tree(argc, hashes, &circular);
tree = bsys->dep_tree(argc, hashes, &circular);
free(hashes);

if (tree == NULL) {
if (circular) {
printf(BOB_DEPS_CIRCULAR);
return 0;
}

return -1;
if (tree == NULL && circular) {
printf(BOB_DEPS_CIRCULAR);
return 0;
}

assert(!circular);

// Serialize and output it.

char* const STR_CLEANUP serialized = dep_node_serialize(tree);
no_tree:;

char* const STR_CLEANUP serialized = tree == NULL ? strdup("") : dep_node_serialize(tree);
printf(DEP_TAG_START "%s" DEP_TAG_END, serialized);

deps_tree_free(tree);
Expand Down
4 changes: 4 additions & 0 deletions src/dep_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ void deps_node_free(dep_node_t* node) {
}

void deps_tree_free(dep_node_t* tree) {
if (tree == NULL) {
return;
}

deps_node_free(tree);
free(tree);
}
Expand Down

0 comments on commit 54b577f

Please sign in to comment.