aports/testing/flutter/version.patch
2025-02-23 21:16:00 +00:00

291 lines
10 KiB
Diff

--- ./packages/flutter_tools/lib/src/version.dart.orig
+++ ./packages/flutter_tools/lib/src/version.dart
@@ -76,7 +76,7 @@
}) {
final File versionFile = getVersionFile(fs, flutterRoot);
- if (!fetchTags && versionFile.existsSync()) {
+ if (versionFile.existsSync()) {
final _FlutterVersionFromFile? version = _FlutterVersionFromFile.tryParseFromFile(
versionFile,
flutterRoot: flutterRoot,
@@ -95,11 +95,7 @@
}
}
- final String frameworkRevision = _runGit(
- gitLog(<String>['-n', '1', '--pretty=format:%H']).join(' '),
- globals.processUtils,
- flutterRoot,
- );
+ final String frameworkRevision = "alpineaports0000000000000000000000000000";
return FlutterVersion.fromRevision(
clock: clock,
@@ -127,7 +123,8 @@
workingDirectory: flutterRoot,
fetchTags: fetchTags,
);
- final String frameworkVersion = gitTagVersion.frameworkVersionFor(frameworkRevision);
+ final String frameworkVersion =
+ globals.fs.file(globals.fs.path.join(Cache.flutterRoot!, 'version')).readAsStringSync();
return _FlutterVersionGit._(
clock: clock,
flutterRoot: flutterRoot,
@@ -192,11 +189,7 @@
// TODO(fujino): calculate this relative to frameworkCommitDate for
// _FlutterVersionFromFile so we don't need a git call.
String get frameworkAge {
- return _frameworkAge ??= _runGit(
- FlutterVersion.gitLog(<String>['-n', '1', '--pretty=format:%ar']).join(' '),
- globals.processUtils,
- flutterRoot,
- );
+ return _frameworkAge ??= 'unknown (alpine package)';
}
void ensureVersionFile();
@@ -281,44 +274,7 @@
/// Returns null if the cached version is out-of-date or missing, and we are
/// unable to reach the server to get the latest version.
Future<DateTime?> _getLatestAvailableFlutterDate() async {
- globals.cache.checkLockAcquired();
- final VersionCheckStamp versionCheckStamp = await VersionCheckStamp.load(
- globals.cache,
- globals.logger,
- );
-
- final DateTime now = _clock.now();
- if (versionCheckStamp.lastTimeVersionWasChecked != null) {
- final Duration timeSinceLastCheck = now.difference(
- versionCheckStamp.lastTimeVersionWasChecked!,
- );
-
- // Don't ping the server too often. Return cached value if it's fresh.
- if (timeSinceLastCheck < VersionFreshnessValidator.checkAgeConsideredUpToDate) {
- return versionCheckStamp.lastKnownRemoteVersion;
- }
- }
-
- // Cache is empty or it's been a while since the last server ping. Ping the server.
- try {
- final DateTime remoteFrameworkCommitDate = DateTime.parse(
- await fetchRemoteFrameworkCommitDate(),
- );
- await versionCheckStamp.store(
- newTimeVersionWasChecked: now,
- newKnownRemoteVersion: remoteFrameworkCommitDate,
- );
- return remoteFrameworkCommitDate;
- } on VersionCheckError catch (error) {
- // This happens when any of the git commands fails, which can happen when
- // there's no Internet connectivity. Remote version check is best effort
- // only. We do not prevent the command from running when it fails.
- globals.printTrace('Failed to check Flutter version in the remote repository: $error');
- // Still update the timestamp to avoid us hitting the server on every single
- // command if for some reason we cannot connect (eg. we may be offline).
- await versionCheckStamp.store(newTimeVersionWasChecked: now);
- return null;
- }
+ return null;
}
/// The date of the latest framework commit in the remote repository.
@@ -404,30 +360,13 @@
bool lenient = false,
required String? workingDirectory,
}) {
- final List<String> args = FlutterVersion.gitLog(<String>[
- gitRef,
- '-n',
- '1',
- '--pretty=format:%ad',
- '--date=iso',
- ]);
- try {
- // Don't plumb 'lenient' through directly so that we can print an error
- // if something goes wrong.
- return _runSync(args, lenient: false, workingDirectory: workingDirectory);
- } on VersionCheckError catch (e) {
- if (lenient) {
- final DateTime dummyDate = DateTime.fromMillisecondsSinceEpoch(0);
- globals.printError(
- 'Failed to find the latest git commit date: $e\n'
- 'Returning $dummyDate instead.',
- );
- // Return something that DateTime.parse() can parse.
- return dummyDate.toString();
- } else {
- rethrow;
- }
- }
+ final File versionFile = globals.fs.file(
+ globals.fs.path.join(workingDirectory!, 'bin', 'cache', 'flutter.version.json'),
+ );
+
+ final _FlutterVersionFromFile version =
+ _FlutterVersionFromFile.tryParseFromFile(versionFile, flutterRoot: workingDirectory)!;
+ return version.frameworkCommitDate;
}
class _FlutterVersionFromFile extends FlutterVersion {
@@ -513,9 +452,7 @@
final String devToolsVersion;
@override
- void ensureVersionFile() {
- _ensureLegacyVersionFile(fs: fs, flutterRoot: flutterRoot, frameworkVersion: frameworkVersion);
- }
+ void ensureVersionFile() {}
}
class _FlutterVersionGit extends FlutterVersion {
@@ -586,27 +523,14 @@
}
@override
- void ensureVersionFile() {
- _ensureLegacyVersionFile(fs: fs, flutterRoot: flutterRoot, frameworkVersion: frameworkVersion);
-
- const JsonEncoder encoder = JsonEncoder.withIndent(' ');
- final File newVersionFile = FlutterVersion.getVersionFile(fs, flutterRoot);
- if (!newVersionFile.existsSync()) {
- newVersionFile.writeAsStringSync(encoder.convert(toJson()));
- }
- }
+ void ensureVersionFile() {}
}
void _ensureLegacyVersionFile({
required FileSystem fs,
required String flutterRoot,
required String frameworkVersion,
-}) {
- final File legacyVersionFile = fs.file(fs.path.join(flutterRoot, 'version'));
- if (!legacyVersionFile.existsSync()) {
- legacyVersionFile.writeAsStringSync(frameworkVersion);
- }
-}
+}) {}
/// Checks if the provided [version] is tracking a standard remote.
///
@@ -632,52 +556,6 @@
///
/// Returns [VersionCheckError] if the tracking remote is not standard.
VersionCheckError? run() {
- final String? flutterGit = platform.environment['FLUTTER_GIT_URL'];
- final String? repositoryUrl = version.repositoryUrl;
-
- if (repositoryUrl == null) {
- return VersionCheckError(
- 'The tool could not determine the remote upstream which is being '
- 'tracked by the SDK.',
- );
- }
-
- // Strip `.git` suffix before comparing the remotes
- final List<String> sanitizedStandardRemotes =
- <String>[
- // If `FLUTTER_GIT_URL` is set, use that as standard remote.
- if (flutterGit != null)
- flutterGit
- // Else use the predefined standard remotes.
- else
- ..._standardRemotes,
- ].map((String remote) => stripDotGit(remote)).toList();
-
- final String sanitizedRepositoryUrl = stripDotGit(repositoryUrl);
-
- if (!sanitizedStandardRemotes.contains(sanitizedRepositoryUrl)) {
- if (flutterGit != null) {
- // If `FLUTTER_GIT_URL` is set, inform to either remove the
- // `FLUTTER_GIT_URL` environment variable or set it to the current
- // tracking remote.
- return VersionCheckError(
- 'The Flutter SDK is tracking "$repositoryUrl" but "FLUTTER_GIT_URL" '
- 'is set to "$flutterGit".\n'
- 'Either remove "FLUTTER_GIT_URL" from the environment or set it to '
- '"$repositoryUrl". '
- 'If this is intentional, it is recommended to use "git" directly to '
- 'manage the SDK.',
- );
- }
- // If `FLUTTER_GIT_URL` is unset, inform to set the environment variable.
- return VersionCheckError(
- 'The Flutter SDK is tracking a non-standard remote "$repositoryUrl".\n'
- 'Set the environment variable "FLUTTER_GIT_URL" to '
- '"$repositoryUrl". '
- 'If this is intentional, it is recommended to use "git" directly to '
- 'manage the SDK.',
- );
- }
return null;
}
@@ -844,7 +722,7 @@
}
String _runGit(String command, ProcessUtils processUtils, String? workingDirectory) {
- return processUtils.runSync(command.split(' '), workingDirectory: workingDirectory).stdout.trim();
+ return '';
}
/// Runs [command] in the root of the Flutter installation and returns the
@@ -871,7 +749,7 @@
if (revision == null) {
return '';
}
- return revision.length > 10 ? revision.substring(0, 10) : revision;
+ return revision.length > 12 ? revision.substring(0, 12) : revision;
}
/// Version of Flutter SDK parsed from Git.
@@ -932,46 +810,10 @@
bool fetchTags = false,
String gitRef = 'HEAD',
}) {
- if (fetchTags) {
- final String channel = _runGit(
- 'git symbolic-ref --short HEAD',
- processUtils,
- workingDirectory,
- );
- if (!kDevelopmentChannels.contains(channel) && kOfficialChannels.contains(channel)) {
- globals.printTrace('Skipping request to fetchTags - on well known channel $channel.');
- } else {
- final String flutterGit =
- platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
- _runGit('git fetch $flutterGit --tags -f', processUtils, workingDirectory);
- }
- }
- // find all tags attached to the given [gitRef]
- final List<String> tags = _runGit(
- 'git tag --points-at $gitRef',
- processUtils,
- workingDirectory,
- ).trim().split('\n');
-
- // Check first for a stable tag
- final RegExp stableTagPattern = RegExp(r'^\d+\.\d+\.\d+$');
- for (final String tag in tags) {
- if (stableTagPattern.hasMatch(tag.trim())) {
- return parse(tag);
- }
- }
- // Next check for a dev tag
- final RegExp devTagPattern = RegExp(r'^\d+\.\d+\.\d+-\d+\.\d+\.pre$');
- for (final String tag in tags) {
- if (devTagPattern.hasMatch(tag.trim())) {
- return parse(tag);
- }
- }
-
// If we're not currently on a tag, use git describe to find the most
// recent tag and number of commits past.
return parse(
- _runGit('git describe --match *.*.* --long --tags $gitRef', processUtils, workingDirectory),
+ globals.fs.file(globals.fs.path.join(Cache.flutterRoot!, 'version')).readAsStringSync(),
);
}