Unverified Commit 1cdf0f44 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Only set `flutter run` usage values for targeted device platforms (#46931)

parent 853c8c56
...@@ -228,30 +228,55 @@ class RunCommand extends RunCommandBase { ...@@ -228,30 +228,55 @@ class RunCommand extends RunCommandBase {
Future<Map<CustomDimensions, String>> get usageValues async { Future<Map<CustomDimensions, String>> get usageValues async {
String deviceType, deviceOsVersion; String deviceType, deviceOsVersion;
bool isEmulator; bool isEmulator;
bool anyAndroidDevices = false;
bool anyIOSDevices = false;
if (devices == null || devices.isEmpty) { if (devices == null || devices.isEmpty) {
deviceType = 'none'; deviceType = 'none';
deviceOsVersion = 'none'; deviceOsVersion = 'none';
isEmulator = false; isEmulator = false;
} else if (devices.length == 1) { } else if (devices.length == 1) {
deviceType = getNameForTargetPlatform(await devices[0].targetPlatform); final TargetPlatform platform = await devices[0].targetPlatform;
anyAndroidDevices = platform == TargetPlatform.android;
anyIOSDevices = platform == TargetPlatform.ios;
deviceType = getNameForTargetPlatform(platform);
deviceOsVersion = await devices[0].sdkNameAndVersion; deviceOsVersion = await devices[0].sdkNameAndVersion;
isEmulator = await devices[0].isLocalEmulator; isEmulator = await devices[0].isLocalEmulator;
} else { } else {
deviceType = 'multiple'; deviceType = 'multiple';
deviceOsVersion = 'multiple'; deviceOsVersion = 'multiple';
isEmulator = false; isEmulator = false;
for (Device device in devices) {
final TargetPlatform platform = await device.targetPlatform;
anyAndroidDevices = anyAndroidDevices || (platform == TargetPlatform.android);
anyIOSDevices = anyIOSDevices || (platform == TargetPlatform.ios);
if (anyAndroidDevices && anyIOSDevices) {
break;
}
}
} }
final String modeName = getBuildInfo().modeName;
final AndroidProject androidProject = FlutterProject.current().android;
final IosProject iosProject = FlutterProject.current().ios;
final List<String> hostLanguage = <String>[
if (androidProject != null && androidProject.existsSync())
if (androidProject.isKotlin) 'kotlin' else 'java',
if (iosProject != null && iosProject.exists)
if (await iosProject.isSwift) 'swift' else 'objc',
];
String androidEmbeddingVersion;
final List<String> hostLanguage = <String>[];
if (anyAndroidDevices) {
final AndroidProject androidProject = FlutterProject.current().android;
if (androidProject != null && androidProject.existsSync()) {
hostLanguage.add(androidProject.isKotlin ? 'kotlin' : 'java');
androidEmbeddingVersion = androidProject.getEmbeddingVersion().toString().split('.').last;
}
}
if (anyIOSDevices) {
final IosProject iosProject = FlutterProject.current().ios;
if (iosProject != null && iosProject.exists) {
final Iterable<File> swiftFiles = iosProject.hostAppRoot
.listSync(recursive: true, followLinks: false)
.whereType<File>()
.where((File file) => fs.path.extension(file.path) == '.swift');
hostLanguage.add(swiftFiles.isNotEmpty ? 'swift' : 'objc');
}
}
final String modeName = getBuildInfo().modeName;
return <CustomDimensions, String>{ return <CustomDimensions, String>{
CustomDimensions.commandRunIsEmulator: '$isEmulator', CustomDimensions.commandRunIsEmulator: '$isEmulator',
CustomDimensions.commandRunTargetName: deviceType, CustomDimensions.commandRunTargetName: deviceType,
...@@ -259,7 +284,8 @@ class RunCommand extends RunCommandBase { ...@@ -259,7 +284,8 @@ class RunCommand extends RunCommandBase {
CustomDimensions.commandRunModeName: modeName, CustomDimensions.commandRunModeName: modeName,
CustomDimensions.commandRunProjectModule: '${FlutterProject.current().isModule}', CustomDimensions.commandRunProjectModule: '${FlutterProject.current().isModule}',
CustomDimensions.commandRunProjectHostLanguage: hostLanguage.join(','), CustomDimensions.commandRunProjectHostLanguage: hostLanguage.join(','),
CustomDimensions.commandRunAndroidEmbeddingVersion: androidProject.getEmbeddingVersion().toString().split('.').last, if (androidEmbeddingVersion != null)
CustomDimensions.commandRunAndroidEmbeddingVersion: androidEmbeddingVersion,
}; };
} }
......
...@@ -36,7 +36,6 @@ Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject, String buildDir ...@@ -36,7 +36,6 @@ Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject, String buildDir
final bool didPodInstall = await cocoaPods.processPods( final bool didPodInstall = await cocoaPods.processPods(
xcodeProject: xcodeProject, xcodeProject: xcodeProject,
engineDir: flutterFrameworkDir(buildMode), engineDir: flutterFrameworkDir(buildMode),
isSwift: await xcodeProject.isSwift,
dependenciesChanged: !fingerprinter.doesFingerprintMatch(), dependenciesChanged: !fingerprinter.doesFingerprintMatch(),
); );
if (didPodInstall) { if (didPodInstall) {
......
...@@ -138,7 +138,6 @@ class CocoaPods { ...@@ -138,7 +138,6 @@ class CocoaPods {
@required XcodeBasedProject xcodeProject, @required XcodeBasedProject xcodeProject,
// For backward compatibility with previously created Podfile only. // For backward compatibility with previously created Podfile only.
@required String engineDir, @required String engineDir,
bool isSwift = false,
bool dependenciesChanged = true, bool dependenciesChanged = true,
}) async { }) async {
if (!xcodeProject.podfile.existsSync()) { if (!xcodeProject.podfile.existsSync()) {
......
...@@ -292,9 +292,6 @@ abstract class XcodeBasedProject { ...@@ -292,9 +292,6 @@ abstract class XcodeBasedProject {
/// The CocoaPods 'Manifest.lock'. /// The CocoaPods 'Manifest.lock'.
File get podManifestLock; File get podManifestLock;
/// True if the host app project is using Swift.
Future<bool> get isSwift;
/// Directory containing symlinks to pub cache plugins source generated on `pod install`. /// Directory containing symlinks to pub cache plugins source generated on `pod install`.
Directory get symlinks; Directory get symlinks;
} }
...@@ -410,10 +407,6 @@ class IosProject implements XcodeBasedProject { ...@@ -410,10 +407,6 @@ class IosProject implements XcodeBasedProject {
return null; return null;
} }
@override
Future<bool> get isSwift async =>
(await buildSettings)?.containsKey('SWIFT_VERSION') ?? false;
/// The build settings for the host app of this project, as a detached map. /// The build settings for the host app of this project, as a detached map.
/// ///
/// Returns null, if iOS tooling is unavailable. /// Returns null, if iOS tooling is unavailable.
...@@ -820,9 +813,6 @@ class MacOSProject implements XcodeBasedProject { ...@@ -820,9 +813,6 @@ class MacOSProject implements XcodeBasedProject {
@override @override
Directory get symlinks => ephemeralDirectory.childDirectory('.symlinks'); Directory get symlinks => ephemeralDirectory.childDirectory('.symlinks');
@override
Future<bool> get isSwift async => true;
/// The file where the Xcode build will write the name of the built app. /// The file where the Xcode build will write the name of the built app.
/// ///
/// Ideally this will be replaced in the future with inspection of the Runner /// Ideally this will be replaced in the future with inspection of the Runner
......
...@@ -237,6 +237,7 @@ void main() { ...@@ -237,6 +237,7 @@ void main() {
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false)); when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false));
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(MockDeviceLogReader()); when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(MockDeviceLogReader());
when(mockDevice.supportsFastStart).thenReturn(true); when(mockDevice.supportsFastStart).thenReturn(true);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13'));
// App fails to start because we're only interested in usage // App fails to start because we're only interested in usage
when(mockDevice.startApp( when(mockDevice.startApp(
any, any,
...@@ -262,6 +263,15 @@ void main() { ...@@ -262,6 +263,15 @@ void main() {
(Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice]) (Invocation invocation) => Future<List<Device>>.value(<Device>[mockDevice])
); );
final Directory tempDir = fs.systemTempDirectory.createTempSync('flutter_run_test.');
tempDir.childDirectory('ios').childFile('AppDelegate.swift').createSync(recursive: true);
tempDir.childFile('.packages').createSync();
tempDir.childDirectory('lib').childFile('main.dart').createSync(recursive: true);
tempDir.childFile('pubspec.yaml')
..createSync()
..writeAsStringSync('# Hello, World');
fs.currentDirectory = tempDir;
try { try {
await createTestCommandRunner(command).run(<String>[ await createTestCommandRunner(command).run(<String>[
'run', 'run',
...@@ -281,7 +291,14 @@ void main() { ...@@ -281,7 +291,14 @@ void main() {
)).captured; )).captured;
expect(captures[0], 'run'); expect(captures[0], 'run');
final Map<String, String> parameters = captures[1] as Map<String, String>; final Map<String, String> parameters = captures[1] as Map<String, String>;
expect(parameters['cd4'], 'ios');
expect(parameters[cdKey(CustomDimensions.commandRunIsEmulator)], 'false');
expect(parameters[cdKey(CustomDimensions.commandRunTargetName)], 'ios');
expect(parameters[cdKey(CustomDimensions.commandRunProjectHostLanguage)], 'swift');
expect(parameters[cdKey(CustomDimensions.commandRunTargetOsVersion)], 'iOS 13');
expect(parameters[cdKey(CustomDimensions.commandRunModeName)], 'debug');
expect(parameters[cdKey(CustomDimensions.commandRunProjectModule)], 'false');
expect(parameters.containsKey(cdKey(CustomDimensions.commandRunAndroidEmbeddingVersion)), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ApplicationPackageFactory: () => mockApplicationPackageFactory, ApplicationPackageFactory: () => mockApplicationPackageFactory,
Artifacts: () => mockArtifacts, Artifacts: () => mockArtifacts,
......
...@@ -304,19 +304,12 @@ void main() { ...@@ -304,19 +304,12 @@ void main() {
testInMemory('default host app language', () async { testInMemory('default host app language', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
expect(await project.ios.isSwift, isFalse);
expect(project.android.isKotlin, isFalse); expect(project.android.isKotlin, isFalse);
}); });
testUsingContext('swift and kotlin host app language', () async { testUsingContext('kotlin host app language', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
when(mockXcodeProjectInterpreter.getBuildSettings(any, any)).thenAnswer(
(_) {
return Future<Map<String, String>>.value(<String, String>{
'SWIFT_VERSION': '5.0',
});
});
addAndroidGradleFile(project.directory, addAndroidGradleFile(project.directory,
gradleFileContent: () { gradleFileContent: () {
return ''' return '''
...@@ -324,7 +317,6 @@ apply plugin: 'com.android.application' ...@@ -324,7 +317,6 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
'''; ''';
}); });
expect(await project.ios.isSwift, isTrue);
expect(project.android.isKotlin, isTrue); expect(project.android.isKotlin, isTrue);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment