Skip to content

Commit

Permalink
Compatible with v3.10.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
soloxiao committed Jul 4, 2023
1 parent a023fef commit 8cefe9a
Show file tree
Hide file tree
Showing 29 changed files with 386 additions and 435 deletions.
2 changes: 1 addition & 1 deletion example/android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=/Users/solo/Library/Android/sdk
flutter.sdk=/Users/solo/SDK/flutter/stable/3.7.12
flutter.sdk=/Users/solo/SDK/flutter/stable/3.10.0
flutter.buildMode=release
=======
flutter.versionName=1.0.0
Expand Down
1 change: 1 addition & 0 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down
2 changes: 1 addition & 1 deletion example/lib/hook_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class AddDemo {

@Add("package:example/receiver_test.dart", "Receiver")
@pragma("vm:entry-point")
dynamic addTest(PointCut pointCut, int j, {String s, int i}) {
dynamic addTest(PointCut pointCut, int j, {String? s, int? i}) {
print('[beike_aspectd]: Add method');
}

Expand Down
27 changes: 3 additions & 24 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({this.title});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
Expand All @@ -80,30 +80,11 @@ class MyHomePage extends StatefulWidget {
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;
final String? title;

@override
_MyHomePageState createState() => _MyHomePageState(i: 19);
}

class TextRightImageModel {
String showName;

String rightIcon;

Widget showCardWidget(BuildContext context) {
return Container(
padding: const EdgeInsets.only(left: 4.0, right: 4.0),
alignment: Alignment.center,
child: wrapTextLimit(context, const Text("")),
);
}

Widget wrapTextLimit(BuildContext str, Widget widget) {
return widget;
}
}

class _MyHomePageState extends State<MyHomePage> {
int i;
String s = 'fffff';
Expand All @@ -128,8 +109,6 @@ class _MyHomePageState extends State<MyHomePage> {
// called again, and so nothing would appear to happen.
i++;
});

TextRightImageModel().showCardWidget(context);
}

static void testFunction() {}
Expand All @@ -153,7 +132,7 @@ class _MyHomePageState extends State<MyHomePage> {
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
title: Text(widget.title??''),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
Expand Down
4 changes: 1 addition & 3 deletions example/lib/receiver_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.10

class Receiver {

final int j;
Expand All @@ -10,7 +8,7 @@ class Receiver {

}

void receiveTapped(int i, {int j}) {
void receiveTapped(int i, {int? j}) {
print('[KWLM]:onPluginDemo111 Called!');
}
}
Expand Down
6 changes: 1 addition & 5 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ description: A new Flutter application.
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
beike_aspectd:
path: ../

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
Binary file modified inner/flutter_frontend_server/frontend_server.dart.snapshot
Binary file not shown.
85 changes: 42 additions & 43 deletions inner/flutter_tools.patch
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
From c4ad8560bde629e5687adda3a84d820208238d43 Mon Sep 17 00:00:00 2001
From 8cfcb6467f8a9631c6b0f82134ff1d9ad8b9a327 Mon Sep 17 00:00:00 2001
From: xiaopeng015 <[email protected]>
Date: Fri, 5 May 2023 11:31:14 +0800
Subject: [PATCH] aop
Date: Tue, 4 Jul 2023 17:42:16 +0800
Subject: [PATCH] 1

---
.../lib/src/aop/aop_manager.dart | 196 ++++++++++++++++
.../flutter_tools/lib/src/aop/aspectd.dart | 221 ++++++++++++++++++
.../lib/src/aop/hook_factory.dart | 96 ++++++++
.../lib/src/aop/hook_factory.dart | 95 ++++++++
.../lib/src/build_system/targets/common.dart | 8 +
.../lib/src/build_system/targets/web.dart | 3 +
.../lib/src/commands/build_bundle.dart | 4 +
packages/flutter_tools/lib/src/compile.dart | 18 ++
7 files changed, 546 insertions(+)
7 files changed, 545 insertions(+)
create mode 100644 packages/flutter_tools/lib/src/aop/aop_manager.dart
create mode 100644 packages/flutter_tools/lib/src/aop/aspectd.dart
create mode 100644 packages/flutter_tools/lib/src/aop/hook_factory.dart
Expand Down Expand Up @@ -447,17 +447,17 @@ index 0000000000..380e51cd08
+}
diff --git a/packages/flutter_tools/lib/src/aop/hook_factory.dart b/packages/flutter_tools/lib/src/aop/hook_factory.dart
new file mode 100644
index 0000000000..db7aa89af0
index 0000000000..f7f22ec88f
--- /dev/null
+++ b/packages/flutter_tools/lib/src/aop/hook_factory.dart
@@ -0,0 +1,96 @@
@@ -0,0 +1,95 @@
+import 'dart:io';
+
+import 'package:flutter_tools/src/artifacts.dart';
+import 'package:flutter_tools/src/base/common.dart';
+import 'package:flutter_tools/src/base/file_system.dart';
+import 'package:flutter_tools/src/build_info.dart';
+import 'package:flutter_tools/src/globals.dart';
+import '../artifacts.dart';
+import '../base/common.dart';
+import '../base/file_system.dart';
+import '../build_info.dart';
+import '../globals.dart';
+
+/// 创建时间:2020-03-28
+/// 作者:liujingguang
Expand Down Expand Up @@ -494,10 +494,9 @@ index 0000000000..db7aa89af0
+ }
+
+ final String outputPath =
+ inputPath + '.${type.toString().toLowerCase()}.result.dill';
+ '$inputPath.${type.toString().toLowerCase()}.result.dill';
+
+ final String engineDartPath =
+ artifacts!.getHostArtifact(HostArtifact.engineDartBinary).path;
+ final String engineDartPath = artifacts!.getArtifactPath(Artifact.engineDartBinary);
+
+ /// 执行hook命令
+ final List<String> command = <String>[
Expand Down Expand Up @@ -548,7 +547,7 @@ index 0000000000..db7aa89af0
+ static String _getSnapShotInputPath(String path) => path;
+}
diff --git a/packages/flutter_tools/lib/src/build_system/targets/common.dart b/packages/flutter_tools/lib/src/build_system/targets/common.dart
index 91a39e6c20..464e8c2db6 100644
index c3e6ea4d72..36c13f9e7b 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/common.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/common.dart
@@ -20,6 +20,7 @@ import 'dart_plugin_registrant.dart';
Expand All @@ -559,11 +558,10 @@ index 91a39e6c20..464e8c2db6 100644

/// Copies the pre-built flutter bundle.
// This is a one-off rule for implementing build bundle in terms of assemble.
@@ -152,6 +153,12 @@ class KernelSnapshot extends Target {
@@ -152,6 +153,11 @@ class KernelSnapshot extends Target {

@override
Future<void> build(Environment environment) async {
+
+ await AspectdHook.enableAspectd();
+ await buildImpl(environment);
+ }
Expand All @@ -572,37 +570,38 @@ index 91a39e6c20..464e8c2db6 100644
final KernelCompiler compiler = KernelCompiler(
fileSystem: environment.fileSystem,
logger: environment.logger,
@@ -245,6 +252,7 @@ class KernelSnapshot extends Target {
@@ -243,6 +249,8 @@ class KernelSnapshot extends Target {
if (output == null || output.errorCount != 0) {
throw Exception();
}
+
+ return output;
}
}

diff --git a/packages/flutter_tools/lib/src/build_system/targets/web.dart b/packages/flutter_tools/lib/src/build_system/targets/web.dart
index 995023d149..b4d2a5d778 100644
index 49f4b11df0..302d627474 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/web.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/web.dart
@@ -27,6 +27,7 @@ import '../exceptions.dart';
@@ -30,6 +30,7 @@ import '../exceptions.dart';
import 'assets.dart';
import 'localizations.dart';
import 'shader_compiler.dart';
+import '../../aop/aop_manager.dart';

/// Whether the application has web plugins.
const String kHasWebPlugins = 'HasWebPlugins';
@@ -225,6 +226,8 @@ class Dart2JSTarget extends Target {
@@ -212,6 +213,8 @@ class Dart2JSTarget extends Dart2WebTarget {
throw Exception(_collectOutput(kernelResult));
}

+ await AopManager.hookSnapshotCommand(environment.buildDir.childFile('app.dill').path, buildMode);
+
final String? dart2jsOptimization = environment.defines[kDart2jsOptimization];
final bool dumpInfo = environment.defines[kDart2jsDumpInfo] == 'true';
final bool noFrequencyBasedMinification = environment.defines[kDart2jsNoFrequencyBasedMinification] == 'true';
final File outputJSFile = environment.buildDir.childFile('main.dart.js');

final ProcessResult javaScriptResult = await environment.processManager.run(<String>[
diff --git a/packages/flutter_tools/lib/src/commands/build_bundle.dart b/packages/flutter_tools/lib/src/commands/build_bundle.dart
index 9cd3413c0b..01f640064d 100644
index 434ab77432..d75f7ceeec 100644
--- a/packages/flutter_tools/lib/src/commands/build_bundle.dart
+++ b/packages/flutter_tools/lib/src/commands/build_bundle.dart
@@ -12,6 +12,7 @@ import '../project.dart';
Expand All @@ -613,18 +612,18 @@ index 9cd3413c0b..01f640064d 100644

class BuildBundleCommand extends BuildSubCommand {
BuildBundleCommand({
@@ -96,6 +97,9 @@ class BuildBundleCommand extends BuildSubCommand {
@@ -93,6 +94,9 @@ class BuildBundleCommand extends BuildSubCommand {

@override
Future<FlutterCommandResult> runCommand() async {
+
+ await AspectdHook.enableAspectd();
+
final String targetPlatform = stringArgDeprecated('target-platform')!;
final String targetPlatform = stringArg('target-platform')!;
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
if (platform == null) {
// Check for target platforms that are only allowed via feature flags.
diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart
index e072e6b7a4..c42311b5ef 100644
index 5b1422b8ba..6826b47cf1 100644
--- a/packages/flutter_tools/lib/src/compile.dart
+++ b/packages/flutter_tools/lib/src/compile.dart
@@ -18,6 +18,7 @@ import 'base/logger.dart';
Expand All @@ -635,17 +634,17 @@ index e072e6b7a4..c42311b5ef 100644

/// Opt-in changes to the dart compilers.
const List<String> kDartCompilerExperiments = <String>[
@@ -248,6 +249,9 @@ class KernelCompiler {
@@ -244,6 +245,9 @@ class KernelCompiler {
required List<String> dartDefines,
required PackageConfig packageConfig,
}) async {
+
+ await AspectdHook.enableAspectd();
+
final TargetPlatform? platform = targetModel == TargetModel.dartdevc ? TargetPlatform.web_javascript : null;
final String frontendServer = _artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk
);
@@ -283,6 +287,8 @@ class KernelCompiler {
Artifact.frontendServerSnapshotForEngineDartSdk,
@@ -281,6 +285,8 @@ class KernelCompiler {
toMultiRootPath(dartPluginRegistrantFileUri, _fileSystemScheme, _fileSystemRoots, _fileSystem.path.separator == r'\');
}

Expand All @@ -654,7 +653,7 @@ index e072e6b7a4..c42311b5ef 100644
final List<String> command = <String>[
engineDartPath,
'--disable-dart-dev',
@@ -326,6 +332,10 @@ class KernelCompiler {
@@ -324,6 +330,10 @@ class KernelCompiler {
'--initialize-from-dill',
initializeFromDill,
],
Expand All @@ -665,18 +664,18 @@ index e072e6b7a4..c42311b5ef 100644
if (platformDill != null) ...<String>[
'--platform',
platformDill,
@@ -740,6 +750,10 @@ class DefaultResidentCompiler implements ResidentCompiler {
String? outputPath,
{String? additionalSourceUri}
) async {
@@ -741,6 +751,10 @@ class DefaultResidentCompiler implements ResidentCompiler {
Artifact.frontendServerSnapshotForEngineDartSdk,
platform: platform,
);
+
+ await AspectdHook.enableAspectd();
+ bool aopConfig = AspectdHook.configFileExists();
+
final String frontendServer = _artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk
);
@@ -800,6 +814,10 @@ class DefaultResidentCompiler implements ResidentCompiler {
final List<String> command = <String>[
_artifacts.getArtifactPath(Artifact.engineDartBinary, platform: platform),
'--disable-dart-dev',
@@ -797,6 +811,10 @@ class DefaultResidentCompiler implements ResidentCompiler {
'--platform',
platformDill!,
],
Expand Down
2 changes: 1 addition & 1 deletion inner/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev_dependencies:
yaml: any

dependency_overrides:
package_config: 1.9.3
package_config: 2.1.0
meta:
path: pkg/meta
frontend_server:
Expand Down
16 changes: 8 additions & 8 deletions inner/tool/starter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ int main(List<String> args) {

final DillOps dillOps = DillOps();
final Component component = dillOps.readComponentFromDill(intputDill);
Component platformStrongComponent;
late Component platformStrongComponent;
if (sdkRoot != null) {
platformStrongComponent =
dillOps.readComponentFromDill(p.join(sdkRoot, 'platform_strong.dill'));
for (Library library in platformStrongComponent.libraries) {
libraryAbbrMap.putIfAbsent(library.name, () => library.reference.node);
libraryAbbrMap.putIfAbsent(library.name!, () => library.reference.node! as Library);

for (Class clazz in library.classes) {
classAbbrMap.putIfAbsent(library.name + '.' + clazz.name,
() => clazz.reference.node);
classAbbrMap.putIfAbsent(library.name! + '.' + clazz.name,
() => clazz.reference.node as Class);
}
}

Expand All @@ -58,8 +58,8 @@ int main(List<String> args) {
childrenToExchange.add(canonicalName.name);
}

Library library = libraryAbbrMap[canonicalName.name];
CanonicalName canonical = canonicalMap[canonicalName.name];
Library? library = libraryAbbrMap[canonicalName.name];
CanonicalName canonical = canonicalMap[canonicalName.name] as CanonicalName;
library ??= libraryAbbrMap[canonicalName.name.replaceAll(':', '.')];
if (canonicalName.reference == null) {
// canonicalName.reference = Reference()..node = library;
Expand Down Expand Up @@ -123,10 +123,10 @@ void completeDartComponent(Component component) {
for (CanonicalName canonicalName
in List<CanonicalName>.from(component.root.children.toList())) {
if (!componentLibraryMap.containsKey(canonicalName.name)) {
Library library = libraryAbbrMap[canonicalName.name];
Library? library = libraryAbbrMap[canonicalName.name];
library ??= libraryAbbrMap[canonicalName.name.replaceAll(':', '.')];
component.root.removeChild(canonicalName.name);
component.libraries.add(library);
component.libraries.add(library!);
}
}
component.adoptChildren();
Expand Down
Loading

0 comments on commit 8cefe9a

Please sign in to comment.