-
Notifications
You must be signed in to change notification settings - Fork 0
/
checksum.dart
55 lines (46 loc) · 1.55 KB
/
checksum.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'dart:io';
import 'package:crypto/crypto.dart';
import 'package:dvmx/src/app/gen/cli_info.dart';
import 'package:grinder/grinder.dart';
const _osToArchs = {
'macos': ['x64', 'arm64'],
'linux': ['ia32', 'x64', 'arm', 'arm64'],
'windows': ['ia32', 'x64'],
};
void addChecksumTasks() {
final osTasks = _osToArchs.entries.map((entry) {
final os = entry.key;
final archTasks = entry.value.map((arch) {
return GrinderTask(
'pkg-checksum-$os-$arch',
taskFunction: () async => _buildChecksum(os, arch),
description: 'Build $os $arch checksum.',
);
}).toList();
archTasks.forEach(addTask);
return GrinderTask(
'pkg-checksum-$os',
description: 'Build $os checksums.',
depends: archTasks.map((task) => task.name),
);
}).toList();
osTasks.forEach(addTask);
addTask(
GrinderTask(
'pkg-checksum-all',
description: 'Build all checksums.',
depends: osTasks.map((task) => task.name),
),
);
}
Future<void> _buildChecksum(String os, String arch) async {
final version = cliInfo.version;
final executableFileExtension = os == 'windows' ? 'zip' : 'tar.gz';
final executableFileName = 'dvm-$version-$os-$arch.$executableFileExtension';
final executableFile = File('build/$executableFileName');
final bytes = await executableFile.readAsBytes();
final digest = sha256.convert(bytes);
final sha256FileName = 'dvm-$version-$os-$arch.sha256';
final sha256File = File('build/$sha256FileName');
await sha256File.writeAsString('$digest $executableFileName\n');
}