From d83d8beae36f0a397060151b649e167c9526ca78 Mon Sep 17 00:00:00 2001 From: Jinho Bang Date: Sun, 19 Nov 2017 20:16:25 +0900 Subject: [PATCH] Introduce `gulp` build to build native/idl files This change introduces `gulp` build system to build native/idl files. After this patch, we no longer need to create and modify `gyp/gypi` files to update the list of native/idl files. This change includes the following things: - Introduce `gulp` build (including some related packages) - Stop using `.gypi` files except `generator.gypi`. Once move TSC build to `gulp`, then we can remove it as well ISSUE=#98,#193 --- binding.gyp | 20 +---- bootstrap/bacardi.sh | 17 ++++- core/core.gypi | 25 ------- examples/electron/native/electron_native.gypi | 32 -------- examples/examples.gypi | 35 --------- gulpfile.ts | 74 +++++++++++++++++++ package.json | 7 ++ test/test.gypi | 31 -------- 8 files changed, 100 insertions(+), 141 deletions(-) delete mode 100644 core/core.gypi delete mode 100644 examples/electron/native/electron_native.gypi delete mode 100644 examples/examples.gypi create mode 100644 gulpfile.ts delete mode 100644 test/test.gypi diff --git a/binding.gyp b/binding.gyp index 89e4573..5a9027d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -14,11 +14,7 @@ { 'includes': [ - 'core/core.gypi', - 'examples/examples.gypi', - 'examples/electron/native/electron_native.gypi', 'generator/generator.gypi', - 'test/test.gypi', ], 'targets': [ @@ -52,13 +48,8 @@ }], ], 'sources': [ - '<@(core_cpp_files)', - '<@(examples_cpp_files)', - '<@(examples_idl_output_files)', - '<@(examples_electron_native_cpp_files)', - '<@(examples_electron_native_idl_output_files)', - '<@(test_cpp_files)', - '<@(test_idl_output_files)', + ' .last_update +elif [ package.json -nt .last_update ]; then + npm update && > .last_update fi for command in $(ls $(bootstrap_command_path)); do @@ -47,3 +58,5 @@ for command in $(ls $(bootstrap_command_path)); do exit fi done + +gulp $@ diff --git a/core/core.gypi b/core/core.gypi deleted file mode 100644 index db55004..0000000 --- a/core/core.gypi +++ /dev/null @@ -1,25 +0,0 @@ -# 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': { - 'core_cpp_files': [ - 'enum_validator.h' - 'idl_base.h', - 'idl_types.h', - 'js_type_traits.h', - 'native_type_traits.h', - ], - }, -} diff --git a/examples/electron/native/electron_native.gypi b/examples/electron/native/electron_native.gypi deleted file mode 100644 index 636e522..0000000 --- a/examples/electron/native/electron_native.gypi +++ /dev/null @@ -1,32 +0,0 @@ -# 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': { - 'examples_electron_native_cpp_files': [ - 'electron_native.cc', - 'electron_native.h', - '<(module_root_dir)/third_party/simrank/simrank.hpp', - ], - - 'examples_electron_native_idl_files': [ - '<(module_root_dir)/examples/electron/native/electron_native.idl', - ], - - 'examples_electron_native_idl_output_files': [ - '<(SHARED_INTERMEDIATE_DIR)/examples/electron/native/electron_native_bridge.cc', - '<(SHARED_INTERMEDIATE_DIR)/examples/electron/native/electron_native_bridge.h', - ], - }, -} diff --git a/examples/examples.gypi b/examples/examples.gypi deleted file mode 100644 index 1c95ac3..0000000 --- a/examples/examples.gypi +++ /dev/null @@ -1,35 +0,0 @@ -# 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': { - 'examples_cpp_files': [ - 'calculator.cc', - 'calculator.h', - 'ternary_calculator.cc', - 'ternary_calculator.h', - ], - - 'examples_idl_files': [ - '<(module_root_dir)/examples/calculator.idl', - ], - - 'examples_idl_output_files': [ - '<(SHARED_INTERMEDIATE_DIR)/examples/calculator_bridge.cc', - '<(SHARED_INTERMEDIATE_DIR)/examples/calculator_bridge.h', - '<(SHARED_INTERMEDIATE_DIR)/examples/ternary_calculator_bridge.cc', - '<(SHARED_INTERMEDIATE_DIR)/examples/ternary_calculator_bridge.h', - ], - }, -} diff --git a/gulpfile.ts b/gulpfile.ts new file mode 100644 index 0000000..df040f3 --- /dev/null +++ b/gulpfile.ts @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2017 The Absolute 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. + */ + +import * as gulp from 'gulp'; +import * as path from 'path'; +import * as through from 'through2'; + +gulp.task('default', (callback) => { + // FIXME(zino): Should print available commands in Bacardi. + return; +}); + +/** + * This task will be used in binding.gyp to build native files. + */ +gulp.task('list_cpp_files', (callback) => { + return gulp + .src([ + 'core/**/*.h', 'core/**/*.cc', 'examples/**/*.h', 'examples/**/*.cc', + 'test/**/*.h', 'test/**/*.cc' + ]) + .pipe(printPath()); +}); + +/** + * This task will be used in binding.gyp to build idl files. + */ +gulp.task('list_idl_files', (callback) => { + return gulp.src(['examples/**/*.idl', 'test/**/*.idl']).pipe(printPath()); +}); + +/** + * This task will be used in binding.gyp to build idl files. + */ +gulp.task('list_generated_cpp_files', (callback) => { + // FIXME(zino): The following file list should be generated by idl generator + // automatically. + const genDir = 'build/Release/obj/gen/'; + const genFiles = [ + path.join(genDir, 'examples/calculator_bridge.cc'), + path.join(genDir, 'examples/calculator_bridge.h'), + path.join(genDir, 'examples/ternary_calculator_bridge.cc'), + path.join(genDir, 'examples/ternary_calculator_bridge.h'), + path.join(genDir, 'examples/electron/native/electron_native_bridge.cc'), + path.join(genDir, 'examples/electron/native/electron_native_bridge.h'), + path.join(genDir, 'test/test_interface_bridge.cc'), + path.join(genDir, 'test/test_interface_bridge.h'), + ]; + + return genFiles.forEach((file) => { + process.stdout.write('"' + file + '"\n'); + }); +}); + +/* Custom plugins */ +function printPath() { + return through.obj((files, encoding, callback) => { + process.stdout.write('"' + path.relative(files.cwd, files.path) + '"\n'); + callback(); + }); +} diff --git a/package.json b/package.json index 3f3111c..65a6b61 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,24 @@ { "devDependencies": { + "@types/gulp": "^4.0.5", + "@types/gulp-typescript": "^2.13.0", "@types/jest": "^21.1.2", "@types/node": "^8.0.24", + "@types/through2": "^2.0.33", "bindings": "^1.3.0", "change-case": "^3.0.1", "electron": "^1.7.8", "electron-rebuild": "^1.6.0", + "gulp": "^3.9.1", + "gulp-typescript": "^3.2.3", "jest": "^21.2.1", "mkdirp": "^0.5.1", "node-addon-api": "^1.0.0", "node-gyp": "^3.6.2", "nunjucks": "^3.0.1", + "through2": "^2.0.3", "ts-jest": "^21.1.0", + "ts-node": "^3.3.0", "typescript": "^2.4.2", "webidl2": "^4.1.0" }, diff --git a/test/test.gypi b/test/test.gypi deleted file mode 100644 index e468ac4..0000000 --- a/test/test.gypi +++ /dev/null @@ -1,31 +0,0 @@ -# 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', - ], - }, -}