2019-10-24 06:01:50 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2019 by its authors. See AUTHORS.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
#include <Eolian.h>
|
|
|
|
|
|
|
|
#include <Eina.hh>
|
|
|
|
#include <Eolian_Cxx.hh>
|
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
#include <eolian/mono/logging.hh>
|
2018-04-16 17:44:27 -07:00
|
|
|
#include <eolian/mono/name_helpers.hh>
|
2017-11-23 16:50:16 -08:00
|
|
|
#include <eolian/mono/klass.hh>
|
|
|
|
#include <eolian/mono/enum_definition.hh>
|
|
|
|
#include <eolian/mono/struct_definition.hh>
|
|
|
|
#include <eolian/mono/type_impl.hh>
|
|
|
|
#include <eolian/mono/marshall_type_impl.hh>
|
|
|
|
#include <eolian/mono/marshall_annotation.hh>
|
|
|
|
#include <eolian/mono/function_pointer.hh>
|
2018-05-10 18:00:07 -07:00
|
|
|
#include <eolian/mono/alias_definition.hh>
|
2019-02-28 06:09:38 -08:00
|
|
|
#include <eolian/mono/variable_definition.hh>
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
namespace eolian_mono {
|
|
|
|
|
|
|
|
/// Program options.
|
|
|
|
struct options_type
|
|
|
|
{
|
|
|
|
std::vector<std::string> include_dirs;
|
|
|
|
std::string in_file;
|
|
|
|
std::string out_file;
|
mono-docs: Allow embedding external examples
Summary:
New option added to eolian_gen: -e <dir>
This specifies a directory to search for examples. If a file is found with the
same name as an EFL C# class (e.g. Efl.Ui.Button.cs) or as an EFL C# method or
property (e.g. Efl.IText.Text.cs, Efl.IText.SetText.cs) its full
contents will be embedded in the documentation for that class or method within
<example> and <code> tags. This is, in turn, is parsed by DocFX and shown
in Example boxes in the generated pages.
If an example file is not found, no examples are embedded for that object.
If -e is not used, no examples are embedded for any object.
New option added to meson: mono-examples-dir to point to the examples directory.
This directory is then passed to eolian_mono through -e.
Do not use it (or define it to nothing) to disable example embedding.
No performance drop has been observed because of these extra tests.
Right now examples can only be given for base classes, not for derived ones
(i.e. Efl.IText.Text but not Efl.Ui.Button.Text). This will be addressed in a
later commit.
Feature
Depends on D8587
Test Plan:
Create an examples folder and put some files in it:
```
mkdir /tmp/examples
echo 'var button = new Efl.Ui.Button();' > /tmp/examples/Efl.Ui.Button.cs
echo 'button.AutoRepeatEnabled = true;' > /tmp/examples/Efl.Ui.IAutorepeat.AutorepeatEnabled.cs
echo 'button.SetAutoRepeatEnabled(true);' > /tmp/examples/Efl.Ui.IAutorepeat.SetAutorepeatEnabled.cs
```
Configure meson to embed examples and build:
```
meson configure -Dmono-examples-dir=/tmp/examples
ninja
```
Examine the generated efl_ui_button.eo.cs file to see embedded <example> tags,
or run DocFX and bask in the glory of documentation pages with examples:
```
cd doc/docfx
./gendoc.sh
```
Reviewers: lauromoura, felipealmeida, vitor.sousa, zmike, bu5hm4n
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8592
2019-04-11 01:38:40 -07:00
|
|
|
std::string examples_dir;
|
2017-11-23 16:50:16 -08:00
|
|
|
std::string dllimport;
|
2018-02-27 04:00:36 -08:00
|
|
|
mutable Eolian_State* state;
|
2017-12-06 08:27:27 -08:00
|
|
|
mutable Eolian_Unit const* unit;
|
2017-11-23 16:50:16 -08:00
|
|
|
int v_major;
|
|
|
|
int v_minor;
|
2019-01-17 04:43:57 -08:00
|
|
|
bool want_beta;
|
2019-08-23 10:27:28 -07:00
|
|
|
bool want_partial;
|
2017-11-23 16:50:16 -08:00
|
|
|
std::map<const std::string, std::string> references_map;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Parses a CSV file in the format 'filename,library' (without trimming spaces around ',')
|
|
|
|
static std::vector<std::pair<std::string, std::string> >
|
|
|
|
parse_reference(std::string filename)
|
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::string> > ret;
|
|
|
|
std::string delimiter = ",";
|
|
|
|
std::ifstream infile(filename);
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
while (std::getline(infile, line))
|
|
|
|
{
|
|
|
|
size_t pos = line.find(delimiter);
|
|
|
|
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
throw std::invalid_argument("Malformed mapping. Must be 'filename,library'");
|
|
|
|
|
|
|
|
std::string eo_filename = line.substr(0, pos);
|
|
|
|
std::string library = line.substr(pos + 1);
|
|
|
|
library[0] = std::toupper(library[0]);
|
|
|
|
ret.push_back(std::pair<std::string, std::string>(eo_filename, library));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
opts_check(eolian_mono::options_type const& opts)
|
|
|
|
{
|
|
|
|
if (opts.in_file.empty())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Nothing to generate?" << std::endl;
|
|
|
|
}
|
|
|
|
else if (opts.out_file.empty())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Nowhere to generate?" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return true; // valid.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run(options_type const& opts)
|
|
|
|
{
|
|
|
|
const Eolian_Class *klass = NULL;
|
|
|
|
Eina_Iterator *aliases = NULL;
|
|
|
|
const Eolian_Typedecl *tp = NULL;
|
|
|
|
char* dup = strdup(opts.in_file.c_str());
|
|
|
|
std::string basename_input = basename(dup);
|
2018-03-02 14:58:20 -08:00
|
|
|
klass = ::eolian_state_class_by_file_get(opts.state, basename_input.c_str());
|
|
|
|
aliases= ::eolian_state_aliases_by_file_get(opts.state, basename_input.c_str());
|
2017-11-23 16:50:16 -08:00
|
|
|
free(dup);
|
|
|
|
|
|
|
|
std::string class_file_name = opts.out_file;
|
|
|
|
|
|
|
|
std::ofstream output_file;
|
|
|
|
std::ostream_iterator<char> iterator
|
|
|
|
{[&]
|
|
|
|
{
|
|
|
|
if(opts.out_file == "-")
|
|
|
|
return std::ostream_iterator<char>(std::cout);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
output_file.open(class_file_name);
|
|
|
|
if (!output_file.good())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Can't open output file: " << class_file_name << std::endl;
|
|
|
|
throw std::runtime_error("");
|
|
|
|
}
|
|
|
|
return std::ostream_iterator<char>(output_file);
|
|
|
|
}
|
|
|
|
}()};
|
|
|
|
|
2019-10-24 06:01:50 -07:00
|
|
|
if (!as_generator(
|
|
|
|
"/*\n"
|
|
|
|
" * Copyright 2019 by its authors. See AUTHORS.\n"
|
|
|
|
" *\n"
|
|
|
|
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
|
|
|
|
" * you may not use this file except in compliance with the License.\n"
|
|
|
|
" * You may obtain a copy of the License at\n"
|
|
|
|
" *\n"
|
|
|
|
" * http://www.apache.org/licenses/LICENSE-2.0\n"
|
|
|
|
" *\n"
|
|
|
|
" * Unless required by applicable law or agreed to in writing, software\n"
|
|
|
|
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
|
|
|
|
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
|
|
|
|
" * See the License for the specific language governing permissions and\n"
|
|
|
|
" * limitations under the License.\n"
|
|
|
|
" */\n\n"
|
|
|
|
).generate(iterator, attributes::unused, efl::eolian::grammar::context_null()))
|
|
|
|
throw std::runtime_error("Failed to generate license notice");
|
|
|
|
|
2018-10-04 00:59:02 -07:00
|
|
|
if (!as_generator("#pragma warning disable CS1591\n").generate(iterator, efl::eolian::grammar::attributes::unused, efl::eolian::grammar::context_null()))
|
|
|
|
throw std::runtime_error("Failed to generate pragma to disable missing docs");
|
|
|
|
|
csharp: Change to new class API.
Summary:
As discussed in T7204:
- Eo Interfaces/mixins -> C# Interfaces with concrete class
implementations
- Eo Regular/Abstracts -> Proper C# classes
- Added some new generators and helper methods.
- Refactored the class generator, splitting into helper methods
Eo handles now are stored only in the "root" class in any given
inheritance tree (generally, Efl.Object), and accessible to each child.
Methods also are defined in a single place instead of repeatedly
generated in everyfile, reducing the size of the generated .dll from
30MB to around 4.5MB.
Mixins are generated as C# interfaces but any regular class it inherits
from is lost, as we can't have interfaces inheriting from regular
classes. This will be dealt with in a later commit.
Summary of API Changes:
- Merged Inherit/Concrete classes. (These suffixes disappear from
regular classes).
- Interface still have implementations with 'Concrete' suffix for when
they are returned from methods.
- Removed 'I' from interface names.
- Removed interfaces for regular/abstract Eo classes.
- Concrete classes for interfaces/mixins hold the event argument struct.
- Removed '_' from classes, enums, structs, etc, as indicated in C#
naming conventions.
- Namespaces are now Camel.Cased.
- Renamed IWrapper's raw_handle/raw_klass to NativeHandle/NativeClass
Also renamed the test classes as after the namespace change, the
test namespace Test can conflict with the helper Test namespace.
(And use more meaningful names than Test.Testing...)
Also Fixes T7336 by removing a deprecated example and adding
efl_loop_timer_example to build system.
Fixes T7451 by hiding the class_get DllImports and renaming the IWrapper
fields. The native handlers are used in the manual binding.
Still need to work:
- As there are still some events names clashing (e.g. Efl.Ui.Bg with "resize"
from Efl.Gfx.Entity and Efl.Gfx.Image), Events are currently declared on
the interface and implemented "namespaced" in the classes,
requiring the cast to the interface to access the event.
- The Mixin Conundrum. Mixin inheritance will be dealt in a future
commit.
Depends on D7260
Reviewers: segfaultxavi, vitor.sousa, felipealmeida, Jaehyun_Cho
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7451, T7336
Differential Revision: https://phab.enlightenment.org/D7262
2018-11-29 15:04:37 -08:00
|
|
|
if (!as_generator("using System;\n"
|
|
|
|
"using System.Runtime.InteropServices;\n"
|
|
|
|
"using System.Collections.Generic;\n"
|
2018-12-14 14:39:09 -08:00
|
|
|
"using System.Linq;\n"
|
2019-04-05 15:59:34 -07:00
|
|
|
"using System.Threading;\n"
|
csharp: Change to new class API.
Summary:
As discussed in T7204:
- Eo Interfaces/mixins -> C# Interfaces with concrete class
implementations
- Eo Regular/Abstracts -> Proper C# classes
- Added some new generators and helper methods.
- Refactored the class generator, splitting into helper methods
Eo handles now are stored only in the "root" class in any given
inheritance tree (generally, Efl.Object), and accessible to each child.
Methods also are defined in a single place instead of repeatedly
generated in everyfile, reducing the size of the generated .dll from
30MB to around 4.5MB.
Mixins are generated as C# interfaces but any regular class it inherits
from is lost, as we can't have interfaces inheriting from regular
classes. This will be dealt with in a later commit.
Summary of API Changes:
- Merged Inherit/Concrete classes. (These suffixes disappear from
regular classes).
- Interface still have implementations with 'Concrete' suffix for when
they are returned from methods.
- Removed 'I' from interface names.
- Removed interfaces for regular/abstract Eo classes.
- Concrete classes for interfaces/mixins hold the event argument struct.
- Removed '_' from classes, enums, structs, etc, as indicated in C#
naming conventions.
- Namespaces are now Camel.Cased.
- Renamed IWrapper's raw_handle/raw_klass to NativeHandle/NativeClass
Also renamed the test classes as after the namespace change, the
test namespace Test can conflict with the helper Test namespace.
(And use more meaningful names than Test.Testing...)
Also Fixes T7336 by removing a deprecated example and adding
efl_loop_timer_example to build system.
Fixes T7451 by hiding the class_get DllImports and renaming the IWrapper
fields. The native handlers are used in the manual binding.
Still need to work:
- As there are still some events names clashing (e.g. Efl.Ui.Bg with "resize"
from Efl.Gfx.Entity and Efl.Gfx.Image), Events are currently declared on
the interface and implemented "namespaced" in the classes,
requiring the cast to the interface to access the event.
- The Mixin Conundrum. Mixin inheritance will be dealt in a future
commit.
Depends on D7260
Reviewers: segfaultxavi, vitor.sousa, felipealmeida, Jaehyun_Cho
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Maniphest Tasks: T7451, T7336
Differential Revision: https://phab.enlightenment.org/D7262
2018-11-29 15:04:37 -08:00
|
|
|
"using System.ComponentModel;\n")
|
2017-11-23 16:50:16 -08:00
|
|
|
.generate(iterator, efl::eolian::grammar::attributes::unused, efl::eolian::grammar::context_null()))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate file preamble");
|
|
|
|
}
|
|
|
|
|
2019-03-22 14:37:50 -07:00
|
|
|
using efl::eolian::grammar::context_add_tag;
|
|
|
|
|
|
|
|
auto context = context_add_tag(eolian_mono::indentation_context{0},
|
|
|
|
context_add_tag(eolian_mono::eolian_state_context{opts.state},
|
mono-docs: Allow embedding external examples
Summary:
New option added to eolian_gen: -e <dir>
This specifies a directory to search for examples. If a file is found with the
same name as an EFL C# class (e.g. Efl.Ui.Button.cs) or as an EFL C# method or
property (e.g. Efl.IText.Text.cs, Efl.IText.SetText.cs) its full
contents will be embedded in the documentation for that class or method within
<example> and <code> tags. This is, in turn, is parsed by DocFX and shown
in Example boxes in the generated pages.
If an example file is not found, no examples are embedded for that object.
If -e is not used, no examples are embedded for any object.
New option added to meson: mono-examples-dir to point to the examples directory.
This directory is then passed to eolian_mono through -e.
Do not use it (or define it to nothing) to disable example embedding.
No performance drop has been observed because of these extra tests.
Right now examples can only be given for base classes, not for derived ones
(i.e. Efl.IText.Text but not Efl.Ui.Button.Text). This will be addressed in a
later commit.
Feature
Depends on D8587
Test Plan:
Create an examples folder and put some files in it:
```
mkdir /tmp/examples
echo 'var button = new Efl.Ui.Button();' > /tmp/examples/Efl.Ui.Button.cs
echo 'button.AutoRepeatEnabled = true;' > /tmp/examples/Efl.Ui.IAutorepeat.AutorepeatEnabled.cs
echo 'button.SetAutoRepeatEnabled(true);' > /tmp/examples/Efl.Ui.IAutorepeat.SetAutorepeatEnabled.cs
```
Configure meson to embed examples and build:
```
meson configure -Dmono-examples-dir=/tmp/examples
ninja
```
Examine the generated efl_ui_button.eo.cs file to see embedded <example> tags,
or run DocFX and bask in the glory of documentation pages with examples:
```
cd doc/docfx
./gendoc.sh
```
Reviewers: lauromoura, felipealmeida, vitor.sousa, zmike, bu5hm4n
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8592
2019-04-11 01:38:40 -07:00
|
|
|
context_add_tag(eolian_mono::options_context{opts.want_beta,
|
|
|
|
opts.examples_dir},
|
2019-03-22 14:37:50 -07:00
|
|
|
context_add_tag(eolian_mono::library_context{opts.dllimport,
|
|
|
|
opts.v_major,
|
|
|
|
opts.v_minor,
|
|
|
|
opts.references_map},
|
|
|
|
efl::eolian::grammar::context_null()))));
|
2018-12-21 05:52:11 -08:00
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
EINA_ITERATOR_FOREACH(aliases, tp)
|
|
|
|
{
|
2018-05-10 18:00:07 -07:00
|
|
|
if (eolian_typedecl_type_get(tp) == EOLIAN_TYPEDECL_FUNCTION_POINTER)
|
|
|
|
{
|
|
|
|
const Eolian_Function *fp = eolian_typedecl_function_pointer_get(tp);
|
|
|
|
efl::eolian::grammar::attributes::function_def function_def(fp, EOLIAN_FUNCTION_POINTER, tp, opts.unit);
|
|
|
|
if (!eolian_mono::function_pointer.generate(iterator, function_def, context))
|
|
|
|
throw std::runtime_error("Failed to generate function pointer wrapper");
|
|
|
|
}
|
|
|
|
else // Regular aliases
|
|
|
|
{
|
|
|
|
efl::eolian::grammar::attributes::alias_def alias(tp, opts.unit);
|
|
|
|
auto alias_cxt = context_add_tag(class_context{class_context::alias}, context);
|
|
|
|
|
|
|
|
if (!eolian_mono::alias_definition.generate(iterator, alias, alias_cxt))
|
|
|
|
throw std::runtime_error("Failed to generate alias.");
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
2019-09-30 06:38:34 -07:00
|
|
|
::eina_iterator_free(aliases);
|
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
|
2019-02-28 06:09:38 -08:00
|
|
|
// Constants
|
|
|
|
{
|
|
|
|
auto var_cxt = context_add_tag(class_context{class_context::variables}, context);
|
2019-09-24 08:06:24 -07:00
|
|
|
for (efl::eina::iterator<const Eolian_Constant> var_iterator( ::eolian_state_constants_by_file_get(opts.state, basename_input.c_str()))
|
2019-02-28 06:09:38 -08:00
|
|
|
, var_last; var_iterator != var_last; ++var_iterator)
|
|
|
|
{
|
2019-09-24 08:06:24 -07:00
|
|
|
efl::eolian::grammar::attributes::constant_def var(&*var_iterator, opts.unit);
|
2019-02-28 06:09:38 -08:00
|
|
|
if (!eolian_mono::constant_definition.generate(iterator, var, var_cxt))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate enum");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 16:50:16 -08:00
|
|
|
if (klass)
|
|
|
|
{
|
2017-12-06 08:27:27 -08:00
|
|
|
efl::eolian::grammar::attributes::klass_def klass_def(klass, opts.unit);
|
2017-11-23 16:50:16 -08:00
|
|
|
std::vector<efl::eolian::grammar::attributes::klass_def> klasses{klass_def};
|
|
|
|
|
2019-08-23 10:27:28 -07:00
|
|
|
auto klass_gen = !opts.want_partial ? eolian_mono::klass
|
|
|
|
: eolian_mono::klass(eolian_mono::class_partial);
|
|
|
|
if (!klass_gen.generate(iterator, klass_def, context))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate class");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
// Enums
|
|
|
|
for (efl::eina::iterator<const Eolian_Typedecl> enum_iterator( ::eolian_state_enums_by_file_get(opts.state, basename_input.c_str()))
|
|
|
|
, enum_last; enum_iterator != enum_last; ++enum_iterator)
|
|
|
|
{
|
|
|
|
efl::eolian::grammar::attributes::enum_def enum_(&*enum_iterator, opts.unit);
|
2018-12-21 05:52:11 -08:00
|
|
|
auto enum_cxt = context_add_tag(class_context{class_context::enums}, context);
|
|
|
|
if (!eolian_mono::enum_definition.generate(iterator, enum_, enum_cxt))
|
2018-04-27 14:08:25 -07:00
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate enum");
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
|
2018-04-27 14:08:25 -07:00
|
|
|
// Structs
|
|
|
|
for (efl::eina::iterator<const Eolian_Typedecl> struct_iterator( ::eolian_state_structs_by_file_get(opts.state, basename_input.c_str()))
|
|
|
|
, struct_last; struct_iterator != struct_last; ++struct_iterator)
|
|
|
|
{
|
|
|
|
efl::eolian::grammar::attributes::struct_def struct_(&*struct_iterator, opts.unit);
|
|
|
|
auto structs_cxt = context_add_tag(class_context{class_context::structs}, context);
|
|
|
|
if (!eolian_mono::struct_entities.generate(iterator, struct_, structs_cxt))
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Failed to generate struct");
|
|
|
|
}
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
database_load(options_type const& opts)
|
|
|
|
{
|
|
|
|
for (auto src : opts.include_dirs)
|
|
|
|
{
|
2018-03-02 04:30:14 -08:00
|
|
|
if (!::eolian_state_directory_add(opts.state, src.c_str()))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_WARN(eolian_mono::domain)
|
|
|
|
<< "Couldn't load eolian from '" << src << "'.";
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 04:30:14 -08:00
|
|
|
if (!::eolian_state_all_eot_files_parse(opts.state))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Eolian failed parsing eot files";
|
|
|
|
assert(false && "Error parsing eot files");
|
|
|
|
}
|
|
|
|
if (opts.in_file.empty())
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "No input file.";
|
|
|
|
assert(false && "Error parsing input file");
|
|
|
|
}
|
2019-05-03 07:55:59 -07:00
|
|
|
if (!::eolian_state_file_path_parse(opts.state, opts.in_file.c_str()))
|
2017-11-23 16:50:16 -08:00
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain)
|
|
|
|
<< "Failed parsing: " << opts.in_file << ".";
|
|
|
|
assert(false && "Error parsing input file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace eolian_mono {
|
|
|
|
|
|
|
|
static void
|
|
|
|
_print_version()
|
|
|
|
{
|
|
|
|
std::cerr
|
|
|
|
<< "Eolian C++ Binding Generator (EFL "
|
|
|
|
<< PACKAGE_VERSION << ")" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_usage(const char *progname)
|
|
|
|
{
|
|
|
|
std::cerr
|
|
|
|
<< progname
|
|
|
|
<< " [options] [file.eo]" << std::endl
|
|
|
|
<< " A single input file must be provided (unless -a is specified)." << std::endl
|
|
|
|
<< "Options:" << std::endl
|
|
|
|
<< " -a, --all Generate bindings for all Eo classes." << std::endl
|
|
|
|
<< " -c, --class <name> The Eo class name to generate code for." << std::endl
|
|
|
|
<< " -D, --out-dir <dir> Output directory where generated code will be written." << std::endl
|
|
|
|
<< " -I, --in <file/dir> The source containing the .eo descriptions." << std::endl
|
2019-04-10 07:23:38 -07:00
|
|
|
<< " -o, --out-file <file> The output file name. [default: <classname>.eo.cs]" << std::endl
|
|
|
|
<< " -n, --namespace <ns> Wrap generated code in a namespace. [Eg: Efl.Ui.Widget]" << std::endl
|
2017-11-23 16:50:16 -08:00
|
|
|
<< " -r, --recurse Recurse input directories loading .eo files." << std::endl
|
|
|
|
<< " -v, --version Print the version." << std::endl
|
2019-01-17 04:43:57 -08:00
|
|
|
<< " -b, --beta Enable @beta methods." << std::endl
|
mono-docs: Allow embedding external examples
Summary:
New option added to eolian_gen: -e <dir>
This specifies a directory to search for examples. If a file is found with the
same name as an EFL C# class (e.g. Efl.Ui.Button.cs) or as an EFL C# method or
property (e.g. Efl.IText.Text.cs, Efl.IText.SetText.cs) its full
contents will be embedded in the documentation for that class or method within
<example> and <code> tags. This is, in turn, is parsed by DocFX and shown
in Example boxes in the generated pages.
If an example file is not found, no examples are embedded for that object.
If -e is not used, no examples are embedded for any object.
New option added to meson: mono-examples-dir to point to the examples directory.
This directory is then passed to eolian_mono through -e.
Do not use it (or define it to nothing) to disable example embedding.
No performance drop has been observed because of these extra tests.
Right now examples can only be given for base classes, not for derived ones
(i.e. Efl.IText.Text but not Efl.Ui.Button.Text). This will be addressed in a
later commit.
Feature
Depends on D8587
Test Plan:
Create an examples folder and put some files in it:
```
mkdir /tmp/examples
echo 'var button = new Efl.Ui.Button();' > /tmp/examples/Efl.Ui.Button.cs
echo 'button.AutoRepeatEnabled = true;' > /tmp/examples/Efl.Ui.IAutorepeat.AutorepeatEnabled.cs
echo 'button.SetAutoRepeatEnabled(true);' > /tmp/examples/Efl.Ui.IAutorepeat.SetAutorepeatEnabled.cs
```
Configure meson to embed examples and build:
```
meson configure -Dmono-examples-dir=/tmp/examples
ninja
```
Examine the generated efl_ui_button.eo.cs file to see embedded <example> tags,
or run DocFX and bask in the glory of documentation pages with examples:
```
cd doc/docfx
./gendoc.sh
```
Reviewers: lauromoura, felipealmeida, vitor.sousa, zmike, bu5hm4n
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8592
2019-04-11 01:38:40 -07:00
|
|
|
<< " -e, --example-dir <dir> Folder to search for example files." << std::endl
|
2019-08-23 10:27:28 -07:00
|
|
|
<< " -p, --partial Create class as a partial class" << std::endl
|
2017-11-23 16:50:16 -08:00
|
|
|
<< " -h, --help Print this help." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_assert_not_dup(std::string option, std::string value)
|
|
|
|
{
|
|
|
|
if (value != "")
|
|
|
|
{
|
|
|
|
EINA_CXX_DOM_LOG_ERR(eolian_mono::domain) <<
|
|
|
|
"Option -" + option + " already set (" + value + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static eolian_mono::options_type
|
|
|
|
opts_get(int argc, char **argv)
|
|
|
|
{
|
2019-03-07 08:06:33 -08:00
|
|
|
eolian_mono::options_type opts{};
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
const struct option long_options[] =
|
|
|
|
{
|
|
|
|
{ "in", required_argument, 0, 'I' },
|
|
|
|
{ "out-file", required_argument, 0, 'o' },
|
|
|
|
{ "version", no_argument, 0, 'v' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
{ "dllimport", required_argument, 0, 'l' },
|
|
|
|
{ "vmaj", required_argument, 0, 'M' },
|
|
|
|
{ "vmin", required_argument, 0, 'm' },
|
|
|
|
{ "references", required_argument, 0, 'r'},
|
2019-01-17 04:43:57 -08:00
|
|
|
{ "beta", no_argument, 0, 'b'},
|
mono-docs: Allow embedding external examples
Summary:
New option added to eolian_gen: -e <dir>
This specifies a directory to search for examples. If a file is found with the
same name as an EFL C# class (e.g. Efl.Ui.Button.cs) or as an EFL C# method or
property (e.g. Efl.IText.Text.cs, Efl.IText.SetText.cs) its full
contents will be embedded in the documentation for that class or method within
<example> and <code> tags. This is, in turn, is parsed by DocFX and shown
in Example boxes in the generated pages.
If an example file is not found, no examples are embedded for that object.
If -e is not used, no examples are embedded for any object.
New option added to meson: mono-examples-dir to point to the examples directory.
This directory is then passed to eolian_mono through -e.
Do not use it (or define it to nothing) to disable example embedding.
No performance drop has been observed because of these extra tests.
Right now examples can only be given for base classes, not for derived ones
(i.e. Efl.IText.Text but not Efl.Ui.Button.Text). This will be addressed in a
later commit.
Feature
Depends on D8587
Test Plan:
Create an examples folder and put some files in it:
```
mkdir /tmp/examples
echo 'var button = new Efl.Ui.Button();' > /tmp/examples/Efl.Ui.Button.cs
echo 'button.AutoRepeatEnabled = true;' > /tmp/examples/Efl.Ui.IAutorepeat.AutorepeatEnabled.cs
echo 'button.SetAutoRepeatEnabled(true);' > /tmp/examples/Efl.Ui.IAutorepeat.SetAutorepeatEnabled.cs
```
Configure meson to embed examples and build:
```
meson configure -Dmono-examples-dir=/tmp/examples
ninja
```
Examine the generated efl_ui_button.eo.cs file to see embedded <example> tags,
or run DocFX and bask in the glory of documentation pages with examples:
```
cd doc/docfx
./gendoc.sh
```
Reviewers: lauromoura, felipealmeida, vitor.sousa, zmike, bu5hm4n
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8592
2019-04-11 01:38:40 -07:00
|
|
|
{ "example-dir", required_argument, 0, 'e' },
|
2019-08-23 10:27:28 -07:00
|
|
|
{ "partial", no_argument, 0, 'p' },
|
2017-11-23 16:50:16 -08:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
2019-08-23 10:27:28 -07:00
|
|
|
const char* options = "I:D:o:c:M:m:ar:vhbpe:";
|
2017-11-23 16:50:16 -08:00
|
|
|
|
|
|
|
int c, idx;
|
|
|
|
while ( (c = getopt_long(argc, argv, options, long_options, &idx)) != -1)
|
|
|
|
{
|
|
|
|
if (c == 'I')
|
|
|
|
{
|
|
|
|
opts.include_dirs.push_back(optarg);
|
|
|
|
}
|
|
|
|
else if (c == 'o')
|
|
|
|
{
|
|
|
|
_assert_not_dup("o", opts.out_file);
|
|
|
|
opts.out_file = optarg;
|
|
|
|
}
|
|
|
|
else if (c == 'h')
|
|
|
|
{
|
|
|
|
_usage(argv[0]);
|
|
|
|
}
|
|
|
|
else if (c == 'l')
|
|
|
|
{
|
|
|
|
opts.dllimport = optarg;
|
|
|
|
}
|
|
|
|
else if (c == 'M')
|
|
|
|
{
|
|
|
|
opts.v_major = std::stoi(optarg);
|
|
|
|
}
|
|
|
|
else if (c == 'm')
|
|
|
|
{
|
|
|
|
opts.v_minor = std::stoi(optarg);
|
|
|
|
}
|
|
|
|
else if (c == 'r')
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::string> > names = eolian_mono::parse_reference(optarg);
|
|
|
|
for (auto&& p : names)
|
|
|
|
{
|
|
|
|
opts.references_map[p.first] = p.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::invalid_argument &e)
|
|
|
|
{
|
|
|
|
std::cerr << "Invalid argument processing argument " << optarg << std::endl;
|
|
|
|
_usage(argv[0]);
|
|
|
|
assert(false && e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == 'v')
|
|
|
|
{
|
|
|
|
_print_version();
|
|
|
|
if (argc == 2) exit(EXIT_SUCCESS);
|
|
|
|
}
|
2019-01-17 04:43:57 -08:00
|
|
|
else if (c == 'b')
|
|
|
|
{
|
|
|
|
opts.want_beta = true;
|
|
|
|
}
|
mono-docs: Allow embedding external examples
Summary:
New option added to eolian_gen: -e <dir>
This specifies a directory to search for examples. If a file is found with the
same name as an EFL C# class (e.g. Efl.Ui.Button.cs) or as an EFL C# method or
property (e.g. Efl.IText.Text.cs, Efl.IText.SetText.cs) its full
contents will be embedded in the documentation for that class or method within
<example> and <code> tags. This is, in turn, is parsed by DocFX and shown
in Example boxes in the generated pages.
If an example file is not found, no examples are embedded for that object.
If -e is not used, no examples are embedded for any object.
New option added to meson: mono-examples-dir to point to the examples directory.
This directory is then passed to eolian_mono through -e.
Do not use it (or define it to nothing) to disable example embedding.
No performance drop has been observed because of these extra tests.
Right now examples can only be given for base classes, not for derived ones
(i.e. Efl.IText.Text but not Efl.Ui.Button.Text). This will be addressed in a
later commit.
Feature
Depends on D8587
Test Plan:
Create an examples folder and put some files in it:
```
mkdir /tmp/examples
echo 'var button = new Efl.Ui.Button();' > /tmp/examples/Efl.Ui.Button.cs
echo 'button.AutoRepeatEnabled = true;' > /tmp/examples/Efl.Ui.IAutorepeat.AutorepeatEnabled.cs
echo 'button.SetAutoRepeatEnabled(true);' > /tmp/examples/Efl.Ui.IAutorepeat.SetAutorepeatEnabled.cs
```
Configure meson to embed examples and build:
```
meson configure -Dmono-examples-dir=/tmp/examples
ninja
```
Examine the generated efl_ui_button.eo.cs file to see embedded <example> tags,
or run DocFX and bask in the glory of documentation pages with examples:
```
cd doc/docfx
./gendoc.sh
```
Reviewers: lauromoura, felipealmeida, vitor.sousa, zmike, bu5hm4n
Reviewed By: vitor.sousa
Subscribers: cedric, #reviewers, #committers
Tags: #efl
Differential Revision: https://phab.enlightenment.org/D8592
2019-04-11 01:38:40 -07:00
|
|
|
else if (c == 'e')
|
|
|
|
{
|
|
|
|
opts.examples_dir = optarg;
|
|
|
|
if (!opts.examples_dir.empty() && opts.examples_dir.back() != '/') opts.examples_dir += "/";
|
|
|
|
}
|
2019-08-23 10:27:28 -07:00
|
|
|
else if (c == 'p')
|
|
|
|
{
|
|
|
|
opts.want_partial = true;
|
|
|
|
}
|
2017-11-23 16:50:16 -08:00
|
|
|
}
|
|
|
|
if (optind == argc-1)
|
|
|
|
{
|
|
|
|
opts.in_file = argv[optind];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eolian_mono::opts_check(opts))
|
|
|
|
{
|
|
|
|
_usage(argv[0]);
|
|
|
|
assert(false && "Wrong options passed in command-line");
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
efl::eina::eina_init eina_init;
|
|
|
|
efl::eolian::eolian_init eolian_init;
|
2019-09-30 06:38:34 -07:00
|
|
|
efl::eolian::eolian_state eolian_state;
|
2017-11-23 16:50:16 -08:00
|
|
|
eolian_mono::options_type opts = opts_get(argc, argv);
|
2019-09-30 06:38:34 -07:00
|
|
|
opts.state = eolian_state.value;
|
|
|
|
opts.unit = eolian_state.as_unit();
|
2017-11-23 16:50:16 -08:00
|
|
|
eolian_mono::database_load(opts);
|
|
|
|
eolian_mono::run(opts);
|
|
|
|
}
|
|
|
|
catch(std::exception const& e)
|
|
|
|
{
|
|
|
|
std::cerr << "EOLCXX: Eolian C++ failed generation for the following reason: " << e.what() << std::endl;
|
|
|
|
std::cout << "EOLCXX: Eolian C++ failed generation for the following reason: " << e.what() << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|