From 347cec5b01a50ab9c0a3caf34ccd9e51ff229391 Mon Sep 17 00:00:00 2001 From: Jinho Bang Date: Sun, 8 Oct 2017 01:15:07 +0900 Subject: [PATCH] Add test/test_interface.* for testing. (#113) This patch is adding a new test IDL interface to test/ directory. After this patch, we can build a multiple IDL files and use them. ISSUE=#99,#100 TBR=@hwanseung,@yjaeseok --- binding.gyp | 5 +++++ generator/main.ts | 10 +++++----- generator/parser/idl_definition.ts | 12 ++++-------- template/bacardi_cpp.njk | 8 ++++---- template/interface_cpp.njk | 2 +- template/interface_header.njk | 2 +- test/test.gypi | 31 ++++++++++++++++++++++++++++++ test/test_interface.cc | 19 ++++++++++++++++++ test/test_interface.h | 25 ++++++++++++++++++++++++ test/test_interface.idl | 18 +++++++++++++++++ 10 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 test/test.gypi create mode 100644 test/test_interface.cc create mode 100644 test/test_interface.h create mode 100644 test/test_interface.idl diff --git a/binding.gyp b/binding.gyp index 6d8f66d..58be9d0 100644 --- a/binding.gyp +++ b/binding.gyp @@ -17,6 +17,7 @@ 'core/core.gypi', 'examples/examples.gypi', 'generator/generator.gypi', + 'test/test.gypi', ], 'targets': [ @@ -53,6 +54,8 @@ '<@(core_cpp_files)', '<@(examples_cpp_files)', '<@(examples_idl_output_files)', + '<@(test_cpp_files)', + '<@(test_idl_output_files)', '<(SHARED_INTERMEDIATE_DIR)/bacardi.cc', ], 'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ], @@ -104,9 +107,11 @@ 'action_name': 'idl', 'inputs': [ '<@(examples_idl_files)', + '<@(test_idl_files)', ], 'outputs': [ '<@(examples_idl_output_files)', + '<@(test_idl_output_files)', ], 'conditions': [ ['OS!="win"', diff --git a/generator/main.ts b/generator/main.ts index 35e78ec..213aec2 100644 --- a/generator/main.ts +++ b/generator/main.ts @@ -35,15 +35,15 @@ async function generateBacardi( [file.read(path.resolve(TEMPLATE_DIR, 'bacardi_cpp.njk'))]); const cpp_file_path = path.resolve(output_path, 'bacardi.cc'); - let idl_interface_names: string[] = []; + let idl_interfaces: IDLDefinition[] = []; definitions.forEach(async (definition) => { if (definition.isIDLInterface()) { - idl_interface_names.push(definition.name); + idl_interfaces.push(definition); } }); return file.write( - cpp_file_path, env.renderString(cpp_tmpl, {names: idl_interface_names})); + cpp_file_path, env.renderString(cpp_tmpl, {interfaces: idl_interfaces})); } async function generateInterface( @@ -58,11 +58,11 @@ async function generateInterface( if (definition.isIDLInterface()) { const header_file_path = path.resolve( output_path, - definition.idlDirName() + '/' + snakeCase(definition.name) + + definition.idl_dir_name + '/' + snakeCase(definition.name) + '_bridge.h'); const cpp_file_path = path.resolve( output_path, - definition.idlDirName() + '/' + snakeCase(definition.name) + + definition.idl_dir_name + '/' + snakeCase(definition.name) + '_bridge.cc'); await file.write( diff --git a/generator/parser/idl_definition.ts b/generator/parser/idl_definition.ts index 68209ee..87ba8b9 100644 --- a/generator/parser/idl_definition.ts +++ b/generator/parser/idl_definition.ts @@ -16,10 +16,14 @@ export default abstract class IDLDefinition { public readonly name: string; + public readonly idl_base_name: string; + public readonly idl_dir_name: string; protected readonly raw_idl_definition_info: {}; protected constructor(name: string, raw_idl_definition_info: {}) { this.name = name; + this.idl_base_name = raw_idl_definition_info['idlBaseName']; + this.idl_dir_name = raw_idl_definition_info['idlDirName']; this.raw_idl_definition_info = raw_idl_definition_info; } @@ -28,12 +32,4 @@ export default abstract class IDLDefinition { public isIDLInterface(): boolean { return this.raw_idl_definition_info['type'] == 'interface'; } - - public idlBaseName(): string { - return this.raw_idl_definition_info['idlBaseName']; - } - - public idlDirName(): string { - return this.raw_idl_definition_info['idlDirName']; - } } diff --git a/template/bacardi_cpp.njk b/template/bacardi_cpp.njk index 19e0b31..04a8022 100644 --- a/template/bacardi_cpp.njk +++ b/template/bacardi_cpp.njk @@ -19,13 +19,13 @@ #include "core/bacardi.h" -{% for name in names %} -#include "examples/{{name | snakecase}}_bridge.h" +{% for interface in interfaces %} +#include "{{interface.idl_dir_name}}/{{interface.name | snakecase}}_bridge.h" {% endfor %} void Init(Napi::Env env, Napi::Object exports, Napi::Object module) { - {% for name in names %} - {{name}}Bridge::Init(env, exports); + {% for interface in interfaces %} + {{interface.name}}Bridge::Init(env, exports); {% endfor %} } diff --git a/template/interface_cpp.njk b/template/interface_cpp.njk index 082e307..f4ce4c1 100644 --- a/template/interface_cpp.njk +++ b/template/interface_cpp.njk @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "examples/{{name | snakecase}}_bridge.h" +#include "{{idl_dir_name}}/{{name | snakecase}}_bridge.h" #include "core/js_type_traits.h" #include "core/native_type_traits.h" diff --git a/template/interface_header.njk b/template/interface_header.njk index 9e191c8..fc13776 100644 --- a/template/interface_header.njk +++ b/template/interface_header.njk @@ -20,7 +20,7 @@ #include #include -#include "examples/{{name | snakecase}}.h" +#include "{{idl_dir_name}}/{{name | snakecase}}.h" class {{name}}Bridge : public Napi::ObjectWrap<{{name}}Bridge> { public: diff --git a/test/test.gypi b/test/test.gypi new file mode 100644 index 0000000..e468ac4 --- /dev/null +++ b/test/test.gypi @@ -0,0 +1,31 @@ +# Copyright (c) 2017 The Bacardi 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. + +{ + 'variables': { + 'test_cpp_files': [ + 'test_interface.cc', + 'test_interface.h', + ], + + 'test_idl_files': [ + '<(module_root_dir)/test/test_interface.idl', + ], + + 'test_idl_output_files': [ + '<(SHARED_INTERMEDIATE_DIR)/test/test_interface_bridge.cc', + '<(SHARED_INTERMEDIATE_DIR)/test/test_interface_bridge.h', + ], + }, +} diff --git a/test/test_interface.cc b/test/test_interface.cc new file mode 100644 index 0000000..90e0219 --- /dev/null +++ b/test/test_interface.cc @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2017 The Bacardi 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. + */ + +#include "test/test_interface.h" + +TestInterface::TestInterface() {} diff --git a/test/test_interface.h b/test/test_interface.h new file mode 100644 index 0000000..fe3f701 --- /dev/null +++ b/test/test_interface.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2017 The Bacardi 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. + */ + +#ifndef TEST_TEST_INTERFACE_H_ +#define TEST_TEST_INTERFACE_H_ + +class TestInterface { + public: + TestInterface(); +}; + +#endif // TEST_TEST_INTERFACE_H_ diff --git a/test/test_interface.idl b/test/test_interface.idl new file mode 100644 index 0000000..dc1c180 --- /dev/null +++ b/test/test_interface.idl @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2017 The Bacardi 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. + */ + +interface TestInterface { +};