q66 pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=b6b7317f4e1ed453db52766faa54ccc9a98a800d

commit b6b7317f4e1ed453db52766faa54ccc9a98a800d
Author: Daniel Kolesa <d.kol...@samsung.com>
Date:   Thu Feb 21 16:52:40 2019 +0100

    eolian gen: generate a separate file with legacy implementations
    
    If legacy implementations are generated, eolian_gen now creates
    a separate file for them and includes it. The file name convention
    for that is <.c file name without ext>.legacy.<.c file name ext>
    or <.c file name>.legacy.c if it has no ext, so for example
    foo.eo.c becomes foo.eo.legacy.c and foo becomes foo.legacy.c.
    
    The file is generated assuming there are any legacy APIs contained
    inside the .eo file.
---
 src/Makefile_Eolian.am                          |  1 +
 src/bin/eolian/main.c                           | 37 +++++++++++++++++++++----
 src/bin/eolian/sources.c                        | 12 ++++----
 src/bin/eolian/sources.h                        |  2 +-
 src/tests/eolian/data/class_simple_ref.c        | 12 +-------
 src/tests/eolian/data/class_simple_ref.legacy.c | 12 ++++++++
 src/tests/eolian/eolian_generation.c            |  1 +
 7 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am
index 2c8d531d9a..c3a6d7b364 100644
--- a/src/Makefile_Eolian.am
+++ b/src/Makefile_Eolian.am
@@ -159,6 +159,7 @@ tests/eolian/data/struct_ref.h \
 tests/eolian/data/struct_ref_stub.h \
 tests/eolian/data/owning.eo.c \
 tests/eolian/data/class_simple_ref.c \
+tests/eolian/data/class_simple_ref.legacy.c \
 tests/eolian/data/override_ref.c \
 tests/eolian/data/class_simple_ref_eo.h \
 tests/eolian/data/class_simple_ref_legacy.h \
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 7db3429aed..c847b0cb9f 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -396,21 +396,48 @@ _write_source(const Eolian_State *eos, const char *ofname,
 {
    INF("generating source: %s", ofname);
    Eina_Strbuf *buf = eina_strbuf_new();
+   Eina_Strbuf *lbuf = eina_strbuf_new();
+   Eina_Strbuf *oflname = eina_strbuf_new();
+   Eina_Bool ret = EINA_FALSE;
 
+   const char *lext = strrchr(ofname, '.');
+   if (!lext)
+     {
+        eina_strbuf_append(oflname, ofname);
+        eina_strbuf_append(oflname, ".legacy.c");
+     }
+   else
+     {
+        eina_strbuf_append_length(oflname, ofname, strlen(ofname) - 
strlen(lext));
+        eina_strbuf_append(oflname, ".legacy");
+        eina_strbuf_append(oflname, lext);
+     }
+   const char *lfname = eina_strbuf_string_get(oflname);
+     {
+        const char *p1 = strrchr(lfname, '/');
+        const char *p2 = strrchr(lfname, '\\');
+        lfname = (p1 || p2) ? ((p1 > p2) ? (p1 + 1) : (p2 + 1)) : lfname;
+     }
    const Eolian_Class *cl = eolian_state_class_by_file_get(eos, ifname);
    eo_gen_types_source_gen(eolian_state_objects_by_file_get(eos, ifname), buf);
-   eo_gen_source_gen(cl, buf);
+   eo_gen_source_gen(cl, buf, lbuf, lfname);
    if (cl || (eot && eina_strbuf_length_get(buf)))
      {
-        if (_write_file(ofname, buf))
+        if (!_write_file(ofname, buf))
+          goto done;
+        if (eina_strbuf_length_get(lbuf))
           {
-             eina_strbuf_free(buf);
-             return EINA_TRUE;
+             if (!_write_file(eina_strbuf_string_get(oflname), lbuf))
+               goto done;
           }
+        ret = EINA_TRUE;
      }
 
+done:
    eina_strbuf_free(buf);
-   return EINA_FALSE;
+   eina_strbuf_free(lbuf);
+   eina_strbuf_free(oflname);
+   return ret;
 }
 
 static Eina_Bool
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index e4491a22b3..2bcda4c382 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -1091,7 +1091,8 @@ _gen_initializer(const Eolian_Class *cl, Eina_Strbuf 
*buf, Eina_Hash *refh)
 }
 
 void
-eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf)
+eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Strbuf *lbuf,
+                  const char *lfname)
 {
    if (!cl)
      return;
@@ -1122,8 +1123,6 @@ eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf 
*buf)
       eina_iterator_free(itr);
    }
 
-   Eina_Strbuf *lbuf = eina_strbuf_new();
-
    /* Eolian_Function -> Eolian_Function_Type
     * maps which parts of which functions are qualified for reflection
     */
@@ -1236,10 +1235,9 @@ eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf 
*buf)
    /* terminate inherits */
    eina_strbuf_append(buf, ", NULL);\n");
 
-   /* append legacy if there */
-   eina_strbuf_append(buf, eina_strbuf_string_get(lbuf));
-
-   eina_strbuf_free(lbuf);
+   /* append legacy include if there */
+   if (eina_strbuf_length_get(lbuf))
+     eina_strbuf_append_printf(buf, "\n#include \"%s\"\n", lfname);
 
    /* and we're done */
    free(cnamel);
diff --git a/src/bin/eolian/sources.h b/src/bin/eolian/sources.h
index 05d711458b..04d6988a0e 100644
--- a/src/bin/eolian/sources.h
+++ b/src/bin/eolian/sources.h
@@ -3,7 +3,7 @@
 
 #include "main.h"
 
-void eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf);
+void eo_gen_source_gen(const Eolian_Class *cl, Eina_Strbuf *buf, Eina_Strbuf 
*lbuf, const char *lfname);
 void eo_gen_impl_gen(const Eolian_Class *cl, Eina_Strbuf *buf);
 
 #endif
diff --git a/src/tests/eolian/data/class_simple_ref.c 
b/src/tests/eolian/data/class_simple_ref.c
index 3bf9d2063b..0ce99ca6d1 100644
--- a/src/tests/eolian/data/class_simple_ref.c
+++ b/src/tests/eolian/data/class_simple_ref.c
@@ -88,14 +88,4 @@ static const Efl_Class_Description _class_simple_class_desc 
= {
 
 EFL_DEFINE_CLASS(class_simple_class_get, &_class_simple_class_desc, NULL, 
NULL);
 
-EAPI void
-evas_object_simple_b_set(Class_Simple *obj)
-{
-   efl_canvas_object_simple_b_set(obj);
-}
-
-EAPI int *
-evas_object_simple_bar(Class_Simple *obj, int x)
-{
-   return efl_canvas_object_simple_bar(obj, x);
-}
+#include "eolian_class_simple.eo.legacy.c"
diff --git a/src/tests/eolian/data/class_simple_ref.legacy.c 
b/src/tests/eolian/data/class_simple_ref.legacy.c
new file mode 100644
index 0000000000..b0f922864a
--- /dev/null
+++ b/src/tests/eolian/data/class_simple_ref.legacy.c
@@ -0,0 +1,12 @@
+
+EAPI void
+evas_object_simple_b_set(Class_Simple *obj)
+{
+   efl_canvas_object_simple_b_set(obj);
+}
+
+EAPI int *
+evas_object_simple_bar(Class_Simple *obj, int x)
+{
+   return efl_canvas_object_simple_bar(obj, x);
+}
diff --git a/src/tests/eolian/eolian_generation.c 
b/src/tests/eolian/eolian_generation.c
index 5167c01d7e..6a43f1fc23 100644
--- a/src/tests/eolian/eolian_generation.c
+++ b/src/tests/eolian/eolian_generation.c
@@ -141,6 +141,7 @@ EFL_START_TEST(eolian_default_values_generation)
    _remove_ref(output_filepath, "eo.c");
    fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/class_simple.eo", 
"-gc", output_filepath));
    fail_if(!_files_compare(TESTS_SRC_DIR"/data/class_simple_ref.c", 
output_filepath, "eo.c"));
+   fail_if(!_files_compare(TESTS_SRC_DIR"/data/class_simple_ref.legacy.c", 
output_filepath, "eo.legacy.c"));
 }
 EFL_END_TEST
 

-- 


Reply via email to