mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
Warn when building on master channel (#25007)
This commit is contained in:
parent
1237ee8f63
commit
dd65a54628
|
@ -4,7 +4,13 @@
|
|||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/terminal.dart';
|
||||
import '../globals.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
import '../version.dart';
|
||||
|
||||
import 'build_aot.dart';
|
||||
import 'build_apk.dart';
|
||||
import 'build_appbundle.dart';
|
||||
|
@ -36,4 +42,16 @@ abstract class BuildSubCommand extends FlutterCommand {
|
|||
BuildSubCommand() {
|
||||
requiresPubspecYaml();
|
||||
}
|
||||
|
||||
@override
|
||||
@mustCallSuper
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
// Warn if building a release app on Master channel
|
||||
final String channel = FlutterVersion.instance.channel;
|
||||
if (channel == 'master') {
|
||||
printStatus('🐉', newline: false, color: TerminalColor.red);
|
||||
printStatus(' This is the $channel channel. Shipping apps from this channel is not recommended as it has not been as heavily tested as the stable channel. To build using the stable channel, consider using:\n flutter channel stable');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ class BuildAotCommand extends BuildSubCommand {
|
|||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
|
||||
final String targetPlatform = argResults['target-platform'];
|
||||
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
|
||||
if (platform == null)
|
||||
|
|
|
@ -42,6 +42,8 @@ class BuildApkCommand extends BuildSubCommand {
|
|||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
|
||||
await buildApk(
|
||||
project: await FlutterProject.current(),
|
||||
target: targetFile,
|
||||
|
|
|
@ -40,6 +40,8 @@ class BuildAppBundleCommand extends BuildSubCommand {
|
|||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
|
||||
await buildAppBundle(
|
||||
project: await FlutterProject.current(),
|
||||
target: targetFile,
|
||||
|
|
|
@ -65,6 +65,8 @@ class BuildBundleCommand extends BuildSubCommand {
|
|||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
|
||||
final String targetPlatform = argResults['target-platform'];
|
||||
final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
|
||||
if (platform == null)
|
||||
|
|
|
@ -20,6 +20,8 @@ class BuildFlxCommand extends BuildSubCommand {
|
|||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
|
||||
printError("'build flx' is no longer supported. Instead, use 'build "
|
||||
"bundle' to build and assemble the application code and resources "
|
||||
'for your app.');
|
||||
|
|
|
@ -50,6 +50,8 @@ class BuildIOSCommand extends BuildSubCommand {
|
|||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
|
||||
final bool forSimulator = argResults['simulator'];
|
||||
defaultBuildMode = forSimulator ? BuildMode.debug : BuildMode.release;
|
||||
|
||||
|
|
93
packages/flutter_tools/test/commands/build_test.dart
Normal file
93
packages/flutter_tools/test/commands/build_test.dart
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Copyright 2019 The Chromium 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 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/commands/build.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
group('Master channel warning', () {
|
||||
testUsingContext('warns on master', () async {
|
||||
final MockBuildCommand buildCommand = MockBuildCommand();
|
||||
try {
|
||||
await createTestCommandRunner(buildCommand).run(<String>['build', 'test']);
|
||||
} finally {}
|
||||
Cache.releaseLockEarly();
|
||||
expect(testLogger.statusText, contains('🐉 This is the master channel. Shipping apps from this channel is not recommended as it has not'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => MockVersion('master'),
|
||||
});
|
||||
|
||||
testUsingContext('no warning on stable', () async {
|
||||
final MockBuildCommand buildCommand = MockBuildCommand();
|
||||
try {
|
||||
await createTestCommandRunner(buildCommand).run(<String>['build', 'test']);
|
||||
} finally {}
|
||||
Cache.releaseLockEarly();
|
||||
expect(testLogger.statusText, '');
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => MockVersion('stable'),
|
||||
});
|
||||
|
||||
testUsingContext('no warning on dev', () async {
|
||||
final MockBuildCommand buildCommand = MockBuildCommand();
|
||||
try {
|
||||
await createTestCommandRunner(buildCommand).run(<String>['build', 'test']);
|
||||
} finally {}
|
||||
Cache.releaseLockEarly();
|
||||
expect(testLogger.statusText, '');
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => MockVersion('dev'),
|
||||
});
|
||||
|
||||
testUsingContext('no warning on beta', () async {
|
||||
final MockBuildCommand buildCommand = MockBuildCommand();
|
||||
try {
|
||||
await createTestCommandRunner(buildCommand).run(<String>['build', 'test']);
|
||||
} finally {}
|
||||
print(testLogger.statusText);
|
||||
Cache.releaseLockEarly();
|
||||
expect(testLogger.statusText, '');
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => MockVersion('beta'),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockVersion extends FlutterVersion {
|
||||
MockVersion(String channel) : _fakeChannel = channel;
|
||||
String _fakeChannel;
|
||||
|
||||
@override
|
||||
String get channel => _fakeChannel;
|
||||
}
|
||||
|
||||
class MockBuildCommand extends BuildCommand {
|
||||
MockBuildCommand() {
|
||||
addSubcommand(MockBuildTestCommand());
|
||||
}
|
||||
}
|
||||
|
||||
// Avoids command validation
|
||||
class MockBuildTestCommand extends BuildSubCommand {
|
||||
@override
|
||||
final String name = 'test';
|
||||
|
||||
@override
|
||||
final String description = 'This is a test class only.';
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
await super.runCommand();
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue