Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .ci/scripts/create_all_packages_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ exclusions=("script/configs/exclude_all_packages_app.yaml")
# Add a wasm-specific exclusion file if "--wasm" is specified.
if [[ "$1" == "--wasm" ]]; then
exclusions+=",script/configs/exclude_all_packages_app_wasm.yaml"
shift 1
fi

# Delete ./all_packages if it exists already
rm -rf ./all_packages

dart ./script/tool/bin/flutter_plugin_tools.dart create-all-packages-app \
--output-dir=. --exclude "$exclusions"
--output-dir=. --exclude "$exclusions" "$@"
3 changes: 3 additions & 0 deletions .ci/targets/ios_build_all_packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ tasks:
infra_step: true
- name: create all_packages app
script: .ci/scripts/create_all_packages_app.sh
# build-examples builds with Swift Package Manager, so run build-all without
# it to test both modes in CI.
args: ["--no-swift-package-manager"]
infra_step: true # Note infra steps failing prevents "always" from running.
- name: build all_packages for iOS debug
script: .ci/scripts/build_all_packages_app.sh
Expand Down
3 changes: 3 additions & 0 deletions .ci/targets/macos_build_all_packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ tasks:
infra_step: true
- name: create all_packages app
script: .ci/scripts/create_all_packages_app.sh
# build-examples builds with Swift Package Manager, so run build-all without
# it to test both modes in CI.
args: ["--no-swift-package-manager"]
infra_step: true # Note infra steps failing prevents "always" from running.
- name: build all_packages for macOS debug
script: .ci/scripts/build_all_packages_app.sh
Expand Down
11 changes: 1 addition & 10 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,8 @@ class AnalyzeCommand extends PackageLoopingCommand {
final xcode = Xcode(processRunner: processRunner, log: true);
final errors = <String>[];
for (final RepositoryPackage example in package.getExamples()) {
// See https://github.com/flutter/flutter/issues/172427 for discussion of
// why this is currently necessary.
print('Disabling Swift Package Manager...');
setSwiftPackageManagerState(example, enabled: false);

// Unconditionally re-run build with --debug --config-only, to ensure that
// the project is in a debug state even if it was previously configured,
// and that SwiftPM is disabled.
// the project is in a debug state even if it was previously configured.
print('Running flutter build --config-only...');
final bool buildSuccess = await runConfigOnlyBuild(
example,
Expand Down Expand Up @@ -490,9 +484,6 @@ class AnalyzeCommand extends PackageLoopingCommand {
'${getRelativePosixPath(example.directory, from: package.directory)} failed analysis.',
);
}

print('Removing Swift Package Manager override...');
setSwiftPackageManagerState(example, enabled: null);
}
return errors.isEmpty
? PackageResult.success()
Expand Down
16 changes: 16 additions & 0 deletions script/tool/lib/src/create_all_packages_app_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'common/core.dart';
import 'common/file_utils.dart';
import 'common/output_utils.dart';
import 'common/package_command.dart';
import 'common/plugin_utils.dart';
import 'common/process_runner.dart';
import 'common/pub_utils.dart';
import 'common/repository_package.dart';
Expand Down Expand Up @@ -52,10 +53,18 @@ class CreateAllPackagesAppCommand extends PackageCommand {
'The replacement will be done before any tool-driven '
'modifications.',
);
argParser.addFlag(
_swiftPackageManagerFlag,
defaultsTo: null,
help:
'Explicitly sets the app-level flag for Swift Package Manager in '
'pubspec.yaml.',
);
}

static const String _legacySourceFlag = 'legacy-source';
static const String _outputDirectoryFlag = 'output-dir';
static const String _swiftPackageManagerFlag = 'swift-package-manager';

/// The location to create the synthesized app project.
Directory get _appDirectory => packagesDir.fileSystem
Expand Down Expand Up @@ -121,6 +130,13 @@ class CreateAllPackagesAppCommand extends PackageCommand {
// flutter pub get above, so can't currently be run on Windows.
if (!platform.isWindows) _updateMacosPodfile(),
]);

final bool? swiftPackageManagerOverride = getNullableBoolArg(
_swiftPackageManagerFlag,
);
if (swiftPackageManagerOverride != null) {
setSwiftPackageManagerState(app, enabled: swiftPackageManagerOverride);
}
}

Future<int> _createApp() async {
Expand Down
41 changes: 0 additions & 41 deletions script/tool/test/analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1093,47 +1093,6 @@ packages/package_a/lib/foo.dart
});

group('Xcode analyze', () {
test('temporarily disables Swift Package Manager', () async {
final RepositoryPackage plugin = createFakePlugin(
'plugin',
packagesDir,
platformSupport: <String, PlatformDetails>{
platformIOS: const PlatformDetails(PlatformSupport.inline),
},
);

final RepositoryPackage example = plugin.getExamples().first;
final String originalPubspecContents = example.pubspecFile
.readAsStringSync();
String? buildTimePubspecContents;
processRunner.mockProcessesForExecutable['xcrun'] = <FakeProcessInfo>[
FakeProcessInfo(MockProcess(), <String>[], () {
buildTimePubspecContents = example.pubspecFile.readAsStringSync();
}),
];

await runCapturingPrint(runner, <String>[
'analyze',
'--no-dart',
'--ios',
]);

// Ensure that SwiftPM was disabled for the package.
expect(
originalPubspecContents,
isNot(contains('enable-swift-package-manager: false')),
);
expect(
buildTimePubspecContents,
contains('enable-swift-package-manager: false'),
);
// And that it was undone after.
expect(
example.pubspecFile.readAsStringSync().trim(),
originalPubspecContents.trim(),
);
});

group('iOS', () {
test('skip if iOS is not supported', () async {
createFakePlugin(
Expand Down
29 changes: 29 additions & 0 deletions script/tool/test/create_all_packages_app_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter_plugin_tools/src/create_all_packages_app_command.dart';
import 'package:platform/platform.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';

import 'mocks.dart';
import 'util.dart';
Expand Down Expand Up @@ -496,6 +497,34 @@ android {
);
});

test('disables Swift Package Manager if requested', () async {
writeFakeFlutterCreateOutput(testRoot);
createFakePlugin('plugina', packagesDir);

await runCapturingPrint(runner, <String>[
'create-all-packages-app',
'--no-swift-package-manager',
]);

final Pubspec pubspec = command.app.parsePubspec();
final flutterConfig = pubspec.flutter?['config'] as YamlMap?;
expect(flutterConfig?['enable-swift-package-manager'], false);
});

test('enables Swift Package Manager if requested', () async {
writeFakeFlutterCreateOutput(testRoot);
createFakePlugin('plugina', packagesDir);

await runCapturingPrint(runner, <String>[
'create-all-packages-app',
'--swift-package-manager',
]);

final Pubspec pubspec = command.app.parsePubspec();
final flutterConfig = pubspec.flutter?['config'] as YamlMap?;
expect(flutterConfig?['enable-swift-package-manager'], true);
});
Comment on lines +500 to +526
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two tests are very similar and contain duplicated setup code. To improve readability and reduce duplication, you could group them under a group and use a setUp block for the common initialization.

    group('Swift Package Manager flag', () {
      setUp(() {
        writeFakeFlutterCreateOutput(testRoot);
        createFakePlugin('plugina', packagesDir);
      });

      test('disables if requested', () async {
        await runCapturingPrint(runner, <String>[
          'create-all-packages-app',
          '--no-swift-package-manager',
        ]);

        final Pubspec pubspec = command.app.parsePubspec();
        final flutterConfig = pubspec.flutter?['config'] as YamlMap?;
        expect(flutterConfig?['enable-swift-package-manager'], false);
      });

      test('enables if requested', () async {
        await runCapturingPrint(runner, <String>[
          'create-all-packages-app',
          '--swift-package-manager',
        ]);

        final Pubspec pubspec = command.app.parsePubspec();
        final flutterConfig = pubspec.flutter?['config'] as YamlMap?;
        expect(flutterConfig?['enable-swift-package-manager'], true);
      });
    });


test('calls flutter pub get', () async {
writeFakeFlutterCreateOutput(testRoot);
createFakePlugin('plugina', packagesDir);
Expand Down
Loading