computeChecksum method
Constructs a checksum for a BuildConfig.
This can be used to construct an output directory name specific to the BuildConfig being built with this BuildConfigBuilder. It is therefore assumed the output directory has not been set yet.
Implementation
String computeChecksum() {
if (json.containsKey(_outDirConfigKey) ||
json.containsKey(_outDirSharedConfigKey)) {
// The bundling tools would first calculate the checksum, create an output
// directory and then call [BuildConfigBuilder.setupBuildRunConfig] &
// [LinkConfigBuilder.setupLinkRunConfig].
throw StateError('The checksum should be generated before setting '
'up the run configuration');
}
final hash = sha256
.convert(const JsonEncoder().fuse(const Utf8Encoder()).convert(json))
.toString()
// 256 bit hashes lead to 64 hex character strings.
// To avoid overflowing file paths limits, only use 32.
// Using 16 hex characters would also be unlikely to have collisions.
.substring(0, 32);
return hash;
}