Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
14016523
Commit
14016523
authored
Sep 07, 2017
by
Mikkel Nygaard Ravn
Committed by
GitHub
Sep 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure snapshot rebuild logic takes main path into account (#11924)
parent
39680ebf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
244 additions
and
212 deletions
+244
-212
build.dart
packages/flutter_tools/lib/src/base/build.dart
+65
-69
build_aot.dart
packages/flutter_tools/lib/src/commands/build_aot.dart
+13
-13
build_test.dart
packages/flutter_tools/test/base/build_test.dart
+166
-130
No files found.
packages/flutter_tools/lib/src/base/build.dart
View file @
14016523
...
@@ -7,7 +7,7 @@ import 'dart:convert' show JSON;
...
@@ -7,7 +7,7 @@ import 'dart:convert' show JSON;
import
'package:crypto/crypto.dart'
show
md5
;
import
'package:crypto/crypto.dart'
show
md5
;
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'package:quiver/core.dart'
show
hash
4
;
import
'package:quiver/core.dart'
show
hash
2
;
import
'../artifacts.dart'
;
import
'../artifacts.dart'
;
import
'../build_info.dart'
;
import
'../build_info.dart'
;
...
@@ -21,7 +21,9 @@ GenSnapshot get genSnapshot => context.putIfAbsent(GenSnapshot, () => const GenS
...
@@ -21,7 +21,9 @@ GenSnapshot get genSnapshot => context.putIfAbsent(GenSnapshot, () => const GenS
/// A snapshot build configuration.
/// A snapshot build configuration.
class
SnapshotType
{
class
SnapshotType
{
const
SnapshotType
(
this
.
platform
,
this
.
mode
);
SnapshotType
(
this
.
platform
,
this
.
mode
)
{
assert
(
mode
!=
null
);
}
final
TargetPlatform
platform
;
final
TargetPlatform
platform
;
final
BuildMode
mode
;
final
BuildMode
mode
;
...
@@ -55,84 +57,70 @@ class GenSnapshot {
...
@@ -55,84 +57,70 @@ class GenSnapshot {
}
}
}
}
/// A
collection of checksums for a set of input fil
es.
/// A
fingerprint for a set of build input files and properti
es.
///
///
/// This class can be used during build actions to compute a
checksum
of the
/// This class can be used during build actions to compute a
fingerprint
of the
/// build action inputs, and if unchanged from the previous build, skip the
/// build action inputs, and if unchanged from the previous build, skip the
/// build step. This assumes that build outputs are strictly a product of the
/// build step. This assumes that build outputs are strictly a product of the
///
input file
s.
///
fingerprint input
s.
class
Checksum
{
class
Fingerprint
{
Checksum
.
fromFiles
(
SnapshotType
type
,
this
.
_mainPath
,
Set
<
String
>
inputPaths
)
{
Fingerprint
.
fromBuildInputs
(
Map
<
String
,
String
>
properties
,
Iterable
<
String
>
inputPaths
)
{
final
Iterable
<
File
>
files
=
inputPaths
.
map
(
fs
.
file
);
final
Iterable
<
File
>
files
=
inputPaths
.
map
(
fs
.
file
);
final
Iterable
<
File
>
missingInputs
=
files
.
where
((
File
file
)
=>
!
file
.
existsSync
());
final
Iterable
<
File
>
missingInputs
=
files
.
where
((
File
file
)
=>
!
file
.
existsSync
());
if
(
missingInputs
.
isNotEmpty
)
if
(
missingInputs
.
isNotEmpty
)
throw
new
ArgumentError
(
'Missing input files:
\n
'
+
missingInputs
.
join
(
'
\n
'
));
throw
new
ArgumentError
(
'Missing input files:
\n
'
+
missingInputs
.
join
(
'
\n
'
));
_buildMode
=
type
.
mode
.
toString
();
_targetPlatform
=
type
.
platform
?.
toString
()
??
''
;
_checksums
=
<
String
,
String
>{};
_checksums
=
<
String
,
String
>{};
for
(
File
file
in
files
)
{
for
(
File
file
in
files
)
{
final
List
<
int
>
bytes
=
file
.
readAsBytesSync
();
final
List
<
int
>
bytes
=
file
.
readAsBytesSync
();
_checksums
[
file
.
path
]
=
md5
.
convert
(
bytes
).
toString
();
_checksums
[
file
.
path
]
=
md5
.
convert
(
bytes
).
toString
();
}
}
_properties
=
<
String
,
String
>{}..
addAll
(
properties
);
}
}
/// Creates a
checksum
from serialized JSON.
/// Creates a
Fingerprint
from serialized JSON.
///
///
/// Throws [ArgumentError] in the following cases:
/// Throws [ArgumentError], if there is a version mismatch between the
/// * Version mismatch between the serializing framework and this framework.
/// serializing framework and this framework.
/// * buildMode is unspecified.
Fingerprint
.
fromJson
(
String
json
)
{
/// * targetPlatform is unspecified.
/// * File checksum map is unspecified.
Checksum
.
fromJson
(
String
json
)
{
final
Map
<
String
,
dynamic
>
content
=
JSON
.
decode
(
json
);
final
Map
<
String
,
dynamic
>
content
=
JSON
.
decode
(
json
);
final
String
version
=
content
[
'version'
];
final
String
version
=
content
[
'version'
];
if
(
version
!=
FlutterVersion
.
instance
.
frameworkRevision
)
if
(
version
!=
FlutterVersion
.
instance
.
frameworkRevision
)
throw
new
ArgumentError
(
'Incompatible checksum version:
$version
'
);
throw
new
ArgumentError
(
'Incompatible fingerprint version:
$version
'
);
_checksums
=
content
[
'files'
]
??
<
String
,
String
>{};
_buildMode
=
content
[
'buildMode'
];
_properties
=
content
[
'properties'
]
??
<
String
,
String
>{};
if
(
_buildMode
==
null
||
_buildMode
.
isEmpty
)
throw
new
ArgumentError
(
'Build mode unspecified in checksum JSON'
);
_targetPlatform
=
content
[
'targetPlatform'
];
if
(
_targetPlatform
==
null
)
throw
new
ArgumentError
(
'Target platform unspecified in checksum JSON'
);
_mainPath
=
content
[
'entrypoint'
];
if
(
_mainPath
==
null
)
throw
new
ArgumentError
(
'Entrypoint unspecified in checksum JSON'
);
_checksums
=
content
[
'files'
];
if
(
_checksums
==
null
)
throw
new
ArgumentError
(
'File checksums unspecified in checksum JSON'
);
}
}
String
_mainPath
;
String
_buildMode
;
String
_targetPlatform
;
Map
<
String
,
String
>
_checksums
;
Map
<
String
,
String
>
_checksums
;
Map
<
String
,
String
>
_properties
;
String
toJson
()
=>
JSON
.
encode
(<
String
,
dynamic
>{
String
toJson
()
=>
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
FlutterVersion
.
instance
.
frameworkRevision
,
'version'
:
FlutterVersion
.
instance
.
frameworkRevision
,
'buildMode'
:
_buildMode
,
'properties'
:
_properties
,
'entrypoint'
:
_mainPath
,
'targetPlatform'
:
_targetPlatform
,
'files'
:
_checksums
,
'files'
:
_checksums
,
});
});
@override
@override
bool
operator
==(
dynamic
other
)
{
bool
operator
==(
dynamic
other
)
{
return
other
is
Checksum
&&
if
(
identical
(
other
,
this
))
_buildMode
==
other
.
_buildMode
&&
return
true
;
_targetPlatform
==
other
.
_targetPlatform
&&
if
(
other
.
runtimeType
!=
runtimeType
)
_mainPath
==
other
.
_mainPath
&&
return
false
;
_checksums
.
length
==
other
.
_checksums
.
length
&&
final
Fingerprint
typedOther
=
other
;
_checksums
.
keys
.
every
((
String
key
)
=>
_checksums
[
key
]
==
other
.
_checksums
[
key
]);
return
_equalMaps
(
typedOther
.
_checksums
,
_checksums
)
&&
_equalMaps
(
typedOther
.
_properties
,
_properties
);
}
bool
_equalMaps
(
Map
<
String
,
String
>
a
,
Map
<
String
,
String
>
b
)
{
return
a
.
length
==
b
.
length
&&
a
.
keys
.
every
((
String
key
)
=>
a
[
key
]
==
b
[
key
]);
}
}
@override
@override
int
get
hashCode
=>
hash4
(
_buildMode
,
_targetPlatform
,
_mainPath
,
_checksums
);
// Ignore map entries here to avoid becoming inconsistent with equals
// due to differences in map entry order.
int
get
hashCode
=>
hash2
(
_properties
.
length
,
_checksums
.
length
);
}
}
final
RegExp
_separatorExpr
=
new
RegExp
(
r'([^\\]) '
);
final
RegExp
_separatorExpr
=
new
RegExp
(
r'([^\\]) '
);
...
@@ -177,14 +165,14 @@ class Snapshotter {
...
@@ -177,14 +165,14 @@ class Snapshotter {
@required
String
depfilePath
,
@required
String
depfilePath
,
@required
String
packagesPath
@required
String
packagesPath
})
async
{
})
async
{
const
SnapshotType
type
=
const
SnapshotType
(
null
,
BuildMode
.
debug
);
final
SnapshotType
type
=
new
SnapshotType
(
null
,
BuildMode
.
debug
);
final
List
<
String
>
args
=
<
String
>[
final
List
<
String
>
args
=
<
String
>[
'--snapshot_kind=script'
,
'--snapshot_kind=script'
,
'--script_snapshot=
$snapshotPath
'
,
'--script_snapshot=
$snapshotPath
'
,
mainPath
,
mainPath
,
];
];
final
String
checksumsPath
=
'
$depfilePath
.checksums
'
;
final
String
fingerprintPath
=
'
$depfilePath
.fingerprint
'
;
final
int
exitCode
=
await
_build
(
final
int
exitCode
=
await
_build
(
snapshotType:
type
,
snapshotType:
type
,
outputSnapshotPath:
snapshotPath
,
outputSnapshotPath:
snapshotPath
,
...
@@ -192,11 +180,11 @@ class Snapshotter {
...
@@ -192,11 +180,11 @@ class Snapshotter {
snapshotArgs:
args
,
snapshotArgs:
args
,
depfilePath:
depfilePath
,
depfilePath:
depfilePath
,
mainPath:
mainPath
,
mainPath:
mainPath
,
checksumsPath:
checksums
Path
,
fingerprintPath:
fingerprint
Path
,
);
);
if
(
exitCode
!=
0
)
if
(
exitCode
!=
0
)
return
exitCode
;
return
exitCode
;
await
_write
Checksum
(
type
,
snapshotPath
,
depfilePath
,
mainPath
,
checksums
Path
);
await
_write
Fingerprint
(
type
,
snapshotPath
,
depfilePath
,
mainPath
,
fingerprint
Path
);
return
exitCode
;
return
exitCode
;
}
}
...
@@ -212,10 +200,10 @@ class Snapshotter {
...
@@ -212,10 +200,10 @@ class Snapshotter {
@required
String
packagesPath
,
@required
String
packagesPath
,
@required
String
depfilePath
,
@required
String
depfilePath
,
@required
String
mainPath
,
@required
String
mainPath
,
@required
String
checksums
Path
,
@required
String
fingerprint
Path
,
})
async
{
})
async
{
if
(!
await
_isBuildRequired
(
snapshotType
,
outputSnapshotPath
,
depfilePath
,
mainPath
,
checksums
Path
))
{
if
(!
await
_isBuildRequired
(
snapshotType
,
outputSnapshotPath
,
depfilePath
,
mainPath
,
fingerprint
Path
))
{
printTrace
(
'Skipping snapshot build.
Checksum
s match.'
);
printTrace
(
'Skipping snapshot build.
Fingerprint
s match.'
);
return
0
;
return
0
;
}
}
...
@@ -229,41 +217,49 @@ class Snapshotter {
...
@@ -229,41 +217,49 @@ class Snapshotter {
if
(
exitCode
!=
0
)
if
(
exitCode
!=
0
)
return
exitCode
;
return
exitCode
;
_write
Checksum
(
snapshotType
,
outputSnapshotPath
,
depfilePath
,
mainPath
,
checksums
Path
);
_write
Fingerprint
(
snapshotType
,
outputSnapshotPath
,
depfilePath
,
mainPath
,
fingerprint
Path
);
return
0
;
return
0
;
}
}
Future
<
bool
>
_isBuildRequired
(
SnapshotType
type
,
String
outputSnapshotPath
,
String
depfilePath
,
String
mainPath
,
String
checksums
Path
)
async
{
Future
<
bool
>
_isBuildRequired
(
SnapshotType
type
,
String
outputSnapshotPath
,
String
depfilePath
,
String
mainPath
,
String
fingerprint
Path
)
async
{
final
File
checksumFile
=
fs
.
file
(
checksums
Path
);
final
File
fingerprintFile
=
fs
.
file
(
fingerprint
Path
);
final
File
outputSnapshotFile
=
fs
.
file
(
outputSnapshotPath
);
final
File
outputSnapshotFile
=
fs
.
file
(
outputSnapshotPath
);
final
File
depfile
=
fs
.
file
(
depfilePath
);
final
File
depfile
=
fs
.
file
(
depfilePath
);
if
(!
outputSnapshotFile
.
existsSync
()
||
!
depfile
.
existsSync
()
||
!
checksum
File
.
existsSync
())
if
(!
outputSnapshotFile
.
existsSync
()
||
!
depfile
.
existsSync
()
||
!
fingerprint
File
.
existsSync
())
return
true
;
return
true
;
try
{
try
{
if
(
checksumFile
.
existsSync
())
{
if
(
fingerprintFile
.
existsSync
())
{
final
Checksum
oldChecksum
=
new
Checksum
.
fromJson
(
await
checksumFile
.
readAsString
());
final
Fingerprint
oldFingerprint
=
new
Fingerprint
.
fromJson
(
await
fingerprintFile
.
readAsString
());
final
Set
<
String
>
checksumPaths
=
await
readDepfile
(
depfilePath
)
final
Set
<
String
>
inputFilePaths
=
await
readDepfile
(
depfilePath
)..
addAll
(<
String
>[
outputSnapshotPath
,
mainPath
]);
..
addAll
(<
String
>[
outputSnapshotPath
,
mainPath
]);
final
Fingerprint
newFingerprint
=
createFingerprint
(
type
,
mainPath
,
inputFilePaths
);
final
Checksum
newChecksum
=
new
Checksum
.
fromFiles
(
type
,
mainPath
,
checksumPaths
);
return
oldFingerprint
!=
newFingerprint
;
return
oldChecksum
!=
newChecksum
;
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
// Log exception and continue, this step is a performance improvement only.
// Log exception and continue, this step is a performance improvement only.
printTrace
(
'Rebuilding snapshot due to
checksum validation
error:
$e
'
);
printTrace
(
'Rebuilding snapshot due to
fingerprint check
error:
$e
'
);
}
}
return
true
;
return
true
;
}
}
Future
<
Null
>
_write
Checksum
(
SnapshotType
type
,
String
outputSnapshotPath
,
String
depfilePath
,
String
mainPath
,
String
checksums
Path
)
async
{
Future
<
Null
>
_write
Fingerprint
(
SnapshotType
type
,
String
outputSnapshotPath
,
String
depfilePath
,
String
mainPath
,
String
fingerprint
Path
)
async
{
try
{
try
{
final
Set
<
String
>
checksum
Paths
=
await
readDepfile
(
depfilePath
)
final
Set
<
String
>
inputFile
Paths
=
await
readDepfile
(
depfilePath
)
..
addAll
(<
String
>[
outputSnapshotPath
,
mainPath
]);
..
addAll
(<
String
>[
outputSnapshotPath
,
mainPath
]);
final
Checksum
checksum
=
new
Checksum
.
fromFiles
(
type
,
mainPath
,
checksum
Paths
);
final
Fingerprint
fingerprint
=
createFingerprint
(
type
,
mainPath
,
inputFile
Paths
);
await
fs
.
file
(
checksumsPath
).
writeAsString
(
checksum
.
toJson
());
await
fs
.
file
(
fingerprintPath
).
writeAsString
(
fingerprint
.
toJson
());
}
catch
(
e
,
s
)
{
}
catch
(
e
,
s
)
{
// Log exception and continue, this step is a performance improvement only.
// Log exception and continue, this step is a performance improvement only.
print
Trace
(
'Error during snapshot checksum output
:
$e
\n
$s
'
);
print
(
'Error during snapshot fingerprinting
:
$e
\n
$s
'
);
}
}
}
}
static
Fingerprint
createFingerprint
(
SnapshotType
type
,
String
mainPath
,
Iterable
<
String
>
inputFilePaths
)
{
final
Map
<
String
,
String
>
properties
=
<
String
,
String
>{
'buildMode'
:
type
.
mode
.
toString
(),
'targetPlatform'
:
type
.
platform
?.
toString
()
??
''
,
'entryPoint'
:
mainPath
,
};
return
new
Fingerprint
.
fromBuildInputs
(
properties
,
inputFilePaths
);
}
}
}
packages/flutter_tools/lib/src/commands/build_aot.dart
View file @
14016523
...
@@ -286,25 +286,25 @@ Future<String> _buildAotSnapshot(
...
@@ -286,25 +286,25 @@ Future<String> _buildAotSnapshot(
genSnapshotCmd
.
add
(
mainPath
);
genSnapshotCmd
.
add
(
mainPath
);
final
SnapshotType
snapshotType
=
new
SnapshotType
(
platform
,
buildMode
);
final
SnapshotType
snapshotType
=
new
SnapshotType
(
platform
,
buildMode
);
final
File
checksumFile
=
fs
.
file
(
'
$dependencies
.checksum
'
);
final
File
fingerprintFile
=
fs
.
file
(
'
$dependencies
.fingerprint
'
);
final
List
<
File
>
checksumFiles
=
<
File
>[
checksum
File
,
fs
.
file
(
dependencies
)]
final
List
<
File
>
fingerprintFiles
=
<
File
>[
fingerprint
File
,
fs
.
file
(
dependencies
)]
..
addAll
(
inputPaths
.
map
(
fs
.
file
))
..
addAll
(
inputPaths
.
map
(
fs
.
file
))
..
addAll
(
outputPaths
.
map
(
fs
.
file
));
..
addAll
(
outputPaths
.
map
(
fs
.
file
));
if
(
checksum
Files
.
every
((
File
file
)
=>
file
.
existsSync
()))
{
if
(
fingerprint
Files
.
every
((
File
file
)
=>
file
.
existsSync
()))
{
try
{
try
{
final
String
json
=
await
checksum
File
.
readAsString
();
final
String
json
=
await
fingerprint
File
.
readAsString
();
final
Checksum
oldChecksum
=
new
Checksum
.
fromJson
(
json
);
final
Fingerprint
oldFingerprint
=
new
Fingerprint
.
fromJson
(
json
);
final
Set
<
String
>
snapshotInputPaths
=
await
readDepfile
(
dependencies
)
final
Set
<
String
>
snapshotInputPaths
=
await
readDepfile
(
dependencies
)
..
add
(
mainPath
)
..
add
(
mainPath
)
..
addAll
(
outputPaths
);
..
addAll
(
outputPaths
);
final
Checksum
newChecksum
=
new
Checksum
.
fromFiles
(
snapshotType
,
mainPath
,
snapshotInputPaths
);
final
Fingerprint
newFingerprint
=
Snapshotter
.
createFingerprint
(
snapshotType
,
mainPath
,
snapshotInputPaths
);
if
(
old
Checksum
==
newChecksum
)
{
if
(
old
Fingerprint
==
newFingerprint
)
{
print
Trace
(
'Skipping AOT snapshot build. Checksums
match.'
);
print
Status
(
'Skipping AOT snapshot build. Fingerprint
match.'
);
return
outputPath
;
return
outputPath
;
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
// Log exception and continue, this step is a performance improvement only.
// Log exception and continue, this step is a performance improvement only.
printTrace
(
'Rebuilding snapshot due to
checksum validation
error:
$e
'
);
printTrace
(
'Rebuilding snapshot due to
fingerprint check
error:
$e
'
);
}
}
}
}
...
@@ -370,16 +370,16 @@ Future<String> _buildAotSnapshot(
...
@@ -370,16 +370,16 @@ Future<String> _buildAotSnapshot(
await
runCheckedAsync
(
linkCommand
);
await
runCheckedAsync
(
linkCommand
);
}
}
// Compute and record
checksums
.
// Compute and record
build fingerprint
.
try
{
try
{
final
Set
<
String
>
snapshotInputPaths
=
await
readDepfile
(
dependencies
)
final
Set
<
String
>
snapshotInputPaths
=
await
readDepfile
(
dependencies
)
..
add
(
mainPath
)
..
add
(
mainPath
)
..
addAll
(
outputPaths
);
..
addAll
(
outputPaths
);
final
Checksum
checksum
=
new
Checksum
.
fromFiles
(
snapshotType
,
mainPath
,
snapshotInputPaths
);
final
Fingerprint
fingerprint
=
Snapshotter
.
createFingerprint
(
snapshotType
,
mainPath
,
snapshotInputPaths
);
await
checksumFile
.
writeAsString
(
checksum
.
toJson
());
await
fingerprintFile
.
writeAsString
(
fingerprint
.
toJson
());
}
catch
(
e
,
s
)
{
}
catch
(
e
,
s
)
{
// Log exception and continue, this step is a performance improvement only.
// Log exception and continue, this step is a performance improvement only.
print
Trace
(
'Error during AOT snapshot checksum output
:
$e
\n
$s
'
);
print
Status
(
'Error during AOT snapshot fingerprinting
:
$e
\n
$s
'
);
}
}
return
outputPath
;
return
outputPath
;
...
...
packages/flutter_tools/test/base/build_test.dart
View file @
14016523
...
@@ -24,14 +24,12 @@ class _FakeGenSnapshot implements GenSnapshot {
...
@@ -24,14 +24,12 @@ class _FakeGenSnapshot implements GenSnapshot {
this
.
succeed
:
true
,
this
.
succeed
:
true
,
this
.
snapshotPath
:
'output.snapshot'
,
this
.
snapshotPath
:
'output.snapshot'
,
this
.
snapshotContent
:
''
,
this
.
snapshotContent
:
''
,
this
.
depfilePath
:
'output.snapshot.d'
,
this
.
depfileContent
:
'output.snapshot.d : main.dart'
,
this
.
depfileContent
:
'output.snapshot.d : main.dart'
,
});
});
final
bool
succeed
;
final
bool
succeed
;
final
String
snapshotPath
;
final
String
snapshotPath
;
final
String
snapshotContent
;
final
String
snapshotContent
;
final
String
depfilePath
;
final
String
depfileContent
;
final
String
depfileContent
;
int
_callCount
=
0
;
int
_callCount
=
0
;
...
@@ -55,7 +53,18 @@ class _FakeGenSnapshot implements GenSnapshot {
...
@@ -55,7 +53,18 @@ class _FakeGenSnapshot implements GenSnapshot {
}
}
void
main
(
)
{
void
main
(
)
{
group
(
'Checksum'
,
()
{
group
(
'SnapshotType'
,
()
{
test
(
'throws, if build mode is null'
,
()
{
expect
(
()
=>
new
SnapshotType
(
TargetPlatform
.
android_x64
,
null
),
throwsA
(
anything
),
);
});
test
(
'does not throw, if target platform is null'
,
()
{
expect
(
new
SnapshotType
(
null
,
BuildMode
.
release
),
isNotNull
);
});
});
group
(
'Fingerprint'
,
()
{
MockFlutterVersion
mockVersion
;
MockFlutterVersion
mockVersion
;
const
String
kVersion
=
'123456abcdef'
;
const
String
kVersion
=
'123456abcdef'
;
...
@@ -64,7 +73,7 @@ void main() {
...
@@ -64,7 +73,7 @@ void main() {
when
(
mockVersion
.
frameworkRevision
).
thenReturn
(
kVersion
);
when
(
mockVersion
.
frameworkRevision
).
thenReturn
(
kVersion
);
});
});
group
(
'from
File
s'
,
()
{
group
(
'from
BuildInput
s'
,
()
{
MemoryFileSystem
fs
;
MemoryFileSystem
fs
;
setUp
(()
{
setUp
(()
{
...
@@ -73,78 +82,69 @@ void main() {
...
@@ -73,78 +82,69 @@ void main() {
testUsingContext
(
'throws if any input file does not exist'
,
()
async
{
testUsingContext
(
'throws if any input file does not exist'
,
()
async
{
await
fs
.
file
(
'a.dart'
).
create
();
await
fs
.
file
(
'a.dart'
).
create
();
const
SnapshotType
snapshotType
=
const
SnapshotType
(
TargetPlatform
.
ios
,
BuildMode
.
debug
);
expect
(
expect
(
()
=>
new
Checksum
.
fromFiles
(
snapshotType
,
'a.dart'
,
<
String
>[
'a.dart'
,
'b.dart'
].
toSet
()),
()
=>
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{},
<
String
>[
'a.dart'
,
'b.dart'
]),
throwsA
(
anything
),
throwsArgumentError
,
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
});
testUsingContext
(
'throws if any build mode is null'
,
()
async
{
await
fs
.
file
(
'a.dart'
).
create
();
const
SnapshotType
snapshotType
=
const
SnapshotType
(
TargetPlatform
.
ios
,
null
);
expect
(
()
=>
new
Checksum
.
fromFiles
(
snapshotType
,
'a.dart'
,
<
String
>[
'a.dart'
,
'b.dart'
].
toSet
()),
throwsA
(
anything
),
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
});
testUsingContext
(
'does not throw if any target platform is null'
,
()
async
{
await
fs
.
file
(
'a.dart'
).
create
();
const
SnapshotType
snapshotType
=
const
SnapshotType
(
null
,
BuildMode
.
debug
);
expect
(
new
Checksum
.
fromFiles
(
snapshotType
,
'a.dart'
,
<
String
>[
'a.dart'
].
toSet
()),
isNotNull
,
);
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
});
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
});
testUsingContext
(
'populates checksums for valid files'
,
()
async
{
testUsingContext
(
'populates checksums for valid files'
,
()
async
{
await
fs
.
file
(
'a.dart'
).
writeAsString
(
'This is a'
);
await
fs
.
file
(
'a.dart'
).
writeAsString
(
'This is a'
);
await
fs
.
file
(
'b.dart'
).
writeAsString
(
'This is b'
);
await
fs
.
file
(
'b.dart'
).
writeAsString
(
'This is b'
);
const
SnapshotType
snapshotType
=
const
SnapshotType
(
TargetPlatform
.
ios
,
BuildMode
.
debug
);
final
Fingerprint
fingerprint
=
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{},
<
String
>[
'a.dart'
,
'b.dart'
]);
final
Checksum
checksum
=
new
Checksum
.
fromFiles
(
snapshotType
,
'a.dart'
,
<
String
>[
'a.dart'
,
'b.dart'
].
toSet
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
checksum
.
toJson
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
fingerprint
.
toJson
());
expect
(
json
,
hasLength
(
5
));
expect
(
json
[
'version'
],
mockVersion
.
frameworkRevision
);
expect
(
json
[
'buildMode'
],
BuildMode
.
debug
.
toString
());
expect
(
json
[
'targetPlatform'
],
TargetPlatform
.
ios
.
toString
());
expect
(
json
[
'entrypoint'
],
'a.dart'
);
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
][
'a.dart'
],
'8a21a15fad560b799f6731d436c1b698'
);
expect
(
json
[
'files'
][
'a.dart'
],
'8a21a15fad560b799f6731d436c1b698'
);
expect
(
json
[
'files'
][
'b.dart'
],
'6f144e08b58cd0925328610fad7ac07c'
);
expect
(
json
[
'files'
][
'b.dart'
],
'6f144e08b58cd0925328610fad7ac07c'
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
});
FileSystem:
()
=>
fs
,
FlutterVersion:
()
=>
mockVersion
,
testUsingContext
(
'includes framework version'
,
()
{
});
final
Fingerprint
fingerprint
=
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{},
<
String
>[]);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
fingerprint
.
toJson
());
expect
(
json
[
'version'
],
mockVersion
.
frameworkRevision
);
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
});
testUsingContext
(
'includes provided properties'
,
()
{
final
Fingerprint
fingerprint
=
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{
'a'
:
'A'
,
'b'
:
'B'
},
<
String
>[]);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
fingerprint
.
toJson
());
expect
(
json
[
'properties'
],
hasLength
(
2
));
expect
(
json
[
'properties'
][
'a'
],
'A'
);
expect
(
json
[
'properties'
][
'b'
],
'B'
);
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
});
});
});
group
(
'fromJson'
,
()
{
group
(
'fromJson'
,
()
{
testUsingContext
(
'throws if JSON is invalid'
,
()
async
{
testUsingContext
(
'throws if JSON is invalid'
,
()
async
{
expect
(()
=>
new
Checksum
.
fromJson
(
'<xml></xml>'
),
throwsA
(
anything
));
expect
(()
=>
new
Fingerprint
.
fromJson
(
'<xml></xml>'
),
throwsA
(
anything
));
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
testUsingContext
(
'
populates checksums for
valid JSON'
,
()
async
{
testUsingContext
(
'
creates fingerprint from
valid JSON'
,
()
async
{
final
String
json
=
JSON
.
encode
(<
String
,
dynamic
>{
final
String
json
=
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
kVersion
,
'version'
:
kVersion
,
'properties'
:
<
String
,
String
>{
'buildMode'
:
BuildMode
.
release
.
toString
(),
'buildMode'
:
BuildMode
.
release
.
toString
(),
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'entrypoint'
:
'a.dart'
,
'entryPoint'
:
'a.dart'
,
},
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
},
},
});
});
final
Checksum
checksum
=
new
Checksum
.
fromJson
(
json
);
final
Fingerprint
fingerprint
=
new
Fingerprint
.
fromJson
(
json
);
final
Map
<
String
,
dynamic
>
content
=
JSON
.
decode
(
fingerprint
.
toJson
());
final
Map
<
String
,
dynamic
>
content
=
JSON
.
decode
(
checksum
.
toJson
());
expect
(
content
,
hasLength
(
3
));
expect
(
content
,
hasLength
(
5
));
expect
(
content
[
'version'
],
mockVersion
.
frameworkRevision
);
expect
(
content
[
'version'
],
mockVersion
.
frameworkRevision
);
expect
(
content
[
'buildMode'
],
BuildMode
.
release
.
toString
());
expect
(
content
[
'properties'
],
hasLength
(
3
));
expect
(
content
[
'targetPlatform'
],
TargetPlatform
.
ios
.
toString
());
expect
(
content
[
'properties'
][
'buildMode'
],
BuildMode
.
release
.
toString
());
expect
(
content
[
'entrypoint'
],
'a.dart'
);
expect
(
content
[
'properties'
][
'targetPlatform'
],
TargetPlatform
.
ios
.
toString
());
expect
(
content
[
'properties'
][
'entryPoint'
],
'a.dart'
);
expect
(
content
[
'files'
],
hasLength
(
2
));
expect
(
content
[
'files'
][
'a.dart'
],
'8a21a15fad560b799f6731d436c1b698'
);
expect
(
content
[
'files'
][
'a.dart'
],
'8a21a15fad560b799f6731d436c1b698'
);
expect
(
content
[
'files'
][
'b.dart'
],
'6f144e08b58cd0925328610fad7ac07c'
);
expect
(
content
[
'files'
][
'b.dart'
],
'6f144e08b58cd0925328610fad7ac07c'
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
...
@@ -154,81 +154,56 @@ void main() {
...
@@ -154,81 +154,56 @@ void main() {
testUsingContext
(
'throws ArgumentError for unknown versions'
,
()
async
{
testUsingContext
(
'throws ArgumentError for unknown versions'
,
()
async
{
final
String
json
=
JSON
.
encode
(<
String
,
dynamic
>{
final
String
json
=
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
'bad'
,
'version'
:
'bad'
,
'buildMode'
:
BuildMode
.
release
.
toString
(),
'properties'
:<
String
,
String
>{},
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'files'
:<
String
,
String
>{},
'entrypoint'
:
'a.dart'
,
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
},
});
});
expect
(()
=>
new
Checksum
.
fromJson
(
json
),
throwsArgumentError
);
expect
(()
=>
new
Fingerprint
.
fromJson
(
json
),
throwsArgumentError
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
});
group
(
'operator =='
,
()
{
testUsingContext
(
'throws ArgumentError if version is not present'
,
()
async
{
testUsingContext
(
'reports not equal if build modes do not match'
,
()
async
{
final
String
json
=
JSON
.
encode
(<
String
,
dynamic
>{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
'properties'
:<
String
,
String
>{},
'version'
:
kVersion
,
'files'
:<
String
,
String
>{},
'buildMode'
:
BuildMode
.
debug
.
toString
(),
});
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
expect
(()
=>
new
Fingerprint
.
fromJson
(
json
),
throwsArgumentError
);
'entrypoint'
:
'a.dart'
,
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
},
};
final
Map
<
String
,
dynamic
>
b
=
new
Map
<
String
,
dynamic
>.
from
(
a
);
b
[
'buildMode'
]
=
BuildMode
.
release
.
toString
();
expect
(
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Checksum
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
testUsingContext
(
'
reports not equal if target platforms do not match
'
,
()
async
{
testUsingContext
(
'
treats missing properties and files entries as if empty
'
,
()
async
{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
final
String
json
=
JSON
.
encode
(
<
String
,
dynamic
>{
'version'
:
kVersion
,
'version'
:
kVersion
,
'buildMode'
:
BuildMode
.
debug
.
toString
(),
});
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
expect
(
new
Fingerprint
.
fromJson
(
json
),
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{},
<
String
>[]));
'entrypoint'
:
'a.dart'
,
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
},
};
final
Map
<
String
,
dynamic
>
b
=
new
Map
<
String
,
dynamic
>.
from
(
a
);
b
[
'targetPlatform'
]
=
TargetPlatform
.
android_arm
.
toString
();
expect
(
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Checksum
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
});
testUsingContext
(
'reports not equal if entrypoints do not match'
,
()
async
{
group
(
'operator =='
,
()
{
testUsingContext
(
'reports not equal if properties do not match'
,
()
async
{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
'version'
:
kVersion
,
'version'
:
kVersion
,
'properties'
:
<
String
,
String
>{
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'entrypoint'
:
'a.dart'
,
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
},
},
'files'
:
<
String
,
dynamic
>{},
};
};
final
Map
<
String
,
dynamic
>
b
=
new
Map
<
String
,
dynamic
>.
from
(
a
);
final
Map
<
String
,
dynamic
>
b
=
new
Map
<
String
,
dynamic
>.
from
(
a
);
b
[
'entrypoint'
]
=
'b.dart'
;
b
[
'properties'
]
=
<
String
,
String
>{
expect
(
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Checksum
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
'buildMode'
:
BuildMode
.
release
.
toString
(),
};
expect
(
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
testUsingContext
(
'reports not equal if checksums do not match'
,
()
async
{
testUsingContext
(
'reports not equal if
file
checksums do not match'
,
()
async
{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
'version'
:
kVersion
,
'version'
:
kVersion
,
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'properties'
:
<
String
,
String
>{},
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'entrypoint'
:
'a.dart'
,
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
...
@@ -239,17 +214,15 @@ void main() {
...
@@ -239,17 +214,15 @@ void main() {
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07d'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07d'
,
};
};
expect
(
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Checksum
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
expect
(
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
testUsingContext
(
'reports not equal if
key
s do not match'
,
()
async
{
testUsingContext
(
'reports not equal if
file path
s do not match'
,
()
async
{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
'version'
:
kVersion
,
'version'
:
kVersion
,
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'properties'
:
<
String
,
String
>{},
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'entrypoint'
:
'a.dart'
,
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
...
@@ -260,27 +233,40 @@ void main() {
...
@@ -260,27 +233,40 @@ void main() {
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'c.dart'
:
'6f144e08b58cd0925328610fad7ac07d'
,
'c.dart'
:
'6f144e08b58cd0925328610fad7ac07d'
,
};
};
expect
(
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Checksum
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
expect
(
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
b
)),
isFalse
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
testUsingContext
(
'reports equal if
all
checksums match'
,
()
async
{
testUsingContext
(
'reports equal if
properties and file
checksums match'
,
()
async
{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
final
Map
<
String
,
dynamic
>
a
=
<
String
,
dynamic
>{
'version'
:
kVersion
,
'version'
:
kVersion
,
'properties'
:
<
String
,
String
>{
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'targetPlatform'
:
TargetPlatform
.
ios
.
toString
(),
'entrypoint'
:
'a.dart'
,
'entryPoint'
:
'a.dart'
,
},
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'a.dart'
:
'8a21a15fad560b799f6731d436c1b698'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
'b.dart'
:
'6f144e08b58cd0925328610fad7ac07c'
,
},
},
};
};
expect
(
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Checksum
.
fromJson
(
JSON
.
encode
(
a
)),
isTrue
);
expect
(
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
a
))
==
new
Fingerprint
.
fromJson
(
JSON
.
encode
(
a
)),
isTrue
);
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
});
});
group
(
'hashCode'
,
()
{
testUsingContext
(
'is consistent with equals, even if map entries are reordered'
,
()
async
{
final
Fingerprint
a
=
new
Fingerprint
.
fromJson
(
'{"version":"
$kVersion
","properties":{"a":"A","b":"B"},"files":{}}'
);
final
Fingerprint
b
=
new
Fingerprint
.
fromJson
(
'{"version":"
$kVersion
","properties":{"b":"B","a":"A"},"files":{}}'
);
expect
(
a
,
b
);
expect
(
a
.
hashCode
,
b
.
hashCode
);
},
overrides:
<
Type
,
Generator
>{
FlutterVersion:
()
=>
mockVersion
,
});
});
});
});
group
(
'readDepfile'
,
()
{
group
(
'readDepfile'
,
()
{
...
@@ -351,7 +337,7 @@ void main() {
...
@@ -351,7 +337,7 @@ void main() {
expect
(
genSnapshot
.
callCount
,
1
);
expect
(
genSnapshot
.
callCount
,
1
);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
checksums
'
).
readAsString
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
fingerprint
'
).
readAsString
());
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
...
@@ -365,7 +351,7 @@ void main() {
...
@@ -365,7 +351,7 @@ void main() {
await
fs
.
file
(
'main.dart'
).
writeAsString
(
'void main() {}'
);
await
fs
.
file
(
'main.dart'
).
writeAsString
(
'void main() {}'
);
await
fs
.
file
(
'output.snapshot'
).
create
();
await
fs
.
file
(
'output.snapshot'
).
create
();
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d.
checksums
'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
await
fs
.
file
(
'output.snapshot.d.
fingerprint
'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
'
$kVersion
'
,
'version'
:
'
$kVersion
'
,
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
...
@@ -382,7 +368,7 @@ void main() {
...
@@ -382,7 +368,7 @@ void main() {
expect
(
genSnapshot
.
callCount
,
1
);
expect
(
genSnapshot
.
callCount
,
1
);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
checksums
'
).
readAsString
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
fingerprint
'
).
readAsString
());
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
...
@@ -395,9 +381,13 @@ void main() {
...
@@ -395,9 +381,13 @@ void main() {
testUsingContext
(
'builds snapshot and checksums when checksums match but previous snapshot not present'
,
()
async
{
testUsingContext
(
'builds snapshot and checksums when checksums match but previous snapshot not present'
,
()
async
{
await
fs
.
file
(
'main.dart'
).
writeAsString
(
'void main() {}'
);
await
fs
.
file
(
'main.dart'
).
writeAsString
(
'void main() {}'
);
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d.
checksums
'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
await
fs
.
file
(
'output.snapshot.d.
fingerprint
'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
'
$kVersion
'
,
'version'
:
'
$kVersion
'
,
'properties'
:
<
String
,
String
>{
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'targetPlatform'
:
''
,
'entryPoint'
:
'main.dart'
,
},
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'main.dart'
:
'27f5ebf0f8c559b2af9419d190299a5e'
,
'main.dart'
:
'27f5ebf0f8c559b2af9419d190299a5e'
,
'output.snapshot'
:
'd41d8cd98f00b204e9800998ecf8427e'
,
'output.snapshot'
:
'd41d8cd98f00b204e9800998ecf8427e'
,
...
@@ -412,7 +402,7 @@ void main() {
...
@@ -412,7 +402,7 @@ void main() {
expect
(
genSnapshot
.
callCount
,
1
);
expect
(
genSnapshot
.
callCount
,
1
);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
checksums
'
).
readAsString
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
fingerprint
'
).
readAsString
());
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
...
@@ -422,10 +412,9 @@ void main() {
...
@@ -422,10 +412,9 @@ void main() {
GenSnapshot:
()
=>
genSnapshot
,
GenSnapshot:
()
=>
genSnapshot
,
});
});
testUsingContext
(
'builds snapshot and
checksums when main entry point changes
'
,
()
async
{
testUsingContext
(
'builds snapshot and
fingerprint when main entry point changes to other dependency
'
,
()
async
{
final
_FakeGenSnapshot
genSnapshot
=
new
_FakeGenSnapshot
(
final
_FakeGenSnapshot
genSnapshot
=
new
_FakeGenSnapshot
(
snapshotPath:
'output.snapshot'
,
snapshotPath:
'output.snapshot'
,
depfilePath:
'output.snapshot.d'
,
depfileContent:
'output.snapshot : main.dart other.dart'
,
depfileContent:
'output.snapshot : main.dart other.dart'
,
);
);
context
.
setVariable
(
GenSnapshot
,
genSnapshot
);
context
.
setVariable
(
GenSnapshot
,
genSnapshot
);
...
@@ -434,10 +423,13 @@ void main() {
...
@@ -434,10 +423,13 @@ void main() {
await
fs
.
file
(
'other.dart'
).
writeAsString
(
'import "main.dart";
\n
void main() {}'
);
await
fs
.
file
(
'other.dart'
).
writeAsString
(
'import "main.dart";
\n
void main() {}'
);
await
fs
.
file
(
'output.snapshot'
).
create
();
await
fs
.
file
(
'output.snapshot'
).
create
();
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d.checksums'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
await
fs
.
file
(
'output.snapshot.d.fingerprint'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
'
$kVersion
'
,
'version'
:
kVersion
,
'properties'
:
<
String
,
String
>{
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'targetPlatform'
:
''
,
'targetPlatform'
:
''
,
'entryPoint'
:
'main.dart'
,
},
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'main.dart'
:
'bc096b33f14dde5e0ffaf93a1d03395c'
,
'main.dart'
:
'bc096b33f14dde5e0ffaf93a1d03395c'
,
'other.dart'
:
'e0c35f083f0ad76b2d87100ec678b516'
,
'other.dart'
:
'e0c35f083f0ad76b2d87100ec678b516'
,
...
@@ -452,7 +444,8 @@ void main() {
...
@@ -452,7 +444,8 @@ void main() {
);
);
expect
(
genSnapshot
.
callCount
,
1
);
expect
(
genSnapshot
.
callCount
,
1
);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.checksums'
).
readAsString
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.fingerprint'
).
readAsString
());
expect
(
json
[
'properties'
][
'entryPoint'
],
'other.dart'
);
expect
(
json
[
'files'
],
hasLength
(
3
));
expect
(
json
[
'files'
],
hasLength
(
3
));
expect
(
json
[
'files'
][
'main.dart'
],
'bc096b33f14dde5e0ffaf93a1d03395c'
);
expect
(
json
[
'files'
][
'main.dart'
],
'bc096b33f14dde5e0ffaf93a1d03395c'
);
expect
(
json
[
'files'
][
'other.dart'
],
'e0c35f083f0ad76b2d87100ec678b516'
);
expect
(
json
[
'files'
][
'other.dart'
],
'e0c35f083f0ad76b2d87100ec678b516'
);
...
@@ -462,15 +455,17 @@ void main() {
...
@@ -462,15 +455,17 @@ void main() {
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
});
});
testUsingContext
(
'skips snapshot when
checksum
s match and previous snapshot is present'
,
()
async
{
testUsingContext
(
'skips snapshot when
fingerprint
s match and previous snapshot is present'
,
()
async
{
await
fs
.
file
(
'main.dart'
).
writeAsString
(
'void main() {}'
);
await
fs
.
file
(
'main.dart'
).
writeAsString
(
'void main() {}'
);
await
fs
.
file
(
'output.snapshot'
).
create
();
await
fs
.
file
(
'output.snapshot'
).
create
();
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d'
).
writeAsString
(
'output.snapshot : main.dart'
);
await
fs
.
file
(
'output.snapshot.d.checksums'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
await
fs
.
file
(
'output.snapshot.d.fingerprint'
).
writeAsString
(
JSON
.
encode
(<
String
,
dynamic
>{
'version'
:
'
$kVersion
'
,
'version'
:
kVersion
,
'properties'
:
<
String
,
String
>{
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'buildMode'
:
BuildMode
.
debug
.
toString
(),
'targetPlatform'
:
''
,
'targetPlatform'
:
''
,
'entrypoint'
:
'main.dart'
,
'entryPoint'
:
'main.dart'
,
},
'files'
:
<
String
,
dynamic
>{
'files'
:
<
String
,
dynamic
>{
'main.dart'
:
'27f5ebf0f8c559b2af9419d190299a5e'
,
'main.dart'
:
'27f5ebf0f8c559b2af9419d190299a5e'
,
'output.snapshot'
:
'd41d8cd98f00b204e9800998ecf8427e'
,
'output.snapshot'
:
'd41d8cd98f00b204e9800998ecf8427e'
,
...
@@ -485,7 +480,7 @@ void main() {
...
@@ -485,7 +480,7 @@ void main() {
expect
(
genSnapshot
.
callCount
,
0
);
expect
(
genSnapshot
.
callCount
,
0
);
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
checksums
'
).
readAsString
());
final
Map
<
String
,
dynamic
>
json
=
JSON
.
decode
(
await
fs
.
file
(
'output.snapshot.d.
fingerprint
'
).
readAsString
());
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
],
hasLength
(
2
));
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'main.dart'
],
'27f5ebf0f8c559b2af9419d190299a5e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
expect
(
json
[
'files'
][
'output.snapshot'
],
'd41d8cd98f00b204e9800998ecf8427e'
);
...
@@ -494,5 +489,46 @@ void main() {
...
@@ -494,5 +489,46 @@ void main() {
FlutterVersion:
()
=>
mockVersion
,
FlutterVersion:
()
=>
mockVersion
,
GenSnapshot:
()
=>
genSnapshot
,
GenSnapshot:
()
=>
genSnapshot
,
});
});
group
(
'createFingerprint'
,
()
{
test
(
'creates fingerprint with target platform'
,
()
{
final
Fingerprint
fingerprint
=
Snapshotter
.
createFingerprint
(
new
SnapshotType
(
TargetPlatform
.
android_x64
,
BuildMode
.
release
),
'a.dart'
,
<
String
>[],
);
expect
(
fingerprint
,
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{
'buildMode'
:
'BuildMode.release'
,
'targetPlatform'
:
'TargetPlatform.android_x64'
,
'entryPoint'
:
'a.dart'
,
},
<
String
>[]));
});
test
(
'creates fingerprint without target platform'
,
()
{
final
Fingerprint
fingerprint
=
Snapshotter
.
createFingerprint
(
new
SnapshotType
(
null
,
BuildMode
.
release
),
'a.dart'
,
<
String
>[],
);
expect
(
fingerprint
,
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{
'buildMode'
:
'BuildMode.release'
,
'targetPlatform'
:
''
,
'entryPoint'
:
'a.dart'
,
},
<
String
>[]));
});
testUsingContext
(
'creates fingerprint with file checksums'
,
()
async
{
await
fs
.
file
(
'a.dart'
).
create
();
await
fs
.
file
(
'b.dart'
).
create
();
final
Fingerprint
fingerprint
=
Snapshotter
.
createFingerprint
(
new
SnapshotType
(
TargetPlatform
.
android_x64
,
BuildMode
.
release
),
'a.dart'
,
<
String
>[
'a.dart'
,
'b.dart'
],
);
expect
(
fingerprint
,
new
Fingerprint
.
fromBuildInputs
(<
String
,
String
>{
'buildMode'
:
'BuildMode.release'
,
'targetPlatform'
:
'TargetPlatform.android_x64'
,
'entryPoint'
:
'a.dart'
,
},
<
String
>[
'a.dart'
,
'b.dart'
]));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
});
});
});
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment