Skip to content

Commit 82c9b8f

Browse files
committed
[dartcv] support user defines
1 parent cd71fb3 commit 82c9b8f

20 files changed

+510
-194
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A sample command-line application with an entrypoint in `bin/`, library code
2+
in `lib/`, and example unit test in `test/`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
#
9+
# If you want a smaller set of lints you can change this to specify
10+
# 'package:lints/core.yaml'. These are just the most critical lints
11+
# (the recommended set includes the core lints).
12+
# The core lints are also what is used by pub.dev for scoring packages.
13+
14+
include: package:lints/recommended.yaml
15+
16+
# Uncomment the following section to specify additional rules.
17+
18+
# linter:
19+
# rules:
20+
# - camel_case_types
21+
22+
# analyzer:
23+
# exclude:
24+
# - path/to/excluded/files/**
25+
26+
# For more information about the core and recommended set of lints, see
27+
# https://dart.dev/go/core-lints
28+
29+
# For additional information about configuring this file, see
30+
# https://dart.dev/guides/language/analysis-options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:dartcv4/dartcv.dart' as cv;
2+
import 'package:modules_example/modules_example.dart' as modules_example;
3+
4+
void main(List<String> arguments) {
5+
print('Hello world: ${modules_example.calculate()}!');
6+
print("Hello OpenCV: ${cv.openCvVersion()}");
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int calculate() {
2+
return 6 * 7;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: modules_example
2+
description: A sample command-line application.
3+
version: 1.0.0
4+
# repository: https://github.com/my_org/my_repo
5+
publish_to: none
6+
7+
environment:
8+
sdk: ^3.3.0
9+
10+
# Add regular dependencies here.
11+
dependencies:
12+
dartcv4:
13+
path: ../..
14+
# path: ^1.8.0
15+
16+
dev_dependencies:
17+
lints: ^5.0.0
18+
test: ^1.24.0
19+
20+
hooks:
21+
user_defines:
22+
dartcv4:
23+
exclude_modules:
24+
- contrib
25+
- calib3d
26+
- features2d
27+
# - dnn
28+
- highgui
29+
- flann
30+
- objdetect
31+
- photo
32+
- stitching
33+
- video
34+
- videoio
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:modules_example/modules_example.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
test('calculate', () {
6+
expect(calculate(), 42);
7+
});
8+
}

packages/dartcv/hook/build.dart

+28-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// ignore: unused_import
77
import 'dart:io';
88

9+
import 'package:dartcv4/src/hook_helpers/parse_user_define.dart';
910
import 'package:logging/logging.dart';
1011
import 'package:native_assets_cli/native_assets_cli.dart';
1112
import 'package:native_toolchain_cmake/native_toolchain_cmake.dart';
@@ -16,15 +17,23 @@ void main(List<String> args) async {
1617

1718
Future<void> _builder(BuildInput input, BuildOutputBuilder output) async {
1819
final packageName = input.packageName;
19-
final packagePath = await getPackagePath(packageName);
20-
final sourceDir = Uri.directory(packagePath).resolve('src/');
20+
final packagePath = Uri.directory(await getPackagePath(packageName));
21+
final sourceDir = packagePath.resolve('src/');
2122
// final outDir = Uri.directory(packagePath).resolve('build/');
22-
final logger =
23-
Logger("")
24-
..level = Level.ALL
25-
..onRecord.listen((record) => stderr.writeln(record.message));
23+
final logger = Logger("")
24+
..level = Level.ALL
25+
..onRecord.listen((record) => stderr.writeln(record.message));
2626
// ..onRecord.listen((record) => print(record.message));
2727

28+
final exModsDefault = parseUserDefinedExcludeModules(packagePath.resolve("pubspec.yaml").toFilePath());
29+
final exModsUser =
30+
parseUserDefinedExcludeModules(Platform.script.resolve('../../../../pubspec.yaml').toFilePath());
31+
final exModsFinal = exModsDefault + exModsUser;
32+
33+
logger.info("default exclude modules: $exModsDefault");
34+
logger.info("user exclude modules: $exModsUser");
35+
logger.info("final exclude modules: $exModsFinal");
36+
2837
final builder = CMakeBuilder.create(
2938
name: packageName,
3039
sourceDir: sourceDir,
@@ -33,17 +42,19 @@ Future<void> _builder(BuildInput input, BuildOutputBuilder output) async {
3342
targets: ['install'],
3443
defines: {
3544
'CMAKE_INSTALL_PREFIX': input.outputDirectory.resolve('install').toFilePath(),
36-
'DARTCV_WITH_CALIB3D': "OFF",
37-
'DARTCV_WITH_DNN': 'OFF',
38-
'DARTCV_WITH_FEATURES2D': 'OFF',
39-
'DARTCV_WITH_HIGHGUI': 'OFF',
40-
'DARTCV_WITH_IMGPROC': 'ON',
41-
'DARTCV_WITH_IMGCODECS': 'OFF',
42-
'DARTCV_WITH_OBJDETECT': 'OFF',
43-
'DARTCV_WITH_PHOTO': 'OFF',
44-
'DARTCV_WITH_STITCHING': 'OFF',
45-
'DARTCV_WITH_VIDEO': 'OFF',
46-
'DARTCV_WITH_VIDEOIO': 'OFF',
45+
'DARTCV_WITH_CALIB3D': exModsFinal.contains('calib3d') ? "OFF" : "ON",
46+
'DARTCV_WITH_CONTRIB': exModsFinal.contains('contrib') ? "OFF" : "ON",
47+
'DARTCV_WITH_DNN': exModsFinal.contains('dnn') ? "OFF" : "ON",
48+
'DARTCV_WITH_FEATURES2D': exModsFinal.contains('features2d') ? "OFF" : "ON",
49+
'DARTCV_WITH_FLANN': exModsFinal.contains('flann') ? "OFF" : "ON",
50+
'DARTCV_WITH_HIGHGUI': exModsFinal.contains('highgui') ? "OFF" : "ON",
51+
'DARTCV_WITH_IMGPROC': exModsFinal.contains('imgproc') ? "OFF" : "ON",
52+
'DARTCV_WITH_IMGCODECS': exModsFinal.contains('imgcodecs') ? "OFF" : "ON",
53+
'DARTCV_WITH_OBJDETECT': exModsFinal.contains('objdetect') ? "OFF" : "ON",
54+
'DARTCV_WITH_PHOTO': exModsFinal.contains('photo') ? "OFF" : "ON",
55+
'DARTCV_WITH_STITCHING': exModsFinal.contains('stitching') ? "OFF" : "ON",
56+
'DARTCV_WITH_VIDEO': exModsFinal.contains('video') ? "OFF" : "ON",
57+
'DARTCV_WITH_VIDEOIO': exModsFinal.contains('videoio') ? "OFF" : "ON",
4758
},
4859
buildLocal: true,
4960
);

0 commit comments

Comments
 (0)