Skip to content

Commit cb81950

Browse files
authored
Revert "Add observatory Bonjour service to built iOS Info.plist bundle (flutter#64988)" (flutter#65109)
This reverts commit 4fde217.
1 parent 237c0ab commit cb81950

File tree

5 files changed

+97
-323
lines changed

5 files changed

+97
-323
lines changed

dev/devicelab/bin/tasks/ios_content_validation_test.dart

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'package:path/path.dart' as path;
1414
Future<void> main() async {
1515
await task(() async {
1616
try {
17+
bool foundProjectName = false;
18+
bool bitcode = false;
1719
await runProjectTest((FlutterProject flutterProject) async {
1820
section('Build app with with --obfuscate');
1921
await inDirectory(flutterProject.rootPath, () async {
@@ -50,13 +52,6 @@ Future<void> main() async {
5052
fail('Failed to produce expected output at ${outputAppFrameworkBinary.path}');
5153
}
5254

53-
if (await dartObservatoryBonjourServiceFound(outputAppPath)) {
54-
throw TaskResult.failure('Release bundle has unexpected NSBonjourServices');
55-
}
56-
if (await localNetworkUsageFound(outputAppPath)) {
57-
throw TaskResult.failure('Release bundle has unexpected NSLocalNetworkUsageDescription');
58-
}
59-
6055
section('Validate obfuscation');
6156

6257
// Verify that an identifier from the Dart project code is not present
@@ -68,11 +63,11 @@ Future<void> main() async {
6863
canFail: true,
6964
);
7065
if (response.trim().contains('matches')) {
71-
throw TaskResult.failure('Found project name in obfuscated dart library');
66+
foundProjectName = true;
7267
}
7368
});
7469

75-
section('Validate release contents');
70+
section('Validate bitcode');
7671

7772
final Directory outputFlutterFramework = Directory(path.join(
7873
flutterProject.rootPath,
@@ -88,13 +83,7 @@ Future<void> main() async {
8883
if (!outputFlutterFrameworkBinary.existsSync()) {
8984
fail('Failed to produce expected output at ${outputFlutterFrameworkBinary.path}');
9085
}
91-
92-
// Archiving should contain a bitcode blob, but not building in release.
93-
// This mimics Xcode behavior and present a developer from having to install a
94-
// 300+MB app to test devices.
95-
if (await containsBitcode(outputFlutterFrameworkBinary.path)) {
96-
throw TaskResult.failure('Bitcode present in Flutter.framework');
97-
}
86+
bitcode = await containsBitcode(outputFlutterFrameworkBinary.path);
9887

9988
section('Xcode backend script');
10089

@@ -112,7 +101,7 @@ Future<void> main() async {
112101
'xcode_backend.sh'
113102
);
114103

115-
// Simulate a common Xcode build setting misconfiguration
104+
// Simulate a commonly Xcode build setting misconfiguration
116105
// where FLUTTER_APPLICATION_PATH is missing
117106
final int result = await exec(
118107
xcodeBackendPath,
@@ -122,7 +111,6 @@ Future<void> main() async {
122111
'TARGET_BUILD_DIR': buildPath,
123112
'FRAMEWORKS_FOLDER_PATH': 'Runner.app/Frameworks',
124113
'VERBOSE_SCRIPT_LOGGING': '1',
125-
'FLUTTER_BUILD_MODE': 'release',
126114
'ACTION': 'install', // Skip bitcode stripping since we just checked that above.
127115
},
128116
);
@@ -138,36 +126,18 @@ Future<void> main() async {
138126
if (!outputAppFrameworkBinary.existsSync()) {
139127
fail('Failed to re-embed ${outputAppFrameworkBinary.path}');
140128
}
141-
142-
section('Clean build');
143-
144-
await inDirectory(flutterProject.rootPath, () async {
145-
await flutter('clean');
146-
});
147-
148-
section('Validate debug contents');
149-
150-
await inDirectory(flutterProject.rootPath, () async {
151-
await flutter('build', options: <String>[
152-
'ios',
153-
'--debug',
154-
'--no-codesign',
155-
]);
156-
});
157-
158-
// Debug should also not contain bitcode.
159-
if (await containsBitcode(outputFlutterFrameworkBinary.path)) {
160-
throw TaskResult.failure('Bitcode present in Flutter.framework');
161-
}
162-
163-
if (!await dartObservatoryBonjourServiceFound(outputAppPath)) {
164-
throw TaskResult.failure('Debug bundle is missing NSBonjourServices');
165-
}
166-
if (!await localNetworkUsageFound(outputAppPath)) {
167-
throw TaskResult.failure('Debug bundle is missing NSLocalNetworkUsageDescription');
168-
}
169129
});
170130

131+
if (foundProjectName) {
132+
return TaskResult.failure('Found project name in obfuscated dart library');
133+
}
134+
// Archiving should contain a bitcode blob, but not building in release.
135+
// This mimics Xcode behavior and present a developer from having to install a
136+
// 300+MB app to test devices.
137+
if (bitcode) {
138+
return TaskResult.failure('Bitcode present in Flutter.framework');
139+
}
140+
171141
return TaskResult.success(null);
172142
} on TaskResult catch (taskResult) {
173143
return taskResult;

dev/devicelab/lib/framework/ios.dart

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import 'dart:async';
66
import 'dart:convert';
77

8-
import 'package:path/path.dart' as path;
9-
108
import 'utils.dart';
119

1210
typedef SimulatorFunction = Future<void> Function(String deviceId);
@@ -104,40 +102,6 @@ Future<bool> containsBitcode(String pathToBinary) async {
104102
return !emptyBitcodeMarkerFound;
105103
}
106104

107-
Future<bool> dartObservatoryBonjourServiceFound(String appBundlePath) async =>
108-
(await eval(
109-
'plutil',
110-
<String>[
111-
'-extract',
112-
'NSBonjourServices',
113-
'xml1',
114-
'-o',
115-
'-',
116-
path.join(
117-
appBundlePath,
118-
'Info.plist',
119-
),
120-
],
121-
canFail: true,
122-
)).contains('_dartobservatory._tcp');
123-
124-
Future<bool> localNetworkUsageFound(String appBundlePath) async =>
125-
await exec(
126-
'plutil',
127-
<String>[
128-
'-extract',
129-
'NSLocalNetworkUsageDescription',
130-
'xml1',
131-
'-o',
132-
'-',
133-
path.join(
134-
appBundlePath,
135-
'Info.plist',
136-
),
137-
],
138-
canFail: true,
139-
) == 0;
140-
141105
/// Creates and boots a new simulator, passes the new simulator's identifier to
142106
/// `testFunction`.
143107
///

packages/flutter_tools/bin/xcode_backend.sh

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,6 @@ AssertExists() {
3838
return 0
3939
}
4040

41-
ParseFlutterBuildMode() {
42-
# Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
43-
# This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
44-
# they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
45-
local build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"
46-
47-
case "$build_mode" in
48-
*release*) build_mode="release";;
49-
*profile*) build_mode="profile";;
50-
*debug*) build_mode="debug";;
51-
*)
52-
EchoError "========================================================================"
53-
EchoError "ERROR: Unknown FLUTTER_BUILD_MODE: ${build_mode}."
54-
EchoError "Valid values are 'Debug', 'Profile', or 'Release' (case insensitive)."
55-
EchoError "This is controlled by the FLUTTER_BUILD_MODE environment variable."
56-
EchoError "If that is not set, the CONFIGURATION environment variable is used."
57-
EchoError ""
58-
EchoError "You can fix this by either adding an appropriately named build"
59-
EchoError "configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the"
60-
EchoError ".xcconfig file for the current build configuration (${CONFIGURATION})."
61-
EchoError "========================================================================"
62-
exit -1;;
63-
esac
64-
echo "${build_mode}"
65-
}
66-
6741
BuildApp() {
6842
local project_path="${SOURCE_ROOT}/.."
6943
if [[ -n "$FLUTTER_APPLICATION_PATH" ]]; then
@@ -98,12 +72,24 @@ BuildApp() {
9872
# Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
9973
# This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
10074
# they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
101-
local build_mode="$(ParseFlutterBuildMode)"
75+
local build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"
10276
local artifact_variant="unknown"
10377
case "$build_mode" in
104-
release ) artifact_variant="ios-release";;
105-
profile ) artifact_variant="ios-profile";;
106-
debug ) artifact_variant="ios";;
78+
*release*) build_mode="release"; artifact_variant="ios-release";;
79+
*profile*) build_mode="profile"; artifact_variant="ios-profile";;
80+
*debug*) build_mode="debug"; artifact_variant="ios";;
81+
*)
82+
EchoError "========================================================================"
83+
EchoError "ERROR: Unknown FLUTTER_BUILD_MODE: ${build_mode}."
84+
EchoError "Valid values are 'Debug', 'Profile', or 'Release' (case insensitive)."
85+
EchoError "This is controlled by the FLUTTER_BUILD_MODE environment variable."
86+
EchoError "If that is not set, the CONFIGURATION environment variable is used."
87+
EchoError ""
88+
EchoError "You can fix this by either adding an appropriately named build"
89+
EchoError "configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the"
90+
EchoError ".xcconfig file for the current build configuration (${CONFIGURATION})."
91+
EchoError "========================================================================"
92+
exit -1;;
10793
esac
10894

10995
# Warn the user if not archiving (ACTION=install) in release mode.
@@ -141,7 +127,7 @@ is set to release or run \"flutter build ios --release\", then re-run Archive fr
141127
fi
142128

143129
local bitcode_flag=""
144-
if [[ "$ENABLE_BITCODE" == "YES" ]]; then
130+
if [[ $ENABLE_BITCODE == "YES" ]]; then
145131
bitcode_flag="true"
146132
fi
147133

@@ -320,32 +306,6 @@ EmbedFlutterFrameworks() {
320306
RunCommand codesign --force --verbose --sign "${EXPANDED_CODE_SIGN_IDENTITY}" -- "${xcode_frameworks_dir}/App.framework/App"
321307
RunCommand codesign --force --verbose --sign "${EXPANDED_CODE_SIGN_IDENTITY}" -- "${xcode_frameworks_dir}/Flutter.framework/Flutter"
322308
fi
323-
324-
AddObservatoryBonjourService
325-
}
326-
327-
# Add the observatory publisher Bonjour service to the produced app bundle Info.plist.
328-
AddObservatoryBonjourService() {
329-
local build_mode="$(ParseFlutterBuildMode)"
330-
# Debug and profile only.
331-
if [[ "${build_mode}" == "release" ]]; then
332-
return
333-
fi
334-
local built_products_plist="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
335-
336-
# If there are already NSBonjourServices specified by the app (uncommon), insert the observatory service name to the existing list.
337-
if plutil -extract NSBonjourServices xml1 -o - "${built_products_plist}"; then
338-
RunCommand plutil -insert NSBonjourServices.0 -string "_dartobservatory._tcp" "${built_products_plist}"
339-
else
340-
# Otherwise, add the NSBonjourServices key and observatory service name.
341-
RunCommand plutil -insert NSBonjourServices -json "[\"_dartobservatory._tcp\"]" "${built_products_plist}"
342-
fi
343-
344-
# Don't override the local network description the Flutter app developer specified (uncommon).
345-
# This text will appear below the "Your app would like to find and connect to devices on your local network" permissions popup.
346-
if ! plutil -extract NSLocalNetworkUsageDescription xml1 -o - "${built_products_plist}"; then
347-
RunCommand plutil -insert NSLocalNetworkUsageDescription -string "Allow Flutter tools on your computer to connect and debug your application. This prompt will not appear on release builds." "${built_products_plist}"
348-
fi
349309
}
350310

351311
EmbedAndThinFrameworks() {
@@ -368,8 +328,5 @@ else
368328
EmbedFlutterFrameworks ;;
369329
"embed_and_thin")
370330
EmbedAndThinFrameworks ;;
371-
"test_observatory_bonjour_service")
372-
# Exposed for integration testing only.
373-
AddObservatoryBonjourService ;;
374331
esac
375332
fi
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_tools/src/base/io.dart';
6+
7+
import '../../src/common.dart';
8+
9+
const String xcodeBackendPath = 'bin/xcode_backend.sh';
10+
const String xcodeBackendErrorHeader = '========================================================================';
11+
12+
// Acceptable $CONFIGURATION/$FLUTTER_BUILD_MODE values should be debug, profile, or release
13+
const Map<String, String> unknownConfiguration = <String, String>{
14+
'CONFIGURATION': 'Custom',
15+
};
16+
17+
// $FLUTTER_BUILD_MODE will override $CONFIGURATION
18+
const Map<String, String> unknownFlutterBuildMode = <String, String>{
19+
'FLUTTER_BUILD_MODE': 'Custom',
20+
'CONFIGURATION': 'Debug',
21+
};
22+
23+
// Can't archive a non-release build.
24+
const Map<String, String> installWithoutRelease = <String, String>{
25+
'CONFIGURATION': 'Debug',
26+
'ACTION': 'install',
27+
};
28+
29+
// Can't use a debug engine build with a release build.
30+
const Map<String, String> localEngineDebugBuildModeRelease = <String, String>{
31+
'SOURCE_ROOT': '../../../examples/hello_world',
32+
'FLUTTER_ROOT': '../../..',
33+
'LOCAL_ENGINE': '/engine/src/out/ios_debug_unopt',
34+
'CONFIGURATION': 'Release',
35+
};
36+
37+
// Can't use a debug build with a profile engine.
38+
const Map<String, String> localEngineProfileBuildeModeRelease = <String, String>{
39+
'SOURCE_ROOT': '../../../examples/hello_world',
40+
'FLUTTER_ROOT': '../../..',
41+
'LOCAL_ENGINE': '/engine/src/out/ios_profile',
42+
'CONFIGURATION': 'Debug',
43+
'FLUTTER_BUILD_MODE': 'Debug',
44+
};
45+
46+
void main() {
47+
Future<void> expectXcodeBackendFails(Map<String, String> environment) async {
48+
final ProcessResult result = await Process.run(
49+
xcodeBackendPath,
50+
<String>['build'],
51+
environment: environment,
52+
);
53+
expect(result.stderr, startsWith(xcodeBackendErrorHeader));
54+
expect(result.exitCode, isNot(0));
55+
}
56+
57+
test('Xcode backend fails for on unsupported configuration combinations', () async {
58+
await expectXcodeBackendFails(unknownConfiguration);
59+
await expectXcodeBackendFails(unknownFlutterBuildMode);
60+
await expectXcodeBackendFails(installWithoutRelease);
61+
await expectXcodeBackendFails(localEngineDebugBuildModeRelease);
62+
await expectXcodeBackendFails(localEngineProfileBuildeModeRelease);
63+
}, skip: true); // https://github.com/flutter/flutter/issues/35707 (non-hermetic test requires precache to have run)
64+
}

0 commit comments

Comments
 (0)