Unverified Commit 1599cbeb authored by Victoria Ashworth's avatar Victoria Ashworth Committed by GitHub

[Reland] Skip injecting Bonjour settings when port publication is disabled (#136751)

Reland of https://github.com/flutter/flutter/pull/136562 with fixes.
parent 697242c9
...@@ -886,6 +886,7 @@ class StartupTest { ...@@ -886,6 +886,7 @@ class StartupTest {
'-v', '-v',
'--profile', '--profile',
'--target=$target', '--target=$target',
if (deviceOperatingSystem == DeviceOperatingSystem.ios) '--no-publish-port',
]); ]);
final String buildRoot = path.join(testDirectory, 'build'); final String buildRoot = path.join(testDirectory, 'build');
applicationBinaryPath = _findDarwinAppInBuildDirectory(buildRoot); applicationBinaryPath = _findDarwinAppInBuildDirectory(buildRoot);
......
...@@ -256,6 +256,12 @@ class Context { ...@@ -256,6 +256,12 @@ class Context {
// Add the vmService publisher Bonjour service to the produced app bundle Info.plist. // Add the vmService publisher Bonjour service to the produced app bundle Info.plist.
void addVmServiceBonjourService() { void addVmServiceBonjourService() {
// Skip adding Bonjour service settings when DISABLE_PORT_PUBLICATION is YES.
// These settings are not needed if port publication is disabled.
if (environment['DISABLE_PORT_PUBLICATION'] == 'YES') {
return;
}
final String buildMode = parseFlutterBuildMode(); final String buildMode = parseFlutterBuildMode();
// Debug and profile only. // Debug and profile only.
......
...@@ -27,7 +27,11 @@ import 'build.dart'; ...@@ -27,7 +27,11 @@ import 'build.dart';
/// Builds an .app for an iOS app to be used for local testing on an iOS device /// Builds an .app for an iOS app to be used for local testing on an iOS device
/// or simulator. Can only be run on a macOS host. /// or simulator. Can only be run on a macOS host.
class BuildIOSCommand extends _BuildIOSSubCommand { class BuildIOSCommand extends _BuildIOSSubCommand {
BuildIOSCommand({ required super.logger, required super.verboseHelp }) { BuildIOSCommand({
required super.logger,
required bool verboseHelp,
}) : super(verboseHelp: verboseHelp) {
addPublishPort(verboseHelp: verboseHelp);
argParser argParser
..addFlag('config-only', ..addFlag('config-only',
help: 'Update the project configuration without performing a build. ' help: 'Update the project configuration without performing a build. '
...@@ -658,6 +662,9 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -658,6 +662,9 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
configOnly: configOnly, configOnly: configOnly,
buildAction: xcodeBuildAction, buildAction: xcodeBuildAction,
deviceID: globals.deviceManager?.specifiedDeviceId, deviceID: globals.deviceManager?.specifiedDeviceId,
disablePortPublication: usingCISystem &&
xcodeBuildAction == XcodeBuildAction.build &&
await disablePortPublication,
); );
xcodeBuildResult = result; xcodeBuildResult = result;
......
...@@ -501,6 +501,7 @@ class IOSDevice extends Device { ...@@ -501,6 +501,7 @@ class IOSDevice extends Device {
targetOverride: mainPath, targetOverride: mainPath,
activeArch: cpuArchitecture, activeArch: cpuArchitecture,
deviceID: id, deviceID: id,
disablePortPublication: debuggingOptions.usingCISystem && debuggingOptions.disablePortPublication,
); );
if (!buildResult.success) { if (!buildResult.success) {
_logger.printError('Could not build the precompiled application for the device.'); _logger.printError('Could not build the precompiled application for the device.');
......
...@@ -135,6 +135,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -135,6 +135,7 @@ Future<XcodeBuildResult> buildXcodeProject({
String? deviceID, String? deviceID,
bool configOnly = false, bool configOnly = false,
XcodeBuildAction buildAction = XcodeBuildAction.build, XcodeBuildAction buildAction = XcodeBuildAction.build,
bool disablePortPublication = false,
}) async { }) async {
if (!upgradePbxProjWithFlutterAssets(app.project, globals.logger)) { if (!upgradePbxProjWithFlutterAssets(app.project, globals.logger)) {
return XcodeBuildResult(success: false); return XcodeBuildResult(success: false);
...@@ -382,6 +383,12 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -382,6 +383,12 @@ Future<XcodeBuildResult> buildXcodeProject({
_kResultBundleVersion, _kResultBundleVersion,
]); ]);
// Adds a setting which xcode_backend.dart will use to skip adding Bonjour
// service settings to the Info.plist.
if (disablePortPublication) {
buildCommands.add('DISABLE_PORT_PUBLICATION=YES');
}
// Don't log analytics for downstream Flutter commands. // Don't log analytics for downstream Flutter commands.
// e.g. `flutter build bundle`. // e.g. `flutter build bundle`.
buildCommands.add('FLUTTER_SUPPRESS_ANALYTICS=true'); buildCommands.add('FLUTTER_SUPPRESS_ANALYTICS=true');
......
...@@ -146,6 +146,7 @@ void main() { ...@@ -146,6 +146,7 @@ void main() {
bool verbose = false, bool verbose = false,
bool simulator = false, bool simulator = false,
bool customNaming = false, bool customNaming = false,
bool disablePortPublication = false,
String? deviceId, String? deviceId,
int exitCode = 0, int exitCode = 0,
String? stdout, String? stdout,
...@@ -189,6 +190,8 @@ void main() { ...@@ -189,6 +190,8 @@ void main() {
], ],
'-resultBundlePath', _xcBundleDirectoryPath, '-resultBundlePath', _xcBundleDirectoryPath,
'-resultBundleVersion', '3', '-resultBundleVersion', '3',
if (disablePortPublication)
'DISABLE_PORT_PUBLICATION=YES',
'FLUTTER_SUPPRESS_ANALYTICS=true', 'FLUTTER_SUPPRESS_ANALYTICS=true',
'COMPILER_INDEX_STORE_ENABLE=NO', 'COMPILER_INDEX_STORE_ENABLE=NO',
], ],
...@@ -303,6 +306,65 @@ void main() { ...@@ -303,6 +306,65 @@ void main() {
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(), XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
}); });
testUsingContext('ios build invokes xcode build with disable port publication setting', () async {
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles();
await createTestCommandRunner(command).run(
const <String>['build', 'ios', '--no-pub', '--no-publish-port', '--ci']
);
expect(testLogger.statusText, contains('build/ios/iphoneos/Runner.app'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(
disablePortPublication: true,
onRun: () {
fileSystem.directory('build/ios/Release-iphoneos/Runner.app').createSync(recursive: true);
},
),
setUpRsyncCommand(),
]),
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
testUsingContext('ios build invokes xcode build without disable port publication setting when not in CI', () async {
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
createMinimalMockProjectFiles();
await createTestCommandRunner(command).run(
const <String>['build', 'ios', '--no-pub', '--no-publish-port']
);
expect(testLogger.statusText, contains('build/ios/iphoneos/Runner.app'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(
onRun: () {
fileSystem.directory('build/ios/Release-iphoneos/Runner.app').createSync(recursive: true);
},
),
setUpRsyncCommand(),
]),
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
testUsingContext('ios build invokes xcode build with renamed xcodeproj and xcworkspace', () async { testUsingContext('ios build invokes xcode build with renamed xcodeproj and xcworkspace', () async {
final BuildCommand command = BuildCommand( final BuildCommand command = BuildCommand(
artifacts: artifacts, artifacts: artifacts,
......
...@@ -604,6 +604,32 @@ void main() { ...@@ -604,6 +604,32 @@ void main() {
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(), XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
}); });
testUsingContext('ipa build invokes xcode build without disablePortPublication', () async {
final BuildCommand command = BuildCommand(
androidSdk: FakeAndroidSdk(),
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
osUtils: FakeOperatingSystemUtils(),
);
fakeProcessManager.addCommands(<FakeCommand>[
xattrCommand,
setUpFakeXcodeBuildHandler(),
exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist),
]);
createMinimalMockProjectFiles();
await createTestCommandRunner(command).run(
const <String>['build', 'ipa', '--no-pub', '--ci']
);
expect(fakeProcessManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => fakeProcessManager,
Platform: () => macosPlatform,
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
});
testUsingContext('ipa build --no-codesign skips codesigning and IPA creation', () async { testUsingContext('ipa build --no-codesign skips codesigning and IPA creation', () async {
final BuildCommand command = BuildCommand( final BuildCommand command = BuildCommand(
artifacts: artifacts, artifacts: artifacts,
......
...@@ -183,5 +183,30 @@ void main() { ...@@ -183,5 +183,30 @@ void main() {
'''); ''');
expect(result, const ProcessResultMatcher()); expect(result, const ProcessResultMatcher());
}); });
test('does not add bonjour settings when port publication is disabled', () async {
infoPlist.writeAsStringSync('''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>''');
final ProcessResult result = await Process.run(
xcodeBackendPath,
<String>['test_vm_service_bonjour_service'],
environment: <String, String>{
'CONFIGURATION': 'Debug',
'BUILT_PRODUCTS_DIR': buildDirectory.path,
'INFOPLIST_PATH': 'Info.plist',
'DISABLE_PORT_PUBLICATION': 'YES',
},
);
expect(infoPlist.readAsStringSync().contains('NSBonjourServices'), isFalse);
expect(infoPlist.readAsStringSync().contains('NSLocalNetworkUsageDescription'), isFalse);
expect(result, const ProcessResultMatcher());
});
}, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain. }, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain.
} }
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