Skip to content

Commit 798076d

Browse files
author
John Messerly
committed
make build_sdk more incremental
saves about 3s off a typical rebuild where nothing changed [email protected] Review URL: https://codereview.chromium.org/1327573002 .
1 parent 707b9cc commit 798076d

File tree

3 files changed

+60
-27
lines changed

3 files changed

+60
-27
lines changed

pkg/dev_compiler/lib/src/compiler.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ class BatchCompiler extends AbstractCompiler {
173173
}
174174

175175
if (_jsGen != null) {
176+
// TODO(jmesserly): full incremental support would avoid checking as well,
177+
// however, we'd lose compiler messages in that case.
178+
179+
// Note: analyzer's modification stamp is millisecondsSinceEpoch
180+
int lastModifyTime = unitElements
181+
.map((e) => context.getModificationStamp(e.source))
182+
.reduce(math.max);
183+
var outFile = new File(getOutputPath(library.source.uri));
184+
if (outFile.existsSync() &&
185+
outFile.lastModifiedSync().millisecondsSinceEpoch >= lastModifyTime) {
186+
// Output already up to date.
187+
return;
188+
}
189+
176190
var unit = units.first;
177191
var parts = units.skip(1).toList();
178192
_jsGen.generateLibrary(new LibraryUnit(unit, parts));

pkg/dev_compiler/tool/build_sdk.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,11 @@ set -e
44
cd $( dirname "${BASH_SOURCE[0]}" )/..
55

66
echo "*** Patching SDK"
7-
rm -r tool/generated_sdk || true
87
dart -c tool/patch_sdk.dart tool/input_sdk tool/generated_sdk
98

109
echo "*** Compiling SDK to JavaScript"
11-
if [[ -d lib/runtime/dart ]] ; then
12-
rm -r lib/runtime/dart
13-
fi
1410

15-
# TODO(jmesserly): this builds dart:js, which pulls in dart:core and many others
16-
# transitively. Ideally we could pass them explicitly, though:
17-
# https://github.com/dart-lang/dev_compiler/issues/219
1811
dart -c bin/devc.dart --no-source-maps --arrow-fn-bind-this --sdk-check \
1912
--force-compile -l warning --dart-sdk tool/generated_sdk -o lib/runtime/ \
2013
dart:js dart:mirrors \
2114
> tool/sdk_expected_errors.txt || true
22-
23-
if [[ ! -f lib/runtime/dart/core.js ]] ; then
24-
echo 'core.js not found, assuming build failed.'
25-
echo './tool/build_sdk.sh can be run to reproduce this.'
26-
exit 1
27-
fi

pkg/dev_compiler/tool/patch_sdk.dart

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
library dev_compiler.tool.patch_sdk;
99

1010
import 'dart:io';
11+
import 'dart:math' as math;
1112

1213
import 'package:analyzer/analyzer.dart';
1314
import 'package:analyzer/src/generated/sdk.dart';
@@ -72,32 +73,63 @@ void main(List<String> argv) {
7273

7374
var libraryFile = new File(libraryIn);
7475
if (libraryFile.existsSync()) {
75-
var contents = <String>[];
76-
var paths = <String>[];
76+
var outPaths = <String>[libraryOut];
7777
var libraryContents = libraryFile.readAsStringSync();
78-
paths.add(libraryOut);
79-
contents.add(libraryContents);
78+
79+
int inputModifyTime =
80+
libraryFile.lastModifiedSync().millisecondsSinceEpoch;
81+
var partFiles = <File>[];
8082
for (var part in parseDirectives(libraryContents).directives) {
8183
if (part is PartDirective) {
8284
var partPath = part.uri.stringValue;
83-
paths.add(path.join(path.dirname(libraryOut), partPath));
84-
contents.add(new File(path.join(path.dirname(libraryIn), partPath))
85-
.readAsStringSync());
85+
outPaths.add(path.join(path.dirname(libraryOut), partPath));
86+
87+
var partFile = new File(path.join(path.dirname(libraryIn), partPath));
88+
partFiles.add(partFile);
89+
inputModifyTime = math.max(inputModifyTime,
90+
partFile.lastModifiedSync().millisecondsSinceEpoch);
8691
}
8792
}
8893

8994
// See if we can find a patch file.
9095
var patchPath = path.join(
9196
patchIn, path.basenameWithoutExtension(libraryIn) + '_patch.dart');
9297

93-
if (new File(patchPath).existsSync()) {
94-
var patchContents = new File(patchPath).readAsStringSync();
95-
contents = _patchLibrary(contents, patchContents);
98+
var patchFile = new File(patchPath);
99+
bool patchExists = patchFile.existsSync();
100+
if (patchExists) {
101+
inputModifyTime = math.max(inputModifyTime,
102+
patchFile.lastModifiedSync().millisecondsSinceEpoch);
103+
}
104+
105+
// Compute output paths
106+
outPaths = outPaths
107+
.map((p) => path.join(sdkOut, path.relative(p, from: sdkLibIn)))
108+
.toList();
109+
110+
// Compare output modify time with input modify time.
111+
bool needsUpdate = false;
112+
for (var outPath in outPaths) {
113+
var outFile = new File(outPath);
114+
if (!outFile.existsSync() ||
115+
outFile.lastModifiedSync().millisecondsSinceEpoch <
116+
inputModifyTime) {
117+
needsUpdate = true;
118+
break;
119+
}
96120
}
97-
for (var i = 0; i < paths.length; i++) {
98-
var outPath =
99-
path.join(sdkOut, path.relative(paths[i], from: sdkLibIn));
100-
_writeSync(outPath, contents[i]);
121+
122+
if (needsUpdate) {
123+
var contents = <String>[libraryContents];
124+
contents.addAll(partFiles.map((f) => f.readAsStringSync()));
125+
if (patchExists) {
126+
var patchContents = patchFile.readAsStringSync();
127+
contents = _patchLibrary(contents, patchContents);
128+
}
129+
130+
for (var i = 0; i < outPaths.length; i++) {
131+
_writeSync(outPaths[i], contents[i]);
132+
}
101133
}
102134
}
103135
}

0 commit comments

Comments
 (0)