static void cork_command_run(struct cork_command *command, int argc, char **argv) { cork_command_add_breadcrumb(command); /* If the gives the --help option at this point, describe the current * command. */ if (argc >= 2 && (streq(argv[1], "--help") || streq(argv[1], "-h"))) { cork_command_show_help(command, NULL); return; } /* Otherwise let the command parse any options that occur here. */ if (command->parse_options != NULL) { int option_count = command->parse_options(argc, argv); argc -= option_count; argv += option_count; } else { argc--; argv++; } switch (command->type) { case CORK_COMMAND_SET: cork_command_set_run(command, argc, argv); return; case CORK_LEAF_COMMAND: cork_command_leaf_run(command, argc, argv); return; default: cork_unreachable(); } }
int vrt_consumer_next(struct vrt_consumer *c, struct vrt_value **value) { do { unsigned int producer_count; struct vrt_value *v; rii_check(vrt_consumer_next_raw(c->queue, c)); v = vrt_queue_get(c->queue, c->current_id); switch (v->special) { case VRT_VALUE_NONE: *value = v; return 0; case VRT_VALUE_EOF: producer_count = cork_array_size(&c->queue->producers); c->eof_count++; clog_debug("<%s> Detected EOF (%u of %u) at value %d", c->name, c->eof_count, producer_count, c->current_id); if (c->eof_count == producer_count) { /* We've run out of values that we know can been * processed. Notify the world how much we've * processed so far. */ clog_debug("<%s> Signal consumption of %d", c->name, c->current_id); vrt_consumer_set_cursor(c, c->current_id); return VRT_QUEUE_EOF; } else { /* There are other producers still producing values, * so we should repeat the loop to grab the next * value. */ break; } case VRT_VALUE_HOLE: /* Repeat the loop to grab the next value. */ break; case VRT_VALUE_FLUSH: /* Return the FLUSH control message. */ return VRT_QUEUE_FLUSH; default: cork_unreachable(); } } while (true); }
static int bz_autotools__build(void *user_data) { struct bz_env *env = user_data; struct bz_value *ctx = bz_env_as_value(env); const char *package_name; struct cork_path *build_dir; struct cork_path *source_dir; struct cork_path *configure; struct bz_value *configure_args; const char *pkgconfig_path; bool exists; bool verbose; struct cork_exec *exec; struct cork_env *exec_env; struct cork_buffer buf = CORK_BUFFER_INIT(); rii_check(bz_install_dependency_string("autoconf", ctx)); rii_check(bz_install_dependency_string("automake", ctx)); rii_check(bz_build_message(env, "autotools")); rip_check(package_name = bz_env_get_string(env, "name", true)); rip_check(build_dir = bz_env_get_path(env, "build_dir", true)); rip_check(source_dir = bz_env_get_path(env, "source_dir", true)); rip_check(configure = bz_env_get_path(env, "autotools.configure.configure", true)); rie_check(pkgconfig_path = bz_env_get_string(env, "pkgconfig.path", false)); rie_check(verbose = bz_env_get_bool(env, "verbose", true)); /* Create the build path */ rii_check(bz_create_directory(cork_path_get(build_dir), 0750)); clog_info("(%s) Configure using autotools", package_name); /* $ autoreconf -i */ rii_check(bz_file_exists(cork_path_get(configure), &exists)); if (!exists) { exec = cork_exec_new("autoreconf"); cork_exec_add_param(exec, "autoreconf"); cork_exec_add_param(exec, "-i"); cork_exec_set_cwd(exec, cork_path_get(source_dir)); ei_check(bz_subprocess_run_exec(verbose, NULL, exec)); } #define add_dir(buzzy_name, param_name) \ do { \ struct cork_path *value; \ ep_check(value = bz_env_get_path(env, buzzy_name, true)); \ cork_buffer_printf(&buf, "--" param_name "=%s", cork_path_get(value)); \ cork_exec_add_param(exec, buf.buf); \ } while (0) /* $ ./configure ... */ exec = cork_exec_new(cork_path_get(configure)); exec_env = cork_env_clone_current(); cork_exec_set_env(exec, exec_env); cork_exec_add_param(exec, cork_path_get(configure)); add_dir("prefix", "prefix"); add_dir("exec_prefix", "exec-prefix"); add_dir("bin_dir", "bindir"); add_dir("sbin_dir", "sbindir"); add_dir("lib_dir", "libdir"); add_dir("libexec_dir", "libexecdir"); add_dir("share_dir", "datadir"); add_dir("man_dir", "mandir"); /* Add custom configure arguments, if given. */ configure_args = bz_env_get_value(env, "autotools.configure.args"); if (configure_args != NULL) { struct bz_configure_add_arg state = { exec, env }; switch (bz_value_kind(configure_args)) { case BZ_VALUE_SCALAR: ei_check(bz_configure_add_arg(&state, configure_args)); break; case BZ_VALUE_ARRAY: ei_check(bz_array_value_map (configure_args, &state, bz_configure_add_arg)); break; case BZ_VALUE_MAP: bz_bad_config("autotools.configure.args cannot be a map"); goto error; default: cork_unreachable(); } } cork_exec_set_cwd(exec, cork_path_get(build_dir)); if (pkgconfig_path != NULL) { cork_env_add(exec_env, "PKG_CONFIG_PATH", pkgconfig_path); } ei_check(bz_subprocess_run_exec(verbose, NULL, exec)); /* $ make */ clog_info("(%s) Build using autotools", package_name); exec = cork_exec_new("make"); cork_exec_add_param(exec, "make"); cork_exec_set_cwd(exec, cork_path_get(build_dir)); ei_check(bz_subprocess_run_exec(verbose, NULL, exec)); cork_buffer_done(&buf); return 0; error: cork_buffer_done(&buf); return -1; }