Skip to content

Commit 08925b3

Browse files
committed
Revert "Disable SwiftPM for xcode-analyze"
This reverts commit 93d8db1.
1 parent 7cfb4fc commit 08925b3

File tree

6 files changed

+230
-207
lines changed

6 files changed

+230
-207
lines changed

script/tool/lib/src/build_examples_command.dart

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,20 @@ class BuildExamplesCommand extends PackageLoopingCommand {
118118
'arguments.';
119119

120120
/// Returns whether the Swift Package Manager feature should be enabled,
121-
/// disabled, or left to the default value.
121+
/// disabled, or left to the release channel's default value.
122122
bool? get _swiftPackageManagerFeatureConfig {
123123
final List<String> platformFlags = _platforms.keys.toList();
124124
if (!platformFlags.contains(platformIOS) &&
125125
!platformFlags.contains(platformMacOS)) {
126126
return null;
127127
}
128128

129+
// TODO(loic-sharma): Allow enabling on stable once Swift Package Manager
130+
// feature is available on stable.
131+
if (platform.environment['CHANNEL'] != 'master') {
132+
return null;
133+
}
134+
129135
return getNullableBoolArg(_swiftPackageManagerFlag);
130136
}
131137

@@ -144,6 +150,23 @@ class BuildExamplesCommand extends PackageLoopingCommand {
144150
'were specified. At least one platform must be provided.');
145151
throw ToolExit(_exitNoPlatformFlags);
146152
}
153+
154+
switch (_swiftPackageManagerFeatureConfig) {
155+
case true:
156+
await processRunner.runAndStream(
157+
flutterCommand,
158+
<String>['config', '--enable-swift-package-manager'],
159+
exitOnError: true,
160+
);
161+
case false:
162+
await processRunner.runAndStream(
163+
flutterCommand,
164+
<String>['config', '--no-enable-swift-package-manager'],
165+
exitOnError: true,
166+
);
167+
case null:
168+
break;
169+
}
147170
}
148171

149172
@override
@@ -189,20 +212,8 @@ class BuildExamplesCommand extends PackageLoopingCommand {
189212
}
190213
print('');
191214

192-
final bool? swiftPackageManagerOverride =
193-
isPlugin ? _swiftPackageManagerFeatureConfig : null;
194-
195215
bool builtSomething = false;
196216
for (final RepositoryPackage example in package.getExamples()) {
197-
// Rather than changing global config state, enable SwiftPM via a
198-
// temporary package-level override.
199-
if (swiftPackageManagerOverride != null) {
200-
print('Overriding enable-swift-package-manager to '
201-
'$swiftPackageManagerOverride');
202-
setSwiftPackageManagerState(example,
203-
enabled: swiftPackageManagerOverride);
204-
}
205-
206217
final String packageName =
207218
getRelativePosixPath(example.directory, from: packagesDir);
208219

@@ -229,12 +240,6 @@ class BuildExamplesCommand extends PackageLoopingCommand {
229240
errors.add('$packageName (${platform.label})');
230241
}
231242
}
232-
233-
// If an override was added, remove it.
234-
if (swiftPackageManagerOverride != null) {
235-
print('Removing enable-swift-package-manager override');
236-
setSwiftPackageManagerState(example, enabled: null);
237-
}
238243
}
239244

240245
if (!builtSomething) {

script/tool/lib/src/common/plugin_utils.dart

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
import 'package:yaml/yaml.dart';
6-
import 'package:yaml_edit/yaml_edit.dart';
76

87
import 'core.dart';
98
import 'repository_package.dart';
@@ -84,57 +83,6 @@ bool pluginHasNativeCodeForPlatform(String platform, RepositoryPackage plugin) {
8483
return pluginClass != null && pluginClass != 'none';
8584
}
8685

87-
/// Adds or removes a package-level Swift Package Manager override to the given
88-
/// package.
89-
///
90-
/// A null enabled state clears the package-local override, defaulting to whatever the
91-
/// global state is.
92-
void setSwiftPackageManagerState(RepositoryPackage package,
93-
{required bool? enabled}) {
94-
const String swiftPMFlag = 'enable-swift-package-manager';
95-
const String flutterKey = 'flutter';
96-
const List<String> flutterPath = <String>[flutterKey];
97-
const List<String> configPath = <String>[flutterKey, 'config'];
98-
99-
final YamlEditor editablePubspec =
100-
YamlEditor(package.pubspecFile.readAsStringSync());
101-
final YamlMap configMap =
102-
editablePubspec.parseAt(configPath, orElse: () => YamlMap()) as YamlMap;
103-
if (enabled == null) {
104-
if (!configMap.containsKey(swiftPMFlag)) {
105-
// Nothing to do.
106-
return;
107-
} else if (configMap.length == 1) {
108-
// The config section only exists for this override, so remove the whole
109-
// section.
110-
editablePubspec.remove(configPath);
111-
// The entire flutter: section may also only have been added for the
112-
// config, in which case it should be removed as well.
113-
final YamlMap flutterMap = editablePubspec.parseAt(flutterPath,
114-
orElse: () => YamlMap()) as YamlMap;
115-
if (flutterMap.isEmpty) {
116-
editablePubspec.remove(flutterPath);
117-
}
118-
} else {
119-
// Remove the specific entry, leaving the rest of the config section.
120-
editablePubspec.remove(<String>[...configPath, swiftPMFlag]);
121-
}
122-
} else {
123-
// Ensure that the section exists.
124-
if (configMap.isEmpty) {
125-
final YamlMap root = editablePubspec.parseAt(<String>[]) as YamlMap;
126-
if (!root.containsKey(flutterKey)) {
127-
editablePubspec.update(flutterPath, YamlMap());
128-
}
129-
editablePubspec.update(configPath, YamlMap());
130-
}
131-
// Then add the flag.
132-
editablePubspec.update(<String>[...configPath, swiftPMFlag], enabled);
133-
}
134-
135-
package.pubspecFile.writeAsStringSync(editablePubspec.toString());
136-
}
137-
13886
/// Returns the
13987
/// flutter:
14088
/// plugin:

script/tool/lib/src/xcode_analyze_command.dart

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,8 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
121121
targetPlatform == FlutterPlatform.ios ? 'iOS' : 'macOS';
122122
bool passing = true;
123123
for (final RepositoryPackage example in plugin.getExamples()) {
124-
// See https://github.com/flutter/flutter/issues/172427 for discussion of
125-
// why this is currently necessary.
126-
print('Disabling Swift Package Manager...');
127-
setSwiftPackageManagerState(example, enabled: false);
128-
129124
// Unconditionally re-run build with --debug --config-only, to ensure that
130-
// the project is in a debug state even if it was previously configured,
131-
// and that SwiftPM is disabled.
125+
// the project is in a debug state even if it was previously configured.
132126
print('Running flutter build --config-only...');
133127
final bool buildSuccess = await runConfigOnlyBuild(
134128
example,
@@ -168,9 +162,6 @@ class XcodeAnalyzeCommand extends PackageLoopingCommand {
168162
printError('$examplePath ($platformString) failed analysis.');
169163
passing = false;
170164
}
171-
172-
print('Removing Swift Package Manager override...');
173-
setSwiftPackageManagerState(example, enabled: null);
174165
}
175166
return passing;
176167
}

0 commit comments

Comments
 (0)