Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 3 | // found in the LICENSE file. |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 4 | |
stuartmorgan | 5f6f70e | 2019-05-30 12:45:33 -0700 | [diff] [blame] | 5 | import '../artifacts.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 6 | import '../base/common.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 7 | import '../base/logger.dart'; |
Jonah Williams | 4803428 | 2019-10-09 18:58:27 -0700 | [diff] [blame] | 8 | import '../base/process.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 9 | import '../build_info.dart'; |
| 10 | import '../cache.dart'; |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 11 | import '../globals.dart' as globals; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 12 | import '../project.dart'; |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 13 | import '../reporting/reporting.dart'; |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 14 | import 'msbuild_utils.dart'; |
stuartmorgan | fb8df82 | 2019-06-06 14:02:27 -0700 | [diff] [blame] | 15 | import 'visual_studio.dart'; |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 16 | |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 17 | /// Builds the Windows project using msbuild. |
stuartmorgan | d6bd1c0 | 2019-07-01 14:49:34 -0700 | [diff] [blame] | 18 | Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {String target}) async { |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 19 | final Map<String, String> environment = <String, String>{ |
| 20 | 'FLUTTER_ROOT': Cache.flutterRoot, |
stuartmorgan | e6ae95c | 2019-09-11 07:46:57 -0700 | [diff] [blame] | 21 | 'FLUTTER_EPHEMERAL_DIR': windowsProject.ephemeralDirectory.path, |
stuartmorgan | 4e1bfca | 2019-05-15 19:32:47 -0400 | [diff] [blame] | 22 | 'PROJECT_DIR': windowsProject.project.directory.path, |
| 23 | 'TRACK_WIDGET_CREATION': (buildInfo?.trackWidgetCreation == true).toString(), |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 24 | }; |
stuartmorgan | d6bd1c0 | 2019-07-01 14:49:34 -0700 | [diff] [blame] | 25 | if (target != null) { |
| 26 | environment['FLUTTER_TARGET'] = target; |
| 27 | } |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 28 | if (globals.artifacts is LocalEngineArtifacts) { |
| 29 | final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts; |
stuartmorgan | 5f6f70e | 2019-05-30 12:45:33 -0700 | [diff] [blame] | 30 | final String engineOutPath = localEngineArtifacts.engineOutPath; |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 31 | environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); |
| 32 | environment['LOCAL_ENGINE'] = globals.fs.path.basename(engineOutPath); |
stuartmorgan | 5f6f70e | 2019-05-30 12:45:33 -0700 | [diff] [blame] | 33 | } |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 34 | writePropertySheet(windowsProject.generatedPropertySheetFile, environment); |
| 35 | |
stuartmorgan | fb8df82 | 2019-06-06 14:02:27 -0700 | [diff] [blame] | 36 | final String vcvarsScript = visualStudio.vcvarsPath; |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 37 | if (vcvarsScript == null) { |
stuartmorgan | fb8df82 | 2019-06-06 14:02:27 -0700 | [diff] [blame] | 38 | throwToolExit('Unable to find suitable Visual Studio toolchain. ' |
| 39 | 'Please run `flutter doctor` for more details.'); |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 40 | } |
| 41 | |
stuartmorgan | 0153092 | 2019-08-20 20:16:29 -0700 | [diff] [blame] | 42 | if (!buildInfo.isDebug) { |
| 43 | const String warning = '🚧 '; |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 44 | globals.printStatus(warning * 20); |
| 45 | globals.printStatus('Warning: Only debug is currently implemented for Windows. This is effectively a debug build.'); |
| 46 | globals.printStatus('See https://github.com/flutter/flutter/issues/38477 for details and updates.'); |
| 47 | globals.printStatus(warning * 20); |
| 48 | globals.printStatus(''); |
stuartmorgan | 0153092 | 2019-08-20 20:16:29 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 51 | final String buildScript = globals.fs.path.join( |
stuartmorgan | e1a784a | 2019-05-28 21:53:03 -0700 | [diff] [blame] | 52 | Cache.flutterRoot, |
| 53 | 'packages', |
| 54 | 'flutter_tools', |
| 55 | 'bin', |
| 56 | 'vs_build.bat', |
| 57 | ); |
| 58 | |
stuartmorgan | 6722fb4 | 2019-05-14 19:24:40 -0400 | [diff] [blame] | 59 | final String configuration = buildInfo.isDebug ? 'Debug' : 'Release'; |
stuartmorgan | 79ae04d | 2019-05-29 13:17:23 -0700 | [diff] [blame] | 60 | final String solutionPath = windowsProject.solutionFile.path; |
Zachary Anderson | b847ba5 | 2019-06-07 13:50:45 -0700 | [diff] [blame] | 61 | final Stopwatch sw = Stopwatch()..start(); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 62 | final Status status = globals.logger.startProgress( |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 63 | 'Building Windows application...', |
| 64 | timeout: null, |
| 65 | ); |
| 66 | int result; |
| 67 | try { |
Jonah Williams | 4803428 | 2019-10-09 18:58:27 -0700 | [diff] [blame] | 68 | // Run the script with a relative path to the project using the enclosing |
| 69 | // directory as the workingDirectory, to avoid hitting the limit on command |
| 70 | // lengths in batch scripts if the absolute path to the project is long. |
| 71 | result = await processUtils.stream(<String>[ |
| 72 | buildScript, |
| 73 | vcvarsScript, |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 74 | globals.fs.path.basename(solutionPath), |
Jonah Williams | 4803428 | 2019-10-09 18:58:27 -0700 | [diff] [blame] | 75 | configuration, |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame^] | 76 | ], workingDirectory: globals.fs.path.dirname(solutionPath), trace: true); |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 77 | } finally { |
| 78 | status.cancel(); |
| 79 | } |
| 80 | if (result != 0) { |
GroovinChip | ced2078 | 2019-08-01 13:32:38 -0400 | [diff] [blame] | 81 | throwToolExit('Build process failed. To view the stack trace, please run `flutter run -d windows -v`.'); |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 82 | } |
Zachary Anderson | b847ba5 | 2019-06-07 13:50:45 -0700 | [diff] [blame] | 83 | flutterUsage.sendTiming('build', 'vs_build', Duration(milliseconds: sw.elapsedMilliseconds)); |
Jonah Williams | ac36e44 | 2019-04-18 18:05:04 -0700 | [diff] [blame] | 84 | } |