Actually use our library for building. Support ./configure and ./autogen.sh. Move some common functions to the library too

This commit is contained in:
Andy Williams 2014-04-27 17:36:20 +01:00
parent 40c206849e
commit 5eff36e8e8
6 changed files with 191 additions and 24 deletions

View File

@ -24,7 +24,6 @@
static Evas_Object *_edi_filepanel, *_edi_logpanel, *_edi_consolepanel;
static Evas_Object *_edi_main_win, *_edi_new_popup;
static const char *_edi_projectpath;
static Evas_Object *edi_win_setup(const char *path);
@ -155,13 +154,9 @@ _tb_new_create_cb(void *data,
void *event_info EINA_UNUSED)
{
const char *path, *name;
int len;
name = elm_entry_entry_get((Evas_Object *) data);
len = strlen(name) + strlen(_edi_projectpath) + 2;
path = malloc(sizeof(char) * len);
snprintf(path, len, "%s/%s", _edi_projectpath, name);
path = edi_project_file_path_get(name);
fclose(fopen(path, "w"));
edi_mainview_open_path(path, NULL);
@ -255,17 +250,19 @@ _tb_paste_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNU
static void
_tb_build_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
unsigned int printed, buffer_len = 512;
char buffer [buffer_len];
FILE *pf;
elm_toolbar_item_selected_set(elm_toolbar_selected_item_get(obj), EINA_FALSE);
edi_consolepanel_clear();
edi_consolepanel_show();
ecore_exe_pipe_run("make", ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR, NULL);
if (!edi_builder_can_build())
{
edi_consolepanel_append_error_line("Cowardly refusing to build unknown project type.");
}
else
{
edi_builder_build();
}
}
static Evas_Object *
@ -312,8 +309,8 @@ _edi_project_chosen_cb(void *data,
if (event_info)
{
_edi_projectpath = event_info;
edi_win_setup(_edi_projectpath);
edi_project_set(event_info);
edi_win_setup(edi_project_get());
}
else
elm_exit();
@ -370,7 +367,7 @@ edi_win_setup(const char *path)
const char *winname;
if (!path) return _edi_project_choose();
_edi_projectpath = path;
edi_project_set(path);
elm_need_ethumb();
elm_need_efreet();
@ -467,8 +464,6 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
if (!(win = edi_win_setup(project_path)))
goto end;
edi_library_call();
elm_run();
end:

View File

@ -89,16 +89,49 @@ EAPI int edi_shutdown(void);
*/
/**
* @brief Main group API that wont do anything
* @defgroup Main Main
* @brief Main group API that manages Edi projects
* @defgroup Main Project level functions
*
* @{
*
* @brief A function that doesn't do any good nor any bad
* Set the current edi project that is loaded.
*
* @param path The path to the current project being loaded.
*
* @ingroup Main
*/
EAPI void edi_library_call(void);
EAPI void edi_project_set(const char *path);
/**
* Get the current edi project that is loaded.
*
* @return the project that Edi is current working with.
*
* @ingroup Main
*/
EAPI const char *edi_project_get(void);
/**
* Get the path to a file within the current project.
*
* @param file The file within a project to get the absolute path for.
*
* @return the full path to the requested file
*
* @ingroup Main
*/
EAPI const char *edi_project_file_path_get(const char *file);
/**
* Find if a requested file exists within the current project.
*
* @param file The filename to check for existance within the current project.
*
* @return whether or not the requested file exists within the current project.
*
* @ingroup Main
*/
EAPI Eina_Bool edi_project_file_exists(const char *file);
/**
* @}

View File

@ -13,6 +13,8 @@ lib_LTLIBRARIES = libedi.la
includes_HEADERS = Edi.h
includesdir = $(includedir)/edi-@VMAJ@
libedi_la_SOURCES = edi.c
libedi_la_SOURCES = \
edi_builder.c \
edi.c
libedi_la_LIBADD = @EFL_LIBS@ -lm
libedi_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@

View File

@ -8,6 +8,7 @@
static int _edi_init = 0;
int _edi_lib_log_dom = -1;
static const char *_edi_project_path;
EAPI int
edi_init(void)
@ -58,7 +59,39 @@ edi_shutdown(void)
}
EAPI void
edi_library_call(void)
edi_project_set(const char *path)
{
INF("Not really doing anything useful.");
_edi_project_path = path;
}
EAPI const char *
edi_project_get()
{
return _edi_project_path;
}
EAPI const char *
edi_project_file_path_get(const char *file)
{
const char *path;
int len;
len = strlen(file) + strlen(edi_project_get()) + 2;
path = malloc(sizeof(char) * len);
snprintf(path, len, "%s/%s", edi_project_get(), file);
return path;
}
EAPI Eina_Bool
edi_project_file_exists(const char *file)
{
const char *path;
Eina_Bool exists;
path = edi_project_file_path_get(file);
exists = ecore_file_exists(path);
free(path);
return exists;
}

49
src/lib/edi_builder.c Normal file
View File

@ -0,0 +1,49 @@
#ifdef HAVE_CONFIG
# include "config.h"
#endif
#include "Edi.h"
#include "edi_builder.h"
#include "edi_private.h"
EAPI Eina_Bool
edi_builder_can_build(void)
{
return edi_project_file_exists("Makefile") ||
edi_project_file_exists("configure") ||
edi_project_file_exists("autogen.sh");
}
EAPI void
_edi_builder_build_make(void)
{
ecore_exe_pipe_run("make", ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR, NULL);
}
EAPI void
_edi_builder_build_configure(void)
{
ecore_exe_pipe_run("./configure && make", ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR, NULL);
}
EAPI void
_edi_builder_build_autogen(void)
{
ecore_exe_pipe_run("./autogen.sh && make", ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR, NULL);
}
EAPI void
edi_builder_build(void)
{
if (edi_project_file_exists("Makefile"))
_edi_builder_build_make();
else if (edi_project_file_exists("configure"))
_edi_builder_build_configure();
else if (edi_project_file_exists("autogen.sh"))
_edi_builder_build_autogen();
}

55
src/lib/edi_builder.h Normal file
View File

@ -0,0 +1,55 @@
#ifndef EDI_BUILDER_H_
# define EDI_BUILDER_H_
#include <Elementary.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* @brief These routines are used for Edi building.
*/
/**
* @brief Main builder management
* @defgroup Builder
*
* @{
*
* Functions of build management and execution.
*
*/
/**
* Check if Edi can build the current project.
*
* @return Whether or not the current project can be built.
*
* @see edi_builder_build().
*
* @ingroup Builder
*/
EAPI Eina_Bool
edi_builder_can_build(void);
/**
* Run a build for the current project.
*
* @see edi_builder_can_build().
*
* @ingroup Builder
*/
EAPI void
edi_builder_build(void);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* EDI_BUILDER_H_ */