Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions packages/flutter_tools/bin/xcode_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ class Context {

final String buildMode = parseFlutterBuildMode();

_validateBuildMode(platform, buildMode);

final List<String> flutterArgs = _generateFlutterArgsForAssemble(
command: 'build',
buildMode: buildMode,
Expand Down Expand Up @@ -570,53 +568,6 @@ class Context {
echo('Project $projectPath built and packaged successfully.');
}

/// Validate that the build mode targeted matches the build mode set by the
/// Flutter CLI.
/// If it doesn't match, print a warning unless the Xcode action is `install`,
/// which means the app is being archived for distribution. In that case, print
/// an error and fail the build.
///
/// The targeted build mode might not match the one set by Flutter CLI when it
/// is changed and ran directly through Xcode.
///
/// Flutter may change settings or files depending on the build mode. For
/// example, dev dependencies are excluded from release builds and requires
/// the Flutter CLI to update certain files.
void _validateBuildMode(TargetPlatform platform, String currentBuildMode) {
final String? buildModeCLILastUsed = environment['FLUTTER_CLI_BUILD_MODE'];

// Also fail the build if ACTION=install, which indicates the app is being
// built for distribution.
final String? action = environment['ACTION'];
final fatal = action == 'install';

if (buildModeCLILastUsed == null) {
final message =
'Your Flutter build settings are outdated. Please run '
'"flutter build ${platform.name} --config-only --$currentBuildMode" in your Flutter '
'project and try again.\n';
if (fatal) {
echoXcodeError(message);
exitApp(-1);
} else {
echoXcodeWarning(message);
return;
}
}
if (currentBuildMode != buildModeCLILastUsed) {
final message =
'Your Flutter project is currently configured for $buildModeCLILastUsed mode. '
'Please run `flutter build ${platform.name} --config-only --$currentBuildMode` '
'in your Flutter project to update your settings.\n';
if (fatal) {
echoXcodeError(message);
exitApp(-1);
} else {
echoXcodeWarning(message);
}
}
}

List<String> _generateFlutterArgsForAssemble({
required String command,
required String buildMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ Future<List<String>> _xcodeBuildSettingsLines({
parsedBuildNumber(manifest: project.manifest, buildInfo: buildInfo) ?? '1';
xcodeBuildSettings.add('FLUTTER_BUILD_NUMBER=$buildNumber');

// The current build mode being targeted.
xcodeBuildSettings.add('FLUTTER_CLI_BUILD_MODE=${buildInfo.mode.cliName}');

// CoreDevices in debug and profile mode are launched, but not built, via Xcode.
// Set the CONFIGURATION_BUILD_DIR so Xcode knows where to find the app
// bundle to launch.
Expand Down
139 changes: 0 additions & 139 deletions packages/flutter_tools/test/general.shard/xcode_backend_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void main() {
'CONFIGURATION': buildMode,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -191,7 +190,6 @@ void main() {
'TREE_SHAKE_ICONS': treeShake,
'SRCROOT': srcRoot,
'TARGET_DEVICE_OS_VERSION': iOSVersion,
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -234,137 +232,6 @@ void main() {
expect(context.stdout, contains('built and packaged successfully.'));
expect(context.stderr, isEmpty);
});

test(
'exits with useful error message when missing FLUTTER_CLI_BUILD_MODE during archive',
() {
final Directory buildDir = fileSystem.directory('/path/to/builds')
..createSync(recursive: true);
final Directory flutterRoot = fileSystem.directory('/path/to/flutter')
..createSync(recursive: true);

const buildMode = 'Release';

final context = TestContext(
<String>['build', platformName],
<String, String>{
'ACTION': 'install',
'CONFIGURATION': buildMode,
'BUILT_PRODUCTS_DIR': buildDir.path,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
},
commands: <FakeCommand>[],
fileSystem: fileSystem,
);
expect(() => context.run(), throwsException);
expect(
context.stderr,
contains(
'error: Your Flutter build settings are outdated. '
'Please run "flutter build ${platform.name} --config-only --release" '
'in your Flutter project and try again.',
),
);
},
);

test('exits with useful error message when build mode mismatches during archive', () {
final Directory buildDir = fileSystem.directory('/path/to/builds')
..createSync(recursive: true);
final Directory flutterRoot = fileSystem.directory('/path/to/flutter')
..createSync(recursive: true);

const buildMode = 'Release';

final context = TestContext(
<String>['build', platformName],
<String, String>{
'ACTION': 'install',
'CONFIGURATION': buildMode,
'BUILT_PRODUCTS_DIR': buildDir.path,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
'FLUTTER_CLI_BUILD_MODE': 'debug',
},
commands: <FakeCommand>[],
fileSystem: fileSystem,
);
expect(() => context.run(), throwsException);
expect(
context.stderr,
contains(
'error: Your Flutter project is currently configured for debug mode. '
'Please run `flutter build ${platform.name} --config-only --release` '
'in your Flutter project to update your settings.',
),
);
});

test('prints useful warning message when missing FLUTTER_CLI_BUILD_MODE', () {
final Directory buildDir = fileSystem.directory('/path/to/builds')
..createSync(recursive: true);
final Directory flutterRoot = fileSystem.directory('/path/to/flutter')
..createSync(recursive: true);

const buildMode = 'Release';

final context = TestContext(
<String>['build', platformName],
<String, String>{
'ACTION': 'build',
'CONFIGURATION': buildMode,
'BUILT_PRODUCTS_DIR': buildDir.path,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
},
commands: <FakeCommand>[],
fileSystem: fileSystem,
fakeProcessManager: FakeProcessManager.any(),
);
context.run();
expect(
context.stderr,
contains(
'warning: Your Flutter build settings are outdated. '
'Please run "flutter build ${platform.name} --config-only --release" '
'in your Flutter project and try again.',
),
);
});

test('prints useful warning message when build mode mismatches', () {
final Directory buildDir = fileSystem.directory('/path/to/builds')
..createSync(recursive: true);
final Directory flutterRoot = fileSystem.directory('/path/to/flutter')
..createSync(recursive: true);

const buildMode = 'Release';

final context = TestContext(
<String>['build', platformName],
<String, String>{
'ACTION': 'debug',
'CONFIGURATION': buildMode,
'BUILT_PRODUCTS_DIR': buildDir.path,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
'FLUTTER_CLI_BUILD_MODE': 'debug',
},
commands: <FakeCommand>[],
fileSystem: fileSystem,
fakeProcessManager: FakeProcessManager.any(),
);
context.run();
expect(
context.stderr,
contains(
'warning: Your Flutter project is currently configured for debug mode. '
'Please run `flutter build ${platform.name} --config-only --release` '
'in your Flutter project to update your settings.',
),
);
});
});
}

Expand Down Expand Up @@ -557,7 +424,6 @@ void main() {
'BUILT_PRODUCTS_DIR': buildDir.path,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -609,7 +475,6 @@ void main() {
'CONFIGURATION': buildMode,
'FLUTTER_ROOT': flutterRoot.path,
'INFOPLIST_PATH': 'Info.plist',
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -689,7 +554,6 @@ void main() {
'TREE_SHAKE_ICONS': treeShake,
'SRCROOT': srcRoot,
'TARGET_DEVICE_OS_VERSION': iOSVersion,
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -747,7 +611,6 @@ void main() {
'ARCHS': 'arm64 x86_64',
'ONLY_ACTIVE_ARCH': 'YES',
'NATIVE_ARCH': 'arm64e',
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -802,7 +665,6 @@ void main() {
'ARCHS': 'arm64',
'ONLY_ACTIVE_ARCH': 'YES',
'NATIVE_ARCH': 'x86_64',
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down Expand Up @@ -856,7 +718,6 @@ void main() {
'INFOPLIST_PATH': 'Info.plist',
'ARCHS': 'arm64 x86_64',
'NATIVE_ARCH': 'arm64e',
'FLUTTER_CLI_BUILD_MODE': buildMode.toLowerCase(),
},
commands: <FakeCommand>[
FakeCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ void main() {
await expectXcodeBackendFails(unknownFlutterBuildMode);
}, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain.

test('Xcode backend warns archiving a non-release build.', () async {
final ProcessResult result = await Process.run(
xcodeBackendPath,
<String>['build'],
environment: <String, String>{
'CONFIGURATION': 'Debug',
'ACTION': 'install',
'FLUTTER_CLI_BUILD_MODE': 'debug',
},
);
expect(result.stderr, contains('warning: Flutter archive not built in Release mode.'));
expect(result.exitCode, isNot(0));
}, skip: !io.Platform.isMacOS); // [intended] requires macos toolchain.

test('Xcode backend warns when unable to determine platform', () async {
final ProcessResult result = await Process.run(
xcodeBackendPath,
Expand Down