build: Add support for tracking build process exit code and add notification.

This patch adds tracking of the build process's status code. This allows us
to respond to the build process within the program much easier. Also added
a simple API for desktop notification of the build process and its exit code
which is useful and pretty.
This commit is contained in:
Al Poole 2017-09-04 20:52:34 +01:00
parent 65477c7d46
commit 5aba714f90
12 changed files with 87 additions and 41 deletions

View File

@ -196,7 +196,7 @@ main(int argc, char **argv)
if (
((ret = _edi_build_action_try(provider, provider->clean, "clean", build_type)) == EXIT_NOACTION) &&
((ret = _edi_build_action_try(provider, provider->test, "test", build_type)) == EXIT_NOACTION) &&
((ret = _edi_build_action_try(provider, provider->build, "build", build_type)) == EXIT_NOACTION))
((ret = _edi_build_action_try(provider, (void *)provider->build, "build", build_type)) == EXIT_NOACTION))
{
fprintf(stderr, "Unrecognized build type - try build, clean, create or test.\n");
goto end;

View File

@ -700,11 +700,30 @@ _edi_launcher_run(Edi_Project_Config_Launch *launch)
edi_builder_run(launch->path, launch->args);
}
static void
_edi_build_project(void)
{
Eina_Strbuf *message;
int status;
message = eina_strbuf_new();
status = edi_builder_build();
if (status != 0)
eina_strbuf_append_printf(message, "Build of project <b>%s</b> in %s failed with status code %d.", edi_project_name_get(), edi_project_get(), status);
else
eina_strbuf_append_printf(message, "Build of project <b>%s</b> in %s was successful.", edi_project_name_get(), edi_project_get());
edi_screens_desktop_notify("EDI Project Build Status", eina_strbuf_string_get(message));
eina_strbuf_free(message);
}
static void
_tb_build_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
if (_edi_build_prep(obj))
edi_builder_build();
_edi_build_project();
}
static void
@ -903,7 +922,7 @@ static void
_edi_menu_build_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
edi_builder_build();
_edi_build_project();
}
static void

View File

@ -119,3 +119,19 @@ void edi_screens_message(Evas_Object *parent, const char *title, const char *mes
evas_object_show(popup);
}
void edi_screens_desktop_notify(const char *title, const char *message)
{
Eina_Strbuf *command;
if (!ecore_file_app_installed("notify-send"))
return;
command = eina_strbuf_new();
eina_strbuf_append_printf(command, "notify-send -t 10000 -i edi '%s' '%s'", title, message);
ecore_exe_run(eina_strbuf_string_get(command), NULL);
eina_strbuf_free(command);
}

View File

@ -83,6 +83,16 @@ void edi_screens_message_confirm(Evas_Object *parent, const char *message, void
*/
void edi_screens_message(Evas_Object *parent, const char *title, const char *message);
/**
* Send a desktop notification message to the window manager.
*
* @param title The title for the notification.
* @param message The text to be displayed in the desktop notification.
*
* @ingroup UI
*/
void edi_screens_desktop_notify(const char *title, const char *message);
/**
* @}
*/

View File

@ -18,7 +18,7 @@ typedef struct _Edi_Build_Provider
Eina_Bool (*file_hidden_is)(const char *path);
Eina_Bool (*project_runnable_is)(const char *path);
void (*build)(void);
int (*build)(void);
void (*test)(void);
void (*run)(const char *path, const char *args);
void (*clean)(void);

View File

@ -56,11 +56,13 @@ _cargo_project_runnable_is(const char *file EINA_UNUSED)
return EINA_TRUE;
}
static void
static int
_cargo_build(void)
{
if (chdir(edi_project_get()) == 0)
_exec_cmd("cargo build");
return edi_exe_wait("cargo build");
return -1;
}
static void

View File

@ -46,15 +46,13 @@ _cmake_project_runnable_is(const char *path)
return ecore_file_exists(path);
}
static void
static int
_cmake_build(void)
{
if (chdir(edi_project_get()) != 0)
ERR("Could not chdir");
ecore_exe_pipe_run("mkdir -p build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. && make && cd ..",
ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR |
ECORE_EXE_PIPE_WRITE | ECORE_EXE_USE_SH, NULL);
return edi_exe_wait("mkdir -p build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .. && make && cd ..");
}
static void

View File

@ -67,7 +67,7 @@ _make_comand_compound_get(const char *prepend, const char *append)
return cmd;
}
static void
static int
_make_build_make(void)
{
static const char *cmd = NULL;
@ -76,12 +76,11 @@ _make_build_make(void)
if (chdir(edi_project_get()) != 0)
ERR("Could not chdir");
ecore_exe_pipe_run(cmd, ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR |
ECORE_EXE_PIPE_WRITE | ECORE_EXE_USE_SH, NULL);
return edi_exe_wait(cmd);
}
static void
static int
_make_build_configure(void)
{
static const char *cmd = NULL;
@ -90,12 +89,11 @@ _make_build_configure(void)
if (chdir(edi_project_get()) != 0)
ERR("Could not chdir");
ecore_exe_pipe_run(cmd, ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR |
ECORE_EXE_PIPE_WRITE | ECORE_EXE_USE_SH, NULL);
return edi_exe_wait(cmd);
}
static void
static int
_make_build_autogen(void)
{
static const char *cmd = NULL;
@ -104,20 +102,21 @@ _make_build_autogen(void)
if (chdir(edi_project_get()) != 0)
ERR("Could not chdir");
ecore_exe_pipe_run(cmd, ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR |
ECORE_EXE_PIPE_WRITE | ECORE_EXE_USE_SH, NULL);
return edi_exe_wait(cmd);
}
static void
static int
_make_build(void)
{
if (edi_project_file_exists("Makefile") || edi_project_file_exists("makefile"))
_make_build_make();
return _make_build_make();
else if (edi_project_file_exists("configure"))
_make_build_configure();
return _make_build_configure();
else if (edi_project_file_exists("autogen.sh"))
_make_build_autogen();
return _make_build_autogen();
return -1;
}
static void

View File

@ -79,16 +79,14 @@ _meson_project_runnable_is(const char *path)
return ecore_file_can_exec(path);
}
static Ecore_Exe *
static int
_meson_ninja_do(Meson_Data *md, const char *arg)
{
const char *cmd;
cmd = eina_slstr_printf("ninja -C %s %s", md->fulldir, arg ?: "");
return ecore_exe_pipe_run(cmd,
ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_PIPE_READ |
ECORE_EXE_PIPE_ERROR_LINE_BUFFERED | ECORE_EXE_PIPE_ERROR |
ECORE_EXE_PIPE_WRITE /*| ECORE_EXE_USE_SH*/, md);
return edi_exe_wait(cmd);
}
static Eina_Bool
@ -125,15 +123,15 @@ _meson_prepare(Meson_Data *md)
return EINA_FALSE;
}
static void
static int
_meson_build(void)
{
Meson_Data *md = _meson_data_get();
if (!_meson_prepare(md))
return;
return -1;
_meson_ninja_do(md, NULL);
return _meson_ninja_do(md, NULL);
}
static void

View File

@ -56,11 +56,13 @@ _python_project_runnable_is(const char *file EINA_UNUSED)
return EINA_TRUE;
}
static void
static int
_python_build(void)
{
if (chdir(edi_project_get()) == 0)
_exec_cmd("./setup.py build");
return edi_exe_wait("./setup.py build");
return -1;
}
static void

View File

@ -29,16 +29,16 @@ edi_builder_can_run(const char *runpath)
return provider && provider->project_runnable_is(runpath);
}
EAPI void
EAPI int
edi_builder_build(void)
{
Edi_Build_Provider *provider;
provider = edi_build_provider_for_project_get();
if (!provider)
return;
return -1;
provider->build();
return provider->build();
}
EAPI void

View File

@ -48,11 +48,13 @@ edi_builder_can_run(const char *runpath);
/**
* Run a build for the current project.
*
* @return The status code of the build process.
*
* @see edi_builder_can_build().
*
* @ingroup Builder
*/
EAPI void
EAPI int
edi_builder_build(void);
/**