From 4d810dec743e9f270b337c397bfead27cd7367e3 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 1 Feb 2018 18:23:27 -0800 Subject: [PATCH] Generate app snapshots for the current OS Might as well give some subset of our users a speed-up while we wait for dart-lang/sdk#28617. --- tool/app-snapshot-input.scss | 21 ++++++++++++++++ tool/grind.dart | 46 ++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 tool/app-snapshot-input.scss diff --git a/tool/app-snapshot-input.scss b/tool/app-snapshot-input.scss new file mode 100644 index 000000000..78f8e1784 --- /dev/null +++ b/tool/app-snapshot-input.scss @@ -0,0 +1,21 @@ +// This file is used to train application snapshots. It exercises the Sass value +// types and the most common AST types so that they're already JIT-compiled when +// the snapshot begins running. + +/* loud comment */ + +@media screen { + type { + &.class#id[attr]%placeholder:pseudo { + number: 1.5px; + color: #abc; + list: 1 2 3; + map: map-get((1: 2), 1); + string: foo; + boolean: true; + null: null; + } + } +} + +* {@extend %placeholder} diff --git a/tool/grind.dart b/tool/grind.dart index b0bec6ec0..980664ca9 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -35,6 +35,9 @@ bool get _isDevSdk => _dartVersion.isPreRelease; /// The root of the Dart SDK. final _sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable)); +/// Whether we're using a 64-bit Dart SDK. +bool get _is64Bit => Platform.version.contains("x64"); + main(List args) => grind(args); @DefaultTask('Compile async code and reformat.') @@ -49,22 +52,32 @@ format() { ..addAll(existingSourceDirs.map((dir) => dir.path))); } -@Task('Build Dart snapshot.') +@Task('Build Dart script snapshot.') snapshot() { _ensureBuild(); Dart.run('bin/sass.dart', vmArgs: ['--snapshot=build/sass.dart.snapshot']); } +@Task('Build Dart application snapshot.') +appSnapshot() { + _ensureBuild(); + Dart.run('bin/sass.dart', + arguments: ['tool/app-snapshot-input.scss'], + vmArgs: [ + '--snapshot=build/sass.dart.app.snapshot', + '--snapshot-kind=app-jit' + ], + quiet: true); +} + @Task('Build standalone packages for all OSes.') -@Depends(snapshot) +@Depends(snapshot, appSnapshot) package() async { var client = new http.Client(); - await _buildPackage(client, "linux", "x64"); - await _buildPackage(client, "linux", "ia32"); - await _buildPackage(client, "macos", "x64"); - await _buildPackage(client, "macos", "ia32"); - await _buildPackage(client, "windows", "x64"); - await _buildPackage(client, "windows", "ia32"); + await Future.wait(["linux", "macos", "windows"].expand((os) => [ + _buildPackage(client, os, x64: true), + _buildPackage(client, os, x64: false) + ])); client.close(); } @@ -245,10 +258,12 @@ void _ensureBuild() { new Directory('build').createSync(recursive: true); } -/// Builds a standalone Sass package for the given [os] and [architecture]. +/// Builds a standalone Sass package for the given [os] and architecture. /// /// The [client] is used to download the corresponding Dart SDK. -Future _buildPackage(http.Client client, String os, String architecture) async { +Future _buildPackage(http.Client client, String os, {bool x64: true}) async { + var architecture = x64 ? "x64" : "ia32"; + // TODO: Compile a single executable that embeds the Dart VM and the snapshot // when dart-lang/sdk#27596 is fixed. var channel = _isDevSdk ? "dev" : "stable"; @@ -267,13 +282,20 @@ Future _buildPackage(http.Client client, String os, String architecture) async { ? file.name.endsWith("/bin/dart.exe") : file.name.endsWith("/bin/dart")); var executable = DelegatingList.typed(dartExecutable.content as List); + + // Use the app snapshot when packaging for the current operating system. + // + // TODO: Use an app snapshot everywhere when dart-lang/sdk#28617 is fixed. + var snapshot = os == Platform.operatingSystem && x64 == _is64Bit + ? "build/sass.dart.app.snapshot" + : "build/sass.dart.snapshot"; + var archive = new Archive() ..addFile(_fileFromBytes( "dart-sass/src/dart${os == 'windows' ? '.exe' : ''}", executable, executable: true)) ..addFile(_file("dart-sass/src/DART_LICENSE", p.join(_sdkDir, 'LICENSE'))) - ..addFile( - _file("dart-sass/src/sass.dart.snapshot", "build/sass.dart.snapshot")) + ..addFile(_file("dart-sass/src/sass.dart.snapshot", snapshot)) ..addFile(_file("dart-sass/src/SASS_LICENSE", "LICENSE")) ..addFile(_fileFromString( "dart-sass/dart-sass${os == 'windows' ? '.bat' : ''}",