Skip to content

Commit

Permalink
deps: Prevent dependencies from building their own dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Dec 21, 2024
1 parent ef3c62d commit fba12d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/bsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int bsys_dep_tree(bsys_t const* bsys, int argc, char* argv[]) {
return 0;
}

static int bsys_build_deps(bsys_t const* bsys) {
static int do_build_deps(bsys_t const* bsys) {
if (bsys->dep_tree == NULL || bsys->build_deps == NULL) {
return 0;
}
Expand Down Expand Up @@ -94,15 +94,13 @@ static int bsys_build_deps(bsys_t const* bsys) {
return rv;
}

int bsys_build(bsys_t const* bsys, char const* preinstall_prefix) {
int bsys_build(bsys_t const* bsys, char const* preinstall_prefix, bool build_deps) {
if (bsys->build == NULL) {
LOG_WARN("%s build system does not have a build step; nothing to build!", bsys->name);
return 0;
}

// Install dependencies.

if (bsys_build_deps(bsys) < 0) {
if (build_deps && do_build_deps(bsys) < 0) {
return -1;
}

Expand Down Expand Up @@ -187,7 +185,7 @@ static int install(bsys_t const* bsys, bool to_tmp_prefix) {

// Run build step.

if (bsys_build(bsys, path) < 0) {
if (bsys_build(bsys, path, true) < 0) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/bsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static bsys_t const* const BSYS[] = {

bsys_t const* bsys_identify(void);
int bsys_dep_tree(bsys_t const* bsys, int argc, char* argv[]);
int bsys_build(bsys_t const* bsys, char const* preinstall_prefix);
int bsys_build(bsys_t const* bsys, char const* preinstall_prefix, bool build_deps);
int bsys_run(bsys_t const* bsys, int argc, char* argv[]);
int bsys_sh(bsys_t const* bsys, int argc, char* argv[]);
int bsys_install(bsys_t const* bsys);
7 changes: 6 additions & 1 deletion src/deps.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ static bool build_task(void* data) {
// XXX If the dependency wants to use a different output path, we should probably add a function in the Bob build script to set the output path to something else instead of having an -o switch.

cmd_t CMD_CLEANUP cmd = {0};
cmd_create(&cmd, init_name, "-t", tmp_install_prefix, "-p", install_prefix, "-C", path, "build", NULL);
cmd_create(&cmd, init_name, "-p", install_prefix, "-C", path, NULL);

cmd_add(&cmd, "-t");
cmd_add(&cmd, tmp_install_prefix);

cmd_add(&cmd, "build-no-deps");

int const rv = cmd_exec(&cmd);

Expand Down
16 changes: 12 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,20 @@ int main(int argc, char* argv[]) {

char const* const instr = *argv++;

// If we explicitly set a temporary installation prefix, we're probably intending to preinstall to that prefix, even when just building.

char* const build_prefix = tmp_install_prefix_set ? tmp_install_prefix : NULL;

if (strcmp(instr, "build") == 0) {
// If we explicitly set a temporary installation prefix, we're probably intending to preinstall to that prefix, even when just building.
if (bsys_build(bsys, build_prefix, true) == 0) {
rv = EXIT_SUCCESS;
}
}

char* const prefix = tmp_install_prefix_set ? tmp_install_prefix : NULL;
// This is intentionally undocumented, as it's only used when the dependencies of this process are already being managed by another.

if (bsys_build(bsys, prefix) == 0) {
else if (strcmp(instr, "build-no-deps") == 0) {
if (bsys_build(bsys, build_prefix, false) == 0) {
rv = EXIT_SUCCESS;
}
}
Expand All @@ -301,7 +309,7 @@ int main(int argc, char* argv[]) {
}
}

// This is purposefully undocumented, as it's really only used for communication between Bob parent processes and their Bob children processes.
// This is intentionally undocumented, as it's really only used for communication between Bob parent processes and their Bob children processes.

else if (strcmp(instr, "dep-tree") == 0) {
LOG_WARN("This command is internal and isn't meant for direct use. A correct consumer of this command should be able to discard this message by reading the contents within the dependency tree tags.");
Expand Down

0 comments on commit fba12d9

Please sign in to comment.