Propagate the results of running the run.sh script.

pull/9/head
Joshua Potter 2023-11-25 09:33:58 -07:00
parent 400388b262
commit 537226c651
5 changed files with 27 additions and 17 deletions

View File

@ -3,7 +3,6 @@
TODO:
- [ ] Make free-ing data consistent with null pointers.
- [ ] Add documentation throughout (ownership, docstrings, etc.).
- [ ] Have main.c return status code of run.sh.
- [ ] Organize variables in each function to the top?
CLI utility for initializing projects in reproducible ways.

View File

@ -22,6 +22,7 @@ enum ErrorCode {
ERROR_VALIDATOR_FIELD_PROMPT_INVALID,
ERROR_EVALUATOR_RUN_SH_NOT_FOUND,
ERROR_EVALUATOR_RUN_SH_NOT_EXEC,
ERROR_EVALUATOR_RESPONSE_INVALID,
};

View File

@ -5,8 +5,10 @@
#include "error.h"
#include "validator.h"
struct Error *evaluate_spec_json(
const struct Config *const config, const struct DynArray *const prompts
int evaluate_run_sh(
const struct Config *const config,
const struct DynArray *const prompts,
struct Error **error
);
#endif /* _BOOTSTRAP_EVALUATOR_H */

9
main.c
View File

@ -38,13 +38,13 @@ static int run(const char *root_dir, const char *target) {
goto cleanup_parsed;
}
if ((error = evaluate_spec_json(config, prompts))) {
fprintf(stderr, "%s", error->message);
if ((retval = evaluate_run_sh(config, prompts, &error))) {
if (error) {
fprintf(stderr, "%s", error->message);
}
goto cleanup_parsed;
}
retval = EXIT_SUCCESS;
cleanup_prompts:
if (prompts) {
dyn_array_free(prompts);
@ -61,6 +61,7 @@ cleanup_config:
cleanup_cwd:
free(cwd);
error_free(error);
return retval;
}

View File

@ -24,17 +24,25 @@ static struct Error *find_run_sh(const struct Config *const config) {
);
}
// TODO: Check run.sh is executable.
if (!(sb.st_mode & S_IXUSR)) {
return ERROR_NEW(
ERROR_EVALUATOR_RUN_SH_NOT_EXEC,
config->target,
"/run.sh is not executable."
);
}
return 0;
}
struct Error *evaluate_spec_json(
const struct Config *const config, const struct DynArray *const prompts
int evaluate_run_sh(
const struct Config *const config,
const struct DynArray *const prompts,
struct Error **error
) {
struct Error *error = find_run_sh(config);
if (error) {
return error;
*error = find_run_sh(config);
if (*error) {
return EXIT_FAILURE;
}
if (prompts) {
@ -61,8 +69,7 @@ struct Error *evaluate_spec_json(
free(filepath);
// TODO: Want to return this status out.
int status = system(command);
return 0;
int exit_code = system(command);
free((void *)command);
return WEXITSTATUS(exit_code);
}