build_linux.dart 2.53 KB
Newer Older
1 2 3 4
// 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.

5
import '../artifacts.dart';
6
import '../base/common.dart';
7
import '../base/file_system.dart';
8
import '../base/logger.dart';
9
import '../base/process.dart';
10 11 12 13
import '../build_info.dart';
import '../cache.dart';
import '../globals.dart';
import '../project.dart';
14
import '../reporting/reporting.dart';
15

16
/// Builds the Linux project through the Makefile.
17 18 19 20 21 22 23 24 25
Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async {
  final StringBuffer buffer = StringBuffer('''
# Generated code do not commit.
export FLUTTER_ROOT=${Cache.flutterRoot}
export TRACK_WIDGET_CREATION=${buildInfo?.trackWidgetCreation == true}
export FLUTTER_TARGET=$target
export PROJECT_DIR=${linuxProject.project.directory.path}
''');
  if (artifacts is LocalEngineArtifacts) {
26
    final LocalEngineArtifacts localEngineArtifacts = artifacts as LocalEngineArtifacts;
27 28 29 30 31 32
    final String engineOutPath = localEngineArtifacts.engineOutPath;
    buffer.writeln('export FLUTTER_ENGINE=${fs.path.dirname(fs.path.dirname(engineOutPath))}');
    buffer.writeln('export LOCAL_ENGINE=${fs.path.basename(engineOutPath)}');
  }

  /// Cache flutter configuration files in the linux directory.
33
  linuxProject.generatedMakeConfigFile
34
    ..createSync(recursive: true)
35
    ..writeAsStringSync(buffer.toString());
36

37 38 39 40 41 42 43 44 45
  if (!buildInfo.isDebug) {
    const String warning = '🚧 ';
    printStatus(warning * 20);
    printStatus('Warning: Only debug is currently implemented for Linux. This is effectively a debug build.');
    printStatus('See https://github.com/flutter/flutter/issues/38478 for details and updates.');
    printStatus(warning * 20);
    printStatus('');
  }

46
  // Invoke make.
47
  final String buildFlag = getNameForBuildMode(buildInfo.mode ?? BuildMode.release);
48
  final Stopwatch sw = Stopwatch()..start();
49 50 51 52 53 54
  final Status status = logger.startProgress(
    'Building Linux application...',
    timeout: null,
  );
  int result;
  try {
55
    result = await processUtils.stream(<String>[
56 57 58 59
      'make',
      '-C',
      linuxProject.makeFile.parent.path,
      'BUILD=$buildFlag',
60
    ], trace: true);
61 62
  } on ArgumentError {
    throwToolExit('make not found. Run \'flutter doctor\' for more information.');
63 64 65 66 67 68
  } finally {
    status.cancel();
  }
  if (result != 0) {
    throwToolExit('Build process failed');
  }
69
  flutterUsage.sendTiming('build', 'make-linux', Duration(milliseconds: sw.elapsedMilliseconds));
70
}