Check for watch companion in build settings (#114078)

This commit is contained in:
Victoria Ashworth
2022-10-27 17:05:05 -05:00
committed by GitHub
parent cece4a5d19
commit 8aad1190b7
8 changed files with 299 additions and 86 deletions

View File

@@ -395,6 +395,76 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('build settings uses watch destination if isWatch is true', () async {
platform.environment = const <String, String>{};
fakeProcessManager.addCommands(<FakeCommand>[
kWhichSysctlCommand,
kx64CheckCommand,
FakeCommand(
command: <String>[
'xcrun',
'xcodebuild',
'-project',
'/',
'-destination',
'generic/platform=watchOS',
'-showBuildSettings',
'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
],
exitCode: 1,
),
]);
expect(
await xcodeProjectInterpreter.getBuildSettings(
'',
buildContext: const XcodeProjectBuildContext(isWatch: true),
),
const <String, String>{},
);
expect(fakeProcessManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('build settings uses watch simulator destination if isWatch is true and environment type is simulator', () async {
platform.environment = const <String, String>{};
fakeProcessManager.addCommands(<FakeCommand>[
kWhichSysctlCommand,
kx64CheckCommand,
FakeCommand(
command: <String>[
'xcrun',
'xcodebuild',
'-project',
'/',
'-sdk',
'iphonesimulator',
'-destination',
'generic/platform=watchOS Simulator',
'-showBuildSettings',
'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
],
exitCode: 1,
),
]);
expect(
await xcodeProjectInterpreter.getBuildSettings(
'',
buildContext: const XcodeProjectBuildContext(environmentType: EnvironmentType.simulator, isWatch: true),
),
const <String, String>{},
);
expect(fakeProcessManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('xcodebuild clean contains Flutter Xcode environment variables', () async {
platform.environment = const <String, String>{
'FLUTTER_XCODE_CODE_SIGN_STYLE': 'Manual',

View File

@@ -458,7 +458,8 @@ apply plugin: 'kotlin-android'
testWithMocks('from build settings, if no plist', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
xcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(scheme: 'Runner');
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
xcodeProjectInterpreter.xcodeProjectInfo = XcodeProjectInfo(<String>[], <String>[], <String>['Runner'], logger);
@@ -486,7 +487,8 @@ apply plugin: 'kotlin-android'
testWithMocks('from build settings and plist, if default variable', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
xcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(scheme: 'Runner');
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
xcodeProjectInterpreter.xcodeProjectInfo = XcodeProjectInfo(<String>[], <String>[], <String>['Runner'], logger);
@@ -499,7 +501,8 @@ apply plugin: 'kotlin-android'
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
project.ios.defaultHostInfoPlist.createSync(recursive: true);
xcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(scheme: 'Runner');
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
'SUFFIX': 'suffix',
};
@@ -534,7 +537,8 @@ apply plugin: 'kotlin-android'
testWithMocks('handles case insensitive flavor', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
xcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(scheme: 'Free');
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
xcodeProjectInterpreter.xcodeProjectInfo =XcodeProjectInfo(<String>[], <String>[], <String>['Free'], logger);
@@ -603,7 +607,8 @@ apply plugin: 'kotlin-android'
testUsingContext('app product name xcodebuild settings', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
mockXcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(scheme: 'Runner');
mockXcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'FULL_PRODUCT_NAME': 'My App.app',
};
mockXcodeProjectInterpreter.xcodeProjectInfo = XcodeProjectInfo(<String>[], <String>[], <String>['Runner'], logger);
@@ -705,7 +710,15 @@ apply plugin: 'kotlin-android'
testUsingContext('cannot find bundle identifier', () async {
final FlutterProject project = await someProject();
expect(await project.ios.containsWatchCompanion(<String>['WatchTarget'], BuildInfo.debug, '123'), isFalse);
final XcodeProjectInfo projectInfo = XcodeProjectInfo(<String>['WatchTarget'], <String>[], <String>[], logger);
expect(
await project.ios.containsWatchCompanion(
projectInfo: projectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isFalse,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
@@ -716,15 +729,23 @@ apply plugin: 'kotlin-android'
group('with bundle identifier', () {
setUp(() {
mockXcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(scheme: 'Runner');
mockXcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
mockXcodeProjectInterpreter.xcodeProjectInfo = XcodeProjectInfo(<String>[], <String>[], <String>['Runner'], logger);
mockXcodeProjectInterpreter.xcodeProjectInfo = XcodeProjectInfo(<String>['Runner', 'WatchTarget'], <String>[], <String>['Runner', 'WatchScheme'], logger);
});
testUsingContext('no Info.plist in target', () async {
final FlutterProject project = await someProject();
expect(await project.ios.containsWatchCompanion(<String>['WatchTarget'], BuildInfo.debug, '123'), isFalse);
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isFalse,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
@@ -737,7 +758,14 @@ apply plugin: 'kotlin-android'
final FlutterProject project = await someProject();
project.ios.hostAppRoot.childDirectory('WatchTarget').childFile('Info.plist').createSync(recursive: true);
expect(await project.ios.containsWatchCompanion(<String>['WatchTarget'], BuildInfo.debug, '123'), isFalse);
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isFalse,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
@@ -751,7 +779,14 @@ apply plugin: 'kotlin-android'
project.ios.hostAppRoot.childDirectory('WatchTarget').childFile('Info.plist').createSync(recursive: true);
testPlistParser.setProperty('WKCompanionAppBundleIdentifier', 'io.flutter.someOTHERproject');
expect(await project.ios.containsWatchCompanion(<String>['WatchTarget'], BuildInfo.debug, '123'), isFalse);
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isFalse,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
@@ -760,13 +795,20 @@ apply plugin: 'kotlin-android'
FlutterProjectFactory: () => flutterProjectFactory,
});
testUsingContext('has watch companion', () async {
testUsingContext('has watch companion in plist', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
project.ios.hostAppRoot.childDirectory('WatchTarget').childFile('Info.plist').createSync(recursive: true);
testPlistParser.setProperty('WKCompanionAppBundleIdentifier', 'io.flutter.someProject');
expect(await project.ios.containsWatchCompanion(<String>['WatchTarget'], BuildInfo.debug, '123'), isTrue);
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isTrue,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
@@ -775,16 +817,109 @@ apply plugin: 'kotlin-android'
FlutterProjectFactory: () => flutterProjectFactory,
});
testUsingContext('has watch companion with build settings', () async {
testUsingContext('has watch companion in plist with xcode variable', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
mockXcodeProjectInterpreter.buildSettings = <String, String>{
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(
scheme: 'Runner',
deviceId: '123',
);
mockXcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
project.ios.hostAppRoot.childDirectory('WatchTarget').childFile('Info.plist').createSync(recursive: true);
testPlistParser.setProperty('WKCompanionAppBundleIdentifier', r'$(PRODUCT_BUNDLE_IDENTIFIER)');
expect(await project.ios.containsWatchCompanion(<String>['WatchTarget'], BuildInfo.debug, '123'), isTrue);
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isTrue,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
PlistParser: () => testPlistParser,
XcodeProjectInterpreter: () => mockXcodeProjectInterpreter,
FlutterProjectFactory: () => flutterProjectFactory,
});
testUsingContext('has watch companion in other scheme build settings', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
project.ios.xcodeProjectInfoFile.writeAsStringSync('''
Build settings for action build and target "WatchTarget":
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = io.flutter.someProject
''');
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(
scheme: 'Runner',
deviceId: '123',
);
mockXcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
const XcodeProjectBuildContext watchBuildContext = XcodeProjectBuildContext(
scheme: 'WatchScheme',
deviceId: '123',
isWatch: true,
);
mockXcodeProjectInterpreter.buildSettingsByBuildContext[watchBuildContext] = <String, String>{
'INFOPLIST_KEY_WKCompanionAppBundleIdentifier': 'io.flutter.someProject',
};
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isTrue,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
PlistParser: () => testPlistParser,
XcodeProjectInterpreter: () => mockXcodeProjectInterpreter,
FlutterProjectFactory: () => flutterProjectFactory,
});
testUsingContext('has watch companion in other scheme build settings with xcode variable', () async {
final FlutterProject project = await someProject();
project.ios.xcodeProject.createSync();
project.ios.xcodeProjectInfoFile.writeAsStringSync(r'''
Build settings for action build and target "WatchTarget":
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = $(PRODUCT_BUNDLE_IDENTIFIER)
''');
const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(
scheme: 'Runner',
deviceId: '123'
);
mockXcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
};
const XcodeProjectBuildContext watchBuildContext = XcodeProjectBuildContext(
scheme: 'WatchScheme',
deviceId: '123',
isWatch: true,
);
mockXcodeProjectInterpreter.buildSettingsByBuildContext[watchBuildContext] = <String, String>{
'PRODUCT_BUNDLE_IDENTIFIER': 'io.flutter.someProject',
'INFOPLIST_KEY_WKCompanionAppBundleIdentifier': r'$(PRODUCT_BUNDLE_IDENTIFIER)',
};
expect(
await project.ios.containsWatchCompanion(
projectInfo: mockXcodeProjectInterpreter.xcodeProjectInfo,
buildInfo: BuildInfo.debug,
deviceId: '123',
),
isTrue,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
@@ -1075,7 +1210,7 @@ File androidPluginRegistrant(Directory parent) {
}
class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterpreter {
Map<String, String> buildSettings = <String, String>{};
final Map<XcodeProjectBuildContext, Map<String, String>> buildSettingsByBuildContext = <XcodeProjectBuildContext, Map<String, String>>{};
late XcodeProjectInfo xcodeProjectInfo;
@override
@@ -1083,7 +1218,10 @@ class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterprete
XcodeProjectBuildContext? buildContext,
Duration timeout = const Duration(minutes: 1),
}) async {
return buildSettings;
if (buildSettingsByBuildContext[buildContext] == null) {
return <String, String>{};
}
return buildSettingsByBuildContext[buildContext]!;
}
@override