Skip to content

Commit

Permalink
parse build version on xcodeproj (#105908)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasguerrero committed Jun 16, 2022
1 parent ddeb0b9 commit 32b22b8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
16 changes: 14 additions & 2 deletions packages/flutter_tools/lib/src/ios/xcodeproj.dart
Expand Up @@ -47,6 +47,7 @@ class XcodeProjectInterpreter {
required FileSystem fileSystem,
required Usage usage,
Version? version,
String? build,
}) : _platform = platform,
_fileSystem = fileSystem,
_logger = logger,
Expand All @@ -58,6 +59,7 @@ class XcodeProjectInterpreter {
processManager: processManager,
),
_version = version,
_build = build,
_versionText = version?.toString(),
_usage = usage;

Expand All @@ -70,6 +72,7 @@ class XcodeProjectInterpreter {
factory XcodeProjectInterpreter.test({
required ProcessManager processManager,
Version? version = const Version.withText(1000, 0, 0, '1000.0.0'),
String? build = '13C100',
}) {
final Platform platform = FakePlatform(
operatingSystem: 'macos',
Expand All @@ -82,6 +85,7 @@ class XcodeProjectInterpreter {
usage: TestUsage(),
logger: BufferLogger.test(),
version: version,
build: build,
);
}

Expand All @@ -91,8 +95,7 @@ class XcodeProjectInterpreter {
final OperatingSystemUtils _operatingSystemUtils;
final Logger _logger;
final Usage _usage;

static final RegExp _versionRegex = RegExp(r'Xcode ([0-9.]+)');
static final RegExp _versionRegex = RegExp(r'Xcode ([0-9.]+).*Build version (\w+)');

void _updateVersion() {
if (!_platform.isMacOS || !_fileSystem.file('/usr/bin/xcodebuild').existsSync()) {
Expand All @@ -118,6 +121,7 @@ class XcodeProjectInterpreter {
final int minorVersion = components.length < 2 ? 0 : int.parse(components[1]);
final int patchVersion = components.length < 3 ? 0 : int.parse(components[2]);
_version = Version(majorVersion, minorVersion, patchVersion);
_build = match.group(2);
} on ProcessException {
// Ignored, leave values null.
}
Expand All @@ -134,13 +138,21 @@ class XcodeProjectInterpreter {
}

Version? _version;
String? _build;
Version? get version {
if (_version == null) {
_updateVersion();
}
return _version;
}

String? get build {
if (_build == null) {
_updateVersion();
}
return _build;
}

/// The `xcrun` Xcode command to run or locate development
/// tools and properties.
///
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/macos/xcode.dart
Expand Up @@ -101,6 +101,8 @@ class Xcode {

Version? get currentVersion => _xcodeProjectInterpreter.version;

String? get buildVersion => _xcodeProjectInterpreter.build;

String? get versionText => _xcodeProjectInterpreter.versionText;

bool? _eulaSigned;
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter_tools/lib/src/macos/xcode_validator.dart
Expand Up @@ -37,6 +37,9 @@ class XcodeValidator extends DoctorValidator {
xcodeVersionInfo = xcodeVersionInfo.substring(0, xcodeVersionInfo.indexOf(','));
}
}
if (_xcode.buildVersion != null) {
messages.add(ValidationMessage('Build ${_xcode.buildVersion}'));
}
if (!_xcode.isInstalledAndMeetsVersionCheck) {
xcodeStatus = ValidationType.partial;
messages.add(ValidationMessage.error(_userMessages.xcodeOutdated(xcodeRequiredVersion.toString())));
Expand Down
Expand Up @@ -146,6 +146,7 @@ void main() {
]);

expect(xcodeProjectInterpreter.version, Version(11, 4, 1));
expect(xcodeProjectInterpreter.build, '11N111s');
expect(fakeProcessManager, hasNoRemainingExpectations);
});

Expand Down Expand Up @@ -173,6 +174,7 @@ void main() {
),
]);
expect(xcodeProjectInterpreter.version, isNull);
expect(xcodeProjectInterpreter.build, isNull);
expect(fakeProcessManager, hasNoRemainingExpectations);
});

Expand Down
Expand Up @@ -183,11 +183,12 @@ void main() {
final XcodeValidator validator = XcodeValidator(xcode: xcode, userMessages: UserMessages());
final ValidationResult result = await validator.validate();
expect(result.type, ValidationType.installed);
expect(result.messages.length, 1);
expect(result.messages.length, 2);
final ValidationMessage firstMessage = result.messages.first;
expect(firstMessage.type, ValidationMessageType.information);
expect(firstMessage.message, 'Xcode at /Library/Developer/CommandLineTools');
expect(result.statusInfo, '1000.0.0');
expect(result.messages[1].message, 'Build 13C100');
});
});
}
3 changes: 3 additions & 0 deletions packages/flutter_tools/test/src/context.dart
Expand Up @@ -296,6 +296,9 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
@override
Version get version => Version(13, null, null);

@override
String get build => '13C100';

@override
Future<Map<String, String>> getBuildSettings(
String projectPath, {
Expand Down

0 comments on commit 32b22b8

Please sign in to comment.