build_windows.dart 1.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// 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 '../base/common.dart';
import '../base/io.dart';
import '../base/logger.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../cache.dart';
import '../convert.dart';
import '../globals.dart';
import '../project.dart';
14
import 'msbuild_utils.dart';
15

16
/// Builds the Windows project using msbuild.
17
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async {
18 19
  final Map<String, String> environment = <String, String>{
    'FLUTTER_ROOT': Cache.flutterRoot,
20 21 22
    'FLUTTER_TARGET': target,
    'PROJECT_DIR': windowsProject.project.directory.path,
    'TRACK_WIDGET_CREATION': (buildInfo?.trackWidgetCreation == true).toString(),
23 24 25 26 27 28 29 30 31
  };
  writePropertySheet(windowsProject.generatedPropertySheetFile, environment);

  final String vcvarsScript = await findVcvars();
  if (vcvarsScript == null) {
    throwToolExit('Unable to build: could not find vcvars64.bat');
  }

  final String configuration = buildInfo.isDebug ? 'Debug' : 'Release';
32
  final Process process = await processManager.start(<String>[
33 34 35
    vcvarsScript, '&&', 'msbuild',
    windowsProject.vcprojFile.path,
    '/p:Configuration=$configuration',
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  ], runInShell: true);
  final Status status = logger.startProgress(
    'Building Windows application...',
    timeout: null,
  );
  int result;
  try {
    process.stderr
      .transform(utf8.decoder)
      .transform(const LineSplitter())
      .listen(printError);
    process.stdout
      .transform(utf8.decoder)
      .transform(const LineSplitter())
      .listen(printTrace);
    result = await process.exitCode;
  } finally {
    status.cancel();
  }
  if (result != 0) {
    throwToolExit('Build process failed');
  }
}