Skip to content

Commit

Permalink
Implement skeleton codes for a new version of WebIDL compiler (#208)
Browse files Browse the repository at this point in the history
This is a new initial implementation of WebIDL compiler. It has the
following differences compared to the existing one.
  - It is built by `gulp` instead of `gyp`
  - No longer build `generator` and `webidl` separately

ISSUE=#207
  • Loading branch information
romandev committed Nov 25, 2017
1 parent 34893d1 commit e848669
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ branches:
- master

build_script:
- bacardi clean && bacardi build_webidl
- bacardi clean && bacardi build

test_script:
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install g++ git make python wget; fi

script:
- ./bacardi clean && ./bacardi build_webidl
- ./bacardi clean && ./bacardi build && ./bacardi lint && ./bacardi test
- ./bacardi clean && ./bacardi build_electron
1 change: 1 addition & 0 deletions bootstrap/bacardi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ for command in $(ls $(bootstrap_command_path)); do
fi
done

export NODE_PATH=$(bacardi_path)
gulp $@
Binary file added docs/images/triggering_webidl_compiler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/webidl_compiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# WebIDL compiler
This document explains how `./bacardi build_webidl` works internally.

- [Triggering WebIDL compiler](#triggering-webidl-compiler)

## Triggering WebIDL compiler

![Triggering WebIDL compiler process](/docs/images/triggering_webidl_compiler.png)
To request building WebIDL, you can just use `./bacardi build_webidl` command.

1. `bacardi build_webidl` command will run `gulp build_webidl` internally.
2. In our project, the `gulp` command will run on `ts-node` runtime.
So, `ts-node` will request to build all related TypeScript modules internally.
3. Then, `ts-node` will generate JS codes using TypeScript compiler.
4. In this step, queries all `*.idl` files in this project.
5. Pass the found WebIDL file list and request to compile WebIDL files.

### bootstrap
The bootstrap is set of scripts that provide required packages via auto-install
in multi-platform environment. With this module, we can handle everything to
build and run our project without any additional works.

### gulp
The [gulp](https://github.com/gulpjs/gulp) provides the streaming build system.
In our project, `./bacardi <command>` will trigger `gulp <task>` internally.

### ts-node
The [ts-node](https://github.com/TypeStrong/ts-node) is a runtime for TypeScript
for Node.js. It makes our TypeScript codes run on Node.js without explicit
TypeScript compile. So, this makes `gulpfile.ts` work. Also, When processing
gulp tasks such as the `build_webidl` as shown in the figure above, the WebIDL
compiler codes(TypeScript codes) is executed by performing TypeScript compiling
internally.

### WebIDL compiler
The WebIDL compiler(or often we called bindings generator) transcompiles WebIDL
to Native codes such as C++ codes.
27 changes: 27 additions & 0 deletions generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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.
*/

import * as assert from 'assert';

export async function run(idlFiles: string[]): Promise<number> {
assert(idlFiles.indexOf('test/test_interface.idl') >= 0);
assert(idlFiles.indexOf('examples/calculator.idl') >= 0);
assert(idlFiles.indexOf('examples/electron/native/electron_native.idl') >= 0);

// Not implemented yet.

return 0;
}
21 changes: 19 additions & 2 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import * as generator from 'generator';
import * as globs from 'globs';
import * as gulp from 'gulp';
import * as shell from 'gulp-shell';
import gulpTslint from 'gulp-tslint';
Expand All @@ -29,6 +31,15 @@ gulp.task('default', () => {
return;
});

/**
* Build WebIDL
*/
gulp.task('build_webidl', (callback) => {
globs(['examples/**/*.idl', 'test/**/*.idl'], async(error, files) => {
callback(await generator.run(files));
});
});

/**
* This task will be used in binding.gyp to build native files.
*/
Expand Down Expand Up @@ -100,7 +111,10 @@ gulp.task('lint_native', shell.task([
gulp.task('lint_ts', () => {
const program: ts.Program = tslint.Linter.createProgram('tsconfig.json');

return gulp.src('gulpfile.ts')
return gulp.src([
'gulpfile.ts',
'generator/index.ts'
])
.pipe(gulpTslint({
formatter: 'codeFrame',
program: program
Expand All @@ -113,7 +127,10 @@ gulp.task('lint_ts', () => {
gulp.task('lint_ts:fix', () => {
const program: ts.Program = tslint.Linter.createProgram('tsconfig.json');

return gulp.src('gulpfile.ts')
return gulp.src([
'gulpfile.ts',
'generator/index.ts'
])
.pipe(gulpTslint({
formatter: 'codeFrame',
program: program,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"change-case": "^3.0.1",
"electron": "^1.7.8",
"electron-rebuild": "^1.6.0",
"globs": "^0.1.3",
"gulp": "^3.9.1",
"gulp-shell": "^0.6.3",
"gulp-tslint": "^8.1.2",
Expand Down

0 comments on commit e848669

Please sign in to comment.