void show_build_progress(int current_step, int exit_code) { if(exit_code != 0) { int len = strlen(step[current_step-1]); int i; for(i = 0; i < len; i++) { printf("\b"); } printf("%s%s\n", yellow(), step[current_step-1]); } else if(current_step == step_count) { int len = strlen(step[current_step-1]); int i; for(i = 0; i < len; i++) { printf("\b"); } printf("%s%s%s\n", green(), step[current_step-1], color_reset()); } else if(current_step > 0) { int len = strlen(step[current_step-1]); int i; for(i = 0; i < len; i++) { printf("\b"); } printf("%s%s\n", green(), step[current_step-1]), printf("%s%s", color_reset(), step[current_step]); fflush(stdout); } else { printf("%s%s", color_reset(), step[current_step]); fflush(stdout); } }
static void print_abort_error(const char *etype, const char *emsg) { fprintf(stderr, _("%s%s%s: %s%s:%s\n %s\n"), color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), color_get(COLOR_ERROR), etype, color_reset(), emsg); }
void erln8_log( const gchar* log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data ) { switch(log_level & G_LOG_LEVEL_MASK) { case G_LOG_FLAG_RECURSION: case G_LOG_LEVEL_CRITICAL: case G_LOG_LEVEL_ERROR: fprintf(stderr, "%s", red()); fprintf(stderr, "ERROR: %s",message); fprintf(stderr, "%s", color_reset()); exit(-1); break; case G_LOG_LEVEL_WARNING: fprintf(stderr, "%s", yellow()); fprintf(stderr, "WARNING: %s",message); fprintf(stderr, "%s", color_reset()); break; case G_LOG_LEVEL_INFO: case G_LOG_LEVEL_MESSAGE: fprintf(stderr, "INFO: %s",message); break; case G_LOG_LEVEL_DEBUG: if(opt_debug) { fprintf(stderr, "DEBUG: %s",message); } break; default: fprintf(stderr, "%s", red()); fprintf(stderr, "UNHANDLED: %s",message); fprintf(stderr, "%s", color_reset()); break; } return; }
void print_fatal_error(const char *emsg, const void *data) { fprintf(stderr, "%s%s:%s %s%s:%s %s\n", color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), color_get(COLOR_ERROR), _("error"), color_reset(), emsg); }
static int lua_likwid_pinProcess(lua_State* L) { int cpuID = luaL_checknumber(L,-2); int silent = luaL_checknumber(L,-1); luaL_argcheck(L, cpuID >= 0, 1, "CPU ID must be greater or equal 0"); if (affinity_isInitialized == 0) { affinity_init(); affinity_isInitialized = 1; affinity = get_affinityDomains(); } affinity_pinProcess(cpuID); if (!silent) { #ifdef COLOR color_on(BRIGHT, COLOR); #endif printf("[likwid-pin] Main PID -> core %d - OK", cpuID); #ifdef COLOR color_reset(); #endif printf("\n"); } return 0; }
void display_latest_quickstart() { gchar* repo = "default"; GHashTable* repos = get_repos(); gboolean has_repo = g_hash_table_contains(repos, repo); g_hash_table_destroy(repos); if(!has_repo) { g_error("Unknown repo %s\n", repo); } gchar* source_path = get_config_subdir_file_name("repos", repo); if(!g_file_test(source_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { g_error("Missing repo for %s, which should be in %s. Maybe you forgot to erln8 --clone repo_name\n", repo, source_path); } // too much color? I'd like this message to stand out printf("%sDetected latest Erlang/OTP tag: %s\n", blue(), green()); gchar* fetchcmd = g_strconcat("cd ", source_path, " && git describe --abbrev=0 --tags", NULL); int result = system(fetchcmd); if(result != 0) { g_error("Error fetching from repo %s\n", repo); } printf("%s\n", color_reset()); g_free(source_path); g_free(fetchcmd); }
void do_internerr(const char *file, int line, const char *func, const char *fmt, ...) { va_list args; va_start(args, fmt); error_context_errmsg_format(fmt, args); va_end(args); fprintf(stderr, "%s%s:%s:%d:%s:%s %s%s:%s %s\n", color_get(COLOR_PROG), dpkg_get_progname(), file, line, func, color_reset(), color_get(COLOR_ERROR), _("internal error"), color_reset(), econtext->errmsg); abort(); }
// write an ERLN8_CONFIG_FILE file into the cwd // won't override an existing file // unless the user specifies --force void init_here(gchar* erlang) { GHashTable* erlangs = get_erlangs(); gboolean has_erlang = g_hash_table_contains(erlangs, erlang); g_hash_table_destroy(erlangs); if(!has_erlang) { g_error("%s is not a configured version of Erlang\n", erlang); } GKeyFile* kf = g_key_file_new(); g_key_file_set_string(kf, "Config", "Erlang", erlang); GError* error = NULL; gchar* d = g_key_file_to_data (kf, NULL, &error); gchar* fn = "./" ERLN8_CONFIG_FILE; gboolean result = FALSE; if(!opt_force) { result = g_file_test(fn, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR); } if(result) { g_error("Config already exists in this directory. Override with --force.\n"); } else { GError* error2 = NULL; if(!g_file_set_contents(fn, d, -1, &error2)) { if (error2 != NULL) { g_error("Unable to write file %s: %s\n", fn, error2->message); } else { g_error("Unable to write file %s\n", fn); } } else { fprintf(stderr, "%sSaved " ERLN8_CONFIG_FILE " to %s%s\n", green(), fn, color_reset()); } } g_key_file_free(kf); }
void dobuild() { gchar* repo = NULL; if(opt_repo == NULL) { printf("%sRepo not specified, using default%s\n", yellow(), color_reset()); repo = "default"; } else { repo = opt_repo; } if(repo == NULL) { g_error("build repo not specified\n"); } if(opt_tag == NULL) { g_error("build tag not specified\n"); } if(opt_id == NULL) { g_error("build id not specified\n"); } // opt_config is optional g_debug("repo:%s\n", repo); g_debug("tag :%s\n", opt_tag); g_debug("id :%s\n", opt_id); g_debug("cfg :%s\n", opt_config); build_erlang(repo, opt_tag, opt_id, opt_config); }
// THIS FUNCTION NEEDS TO BE BROKEN UP INTO SMALLER PIECES! void build_erlang(gchar* repo, gchar* tag, gchar* id, gchar* build_config) { // check to see if the ID has already been used GHashTable* otps = get_erlangs(); gboolean has_otp = g_hash_table_contains(otps, id); g_hash_table_destroy(otps); if(has_otp) { g_error("A version of Erlang already exists with this id: %s\n", id); } // check to see if the repo exists GHashTable* repos = get_repos(); gboolean has_repo = g_hash_table_contains(repos, repo); g_hash_table_destroy(repos); if(!has_repo) { g_error("Unconfigured repo: %s\n", repo); } // check for a valid build config if one is specified GHashTable* configs = get_configs(); if(build_config) { if(!g_hash_table_contains(configs, build_config)) { g_hash_table_destroy(configs); g_error("Unconfigured build config: %s\n", build_config); } } else { // check the default GHashTable* e8 = get_erln8(); if(g_hash_table_contains(e8, "default_config")) { build_config = strdup((gchar*)g_hash_table_lookup(e8, "default_config")); printf("%sUsing default config %s%s\n", build_config, yellow(), color_reset()); } g_hash_table_destroy(e8); } gchar pattern[] = "/tmp/erln8.buildXXXXXX"; gchar* tmp = g_mkdtemp(pattern); g_debug("building in %s\n", tmp); gchar* output_root = get_config_subdir_file_name("otps",id); gchar* output_path = g_strconcat(output_root, "/dist", NULL); gchar* source_path = get_config_subdir_file_name("repos", repo); GTimeVal t; g_get_current_time(&t); gchar* ts = g_time_val_to_iso8601(&t); gchar* ld = g_strconcat("logs/build_", id, "_", ts, NULL); gchar* log_path = get_configdir_file_name(ld); // check that the branch or tag exists in the specified repo gchar* check_obj = g_strconcat("cd ", source_path, "&& git show-ref ", tag, " > /dev/null", NULL); if(system(check_obj) != 0) { g_free(check_obj); g_error("branch or tag %s does not exist in %s Git repo\n", tag, repo); } g_free(check_obj); /// check that the repo has been cloned if(!g_file_test(source_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { g_error("Missing repo for %s, which should be in %s.\nDid you forget to `erln8 --clone <repo_name>?`\n", repo, source_path); } gchar* bc = NULL; gchar* env = NULL; if(build_config != NULL) { bc = (gchar*)g_hash_table_lookup(configs, build_config); // don't drop a NULL into the middle of the command string if(bc == NULL) { bc = ""; } else { gchar* env_name = g_strconcat(build_config, "_env", NULL); env = (gchar*)g_hash_table_lookup(configs, env_name); if(env == NULL) { env = ""; } g_free(env_name); } } else { if(env == NULL) { env = ""; } } g_free(ld); g_debug("Output path = %s\n", output_path); g_debug("Source path = %s\n", source_path); g_debug("Log path = %s\n", log_path); printf("Building %s from tag/branch %s of repo %s\n", id, tag, repo); printf("Custom build config: %s\n", bc); printf("Custom build env: %s\n", env); printf("Build log: %s\n", log_path); gchar* buildcmd0 = g_strconcat(env, " cd ", source_path, " && git archive ", tag, " | (cd ", tmp, "; tar -f - -x)", NULL); gchar* buildcmd1 = g_strconcat(env, " cd ", tmp, " && ./otp_build autoconf > ", log_path, " 2>&1", NULL); gchar* buildcmd2 = g_strconcat(env, " cd ", tmp, " && ./configure --prefix=", output_path," ", bc == NULL ? "" : bc, " >> ", log_path, " 2>&1", NULL); gchar* buildcmd3 = g_strconcat(env, " cd ", tmp, " && make >> ", log_path, " 2>&1", NULL); gchar* buildcmd4 = g_strconcat(env, " cd ", tmp, " && make install >> ", log_path, " 2>&1", NULL); gchar* build_cmds[] = { buildcmd0, buildcmd1, buildcmd2, buildcmd3, buildcmd4, NULL }; int result = 0; int i = 0; for(i = 0; i < step_count; i++) { show_build_progress(i, result); if(result != 0) { g_debug("STATUS = %d\n", result); printf("Here are the last 10 lines of the log file:\n"); gchar* tail = g_strconcat("tail -10 ", log_path, NULL); int tailresult = system(tail); if(tailresult != 0) { g_error("Cannot run tail -10 on %s\n", log_path); } g_free(tail); printf("---------------------------------------------------------\n"); g_error("Build error, please check the build logs for more details\n"); } g_debug("running %s\n", build_cmds[i]); if(!opt_dryrun) { result = system(build_cmds[i]); } else { result = 0; printf("%s\n", build_cmds[i]); } } show_build_progress(step_count, result); printf("Registering Erlang installation\n"); if(!opt_dryrun) { set_config_kv("Erlangs", id, output_root); } printf("Generating links\n"); setup_binaries(id); printf("%sBuild complete%s\n", green(), color_reset() ); g_free(buildcmd0); g_free(buildcmd1); g_free(buildcmd2); g_free(buildcmd3); g_free(buildcmd4); g_free(log_path); g_free(source_path); g_free(output_path); g_free(output_root); // destroy close to the end so the string isn't freed before it's used g_hash_table_destroy(configs); }
// generate the initial ~/ERLN8_CONFIG_DIR/config file with some // default settings // TODO: more settings, Linux, FreeBSD etc void init_main_config() { GKeyFile* kf = g_key_file_new(); g_key_file_set_boolean(kf, "Erln8", "color", TRUE); g_key_file_set_comment(kf, "Erln8", "color", "Either true or false, case sensitive", NULL); g_key_file_set_boolean(kf, "Erln8", "banner", FALSE); g_key_file_set_comment(kf, "Erln8", "banner", "Show the version of Erlang that erln8 is running", NULL); g_key_file_set_string(kf, "Erln8", "default_config", "default"); g_key_file_set_comment(kf, "Erln8", "default_config", "The default config to use for a build", NULL); g_key_file_set_string(kf, "Erln8", "system_default", ""); g_key_file_set_comment(kf, "Erln8", "system_default", "If an erln8.config file isn't found, use this one.", NULL); g_key_file_set_string(kf, "Repos", "default", "https://github.com/erlang/otp.git"); g_key_file_set_string(kf, "Erlangs", "none", ""); g_key_file_set_string(kf, "Configs", "default", ""); g_key_file_set_string(kf, "Configs", "osx_llvm", "--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit"); g_key_file_set_string(kf, "Configs", "osx_llvm_dtrace", "--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit --enable-vm-probes --with-dynamic-trace=dtrace"); g_key_file_set_string(kf, "Configs", "osx_gcc", "--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit"); g_key_file_set_string(kf, "Configs", "osx_gcc_env", "CC=gcc-4.2 CPPFLAGS=\'-DNDEBUG\' MAKEFLAGS=\'-j 3\'"); GError* error = NULL; gchar* d = g_key_file_to_data (kf, NULL, &error); if(error != NULL) { g_error("Unable to create ~/" ERLN8_CONFIG_DIR "/config: %s\n", error->message); //g_error_free(error); } gchar* fn = get_configdir_file_name("config"); printf("Creating " ERLN8_CONFIG_FILE " file: %s\n", fn); GError* contentserror = NULL; if(!g_file_set_contents(fn, d, -1, &contentserror)) { if(contentserror != NULL) { g_error("Unable to write contents to ~/" ERLN8_CONFIG_DIR "/config: %s\n", contentserror->message); } else { g_error("Unable to write contents to ~/" ERLN8_CONFIG_DIR "/config\n"); } } g_free(fn); g_free(d); g_key_file_free(kf); if(!opt_quickstart) { printf("%sIf you only want to use the canonical OTP repo, run `erln8 --clone default` before continuing%s\n", yellow(), color_reset()); } }
int main(int argc, char* argv[]) { // compiler will whine about it being deprecated, but taking it out // blows things up // used for GIO g_type_init(); g_log_set_always_fatal(G_LOG_LEVEL_ERROR); g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL, erln8_log, NULL); homedir = g_getenv("ERLN8_HOME"); if(homedir == NULL) { homedir = g_get_home_dir(); } else { // builds will fail if ERLN8_HOME is not an absolute path if(homedir[0] != '/') { g_error("ERLN8_HOME must be an absolute path\n"); } } g_debug("home directory = %s\n", homedir); gchar* basename = g_path_get_basename(argv[0]); g_debug("basename = %s\n", basename); if((!strcmp(basename, "erln8")) || (!strcmp(basename, "./erln8"))) { erln8(argc, argv); g_free(basename); } else { gchar* erl = which_erlang(); if(erl == NULL) { g_message("Can't find an " ERLN8_CONFIG_FILE " file to use\n"); g_error("No " ERLN8_CONFIG_FILE " file\n"); } GHashTable* erlangs = get_erlangs(); GHashTable* runtime_options = get_erln8(); gchar* path = g_hash_table_lookup(erlangs, erl); if(path == NULL) { g_hash_table_destroy(erlangs); g_hash_table_destroy(runtime_options); g_error("Version of Erlang (%s) isn't configured in erln8\n", erl); } gchar* use_color = (gchar*)g_hash_table_lookup(runtime_options, "color"); if(g_strcmp0(use_color, "true") == 0) { opt_color = TRUE; } else { opt_color = FALSE; } gchar* use_banner = (gchar*)g_hash_table_lookup(runtime_options, "banner"); if(g_strcmp0(use_banner, "true") == 0) { opt_banner = TRUE; } else { opt_banner = FALSE; } gchar* s = get_bin(erl, basename); g_debug("%s\n",s); gboolean result = g_file_test(s, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR); g_free(basename); if(!result) { g_hash_table_destroy(erlangs); g_hash_table_destroy(runtime_options); g_free(s); g_error("Can't run %s, check to see if the file exists\n", s); } if(opt_banner) { printf("%s", red()); printf("erln8: %s", blue()); printf("using Erlang %s", path); printf("%s\n", color_reset()); } g_hash_table_destroy(erlangs); g_hash_table_destroy(runtime_options); // can't free s execv(s, argv); } return 0; }