Skip to content

Commit

Permalink
update for flutter 2.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lancexin committed Jan 13, 2022
1 parent 81d1c9d commit 8f774bf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ dart --deterministic --no-sound-null-safety --packages=rebased_package_config.js
2. 执行下面命令测试(注意目录替换)):

编译aot dill
dart run frontend_server.dart.snapshot --sdk-root /Users/lixin/Documents/flutter_macos_stable/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --target=flutter --aot --tfa --no-print-incremental-dependencies -Dflutter.inspector.structuredErrors=true -DFLUTTER_WEB_AUTO_DETECT=true -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --packages /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/package_config.json --output-dill app.dill --depfile /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/flutter_build/7e3ee53a02512eed13521d997dab4d35/kernel_snapshot.d package:example/main.dart
dart run frontend_server.dart.snapshot --sdk-root /Users/lixin/Documents/flutter_macos_stable/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --target=flutter --aot --tfa --no-print-incremental-dependencies -Dflutter.inspector.structuredErrors=true -DFLUTTER_WEB_AUTO_DETECT=true -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --packages /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/package_config.json --output-dill app.dill --depfile /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/flutter_build/b0fee5c86b6ccb9c75440c36f0f7cea4/kernel_snapshot.d package:example/main.dart

编译运行时dill
dart run frontend_server.dart.snapshot --sdk-root /Users/lixin/Documents/flutter_macos_stable/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --target=flutter --no-print-incremental-dependencies -Dflutter.inspector.structuredErrors=true -DFLUTTER_WEB_AUTO_DETECT=true -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --packages /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/package_config.json --output-dill app.dill --depfile /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/flutter_build/7e3ee53a02512eed13521d997dab4d35/kernel_snapshot.d package:example/main.dart
dart run frontend_server.dart.snapshot --sdk-root /Users/lixin/Documents/flutter_macos_stable/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --target=flutter --verbose --no-print-incremental-dependencies -Dflutter.inspector.structuredErrors=true -DFLUTTER_WEB_AUTO_DETECT=true -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --packages /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/package_config.json --output-dill app.dill --depfile /Users/lixin/Documents/FlutterWorkspace/aspect_frontend_server/example/.dart_tool/flutter_build/b0fee5c86b6ccb9c75440c36f0f7cea4/kernel_snapshot.d package:example/main.dart

测试aot编译成二进制
flutter_macos_stable/bin/cache/artifacts/engine/android-arm64-release/darwin-x64/gen_snapshot --deterministic --snapshot_kind=app-aot-elf --elf=app.so --strip app.dill
Expand Down
12 changes: 6 additions & 6 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -87,7 +87,7 @@ packages:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.10"
version: "0.12.11"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -148,7 +148,7 @@ packages:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.2"
version: "0.4.3"
typed_data:
dependency: transitive
description:
Expand All @@ -162,6 +162,6 @@ packages:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
Binary file modified frontend_server.dart.snapshot
Binary file not shown.
3 changes: 1 addition & 2 deletions lib/starter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ import 'dart:io';
import 'package:args/args.dart';

import 'package:frontend_server/frontend_server.dart' as frontend;
import 'package:vm/target/flutter.dart';
import 'transformer.dart';

Future<void> main(List<String> args) async {
try {
ArgResults options = frontend.argParser.parse(args);
frontend.FrontendCompiler compiler = frontend.FrontendCompiler(stdout,
printerFactory: frontend.BinaryPrinterFactory(),
//添加注入逻辑
transformer: AspectAopTransformer(),
unsafePackageSerialization: options['unsafe-package-serialization'],
incrementalSerialization: options['incremental-serialization'],
useDebuggerModuleNames: options['debugger-module-names'],
emitDebugMetadata: options['experimental-emit-debug-metadata'],
emitDebugSymbols: options['emit-debug-symbols']);
//FlutterTarget.flutterProgramTransformer = AspectAopTransformer();
final int exitCode = await frontend.starter(args, compiler: compiler);
if (exitCode != 0) {
exit(exitCode);
Expand Down
3 changes: 1 addition & 2 deletions lib/transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class AopItem {
}
}

class AspectAopTransformer
implements frontend.ProgramTransformer, FlutterProgramTransformer {
class AspectAopTransformer implements frontend.ProgramTransformer {
final List<AopItem> _aopItemList = <AopItem>[];

@override
Expand Down
33 changes: 20 additions & 13 deletions lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class AopUtils {
flags: node.flags,
isFinal: node.isFinal,
isConst: node.isConst,
isFieldFormal: node.isFieldFormal,
isCovariant: node.isCovariant,
isLate: node.isLate,
isRequired: node.isRequired,
isInitializingFormal: node.isInitializingFormal,
isCovariantByDeclaration: node.isCovariantByDeclaration,
isLowered: node.isLowered,
);
}
if (node is TypeParameterType) {
Expand Down Expand Up @@ -189,20 +192,24 @@ class AopUtils {
if (annotationName != kImportUriAopInjectName) {
continue;
}
var list =
((instanceConstant.fieldValues.values.last as InstanceConstant)
.fieldValues
.values
.first as ListConstant)
.entries;
if (list.length != 8) {
List<ConstantMapEntry> list =
(instanceConstant.fieldValues.values.last as MapConstant).entries;

if (list.length != 4) {
continue;
}

if (!(list[0].value is StringConstant &&
list[1].value is StringConstant &&
list[2].value is StringConstant &&
list[3].value is BoolConstant)) {
continue;
}

String importUri = (list[1] as StringConstant).value;
String clsName = (list[3] as StringConstant).value;
String methodName = (list[5] as StringConstant).value;
bool isRegex = (list[7] as BoolConstant).value;
String importUri = (list[0].value as StringConstant).value;
String clsName = (list[1].value as StringConstant).value;
String methodName = (list[2].value as StringConstant).value;
bool isRegex = (list[3].value as BoolConstant).value;
bool isStatic = false;
if (methodName
.startsWith(AopUtils.kAopAnnotationInstanceMethodPrefix)) {
Expand Down

0 comments on commit 8f774bf

Please sign in to comment.