From 5e318be09caad8d81df9ec24c9df95db417a9ed9 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 17 Feb 2018 20:02:03 +0000 Subject: [PATCH] build: Add support for Go building --- NEWS | 1 + src/lib/edi_build_provider.c | 5 ++ src/lib/edi_build_provider_go.c | 109 ++++++++++++++++++++++++++++++++ src/lib/meson.build | 1 + 4 files changed, 116 insertions(+) create mode 100644 src/lib/edi_build_provider_go.c diff --git a/NEWS b/NEWS index 48978cf..2b75cef 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ Features: * Added split-view option for editors. * Updated project wizard and added new project templates. * Include EFL examples in project wizard. + * Add support for Go projects. * Improved debugging support. * Added edi_scm helper command. * Replace all in project. diff --git a/src/lib/edi_build_provider.c b/src/lib/edi_build_provider.c index ecfe700..c2159a1 100644 --- a/src/lib/edi_build_provider.c +++ b/src/lib/edi_build_provider.c @@ -12,6 +12,7 @@ extern Edi_Build_Provider _edi_build_provider_cmake; extern Edi_Build_Provider _edi_build_provider_cargo; extern Edi_Build_Provider _edi_build_provider_python; extern Edi_Build_Provider _edi_build_provider_meson; +extern Edi_Build_Provider _edi_build_provider_go; EAPI Edi_Build_Provider *edi_build_provider_for_project_get() { @@ -31,6 +32,8 @@ EAPI Edi_Build_Provider *edi_build_provider_for_project_path_get(const char *pat return &_edi_build_provider_python; if (_edi_build_provider_meson.path_supported_is(path)) return &_edi_build_provider_meson; + if (_edi_build_provider_go.path_supported_is(path)) + return &_edi_build_provider_go; if (_edi_build_provider_make.path_supported_is(path)) return &_edi_build_provider_make; @@ -49,6 +52,8 @@ EAPI Edi_Build_Provider *edi_build_provider_for_id_get(const char *id) return &_edi_build_provider_python; if (!strcmp("meson", id)) return &_edi_build_provider_meson; + if (!strcmp("go", id)) + return &_edi_build_provider_go; return NULL; } diff --git a/src/lib/edi_build_provider_go.c b/src/lib/edi_build_provider_go.c new file mode 100644 index 0000000..119010b --- /dev/null +++ b/src/lib/edi_build_provider_go.c @@ -0,0 +1,109 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include +#include +#include + +#include "Edi.h" + +#include "edi_private.h" + +static Eina_Bool +_go_project_supported(const char *path) +{ + Eina_List *files, *l; + const char *name; + + files = ecore_file_ls(path); + + EINA_LIST_FOREACH(files, l, name) + { + if (strlen(name) < 4) + continue; + + if (strstr(name, ".go")) + return EINA_TRUE; + } + + return EINA_FALSE; +} + +static Eina_Bool +_go_file_hidden_is(const char *file) +{ + if (!file || strlen(file) == 0) + return EINA_FALSE; + + if (!strcmp(ecore_file_file_get(file), "_obj") || !strcmp(ecore_file_file_get(file), "target") || + eina_str_has_extension(file, ".so")) + return EINA_TRUE; + + return EINA_FALSE; +} + +static Eina_Bool +_go_project_runnable_is(const char *path EINA_UNUSED) +{ + if (!path || !path[0]) + return EINA_FALSE; + + return EINA_TRUE; +} + +static void +_go_build(void) +{ + if (chdir(edi_project_get()) == 0) + edi_exe_notify("edi_build", "go build"); +} + +static void +_go_test(void) +{ + if (chdir(edi_project_get()) == 0) + edi_exe_notify("edi_test", "go test -v ./..."); +} + +static void +_go_run(const char *path EINA_UNUSED, const char *args EINA_UNUSED) +{ + char *full_cmd; + int full_len; + + if (!path) return; + if (chdir(edi_project_get()) !=0) + ERR("Could not chdir"); + + full_len = strlen(path) + 8; + if (args) + full_len += strlen(args); + full_cmd = malloc(sizeof(char) * (full_len + 1)); + snprintf(full_cmd, full_len + 1, "go run %s %s", path, args?args:""); + + ecore_exe_pipe_run(full_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); + + free(full_cmd); +} + +static void +_go_clean(void) +{ + if (chdir(edi_project_get()) == 0) + edi_exe_notify("edi_clean", "go clean"); +} + +Edi_Build_Provider _edi_build_provider_go = + { + "go", + _go_project_supported, + _go_file_hidden_is, + _go_project_runnable_is, + _go_build, + _go_test, + _go_run, + _go_clean + }; diff --git a/src/lib/meson.build b/src/lib/meson.build index 691a47d..ca5f978 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -8,6 +8,7 @@ src = files([ 'edi_build_provider_make.c', 'edi_build_provider_meson.c', 'edi_build_provider_python.c', + 'edi_build_provider_go.c', 'edi_builder.c', 'edi_builder.h', 'edi_create.c',