From 49dc819d238b09cb4c0103ae916d2971f698f8ef Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Wed, 3 Jun 2015 17:22:30 -0700 Subject: [PATCH] chore(build): add experimental Dart build that uses DDC for code analysis --- .travis.yml | 1 + gulpfile.js | 6 +++++ scripts/ci/build_and_test.sh | 11 ++++++--- scripts/ci/build_dart_experimental.sh | 15 ++++++++++++ scripts/ci/env_dart.sh | 4 +++- tools/build/dartanalyzer.js | 34 ++++++++++++++++++++++----- 6 files changed, 61 insertions(+), 10 deletions(-) create mode 100755 scripts/ci/build_dart_experimental.sh diff --git a/.travis.yml b/.travis.yml index 9d31d7b4f1..c70091a2d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ env: - MODE=js DART_CHANNEL=dev - MODE=dart DART_CHANNEL=stable - MODE=dart DART_CHANNEL=dev + - MODE=dart_experimental DART_CHANNEL=dev addons: firefox: "38.0" diff --git a/gulpfile.js b/gulpfile.js index 537a94ac24..0ecb37b727 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -243,6 +243,12 @@ gulp.task('build/analyze.dart', dartanalyzer(gulp, gulpPlugins, { command: DART_SDK.ANALYZER })); +gulp.task('build/analyze.ddc.dart', dartanalyzer(gulp, gulpPlugins, { + dest: CONFIG.dest.dart, + command: DART_SDK.ANALYZER, + use_ddc: true +})); + // ------------ // pubbuild // WARNING: this task is very slow (~15m as of July 2015) diff --git a/scripts/ci/build_and_test.sh b/scripts/ci/build_and_test.sh index 75059046a8..444f06a84d 100755 --- a/scripts/ci/build_and_test.sh +++ b/scripts/ci/build_and_test.sh @@ -8,6 +8,11 @@ echo =========================================================================== SCRIPT_DIR=$(dirname $0) cd $SCRIPT_DIR/../.. -${SCRIPT_DIR}/build_$MODE.sh -mkdir deploy; tar -czpf deploy/dist.tgz -C dist . -${SCRIPT_DIR}/test_$MODE.sh +if [ "$MODE" = "dart_experimental" ] +then + ${SCRIPT_DIR}/build_$MODE.sh +else + ${SCRIPT_DIR}/build_$MODE.sh + mkdir deploy; tar -czpf deploy/dist.tgz -C dist . + ${SCRIPT_DIR}/test_$MODE.sh +fi diff --git a/scripts/ci/build_dart_experimental.sh b/scripts/ci/build_dart_experimental.sh new file mode 100755 index 0000000000..dd72e16633 --- /dev/null +++ b/scripts/ci/build_dart_experimental.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +echo ============================================================================= +echo EXPERIMENTAL DART BUILD +echo ============================================================================= + +# go to project dir +SCRIPT_DIR=$(dirname $0) +source $SCRIPT_DIR/env_dart.sh +cd $SCRIPT_DIR/../.. + +./node_modules/.bin/gulp build/packages.dart +./node_modules/.bin/gulp build/pubspec.dart +./node_modules/.bin/gulp build/analyze.ddc.dart diff --git a/scripts/ci/env_dart.sh b/scripts/ci/env_dart.sh index 1f384ea1c6..465603ed4d 100755 --- a/scripts/ci/env_dart.sh +++ b/scripts/ci/env_dart.sh @@ -70,7 +70,9 @@ if [[ -z $ENV_SET ]]; then export DARTSDK export DART export PUB=${PUB:-"$DART_SDK/bin/pub"} - export PUB_CACHE=$DART_SDK/pub-cache + if [ -z "$PUB_CACHE" ]; then + export PUB_CACHE=$DART_SDK/pub-cache + fi export DARTANALYZER=${DARTANALYZER:-"$DART_SDK/bin/dartanalyzer"} export DARTDOC=${DARTDOC:-"$DART_SDK/bin/dartdoc"} export DART_DOCGEN=${DART_DOCGEN:-"$DART_SDK/bin/docgen"} diff --git a/tools/build/dartanalyzer.js b/tools/build/dartanalyzer.js index edd51f7023..7321fe2cf8 100644 --- a/tools/build/dartanalyzer.js +++ b/tools/build/dartanalyzer.js @@ -16,10 +16,9 @@ module.exports = function(gulp, plugins, config) { var packageName = pubspec.name; var libFiles = [].slice.call(glob.sync('lib/**/*.dart', {cwd: dir})); - var webFiles = [].slice.call(glob.sync('web/**/*.dart', {cwd: dir})); - var testFiles = [].slice.call(glob.sync('test/**/*_spec.dart', {cwd: dir})); + var analyzeFile = ['library _analyzer;']; libFiles.concat(testFiles).concat(webFiles).forEach(function(fileName, index) { if (fileName !== tempFile && fileName.indexOf("/packages/") === -1) { @@ -31,13 +30,24 @@ module.exports = function(gulp, plugins, config) { }); fs.writeFileSync(path.join(dir, tempFile), analyzeFile.join('\n')); var defer = Q.defer(); - analyze(dir, defer.makeNodeResolver()); + if (config.use_ddc) { + analyze(dir, defer.makeNodeResolver(), true); + } else { + analyze(dir, defer.makeNodeResolver()); + } return defer.promise; }); - function analyze(dirName, done) { + function analyze(dirName, done, useDdc) { // TODO remove --package-warnings once dartanalyzer handles transitive libraries - var args = ['--fatal-warnings', '--package-warnings', '--format=machine'].concat(tempFile); + var flags = ['--fatal-warnings', '--package-warnings', '--format=machine']; + + if (useDdc) { + console.log('Using DDC analyzer to analyze', dirName); + flags.push('--strong'); + } + + var args = flags.concat(tempFile); var stream = spawn(config.command, args, { // inherit stdin and stderr, but filter stdout @@ -97,7 +107,19 @@ module.exports = function(gulp, plugins, config) { if (report.length > 0) { error = 'Dartanalyzer showed ' + report.join(', '); } - done(error); + if (useDdc) { + // TODO(yjbanov): fail the build when: + // - DDC analyzer is stable enough + // - We have cleaned up all DDC warnings + console.log(error); + done(); + } else { + done(error); + } + }); + stream.on('error', function(e) { + // TODO(yjbanov): fail the build when DDC is stable enough + console.log('ERROR: failed to run DDC at all: ' + e); }); } };