Skip to content

Commit

Permalink
fix: invalid windows build directory above 3.16.0 or 3.15.0-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 23, 2023
1 parent 0add98c commit 197fd0a
Showing 1 changed file with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter_app_builder/src/build_config.dart';
Expand All @@ -14,10 +15,63 @@ class BuildWindowsResultResolver extends BuildResultResolver {
class BuildWindowsResult extends BuildResult {
BuildWindowsResult(BuildConfig config) : super(config);

String? _arch;

String get arch {
if (_arch == null) {
final winArch = Platform.environment['PROCESSOR_ARCHITECTURE'];
if (winArch == 'ARM64') {
_arch = 'arm64';
} else {
_arch = 'x64';
}
}
return _arch!;
}

set arch(String value) {
_arch = value;
}

bool isVersionGreaterOrEqual(String fromVersion, String toVersion) {
if (fromVersion == toVersion) {
return true;
}

final from = fromVersion.split('.').map(int.parse).toList();
final to = toVersion.split('.').map(int.parse).toList();

if (from[0] > to[0]) {
return true;
} else if (from[0] == to[0] && from[1] > to[1]) {
return true;
} else if (from[0] == to[0] && from[1] == to[1] && from[2] > to[2]) {
return true;
}
return false;
}

@override
Directory get outputDirectory {
String buildMode = ReCase(config.mode.name).sentenceCase;
String path = 'build/windows/runner/$buildMode';
final versionInfo = jsonDecode(
Process.runSync('flutter', ['--version', '--machine'], runInShell: true)
.stdout
.toString(),
) as Map<String, dynamic>;

final flutterVersion = versionInfo['frameworkVersion'] as String;
final flutterChannel = versionInfo['channel'] as String;

String path;
if ((flutterChannel == 'master' &&
isVersionGreaterOrEqual(flutterVersion, '3.15.0')) ||
(flutterChannel != 'master' &&
isVersionGreaterOrEqual(flutterVersion, '3.16.0'))) {
path = 'build/windows/$arch/runner/$buildMode';
} else {
path = 'build/windows/runner/$buildMode';
}
return Directory(path);
}
}

0 comments on commit 197fd0a

Please sign in to comment.