Check for desktop project files before building (#48350)

Moves the checks that projects have been configured for desktop to a lower level, where they will cover more codepaths (e.g., 'run'), and improves them to check for native build projects, rather than just directories, to catch cases where the directory exists (e.g., due to accidental creation of generated files).

Also adds links to the error messages pointing to instructions on adding desktop support to a project.

Fixes #47145
This commit is contained in:
stuartmorgan
2020-01-08 12:39:49 -08:00
committed by GitHub
parent 67c843f7b6
commit 58d6c425e4
9 changed files with 61 additions and 35 deletions

View File

@@ -46,9 +46,6 @@ class BuildLinuxCommand extends BuildSubCommand {
if (!globals.platform.isLinux) {
throwToolExit('"build linux" only supported on Linux hosts.');
}
if (!flutterProject.linux.existsSync()) {
throwToolExit('No Linux desktop project configured.');
}
await buildLinux(flutterProject.linux, buildInfo, target: targetFile);
return null;
}

View File

@@ -46,9 +46,6 @@ class BuildMacosCommand extends BuildSubCommand {
if (!globals.platform.isMacOS) {
throwToolExit('"build macos" only supported on macOS hosts.');
}
if (!flutterProject.macos.existsSync()) {
throwToolExit('No macOS desktop project configured.');
}
await buildMacOS(
flutterProject: flutterProject,
buildInfo: buildInfo,

View File

@@ -46,9 +46,6 @@ class BuildWindowsCommand extends BuildSubCommand {
if (!globals.platform.isWindows) {
throwToolExit('"build windows" only supported on Windows hosts.');
}
if (!flutterProject.windows.existsSync()) {
throwToolExit('No Windows desktop project configured.');
}
await buildWindows(flutterProject.windows, buildInfo, target: targetFile);
return null;
}

View File

@@ -14,6 +14,12 @@ import '../reporting/reporting.dart';
/// Builds the Linux project through the Makefile.
Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async {
if (!linuxProject.makeFile.existsSync()) {
throwToolExit('No Linux desktop project configured. See '
'https://github.com/flutter/flutter/wiki/Desktop-shells#create '
'to learn about adding Linux support to a project.');
}
final StringBuffer buffer = StringBuffer('''
# Generated code do not commit.
export FLUTTER_ROOT=${Cache.flutterRoot}

View File

@@ -20,6 +20,12 @@ Future<void> buildMacOS({
BuildInfo buildInfo,
String targetOverride,
}) async {
if (!flutterProject.macos.xcodeWorkspace.existsSync()) {
throwToolExit('No macOS desktop project configured. '
'See https://flutter.dev/desktop#add-desktop-support-to-an-existing-flutter-project '
'to learn about adding macOS support to a project.');
}
final Directory flutterBuildDir = globals.fs.directory(getMacOSBuildDirectory());
if (!flutterBuildDir.existsSync()) {
flutterBuildDir.createSync(recursive: true);

View File

@@ -16,6 +16,13 @@ import 'visual_studio.dart';
/// Builds the Windows project using msbuild.
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {String target}) async {
if (!windowsProject.solutionFile.existsSync()) {
throwToolExit(
'No Windows desktop project configured. '
'See https://github.com/flutter/flutter/wiki/Desktop-shells#create '
'to learn about adding Windows support to a project.');
}
final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': Cache.flutterRoot,
'FLUTTER_EPHEMERAL_DIR': windowsProject.ephemeralDirectory.path,