Skip to content

Commit eeb9686

Browse files
committed
setup: use cache and add -f option
1 parent c902fee commit eeb9686

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 1.0.2+2
22

33
- Fix: update archive version to 3.5.1
4+
- Minor change: change cache, .cache -> .dart_tool/.cache
5+
- Minor change: setup script, use cache, add -f flag to force download
46

57
## 1.0.2+1
68

bin/setup_commands.dart

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ abstract class BaseSetupCommand extends Command {
2222
return arch_;
2323
}
2424

25+
bool get force => argResults?.flag("force") ?? false;
2526
String get os => name;
2627

2728
Future<void> downloadAndExtract() async {
2829
// Detect dependencies
2930
// Assumed package root
3031
final root = Directory.current.uri;
31-
print('Building with assumed project root in:');
32-
print(root.toFilePath());
32+
print('Building with assumed project root in: ${root.toFilePath()}');
3333

3434
// Assumed package_config.json
3535
final packageConfigFile = File.fromUri(
@@ -64,22 +64,25 @@ abstract class BaseSetupCommand extends Command {
6464
final version = doc["binary_version"] as String;
6565
final libTarName = "libopencv_dart-$os-$arch.tar.gz";
6666

67-
print('Downloading prebuilt binary...');
68-
String url = "https://github.com/rainyl/opencv_dart/releases/download/v$version/$libTarName";
69-
70-
final cacheTarPath = p.join(opencvRoot.toFilePath(), ".cache", libTarName);
67+
final cacheTarPath = p.join(opencvRoot.toFilePath(), ".dart_tool", ".cache", libTarName);
7168
final saveFile = File(cacheTarPath);
72-
if (!saveFile.parent.existsSync()) saveFile.parent.createSync(recursive: true);
73-
74-
print("Downloading $url");
75-
final request = await HttpClient().getUrl(Uri.parse(url));
76-
final response = await request.close();
77-
if (response.statusCode == 200) {
78-
await response.pipe(saveFile.openWrite());
79-
print("Cached to $cacheTarPath");
69+
70+
if (force || !saveFile.existsSync()) {
71+
if (!saveFile.parent.existsSync()) saveFile.parent.createSync(recursive: true);
72+
73+
String url = "https://github.com/rainyl/opencv_dart/releases/download/v$version/$libTarName";
74+
print("Downloading $url");
75+
final request = await HttpClient().getUrl(Uri.parse(url));
76+
final response = await request.close();
77+
if (response.statusCode == 200) {
78+
await response.pipe(saveFile.openWrite());
79+
print("Cached to $cacheTarPath");
80+
} else {
81+
print("Download Failed with status: ${response.statusCode}");
82+
exit(1);
83+
}
8084
} else {
81-
print("Download Failed with status: ${response.statusCode}");
82-
exit(1);
85+
print("Using cached $cacheTarPath");
8386
}
8487

8588
String extractPath = "";
@@ -132,6 +135,7 @@ class MacOsSetupCommand extends BaseSetupCommand {
132135
allowed: ["x64", "arm64"],
133136
mandatory: true,
134137
);
138+
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
135139
}
136140
}
137141

@@ -144,6 +148,7 @@ class WindowsSetupCommand extends BaseSetupCommand {
144148

145149
WindowsSetupCommand() {
146150
argParser.addOption("arch", abbr: "a", allowed: ["x64"], mandatory: true);
151+
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
147152
}
148153
}
149154

@@ -156,6 +161,7 @@ class LinuxSetupCommand extends BaseSetupCommand {
156161

157162
LinuxSetupCommand() {
158163
argParser.addOption("arch", abbr: "a", allowed: ["x64"], mandatory: true);
164+
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
159165
}
160166
}
161167

@@ -173,6 +179,7 @@ class AndroidSetupCommand extends BaseSetupCommand {
173179
allowed: ["x86_64", "arm64-v8a", "armeabi-v7a"],
174180
mandatory: true,
175181
);
182+
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
176183
}
177184
}
178185

@@ -190,6 +197,7 @@ class IosSetupCommand extends BaseSetupCommand {
190197
allowed: ["x64", "arm64"],
191198
mandatory: true,
192199
);
200+
argParser.addFlag("force", abbr: "f", defaultsTo: false, help: "Force download and extract");
193201
}
194202
}
195203

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ dependencies:
1616
equatable: ^2.0.5
1717
yaml: ^3.1.2
1818
path: ^1.9.0
19-
args: ^2.4.2
19+
args: ^2.5.0
2020
archive: ^3.5.1
2121

2222
dev_dependencies:
2323
ffigen: ^11.0.0
24-
flutter_lints: ^3.0.1
25-
test: ^1.25.2
24+
flutter_lints: ^4.0.0
25+
test: ^1.25.5
2626

2727
topics:
2828
- opencv

0 commit comments

Comments
 (0)