-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.dart
executable file
·184 lines (167 loc) · 5.47 KB
/
run.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env dart
import 'dart:io';
import 'package:path/path.dart' as p;
var rootDir;
void main(List<String> args) {
rootDir = Directory.current.path;
switch (args[0]) {
case "setup":
setup();
break;
case "build":
build();
break;
case "submit":
submit();
break;
}
}
Future<void> setup() async {
await setupFFmpeg();
await setupWhisper();
await flutter(["doctor"]);
}
Future<void> setupFFmpeg() async {
switch (Platform.operatingSystem) {
case "windows":
if (File("exe/ffmpeg.exe").existsSync()) {
print("Skip download ffmpeg.");
return;
}
print("Download ffmpeg...");
await wget("https://github.com/GyanD/codexffmpeg/releases/download/6.0/ffmpeg-6.0-essentials_build.7z", "exe/ffmpeg.7z");
await sh(["7z", "x", "-oexe", "exe/ffmpeg.7z"]);
await sh(["powershell", "Copy-Item", "exe/ffmpeg-*/bin/ffmpeg.exe", "exe/"]);
await sh(["powershell", "Remove-Item", "-Recurse", "exe/ffmpeg-*"]);
await sh(["powershell", "Remove-Item", "exe/ffmpeg.7z"]);
break;
case "macos":
if (File("exe/ffmpeg").existsSync()) {
print("Skip download ffmpeg.");
return;
}
print("Download ffmpeg...");
await wget("https://evermeet.cx/ffmpeg/ffmpeg-6.0.7z", "exe/ffmpeg.7z");
await sh(["7z", "x", "-oexe", "exe/ffmpeg.7z"]);
await sh(["rm", "exe/ffmpeg.7z"]);
break;
}
}
Future<void> setupWhisper() async {
switch (Platform.operatingSystem) {
case "windows":
if (File("exe/whispercpp.exe").existsSync()) {
print("Skip download whisper.cpp.");
return;
}
print("Download whisper.cpp...");
await wget("https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.1/whisper-bin-x64.zip", "exe/whisper.zip");
await sh(["7z", "x", "-oexe", "exe/whisper.zip", "main.exe", "whisper.dll"]);
await sh(["powershell", "Rename-Item", "exe/main.exe", "whispercpp.exe"]);
await sh(["powershell", "Remove-Item", "exe/whisper.zip"]);
break;
case "macos":
if (File("exe/whispercpp").existsSync()) {
print("Skip download whisper.cpp.");
return;
}
print("Build whisper.cpp...");
Directory.current = "whisper.cpp";
await sh(["make", "clean", "main"]);
await sh(["cp", "main", "main.arm64"]);
await sh(["arch", "-x86_64", "make", "clean", "main"]);
await sh(["cp", "main", "main.x86_64"]);
await sh(["lipo", "-create", "-output", "../exe/whispercpp", "main.arm64", "main.x86_64"]);
await sh(["rm", "main.arm64", "main.x86_64"]);
await sh(["make", "clean"]);
break;
}
}
Future<void> build() async {
switch (Platform.operatingSystem) {
case "windows":
await flutter(["build", "windows", "--release"]);
Directory.current = "build/windows/runner";
if (File(appZipName()).existsSync()) {
await sh(["powershell", "Remove-Item", appZipName()]);
}
if (Directory("whispercppapp").existsSync()) {
await sh(["powershell", "Remove-Item", "-Recurse", "whispercppapp"]);
}
await sh(["powershell", "Copy-Item", "-Recurse", "Release", "whispercppapp"]);
await sh(["powershell", "Compress-Archive", "-Path", "whispercppapp", "-DestinationPath", appZipName()]);
break;
case "macos":
await sign_binary("exe/ffmpeg");
await sign_binary("exe/whispercpp");
await flutter(["build", "macos", "--release"]);
Directory.current = "build/macos/Build/Products/Release";
await sh(["rm", "-f", appZipName()]);
await sh(["ditto", "-c", "-k", "--keepParent", "whispercppapp.app", appZipName()]);
break;
}
}
Future<void> submit() async {
switch (Platform.operatingSystem) {
case "windows":
break;
case "macos":
await sh([
"xcrun",
"notarytool",
"submit",
"build/macos/Build/Products/Release/${appZipName()}",
"--apple-id", env("APPLE_DEVELOPER_ID"),
"--password", env("APPLE_DEVELOPER_PASSWORD"),
"--team-id", env("APPLE_DEVELOPER_TEAM_ID"),
"--wait",
]);
break;
}
}
String appVersion() {
return File(p.join(rootDir, "pubspec.yaml"))
.readAsStringSync()
.split("\n")
.firstWhere((line) => line.startsWith("version: "))
.replaceFirst("version: ", "")
.replaceAll("\r", "");
}
String appZipName() {
return "whispercppapp-${Platform.operatingSystem}-${appVersion()}.zip";
}
Future<void> sign_binary(String binary) async {
await sh(["codesign", "-f", "-s", "Developer ID Application: Komuro Sunao (QMQNVXM7VQ)", "--options=runtime", binary]);
}
Future<void> wget(String url, String outfile) async {
switch (Platform.operatingSystem) {
case "windows":
await sh(["powershell", "Invoke-WebRequest", url, "-Outfile", outfile]);
break;
case "macos":
await sh(["wget", "--quiet", "--show-progress", "-O", outfile, url]);
break;
}
}
Future<void> sh(List<String> commands) async {
Process process = await Process.start(commands[0], commands.sublist(1));
stdout.addStream(process.stdout);
stderr.addStream(process.stderr);
int exitCode = await process.exitCode;
if (exitCode != 0) {
throw commands;
}
}
Future<void> flutter(List<String> args) async {
switch (Platform.operatingSystem) {
case "windows":
await sh(["flutter.bat", ...args]);
break;
case "macos":
await sh(["flutter", ...args]);
break;
}
}
String env(String key) {
return Platform.environment[key]!;
}