Unverified Commit b947121f authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Clean up null assumptions for project.dart dependencies (#83445)

parent a84bb4eb
......@@ -63,10 +63,10 @@ list(APPEND FLUTTER_TOOL_ENVIRONMENT
"FLUTTER_ROOT=$escapedFlutterRoot"
"PROJECT_DIR=$escapedProjectDir"
''');
for (final String key in environment.keys) {
final String value = _escapeBackslashes(environment[key]);
buffer.writeln(' "$key=$value"');
}
environment.forEach((String key, String value) {
final String configValue = _escapeBackslashes(value);
buffer.writeln(' "$key=$configValue"');
});
buffer.writeln(')');
project.generatedCmakeConfigFile
......
......@@ -1107,7 +1107,8 @@ List<PluginInterfaceResolution> resolvePlatformImplementation(
continue;
}
// The plugin doesn't implement an interface, verify that it has a default implementation.
if (plugin.implementsPackage == null || plugin.implementsPackage.isEmpty) {
final String implementsPackage = plugin.implementsPackage;
if (implementsPackage == null || implementsPackage.isEmpty) {
final String defaultImplementation = plugin.defaultPackagePlatforms[platform];
if (defaultImplementation == null) {
if (throwOnPluginPubspecError) {
......@@ -1138,7 +1139,7 @@ List<PluginInterfaceResolution> resolvePlatformImplementation(
plugin.pluginDartClassPlatforms[platform] == 'none') {
continue;
}
final String resolutionKey = '$platform/${plugin.implementsPackage}';
final String resolutionKey = '$platform/$implementsPackage';
if (directDependencyResolutions.containsKey(resolutionKey)) {
final PluginInterfaceResolution currResolution = directDependencyResolutions[resolutionKey];
if (currResolution != null && currResolution.plugin.isDirectDependency) {
......@@ -1200,12 +1201,12 @@ Future<void> generateMainDartWithPluginRegistrant(
String currentMainUri,
File newMainDart,
File mainFile, {
bool throwOnPluginPubspecError,
bool throwOnPluginPubspecError = false,
}) async {
final List<Plugin> plugins = await findPlugins(rootProject);
final List<PluginInterfaceResolution> resolutions = resolvePlatformImplementation(
plugins,
throwOnPluginPubspecError: throwOnPluginPubspecError ?? false,
throwOnPluginPubspecError: throwOnPluginPubspecError,
);
final LanguageVersion entrypointVersion = determineLanguageVersion(
mainFile,
......
......@@ -120,24 +120,40 @@ class FlutterProject {
/// part of iOS product bundle identifier, Android application ID, or
/// Gradle group ID.
Future<Set<String>> get organizationNames async {
final List<String> candidates = <String>[
final List<String> candidates = <String>[];
if (ios.existsSync()) {
// Don't require iOS build info, this method is only
// used during create as best-effort, use the
// default target bundle identifier.
if (ios.existsSync())
await ios.productBundleIdentifier(null),
if (android.existsSync()) ...<String>[
android.applicationId,
android.group,
],
if (example.android.existsSync())
example.android.applicationId,
if (example.ios.existsSync())
await example.ios.productBundleIdentifier(null),
];
return Set<String>.of(candidates
.map<String>(_organizationNameFromPackageName)
.where((String name) => name != null));
final String bundleIdentifier = await ios.productBundleIdentifier(null);
if (bundleIdentifier != null) {
candidates.add(bundleIdentifier);
}
}
if (android.existsSync()) {
final String applicationId = android.applicationId;
final String group = android.group;
candidates.addAll(<String>[
if (applicationId != null)
applicationId,
if (group != null)
group,
]);
}
if (example.android.existsSync()) {
final String applicationId = example.android.applicationId;
if (applicationId != null) {
candidates.add(applicationId);
}
}
if (example.ios.existsSync()) {
final String bundleIdentifier = await example.ios.productBundleIdentifier(null);
if (bundleIdentifier != null) {
candidates.add(bundleIdentifier);
}
}
return Set<String>.of(candidates.map<String>(_organizationNameFromPackageName).whereType<String>());
}
String _organizationNameFromPackageName(String packageName) {
......@@ -334,10 +350,14 @@ class FlutterProject {
/// Returns a json encoded string containing the [appName], [version], and [buildNumber] that is used to generate version.json
String getVersionInfo() {
final String buildName = manifest.buildName;
final String buildNumber = manifest.buildNumber;
final Map<String, String> versionFileJson = <String, String>{
'app_name': manifest.appName,
'version': manifest.buildName,
'build_number': manifest.buildNumber
if (buildName != null)
'version': buildName,
if (buildNumber != null)
'build_number': buildNumber,
};
return jsonEncode(versionFileJson);
}
......@@ -613,25 +633,33 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
scheme,
);
final XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(environmentType: environmentType, scheme: scheme, configuration: configuration);
return _buildSettingsByBuildContext[buildContext] ??= await _xcodeProjectBuildSettings(buildContext);
if (_buildSettingsByBuildContext[buildContext] == null) {
final Map<String, String> calculatedBuildSettings = await _xcodeProjectBuildSettings(buildContext);
if (calculatedBuildSettings != null) {
_buildSettingsByBuildContext[buildContext] = calculatedBuildSettings;
}
}
return _buildSettingsByBuildContext[buildContext];
}
final Map<XcodeProjectBuildContext, Map<String, String>> _buildSettingsByBuildContext = <XcodeProjectBuildContext, Map<String, String>>{};
Future<XcodeProjectInfo> projectInfo() async {
if (!xcodeProject.existsSync() || !globals.xcodeProjectInterpreter.isInstalled) {
final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter;
if (!xcodeProject.existsSync() || xcodeProjectInterpreter == null || !xcodeProjectInterpreter.isInstalled) {
return null;
}
return _projectInfo ??= await globals.xcodeProjectInterpreter.getInfo(hostAppRoot.path);
return _projectInfo ??= await xcodeProjectInterpreter.getInfo(hostAppRoot.path);
}
XcodeProjectInfo _projectInfo;
Future<Map<String, String>> _xcodeProjectBuildSettings(XcodeProjectBuildContext buildContext) async {
if (!globals.xcodeProjectInterpreter.isInstalled) {
final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter;
if (xcodeProjectInterpreter == null || !xcodeProjectInterpreter.isInstalled) {
return null;
}
final Map<String, String> buildSettings = await globals.xcodeProjectInterpreter.getBuildSettings(
final Map<String, String> buildSettings = await xcodeProjectInterpreter.getBuildSettings(
xcodeProject.path,
buildContext: buildContext,
);
......@@ -791,12 +819,13 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
logger: globals.logger,
templateRenderer: globals.templateRenderer,
);
final String iosBundleIdentifier = parent.manifest.iosBundleIdentifier ?? 'com.example.${parent.manifest.appName}';
template.render(
target,
<String, Object>{
'ios': true,
'projectName': parent.manifest.appName,
'iosIdentifier': parent.manifest.iosBundleIdentifier,
'iosIdentifier': iosBundleIdentifier,
},
printStatusWhenWriting: false,
overwriteExisting: true,
......@@ -975,12 +1004,13 @@ to migrate your project.
logger: globals.logger,
templateRenderer: globals.templateRenderer,
);
final String androidIdentifier = parent.manifest.androidPackage ?? 'com.example.${parent.manifest.appName}';
template.render(
target,
<String, Object>{
'android': true,
'projectName': parent.manifest.appName,
'androidIdentifier': parent.manifest.androidPackage,
'androidIdentifier': androidIdentifier,
'androidX': usesAndroidX,
},
printStatusWhenWriting: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment