示例#1
0
文件: project.c 项目: ylecuyer/fatso
int
fatso_load_project(struct fatso* f) {
  int r = 0;
  char* fatso_yml = NULL;
  char* error_message = NULL;

  if (f->project != NULL) {
    // Project is already loaded.
    goto out;
  }

  f->project = fatso_alloc(sizeof(struct fatso_project));
  fatso_project_init(f->project);
  f->project->path = strdup(fatso_project_directory(f));

  asprintf(&fatso_yml, "%s/fatso.yml", f->project->path);
  r = parse_fatso_yml(f->project, fatso_yml, &error_message);
  if (r != 0) {
    fatso_logf(f, FATSO_LOG_FATAL, "Cannot load project: %s", error_message);
    goto error;
  }

out:
  fatso_free(error_message);
  fatso_free(fatso_yml);
  return r;
error:
  r = 1;
  fatso_unload_project(f);
  goto out;
}
示例#2
0
void
fatso_configuration_destroy(struct fatso_configuration* e) {
  fatso_free(e->name);
  for (size_t i = 0; i < e->dependencies.size; ++i) {
    fatso_dependency_destroy(&e->dependencies.data[i]);
  }
  fatso_free(e->dependencies.data);
  for (size_t i = 0; i < e->defines.size; ++i) {
    fatso_define_destroy(&e->defines.data[i]);
  }
  fatso_free(e->defines.data);
  memset(e, 0, sizeof(*e));
}
示例#3
0
int
fatso_guess_toolchain(struct fatso* f, struct fatso_package* p, struct fatso_toolchain* out_toolchain) {

  if( p->toolchain != NULL ){
    fatso_logf(f, FATSO_LOG_INFO, "Using explicitly provided toolchain '%s'.", p->toolchain );

    // TODO: optionally set this to p->toolchain
    out_toolchain->name = "[config provided]";
    out_toolchain->build = &build_provided_toolchain;
    out_toolchain->install = &install_provided_toolchain;
    return 0; // we found the toolchain
  }

  char* path = fatso_package_build_path(f, p);
  bool found = false;
  for (const struct init_named_toolchain* i = named_toolchains; i->name; ++i) {
    if (i->guess(path)) {
      found = true;
      i->init(out_toolchain);
    }
  }
  fatso_free(path);
  if (!found) {
    fatso_logf(f, FATSO_LOG_FATAL, "Fatso couldn't guess the toolchain of package '%s', and none was explicitly defined!", p->name);
    return 1;
  }
  return 0;
}
示例#4
0
文件: project.c 项目: ylecuyer/fatso
int fatso_generate_dependency_graph(struct fatso* f) {
  int r = 0;

  enum fatso_dependency_graph_resolution_status status;
  struct fatso_dependency_graph* graph = fatso_dependency_graph_for_package(f, &f->project->package, &status);

  fatso_strbuf_t msg;
  fatso_strbuf_init(&msg);

  switch (status) {
    case FATSO_DEPENDENCY_GRAPH_CONFLICT: {
      fatso_strbuf_printf(&msg, "The following dependencies could not be simultaneously met:\n");

      fatso_conflicts_t conflicts = {0};
      fatso_dependency_graph_get_conflicts(graph, &conflicts);
      for (size_t i = 0; i < conflicts.size; ++i) {
        struct fatso_dependency* dep = conflicts.data[i].dependency;
        fatso_strbuf_printf(&msg, "  %s ", dep->name);
        for (size_t j = 0; j < dep->constraints.size; ++j) {
          fatso_strbuf_printf(&msg, "%s", fatso_constraint_to_string_unsafe(&dep->constraints.data[j]));
          if (j + 1 < dep->constraints.size) {
            fatso_strbuf_printf(&msg, ", ");
          }
        }
        fatso_strbuf_printf(&msg, " (from %s %s)\n", conflicts.data[i].package->name, fatso_version_string(&conflicts.data[i].package->version));
      }

      r = 1;
      break;
    }
    case FATSO_DEPENDENCY_GRAPH_UNKNOWN: {
      fatso_strbuf_printf(&msg, "The following packages could not be found in any repository:\n");
      fatso_unknown_dependencies_t unknowns = {0};
      fatso_dependency_graph_get_unknown_dependencies(graph, &unknowns);
      for (size_t i = 0; i < unknowns.size; ++i) {
        fatso_strbuf_printf(&msg, "  %s\n", unknowns.data[i]->name);
      }

      r = 1;
      break;
    }
    case FATSO_DEPENDENCY_GRAPH_SUCCESS: {
      fatso_dependency_graph_topological_sort(graph, f, &f->project->install_order.data, &f->project->install_order.size);
      break;
    }
  }
  if (msg.size) {
    char* message = fatso_strbuf_strdup(&msg);
    fatso_logz(f, FATSO_LOG_FATAL, message, msg.size);
    fatso_free(message);
  }
  fatso_strbuf_destroy(&msg);
  fatso_dependency_graph_free(graph);

  return r;
}
示例#5
0
int
fatso_guess_toolchain(struct fatso* f, struct fatso_package* p, struct fatso_toolchain* out_toolchain) {
  // TODO: Use 'toolchain' option in package.

  char* path = fatso_package_build_path(f, p);
  bool found = false;
  for (const struct init_named_toolchain* i = named_toolchains; i->name; ++i) {
    if (i->guess(path)) {
      found = true;
      i->init(out_toolchain);
    }
  }
  fatso_free(path);
  if (!found) {
    fatso_logf(f, FATSO_LOG_FATAL, "Fatso couldn't guess the toolchain of package '%s', and none was explicitly defined!", p->name);
    return 1;
  }
  return 0;
}
示例#6
0
文件: project.c 项目: ylecuyer/fatso
void
fatso_unload_project(struct fatso* f) {
  fatso_project_destroy(f->project);
  fatso_free(f->project);
  f->project = NULL;
}
示例#7
0
文件: project.c 项目: ylecuyer/fatso
void
fatso_project_destroy(struct fatso_project* p) {
  fatso_free(p->path);
  p->path = NULL;
  fatso_package_destroy(&p->package);
}
示例#8
0
文件: define.c 项目: ylecuyer/fatso
void
fatso_define_destroy(struct fatso_define* def) {
  fatso_free(def->key);
  fatso_free(def->value);
}