3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'dart:async' ;
6
+ import 'dart:convert' ;
7
+ import 'dart:io' ;
6
8
import 'dart:isolate' ;
7
9
8
10
/// State for the whole build process.
@@ -21,6 +23,12 @@ class BuildProcessState {
21
23
int ? get isolateExitCode => _state['isolateExitCode' ] as int ? ;
22
24
set isolateExitCode (int ? value) => _state['isolateExitCode' ] = value;
23
25
26
+ /// Whether outputs are from a previous build script.
27
+ bool get outputsAreFromStaleBuildScript =>
28
+ _state['outputsAreFromStaleBuildScript' ] as bool ? ?? false ;
29
+ set outputsAreFromStaleBuildScript (bool value) =>
30
+ _state['outputsAreFromStaleBuildScript' ] = value;
31
+
24
32
/// For `buildLog` , the log mode.
25
33
BuildLogMode get buildLogMode => BuildLogMode .values.singleWhere (
26
34
(mode) => mode.name == _state['buildLogMode' ],
@@ -55,31 +63,33 @@ class BuildProcessState {
55
63
_beforeSends.add (function);
56
64
}
57
65
58
- /// Sends `this` to [sendPort] .
59
- Future <void > send (SendPort ? sendPort) async {
66
+ void write () async {
60
67
for (final beforeSend in _beforeSends) {
61
68
beforeSend ();
62
69
}
63
- sendPort? .send (_state);
70
+ File (
71
+ '.dart_tool/build/entrypoint/state.json' ,
72
+ ).writeAsStringSync (json.encode (_state));
64
73
}
65
74
66
75
void doAfterReceive (void Function () function) {
67
76
_afterReceives.add (function);
68
77
}
69
78
70
- /// Receives `this` from [sendPort] , by sending a `SendPort` then listening
71
- /// on its corresponding `ReceivePort` .
72
- Future <void > receive (SendPort ? sendPort) async {
73
- if (sendPort == null ) {
74
- _state.clear ();
75
- return ;
76
- }
77
- final receivePort = ReceivePort ();
78
- sendPort.send (receivePort.sendPort);
79
- final received = await receivePort.first;
79
+ void read () async {
80
+ var data = < String , Object ? > {};
81
+ try {
82
+ data =
83
+ json.decode (
84
+ File (
85
+ '.dart_tool/build/entrypoint/state.json' ,
86
+ ).readAsStringSync (),
87
+ )
88
+ as Map <String , Object ?>;
89
+ } catch (_) {}
80
90
_state
81
91
..clear ()
82
- ..addAll (received as Map < String , Object ?> );
92
+ ..addAll (data );
83
93
for (final afterReceive in _afterReceives) {
84
94
afterReceive ();
85
95
}
0 commit comments