Skip to content

Commit 3c3d414

Browse files
authored
[Reland] Skip injecting Bonjour settings when port publication is disabled (#136842)
Reland flutter/flutter#136751 with fixes.
1 parent 9fa9fd3 commit 3c3d414

File tree

8 files changed

+142
-1
lines changed

8 files changed

+142
-1
lines changed

dev/devicelab/lib/tasks/perf_tests.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ class StartupTest {
886886
'-v',
887887
'--profile',
888888
'--target=$target',
889+
if (deviceOperatingSystem == DeviceOperatingSystem.ios) '--no-publish-port',
889890
]);
890891
final String buildRoot = path.join(testDirectory, 'build');
891892
applicationBinaryPath = _findDarwinAppInBuildDirectory(buildRoot);

packages/flutter_tools/bin/xcode_backend.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ class Context {
256256

257257
// Add the vmService publisher Bonjour service to the produced app bundle Info.plist.
258258
void addVmServiceBonjourService() {
259+
// Skip adding Bonjour service settings when DISABLE_PORT_PUBLICATION is YES.
260+
// These settings are not needed if port publication is disabled.
261+
if (environment['DISABLE_PORT_PUBLICATION'] == 'YES') {
262+
return;
263+
}
264+
259265
final String buildMode = parseFlutterBuildMode();
260266

261267
// Debug and profile only.

packages/flutter_tools/lib/src/commands/build_ios.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ import 'build.dart';
2727
/// Builds an .app for an iOS app to be used for local testing on an iOS device
2828
/// or simulator. Can only be run on a macOS host.
2929
class BuildIOSCommand extends _BuildIOSSubCommand {
30-
BuildIOSCommand({ required super.logger, required super.verboseHelp }) {
30+
BuildIOSCommand({
31+
required super.logger,
32+
required bool verboseHelp,
33+
}) : super(verboseHelp: verboseHelp) {
34+
addPublishPort(verboseHelp: verboseHelp);
3135
argParser
3236
..addFlag('config-only',
3337
help: 'Update the project configuration without performing a build. '
@@ -658,6 +662,9 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
658662
configOnly: configOnly,
659663
buildAction: xcodeBuildAction,
660664
deviceID: globals.deviceManager?.specifiedDeviceId,
665+
disablePortPublication: usingCISystem &&
666+
xcodeBuildAction == XcodeBuildAction.build &&
667+
await disablePortPublication,
661668
);
662669
xcodeBuildResult = result;
663670

packages/flutter_tools/lib/src/ios/devices.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ class IOSDevice extends Device {
501501
targetOverride: mainPath,
502502
activeArch: cpuArchitecture,
503503
deviceID: id,
504+
disablePortPublication: debuggingOptions.usingCISystem && debuggingOptions.disablePortPublication,
504505
);
505506
if (!buildResult.success) {
506507
_logger.printError('Could not build the precompiled application for the device.');

packages/flutter_tools/lib/src/ios/mac.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Future<XcodeBuildResult> buildXcodeProject({
135135
String? deviceID,
136136
bool configOnly = false,
137137
XcodeBuildAction buildAction = XcodeBuildAction.build,
138+
bool disablePortPublication = false,
138139
}) async {
139140
if (!upgradePbxProjWithFlutterAssets(app.project, globals.logger)) {
140141
return XcodeBuildResult(success: false);
@@ -382,6 +383,12 @@ Future<XcodeBuildResult> buildXcodeProject({
382383
_kResultBundleVersion,
383384
]);
384385

386+
// Adds a setting which xcode_backend.dart will use to skip adding Bonjour
387+
// service settings to the Info.plist.
388+
if (disablePortPublication) {
389+
buildCommands.add('DISABLE_PORT_PUBLICATION=YES');
390+
}
391+
385392
// Don't log analytics for downstream Flutter commands.
386393
// e.g. `flutter build bundle`.
387394
buildCommands.add('FLUTTER_SUPPRESS_ANALYTICS=true');

packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ void main() {
146146
bool verbose = false,
147147
bool simulator = false,
148148
bool customNaming = false,
149+
bool disablePortPublication = false,
149150
String? deviceId,
150151
int exitCode = 0,
151152
String? stdout,
@@ -189,6 +190,8 @@ void main() {
189190
],
190191
'-resultBundlePath', _xcBundleDirectoryPath,
191192
'-resultBundleVersion', '3',
193+
if (disablePortPublication)
194+
'DISABLE_PORT_PUBLICATION=YES',
192195
'FLUTTER_SUPPRESS_ANALYTICS=true',
193196
'COMPILER_INDEX_STORE_ENABLE=NO',
194197
],
@@ -303,6 +306,69 @@ void main() {
303306
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
304307
});
305308

309+
testUsingContext('ios build invokes xcode build with disable port publication setting', () async {
310+
final BuildCommand command = BuildCommand(
311+
artifacts: artifacts,
312+
androidSdk: FakeAndroidSdk(),
313+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
314+
fileSystem: fileSystem,
315+
logger: logger,
316+
processUtils: processUtils,
317+
osUtils: FakeOperatingSystemUtils(),
318+
);
319+
createMinimalMockProjectFiles();
320+
321+
await createTestCommandRunner(command).run(
322+
const <String>['build', 'ios', '--no-pub', '--no-publish-port', '--ci']
323+
);
324+
expect(testLogger.statusText, contains('build/ios/iphoneos/Runner.app'));
325+
}, overrides: <Type, Generator>{
326+
FileSystem: () => fileSystem,
327+
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
328+
xattrCommand,
329+
setUpFakeXcodeBuildHandler(
330+
disablePortPublication: true,
331+
onRun: () {
332+
fileSystem.directory('build/ios/Release-iphoneos/Runner.app').createSync(recursive: true);
333+
},
334+
),
335+
setUpRsyncCommand(),
336+
]),
337+
Platform: () => macosPlatform,
338+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
339+
});
340+
341+
testUsingContext('ios build invokes xcode build without disable port publication setting when not in CI', () async {
342+
final BuildCommand command = BuildCommand(
343+
artifacts: artifacts,
344+
androidSdk: FakeAndroidSdk(),
345+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
346+
fileSystem: fileSystem,
347+
logger: logger,
348+
processUtils: processUtils,
349+
osUtils: FakeOperatingSystemUtils(),
350+
);
351+
createMinimalMockProjectFiles();
352+
353+
await createTestCommandRunner(command).run(
354+
const <String>['build', 'ios', '--no-pub', '--no-publish-port']
355+
);
356+
expect(testLogger.statusText, contains('build/ios/iphoneos/Runner.app'));
357+
}, overrides: <Type, Generator>{
358+
FileSystem: () => fileSystem,
359+
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
360+
xattrCommand,
361+
setUpFakeXcodeBuildHandler(
362+
onRun: () {
363+
fileSystem.directory('build/ios/Release-iphoneos/Runner.app').createSync(recursive: true);
364+
},
365+
),
366+
setUpRsyncCommand(),
367+
]),
368+
Platform: () => macosPlatform,
369+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
370+
});
371+
306372
testUsingContext('ios build invokes xcode build with renamed xcodeproj and xcworkspace', () async {
307373
final BuildCommand command = BuildCommand(
308374
artifacts: artifacts,

packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,34 @@ void main() {
604604
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
605605
});
606606

607+
testUsingContext('ipa build invokes xcode build without disablePortPublication', () async {
608+
final BuildCommand command = BuildCommand(
609+
artifacts: artifacts,
610+
androidSdk: FakeAndroidSdk(),
611+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
612+
logger: logger,
613+
fileSystem: fileSystem,
614+
processUtils: processUtils,
615+
osUtils: FakeOperatingSystemUtils(),
616+
);
617+
fakeProcessManager.addCommands(<FakeCommand>[
618+
xattrCommand,
619+
setUpFakeXcodeBuildHandler(),
620+
exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist),
621+
]);
622+
createMinimalMockProjectFiles();
623+
624+
await createTestCommandRunner(command).run(
625+
const <String>['build', 'ipa', '--no-pub', '--ci']
626+
);
627+
expect(fakeProcessManager, hasNoRemainingExpectations);
628+
}, overrides: <Type, Generator>{
629+
FileSystem: () => fileSystem,
630+
ProcessManager: () => fakeProcessManager,
631+
Platform: () => macosPlatform,
632+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
633+
});
634+
607635
testUsingContext('ipa build --no-codesign skips codesigning and IPA creation', () async {
608636
final BuildCommand command = BuildCommand(
609637
artifacts: artifacts,

packages/flutter_tools/test/integration.shard/xcode_backend_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,30 @@ void main() {
183183
''');
184184
expect(result, const ProcessResultMatcher());
185185
});
186+
187+
test('does not add bonjour settings when port publication is disabled', () async {
188+
infoPlist.writeAsStringSync('''
189+
<?xml version="1.0" encoding="UTF-8"?>
190+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
191+
<plist version="1.0">
192+
<dict>
193+
</dict>
194+
</plist>''');
195+
196+
final ProcessResult result = await Process.run(
197+
xcodeBackendPath,
198+
<String>['test_vm_service_bonjour_service'],
199+
environment: <String, String>{
200+
'CONFIGURATION': 'Debug',
201+
'BUILT_PRODUCTS_DIR': buildDirectory.path,
202+
'INFOPLIST_PATH': 'Info.plist',
203+
'DISABLE_PORT_PUBLICATION': 'YES',
204+
},
205+
);
206+
207+
expect(infoPlist.readAsStringSync().contains('NSBonjourServices'), isFalse);
208+
expect(infoPlist.readAsStringSync().contains('NSLocalNetworkUsageDescription'), isFalse);
209+
expect(result, const ProcessResultMatcher());
210+
});
186211
}, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain.
187212
}

0 commit comments

Comments
 (0)