Allow dynamic patches without a patch number. (#25796)

Unique patch numbers are mainly useful for canary and A-B testing, but otherwise complicate things and can now be omitted.
This commit is contained in:
Stanislav Baranov
2018-12-27 11:57:16 -08:00
committed by GitHub
parent 52bd2ccb8b
commit bacaab9795
3 changed files with 19 additions and 6 deletions

View File

@@ -469,8 +469,14 @@ Future<void> _buildGradleProjectV2(
update.addFile(ArchiveFile(name, newFile.content.length, newFile.content));
}
final File updateFile = fs.directory(buildInfo.patchDir)
.childFile('${package.versionCode}-${buildInfo.patchNumber}.zip');
File updateFile;
if (buildInfo.patchNumber != null) {
updateFile = fs.directory(buildInfo.patchDir)
.childFile('${package.versionCode}-${buildInfo.patchNumber}.zip');
} else {
updateFile = fs.directory(buildInfo.patchDir)
.childFile('${package.versionCode}.zip');
}
if (update.files.isEmpty) {
printStatus('No changes detected relative to baseline build.');
@@ -490,9 +496,14 @@ Future<void> _buildGradleProjectV2(
final Map<String, dynamic> manifest = <String, dynamic>{
'baselineChecksum': baselineChecksum,
'buildNumber': package.versionCode,
'patchNumber': buildInfo.patchNumber,
};
if (buildInfo.patchNumber != null) {
manifest.addAll(<String, dynamic>{
'patchNumber': buildInfo.patchNumber,
});
}
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
final String manifestJson = encoder.convert(manifest);
update.addFile(ArchiveFile('manifest.json', manifestJson.length, manifestJson.codeUnits));

View File

@@ -54,7 +54,7 @@ class BuildInfo {
final bool createPatch;
/// Internal version number of dynamic patch (not displayed to users).
/// Each patch should have a unique number to differentiate from previous
/// Each patch may have a unique number to differentiate from previous
/// patches for the same versionCode on Android or CFBundleVersion on iOS.
final int patchNumber;

View File

@@ -261,11 +261,13 @@ abstract class FlutterCommand extends Command<void> {
void addDynamicPatchingFlags({bool verboseHelp = false}) {
argParser.addOption('patch-number',
defaultsTo: '1',
hide: !verboseHelp,
help: 'An integer used as an internal version number for dynamic patch.\n'
'Each update should have a unique number to differentiate from previous '
'Each update may have a unique number to differentiate from previous\n'
'patches for same \'versionCode\' on Android or \'CFBundleVersion\' on iOS.\n'
'This optional setting allows several dynamic patches to coexist\n'
'for same baseline build, and is useful for canary and A-B testing\n'
'of dynamic patches.\n'
'This flag is only used when --dynamic --patch is specified.\n'
);
argParser.addOption('patch-dir',