Skip to content

Commit 6b73d09

Browse files
committed
chore(build): make experimental Dart build useful
Previously we grepped all hand-written Dart code and ran analyzer in strong mode against it. Now we run it against transformed playground apps, which: 1. does not analyze unnecessary code (we primarily care about stuff that runs in the browser) 2. analyzes generated code, which does run in the browser and which we failed to analyze in the previous version of the build Closes angular#6436
1 parent ac85cbb commit 6b73d09

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

scripts/ci/build_dart_experimental.sh

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,53 @@ SCRIPT_DIR=$(dirname $0)
1010
source $SCRIPT_DIR/env_dart.sh
1111
cd $SCRIPT_DIR/../..
1212

13+
# Variables
14+
DDC_WARNING_CAP="260"
15+
DDC_DIR=`pwd`/tmp/dev_compiler
16+
DDC_VERSION="0.1.14"
17+
18+
# Get DDC
19+
mkdir -p tmp
20+
rm -rf tmp/dev_compiler
21+
git clone https://github.com/dart-lang/dev_compiler.git tmp/dev_compiler
22+
(cd $DDC_DIR && \
23+
git checkout tags/$DDC_VERSION && \
24+
$PUB get)
25+
26+
# Convert TypeScript to Dart
1327
./node_modules/.bin/gulp build/packages.dart
1428
./node_modules/.bin/gulp build/pubspec.dart
15-
./node_modules/.bin/gulp build/analyze.ddc.dart
29+
node ./scripts/ci/dart_experimental/pubspec_for_ddc.js \
30+
--pubspec-file=dist/dart/playground/pubspec.yaml
31+
32+
# Compile playground
33+
cd dist/dart/playground
34+
$PUB build --mode=debug
35+
cd build/web
36+
LOG_FILE="analyzer.log"
37+
set +e
38+
$DART_SDK/bin/dart $DDC_DIR/bin/dartdevc.dart \
39+
--dart-sdk=$DART_SDK_LIB_SEARCH_PATH -o out src/hello_world/index.dart \
40+
>$LOG_FILE
41+
EXIT_CODE=`echo $?`
42+
set -e
43+
44+
# Analyzer exits with 1 when there are warnings and something crazy
45+
# like 255 when it crashes. We don't want to fail the build if its
46+
# only warnings (until our code is warning-free).
47+
if [[ "$EXIT_CODE" -ne "0" && "$EXIT_CODE" -ne "1" ]]
48+
then
49+
echo "DDC compiler crashed with exit code $EXIT_CODE"
50+
exit 1
51+
fi
52+
53+
cat $LOG_FILE
54+
WARNING_COUNT=`cat $LOG_FILE | wc -l | sed -e 's/^[[:space:]]*//'`
55+
56+
if [[ "$WARNING_COUNT" -gt "$DDC_WARNING_CAP" ]]
57+
then
58+
echo "Too many warnings: $WARNING_COUNT"
59+
exit 1
60+
else
61+
echo "Warning count ok"
62+
fi
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Removes dart2js from pubspec.yaml for faster building
2+
// Usage: node pubspec_for_ddc.js --pubspec-file=PATH_TO_PUBSPEC_YAML
3+
4+
var fs = require('fs');
5+
var yaml = require('js-yaml');
6+
var yargs = require('yargs');
7+
8+
var pubspecFileOpt = 'pubspec-file';
9+
var pubspecFile = yargs
10+
.demand([pubspecFileOpt])
11+
.argv[pubspecFileOpt];
12+
13+
var doc = yaml.safeLoad(fs.readFileSync(pubspecFile, 'utf8'));
14+
15+
var transformers = doc['transformers'];
16+
if (transformers) {
17+
transformers.forEach(function (transformer) {
18+
var dart2js = transformer['\$dart2js'];
19+
if (dart2js) {
20+
dart2js['$exclude'] = [ 'web/**/*' ];
21+
}
22+
});
23+
}
24+
25+
fs.writeFileSync(pubspecFile, yaml.safeDump(doc));

scripts/ci/env_dart.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ if [[ -z $ENV_SET ]]; then
6666
fi
6767
fi
6868

69+
case "$PLATFORM" in
70+
(Linux) export DART_SDK_LIB_SEARCH_PATH="$DART_SDK" ;;
71+
(Darwin) export DART_SDK_LIB_SEARCH_PATH="$DART_SDK/libexec" ;;
72+
(*) echo Unsupported platform $PLATFORM. Exiting ... >&2 ; exit 3 ;;
73+
esac
74+
6975
export DART_SDK
7076
export DARTSDK
7177
export DART
@@ -85,6 +91,7 @@ if [[ -z $ENV_SET ]]; then
8591
echo '** ENV **'
8692
echo '*********'
8793
echo DART_SDK=$DART_SDK
94+
echo DART_SDK_LIB_SEARCH_PATH=$DART_SDK_LIB_SEARCH_PATH
8895
echo DART=$DART
8996
echo PUB=$PUB
9097
echo DARTANALYZER=$DARTANALYZER

0 commit comments

Comments
 (0)