Move build info checks from generating files to the xcode build (#40792)
This commit is contained in:
@@ -20,6 +20,7 @@ import '../base/process_manager.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../flutter_manifest.dart';
|
||||
import '../globals.dart';
|
||||
import '../macos/cocoapod_utils.dart';
|
||||
import '../macos/xcode.dart';
|
||||
@@ -323,6 +324,25 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
return XcodeBuildResult(success: false);
|
||||
}
|
||||
|
||||
final FlutterManifest manifest = app.project.parent.manifest;
|
||||
final String buildName = parsedBuildName(manifest: manifest, buildInfo: buildInfo);
|
||||
final bool buildNameIsMissing = buildName == null || buildName.isEmpty;
|
||||
|
||||
if (buildNameIsMissing) {
|
||||
printStatus('Warning: Missing build name (CFBundleShortVersionString).');
|
||||
}
|
||||
|
||||
final String buildNumber = parsedBuildNumber(manifest: manifest, buildInfo: buildInfo);
|
||||
final bool buildNumberIsMissing = buildNumber == null || buildNumber.isEmpty;
|
||||
|
||||
if (buildNumberIsMissing) {
|
||||
printStatus('Warning: Missing build number (CFBundleVersion).');
|
||||
}
|
||||
if (buildNameIsMissing || buildNumberIsMissing) {
|
||||
printError('Action Required: You must set a build name and number in the pubspec.yaml '
|
||||
'file version field before submitting to the App Store.');
|
||||
}
|
||||
|
||||
Map<String, String> autoSigningConfigs;
|
||||
if (codesign && buildForDevice) {
|
||||
autoSigningConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app);
|
||||
|
||||
@@ -18,6 +18,7 @@ import '../base/process.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../flutter_manifest.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
@@ -118,6 +119,31 @@ void _updateGeneratedEnvironmentVariablesScript({
|
||||
os.chmod(generatedModuleBuildPhaseScript, '755');
|
||||
}
|
||||
|
||||
/// Build name parsed and validated from build info and manifest. Used for CFBundleShortVersionString.
|
||||
String parsedBuildName({
|
||||
@required FlutterManifest manifest,
|
||||
@required BuildInfo buildInfo,
|
||||
}) {
|
||||
final String buildNameToParse = buildInfo?.buildName ?? manifest.buildName;
|
||||
return validatedBuildNameForPlatform(TargetPlatform.ios, buildNameToParse);
|
||||
}
|
||||
|
||||
/// Build number parsed and validated from build info and manifest. Used for CFBundleVersion.
|
||||
String parsedBuildNumber({
|
||||
@required FlutterManifest manifest,
|
||||
@required BuildInfo buildInfo,
|
||||
}) {
|
||||
String buildNumberToParse = buildInfo?.buildNumber ?? manifest.buildNumber;
|
||||
final String buildNumber = validatedBuildNumberForPlatform(TargetPlatform.ios, buildNumberToParse);
|
||||
if (buildNumber != null && buildNumber.isNotEmpty) {
|
||||
return buildNumber;
|
||||
}
|
||||
// Drop back to parsing build name if build number is not present. Build number is optional in the manifest, but
|
||||
// FLUTTER_BUILD_NUMBER is required as the backing value for the required CFBundleVersion.
|
||||
buildNumberToParse = buildInfo?.buildName ?? manifest.buildName;
|
||||
return validatedBuildNumberForPlatform(TargetPlatform.ios, buildNumberToParse);
|
||||
}
|
||||
|
||||
/// List of lines of build settings. Example: 'FLUTTER_BUILD_DIR=build'
|
||||
List<String> _xcodeBuildSettingsLines({
|
||||
@required FlutterProject project,
|
||||
@@ -158,51 +184,11 @@ List<String> _xcodeBuildSettingsLines({
|
||||
xcodeBuildSettings.add('FLUTTER_FRAMEWORK_DIR=$frameworkDir');
|
||||
}
|
||||
|
||||
final String buildNameToParse = buildInfo?.buildName ?? project.manifest.buildName;
|
||||
final bool buildNameIsMissing = buildNameToParse == null || buildNameToParse.isEmpty;
|
||||
String buildName;
|
||||
const String defaultBuildName = '1.0.0';
|
||||
if (buildNameIsMissing) {
|
||||
buildName = defaultBuildName;
|
||||
} else {
|
||||
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, buildNameToParse);
|
||||
}
|
||||
|
||||
final String buildNumberToParse = buildInfo?.buildNumber ?? project.manifest.buildNumber;
|
||||
final bool buildNumberIsMissing =
|
||||
(buildNumberToParse == null || buildNumberToParse.isEmpty) && buildNameIsMissing;
|
||||
String buildNumber;
|
||||
|
||||
const String defaultBuildNumber = '1';
|
||||
if (buildNumberIsMissing) {
|
||||
buildNumber = defaultBuildNumber;
|
||||
} else {
|
||||
buildNumber = validatedBuildNumberForPlatform(TargetPlatform.ios, buildNumberToParse);
|
||||
// Drop back to parsing build name if build number is not present. Build number is optional in the manifest, but
|
||||
// FLUTTER_BUILD_NUMBER is required as the backing value for the required CFBundleVersion.
|
||||
buildNumber ??= validatedBuildNumberForPlatform(TargetPlatform.ios, buildNameToParse);
|
||||
}
|
||||
|
||||
if (buildNameIsMissing) {
|
||||
printError('Warning: Missing build name (CFBundleShortVersionString), defaulting to $defaultBuildName.');
|
||||
}
|
||||
if (buildNumberIsMissing) {
|
||||
printError('Warning: Missing build number (CFBundleVersion), defaulting to $defaultBuildNumber.');
|
||||
}
|
||||
if (buildNameIsMissing || buildNumberIsMissing) {
|
||||
printError('Action Required: You must set a build name and number in the pubspec.yaml '
|
||||
'file version field before submitting to the App Store.');
|
||||
}
|
||||
|
||||
if (buildName == null && buildNumber == null) {
|
||||
throwToolExit('Cannot parse build number $buildNumberToParse or build name $buildNameToParse, check pubspec.yaml version.');
|
||||
} else if (buildName == null) {
|
||||
throwToolExit('Cannot parse build name $buildNameToParse, check pubspec.yaml version.');
|
||||
} else if (buildNumber == null) {
|
||||
throwToolExit('Cannot parse build number $buildNumberToParse, check pubspec.yaml version.');
|
||||
}
|
||||
|
||||
final String buildName = parsedBuildName(manifest: project.manifest, buildInfo: buildInfo) ?? '1.0.0';
|
||||
xcodeBuildSettings.add('FLUTTER_BUILD_NAME=$buildName');
|
||||
|
||||
final String buildNumber = parsedBuildNumber(manifest: project.manifest, buildInfo: buildInfo) ?? '1';
|
||||
xcodeBuildSettings.add('FLUTTER_BUILD_NUMBER=$buildNumber');
|
||||
|
||||
if (artifacts is LocalEngineArtifacts) {
|
||||
|
||||
@@ -646,24 +646,6 @@ flutter:
|
||||
expectedBuildNumber: '1',
|
||||
);
|
||||
});
|
||||
|
||||
testUsingOsxContext('fail when build name cannot be parsed', () async {
|
||||
const String manifest = '''
|
||||
name: test
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter:
|
||||
''';
|
||||
const BuildInfo buildInfo = BuildInfo(BuildMode.release, null, buildName: 'abc', buildNumber: '1');
|
||||
|
||||
const String stderr = 'Cannot parse build name abc, check pubspec.yaml version.';
|
||||
expect(() async => await checkBuildVersion(
|
||||
manifestString: manifest,
|
||||
buildInfo: buildInfo
|
||||
),
|
||||
throwsToolExit(message: stderr));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user