Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce gulp build to build native/idl files #194

Merged
merged 1 commit into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

{
'includes': [
'core/core.gypi',
'examples/examples.gypi',
'examples/electron/native/electron_native.gypi',
'generator/generator.gypi',
'test/test.gypi',
],

'variables': {
'bacardi_command%': './bacardi',
'conditions': [
['OS == "win"', {
'bacardi_command': 'bacardi.cmd',
}],
],
},

'targets': [
{
'target_name': 'bacardi',
Expand Down Expand Up @@ -52,13 +57,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)',
'<!@(<(bacardi_command) list_cpp_files --silent)',
'<!@(<(bacardi_command) list_generated_cpp_files --silent)',
'<(SHARED_INTERMEDIATE_DIR)/bacardi.cc',
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
Expand Down Expand Up @@ -109,13 +109,10 @@
{
'action_name': 'idl',
'inputs': [
'<@(examples_idl_files)',
'<@(examples_electron_native_idl_files)',
'<@(test_idl_files)',
'<!@(<(bacardi_command) list_idl_files --silent)',
],
'outputs': [
'<@(examples_electron_native_idl_output_files)',
'<@(test_idl_output_files)',
'<!@(<(bacardi_command) list_generated_cpp_files --silent)',
],
'conditions': [
['OS!="win"',
Expand Down
14 changes: 13 additions & 1 deletion bootstrap/bacardi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

. $BACARDI_PATH/bootstrap/common/path_info.sh
. $BACARDI_PATH/bootstrap/common/string_util.sh
. $BACARDI_PATH/bootstrap/common/sync_third_party.sh

# Set path
Expand All @@ -35,7 +36,16 @@ git submodule update
# Sync third_parties.
sync_node

# NPM update
# FIXME(zino): If npm packages are updated, then node-gyp will be triggered
# automatically. To get native/idl file list, we will use ./bacardi list*
# command again in binding.gyp. Then, it causes infinite loop finally.
# To avoid the problem, as a workaround, we should filter list* commands here.
if [ "$(substr $1 1 4)" = "list" ]; then
gulp $@
exit
fi

# NPM install or update
if [ ! -f .last_update ] || [ package.json -nt .last_update ]; then
npm install && > .last_update
fi
Expand All @@ -47,3 +57,5 @@ for command in $(ls $(bootstrap_command_path)); do
exit
fi
done

gulp $@
10 changes: 10 additions & 0 deletions bootstrap/common/string_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ function to_lower() {
function to_upper() {
echo $1 | tr '[:lower:]' '[:upper:]'
}

# Extract input length characters of substring from input string at input
# position.
# $1: Input string
# $2: Input position
# $3: Input length
# Out: Extracted substring
function substr() {
echo $1 | cut -c $2-$3
}
25 changes: 0 additions & 25 deletions core/core.gypi

This file was deleted.

32 changes: 0 additions & 32 deletions examples/electron/native/electron_native.gypi

This file was deleted.

35 changes: 0 additions & 35 deletions examples/examples.gypi

This file was deleted.

84 changes: 84 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* 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(printAbsolutePath());
});

/**
* 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 isWindows = /^win/.test(process.platform);
const genDir =
'build/Release/obj/' + (isWindows ? 'global_intermediate/' : '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((file, encoding, callback) => {
process.stdout.write('"' + path.relative(file.cwd, file.path) + '"\n');
callback();
});
}

function printAbsolutePath() {
return through.obj((file, encoding, callback) => {
process.stdout.write('"' + file.path + '"\n');
callback();
});
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{
"devDependencies": {
"@types/gulp": "^4.0.5",
"@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"
},
Expand Down
31 changes: 0 additions & 31 deletions test/test.gypi

This file was deleted.