Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: speed up running flutter app on flutter linux embedder #34

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions lib/host_runner/host_runner_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,49 @@ 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<String> compressCommand({
String compressedFileName = 'archive.tar.gz',
String source = '.',
bool lastCommand = false,
List<String> 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<String> compressCurrentProjectCommand({
required String compressedFileName,
}) =>
compressCommand(
compressedFileName: compressedFileName,
exclude: [
'.dart_tool',
'.idea',
'android',
'build',
'ios',
'macos',
'test',
'web',
'windows',
],
);

List<String> deleteFile({
required String target,
bool lastCommand = false,
});
}

class WindowsHostRunnerPlatform extends HostRunnerPlatform {
Expand Down Expand Up @@ -171,6 +214,17 @@ class WindowsHostRunnerPlatform extends HostRunnerPlatform {
'ssh $targetDevice "cat >> .ssh/authorized_keys"'
]);
}

@override
List<String> deleteFile({
required String target,
bool lastCommand = false,
}) =>
[
'del',
target,
lastCommand ? '' : ';',
];
}

class UnixHostRunnerPlatform extends HostRunnerPlatform {
Expand Down Expand Up @@ -220,6 +274,14 @@ class UnixHostRunnerPlatform extends HostRunnerPlatform {
targetDevice,
];
}

@override
List<String> deleteFile({required String target, bool lastCommand = false}) =>
[
'rm',
target,
lastCommand ? '' : ';',
];
}

extension StringListExtension on List<String> {
Expand Down
44 changes: 37 additions & 7 deletions lib/service/custom_device_builder/src/flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,11 +52,15 @@ class FlutterCustomDeviceBuilder extends CustomDeviceBuilder {
pingSuccessRegex: hostPlatform.pingSuccessRegex,
postBuildCommand: const <String>[],

// 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(
<String>[
// create the necessary directories in the remote machine
Expand All @@ -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(
Expand All @@ -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,
Expand Down