Skip to content

Commit

Permalink
Makes scheme and target optional parameter when getting universal lin…
Browse files Browse the repository at this point in the history
…… (#134571)

�k settings

the show build settings xcode command can only accept one of the target or scheme flag. Therefore I make them optional.
  • Loading branch information
chunhtai authored Sep 15, 2023
1 parent f629dc8 commit 367203b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
15 changes: 1 addition & 14 deletions packages/flutter_tools/lib/src/commands/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class AnalyzeCommand extends FlutterCommand {
argParser.addFlag('output-universal-link-settings',
negatable: false,
help: 'Output a JSON with iOS Xcode universal link settings into a file. '
'The "--configuration", "--scheme", and "--target" must also be set.',
'The "--configuration" and "--target" must be set.',
hide: !verboseHelp,
);

Expand All @@ -162,12 +162,6 @@ class AnalyzeCommand extends FlutterCommand {
hide: !verboseHelp,
);

argParser.addOption('scheme',
help: 'Sets the iOS build scheme to be analyzed.',
valueHelp: 'scheme',
hide: !verboseHelp,
);

argParser.addOption('target',
help: 'Sets the iOS build target to be analyzed.',
valueHelp: 'target',
Expand Down Expand Up @@ -264,15 +258,13 @@ class AnalyzeCommand extends FlutterCommand {
final IOSAnalyzeOption option;
final String? configuration;
final String? target;
final String? scheme;
if (argResults!['list-build-options'] as bool && argResults!['output-universal-link-settings'] as bool) {
throwToolExit('Only one of "--list-build-options" or "--output-universal-link-settings" can be provided');
}
if (argResults!['list-build-options'] as bool) {
option = IOSAnalyzeOption.listBuildOptions;
configuration = null;
target = null;
scheme = null;
} else if (argResults!['output-universal-link-settings'] as bool) {
option = IOSAnalyzeOption.outputUniversalLinkSettings;
configuration = argResults!['configuration'] as String?;
Expand All @@ -283,10 +275,6 @@ class AnalyzeCommand extends FlutterCommand {
if (target == null) {
throwToolExit('"--target" must be provided');
}
scheme = argResults!['scheme'] as String?;
if (scheme == null) {
throwToolExit('"--scheme" must be provided');
}
} else {
throwToolExit('No argument is provided to analyze. Use -h to see available commands.');
}
Expand All @@ -304,7 +292,6 @@ class AnalyzeCommand extends FlutterCommand {
option: option,
configuration: configuration,
target: target,
scheme: scheme,
logger: _logger,
).analyze();
} else if (boolArg('suggestions')) {
Expand Down
13 changes: 6 additions & 7 deletions packages/flutter_tools/lib/src/commands/ios_analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum IOSAnalyzeOption {
///
/// An example output:
///
/// {"configurations":["Debug","Release","Profile"],"schemes":["Runner"],"targets":["Runner","RunnerTests"]}
/// {"configurations":["Debug","Release","Profile"],"targets":["Runner","RunnerTests"]}
listBuildOptions,

/// Outputs universal link settings of the iOS Xcode sub-project into a file.
Expand All @@ -32,16 +32,14 @@ class IOSAnalyze {
required this.project,
required this.option,
this.configuration,
this.scheme,
this.target,
required this.logger,
}) : assert(option == IOSAnalyzeOption.listBuildOptions ||
(configuration != null && scheme != null && target != null));
(configuration != null && target != null));

final FlutterProject project;
final IOSAnalyzeOption option;
final String? configuration;
final String? scheme;
final String? target;
final Logger logger;

Expand All @@ -55,14 +53,15 @@ class IOSAnalyze {
} else {
result = <String, List<String>>{
'configurations': info.buildConfigurations,
'schemes': info.schemes,
'targets': info.targets,
};
}
logger.printStatus(jsonEncode(result));
case IOSAnalyzeOption.outputUniversalLinkSettings:
await project.ios.outputsUniversalLinkSettings(configuration: configuration!, scheme: scheme!, target: target!);
final String filePath = await project.ios.outputsUniversalLinkSettings(configuration: configuration!, scheme: scheme!, target: target!);
final String filePath = await project.ios.outputsUniversalLinkSettings(
configuration: configuration!,
target: target!,
);
logger.printStatus('result saved in $filePath');
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/flutter_tools/lib/src/xcode_project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,17 @@ class IosProject extends XcodeBasedProject {
/// The return future will resolve to string path to the output file.
Future<String> outputsUniversalLinkSettings({
required String configuration,
required String scheme,
required String target,
}) async {
final XcodeProjectBuildContext context = XcodeProjectBuildContext(
configuration: configuration,
scheme: scheme,
target: target,
);
final File file = await parent.buildDirectory
.childDirectory('deeplink_data')
.childFile('universal-link-settings-$configuration-$scheme-$target.json')
.childFile('universal-link-settings-$configuration-$target.json')
.create(recursive: true);

await file.writeAsString(jsonEncode(<String, Object?>{
'bundleIdentifier': await _productBundleIdentifierWithBuildContext(context),
'teamIdentifier': await _getTeamIdentifier(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,18 @@ void main() {
final MockIosProject ios = MockIosProject();
final MockFlutterProject project = MockFlutterProject(ios);
const String expectedConfig = 'someConfig';
const String expectedScheme = 'someScheme';
const String expectedTarget = 'someConfig';
const String expectedTarget = 'someTarget';
const String expectedOutputFile = '/someFile';
ios.outputFileLocation = expectedOutputFile;
await IOSAnalyze(
project: project,
option: IOSAnalyzeOption.outputUniversalLinkSettings,
configuration: expectedConfig,
scheme: expectedScheme,
target: expectedTarget,
logger: logger,
).analyze();
expect(logger.statusText, contains(expectedOutputFile));
expect(ios.outputConfiguration, expectedConfig);
expect(ios.outputScheme, expectedScheme);
expect(ios.outputTarget, expectedTarget);
});

Expand All @@ -91,8 +88,7 @@ void main() {
final MockFlutterProject project = MockFlutterProject(ios);
const List<String> targets = <String>['target1', 'target2'];
const List<String> configs = <String>['config1', 'config2'];
const List<String> schemes = <String>['scheme1', 'scheme2'];
ios.expectedProjectInfo = XcodeProjectInfo(targets, configs, schemes, logger);
ios.expectedProjectInfo = XcodeProjectInfo(targets, configs, const <String>[], logger);
await IOSAnalyze(
project: project,
option: IOSAnalyzeOption.listBuildOptions,
Expand All @@ -101,7 +97,6 @@ void main() {
final Map<String, Object?> jsonOutput = jsonDecode(logger.statusText) as Map<String, Object?>;
expect(jsonOutput['targets'], unorderedEquals(targets));
expect(jsonOutput['configurations'], unorderedEquals(configs));
expect(jsonOutput['schemes'], unorderedEquals(schemes));
});

testUsingContext('throws if provide multiple path', () async {
Expand Down Expand Up @@ -144,15 +139,13 @@ class MockFlutterProject extends Fake implements FlutterProject {

class MockIosProject extends Fake implements IosProject {
String? outputConfiguration;
String? outputScheme;
String? outputTarget;
late String outputFileLocation;
late XcodeProjectInfo expectedProjectInfo;

@override
Future<String> outputsUniversalLinkSettings({required String configuration, required String scheme, required String target}) async {
Future<String> outputsUniversalLinkSettings({required String configuration, required String target}) async {
outputConfiguration = configuration;
outputScheme = scheme;
outputTarget = target;
return outputFileLocation;
}
Expand Down
6 changes: 0 additions & 6 deletions packages/flutter_tools/test/general.shard/project_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ apply plugin: 'kotlin-android'

const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(
target: 'Runner',
scheme: 'Debug',
configuration: 'config',
);
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
Expand All @@ -753,7 +752,6 @@ apply plugin: 'kotlin-android'
);
final String outputFilePath = await project.ios.outputsUniversalLinkSettings(
target: 'Runner',
scheme: 'Debug',
configuration: 'config',
);
final File outputFile = fs.file(outputFilePath);
Expand Down Expand Up @@ -781,7 +779,6 @@ apply plugin: 'kotlin-android'

const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(
target: 'Runner',
scheme: 'Debug',
configuration: 'config',
);
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
Expand All @@ -802,7 +799,6 @@ apply plugin: 'kotlin-android'

final String outputFilePath = await project.ios.outputsUniversalLinkSettings(
target: 'Runner',
scheme: 'Debug',
configuration: 'config',
);
final File outputFile = fs.file(outputFilePath);
Expand All @@ -827,7 +823,6 @@ apply plugin: 'kotlin-android'

const XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(
target: 'Runner',
scheme: 'Debug',
configuration: 'config',
);
xcodeProjectInterpreter.buildSettingsByBuildContext[buildContext] = <String, String>{
Expand All @@ -838,7 +833,6 @@ apply plugin: 'kotlin-android'
testPlistUtils.setProperty(PlistParser.kCFBundleIdentifierKey, r'$(PRODUCT_BUNDLE_IDENTIFIER)');
final String outputFilePath = await project.ios.outputsUniversalLinkSettings(
target: 'Runner',
scheme: 'Debug',
configuration: 'config',
);
final File outputFile = fs.file(outputFilePath);
Expand Down

0 comments on commit 367203b

Please sign in to comment.