Unverified Commit 693fb656 authored by Stanislav Baranov's avatar Stanislav Baranov Committed by GitHub

Fix flutter tool to actually honor --build-number/--build-name flags. (#25520)

parent 0d4f279f
......@@ -231,7 +231,11 @@ void updateLocalProperties({
void changeIfNecessary(String key, String value) {
if (settings.values[key] != value) {
if (value == null) {
settings.values.remove(key);
} else {
settings.values[key] = value;
}
changed = true;
}
}
......@@ -240,15 +244,16 @@ void updateLocalProperties({
if (androidSdk != null)
changeIfNecessary('sdk.dir', escapePath(androidSdk.directory));
changeIfNecessary('flutter.sdk', escapePath(Cache.flutterRoot));
if (buildInfo != null)
if (buildInfo != null) {
changeIfNecessary('flutter.buildMode', buildInfo.modeName);
final String buildName = buildInfo?.buildName ?? manifest.buildName;
if (buildName != null)
final String buildName = buildInfo.buildName ?? manifest.buildName;
changeIfNecessary('flutter.versionName', buildName);
final int buildNumber = buildInfo?.buildNumber ?? manifest.buildNumber;
if (buildNumber != null)
changeIfNecessary('flutter.versionCode', '$buildNumber');
final int buildNumber = buildInfo.buildNumber ?? manifest.buildNumber;
changeIfNecessary('flutter.versionCode', buildNumber?.toString());
}
if (changed)
settings.writeContents(localProperties);
......
......@@ -325,6 +325,48 @@ flutter:
expectedBuildNumber: '3',
);
});
testUsingAndroidContext('allow build info to unset build name and number', () async {
const String manifest = '''
name: test
dependencies:
flutter:
sdk: flutter
flutter:
''';
await checkBuildVersion(
manifest: manifest,
buildInfo: const BuildInfo(BuildMode.release, null, buildName: null, buildNumber: null),
expectedBuildName: null,
expectedBuildNumber: null,
);
await checkBuildVersion(
manifest: manifest,
buildInfo: const BuildInfo(BuildMode.release, null, buildName: '1.0.2', buildNumber: 3),
expectedBuildName: '1.0.2',
expectedBuildNumber: '3',
);
await checkBuildVersion(
manifest: manifest,
buildInfo: const BuildInfo(BuildMode.release, null, buildName: '1.0.3', buildNumber: 4),
expectedBuildName: '1.0.3',
expectedBuildNumber: '4',
);
// Values don't get unset.
await checkBuildVersion(
manifest: manifest,
buildInfo: null,
expectedBuildName: '1.0.3',
expectedBuildNumber: '4',
);
// Values get unset.
await checkBuildVersion(
manifest: manifest,
buildInfo: const BuildInfo(BuildMode.release, null, buildName: null, buildNumber: null),
expectedBuildName: null,
expectedBuildNumber: null,
);
});
});
}
......
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