From c96a3c1e2e6f552284359a42cd93e74033316b63 Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Tue, 18 Jun 2024 13:37:58 +0200 Subject: [PATCH 1/3] feat: add compress func in host platform --- lib/host_runner/host_runner_platform.dart | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/host_runner/host_runner_platform.dart b/lib/host_runner/host_runner_platform.dart index 1fdebba..e82f114 100644 --- a/lib/host_runner/host_runner_platform.dart +++ b/lib/host_runner/host_runner_platform.dart @@ -123,6 +123,44 @@ abstract class HostRunnerPlatform { required bool ipv6, required String targetDevice, }); + + /// This command is used to compress a folder + /// + /// since we can use tar command in powershell in windows 10 and above + /// we can use the same command for windows, linux and macos + List compressCommand({ + String compressedFileName = 'archive.tar.gz', + String source = '.', + bool lastCommand = false, + List exclude = const [], + }) => + [ + 'tar', + '-czvf', + compressedFileName, + if (exclude.isNotEmpty) ...exclude.map((e) => '--exclude=\'$e\''), + source, + lastCommand ? '' : ';', + ]; + + /// This command is used to compress the current project + List compressCurrentProjectCommand({ + required String compressedFileName, + }) => + compressCommand( + compressedFileName: compressedFileName, + exclude: [ + '.dart_tool', + '.idea', + 'android', + 'build', + 'ios', + 'macos', + 'test', + 'web', + 'windows', + ], + ); } class WindowsHostRunnerPlatform extends HostRunnerPlatform { From 19a85dc207e5abf8b500aeff6046f78c88babd73 Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Tue, 18 Jun 2024 13:39:08 +0200 Subject: [PATCH 2/3] feat: add delete command to host runner --- lib/host_runner/host_runner_platform.dart | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/host_runner/host_runner_platform.dart b/lib/host_runner/host_runner_platform.dart index e82f114..9753409 100644 --- a/lib/host_runner/host_runner_platform.dart +++ b/lib/host_runner/host_runner_platform.dart @@ -161,6 +161,11 @@ abstract class HostRunnerPlatform { 'windows', ], ); + + List deleteFile({ + required String target, + bool lastCommand = false, + }); } class WindowsHostRunnerPlatform extends HostRunnerPlatform { @@ -209,6 +214,17 @@ class WindowsHostRunnerPlatform extends HostRunnerPlatform { 'ssh $targetDevice "cat >> .ssh/authorized_keys"' ]); } + + @override + List deleteFile({ + required String target, + bool lastCommand = false, + }) => + [ + 'del', + target, + lastCommand ? '' : ';', + ]; } class UnixHostRunnerPlatform extends HostRunnerPlatform { @@ -258,6 +274,14 @@ class UnixHostRunnerPlatform extends HostRunnerPlatform { targetDevice, ]; } + + @override + List deleteFile({required String target, bool lastCommand = false}) => + [ + 'rm', + target, + lastCommand ? '' : ';', + ]; } extension StringListExtension on List { From 82a73db80d4b769b650e9265169cd984d4ca7a4e Mon Sep 17 00:00:00 2001 From: Payam Zahedi Date: Tue, 18 Jun 2024 13:39:25 +0200 Subject: [PATCH 3/3] feat: add use tar to send project to host --- .../custom_device_builder/src/flutter.dart | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/service/custom_device_builder/src/flutter.dart b/lib/service/custom_device_builder/src/flutter.dart index 8eafdb1..0336883 100644 --- a/lib/service/custom_device_builder/src/flutter.dart +++ b/lib/service/custom_device_builder/src/flutter.dart @@ -36,6 +36,8 @@ class FlutterCustomDeviceBuilder extends CustomDeviceBuilder { final remoteAppExecuter = context.appExecuterPath!; + final appArchiveName = '\${appName}.tar.gz'; + return CustomDeviceConfig( id: context.id!, label: context.formattedLabel, @@ -50,11 +52,15 @@ class FlutterCustomDeviceBuilder extends CustomDeviceBuilder { pingSuccessRegex: hostPlatform.pingSuccessRegex, postBuildCommand: const [], - // just install to /tmp/${appName} by default - // returns the command runner for the current platform - // for example: - // on windows it returns "powershell -c" - // on linux and macOS it returns "bash -c" + /// installing process of the app on the remote machine + /// + /// 1. create the necessary directories in the remote machine + /// 2. compress the current project on the host without unnecessary files + /// 3. copy the archive project file to the remote + /// 4. extract the project on the remote + /// 5. copy the build artifacts from host to the remote + /// 6. copy the icu data file from host to the remote + /// 7. remove the archive file on host after sending it to the remote installCommand: hostPlatform.commandRunner( [ // create the necessary directories in the remote machine @@ -66,15 +72,32 @@ class FlutterCustomDeviceBuilder extends CustomDeviceBuilder { ) .asString, - // copy the current project files from host to the remote + // compress the current project on the host + hostPlatform + .compressCurrentProjectCommand( + compressedFileName: appArchiveName, + ) + .asString, + + // copy the archive project file to the remote hostPlatform .scpCommand( ipv6: ipv6, - source: '${hostPlatform.currentSourcePath}*', + source: appArchiveName, dest: '$sshTarget:/tmp/\${appName}', ) .asString, + // extract the project on the remote + hostPlatform + .sshCommand( + ipv6: ipv6, + sshTarget: sshTarget, + command: + 'tar -xvf /tmp/\${appName}/$appArchiveName -C /tmp/\${appName}', + ) + .asString, + // copy the build artifacts from host to the remote hostPlatform .scpCommand( @@ -90,6 +113,13 @@ class FlutterCustomDeviceBuilder extends CustomDeviceBuilder { ipv6: ipv6, source: hostIcuDataPath, dest: '$sshTarget:/tmp/\${appName}/$hostIcuDataClone', + ) + .asString, + + // remove the archive file on host after sending it to the remote + hostPlatform + .deleteFile( + target: appArchiveName, lastCommand: true, ) .asString,