Add ios analyzer command for universal links (#134155)

ios version of https://github.com/flutter/flutter/pull/131009/files
This commit is contained in:
chunhtai
2023-09-08 12:22:44 -07:00
committed by GitHub
parent 2f66f25f34
commit f851e7faf0
5 changed files with 327 additions and 7 deletions

View File

@@ -11,12 +11,14 @@ import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/platform.dart';
import '../base/terminal.dart';
import '../project.dart';
import '../project_validator.dart';
import '../runner/flutter_command.dart';
import 'analyze_base.dart';
import 'analyze_continuously.dart';
import 'analyze_once.dart';
import 'android_analyze.dart';
import 'ios_analyze.dart';
import 'validate_project.dart';
class AnalyzeCommand extends FlutterCommand {
@@ -107,6 +109,12 @@ class AnalyzeCommand extends FlutterCommand {
hide: !verboseHelp,
);
argParser.addFlag('ios',
negatable: false,
help: 'Analyze iOS Xcode sub-project. Used by internal tools only.',
hide: !verboseHelp,
);
if (verboseHelp) {
argParser.addSeparator('Usage: flutter analyze --android [arguments]');
}
@@ -127,8 +135,42 @@ class AnalyzeCommand extends FlutterCommand {
argParser.addOption('build-variant',
help: 'Sets the Android build variant to be analyzed.',
valueHelp: 'use "flutter analyze --android --list-build-variants" to get '
'all available build variants',
valueHelp: 'build variant',
hide: !verboseHelp,
);
if (verboseHelp) {
argParser.addSeparator('Usage: flutter analyze --ios [arguments]');
}
argParser.addFlag('list-build-options',
help: 'Print out a list of available build options for the '
'iOS Xcode sub-project.',
hide: !verboseHelp,
);
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.',
hide: !verboseHelp,
);
argParser.addOption('configuration',
help: 'Sets the iOS build configuration to be analyzed.',
valueHelp: 'configuration',
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',
hide: !verboseHelp,
);
}
@@ -218,6 +260,53 @@ class AnalyzeCommand extends FlutterCommand {
buildVariant: buildVariant,
logger: _logger,
).analyze();
} else if (boolArg('ios')) {
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?;
if (configuration == null) {
throwToolExit('"--configuration" must be provided');
}
target = argResults!['target'] as String?;
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.');
}
final Set<String> items = findDirectories(argResults!, _fileSystem);
final String directoryPath;
if (items.isEmpty) { // user did not specify any path
directoryPath = _fileSystem.currentDirectory.path;
} else if (items.length > 1) { // if the user sends more than one path
throwToolExit('The iOS analyze can process only one directory path');
} else {
directoryPath = items.first;
}
await IOSAnalyze(
project: FlutterProject.fromDirectory(_fileSystem.directory(directoryPath)),
option: option,
configuration: configuration,
target: target,
scheme: scheme,
logger: _logger,
).analyze();
} else if (boolArg('suggestions')) {
final String directoryPath;
if (boolArg('watch')) {

View File

@@ -0,0 +1,69 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import '../base/logger.dart';
import '../convert.dart';
import '../ios/xcodeproj.dart';
import '../project.dart';
/// The type of analysis to perform.
enum IOSAnalyzeOption {
/// Prints out available build variants of the iOS Xcode sub-project.
///
/// An example output:
///
/// {"configurations":["Debug","Release","Profile"],"schemes":["Runner"],"targets":["Runner","RunnerTests"]}
listBuildOptions,
/// Outputs universal link settings of the iOS Xcode sub-project into a file.
///
/// The file path will be printed after the command is run successfully.
outputUniversalLinkSettings,
}
/// Analyze the iOS Xcode sub-project of a Flutter project.
///
/// The [userPath] must be point to a flutter project.
class IOSAnalyze {
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));
final FlutterProject project;
final IOSAnalyzeOption option;
final String? configuration;
final String? scheme;
final String? target;
final Logger logger;
Future<void> analyze() async {
switch (option) {
case IOSAnalyzeOption.listBuildOptions:
final XcodeProjectInfo? info = await project.ios.projectInfo();
final Map<String, List<String>> result;
if (info == null) {
result = const <String, List<String>>{};
} 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!);
logger.printStatus('result saved in $filePath');
}
}
}

View File

@@ -215,11 +215,11 @@ class IosProject extends XcodeBasedProject {
return parent.isModule || _editableDirectory.existsSync();
}
/// Output universal link related project settings of the iOS sub-project into
/// Outputs universal link related project settings of the iOS sub-project into
/// a json file.
///
/// The return future will resolve to string path to the output file.
Future<String> outputUniversalLinkSettings({
Future<String> outputsUniversalLinkSettings({
required String configuration,
required String scheme,
required String target,