1// Copyright 2019 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import '../artifacts.dart'; 6import '../base/common.dart'; 7import '../base/file_system.dart'; 8import '../base/io.dart'; 9import '../base/logger.dart'; 10import '../base/process_manager.dart'; 11import '../build_info.dart'; 12import '../cache.dart'; 13import '../convert.dart'; 14import '../globals.dart'; 15import '../project.dart'; 16import '../reporting/reporting.dart'; 17 18/// Builds the Linux project through the Makefile. 19Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async { 20 final String buildFlag = buildInfo?.isDebug == true ? 'debug' : 'release'; 21 final StringBuffer buffer = StringBuffer(''' 22# Generated code do not commit. 23export FLUTTER_ROOT=${Cache.flutterRoot} 24export BUILD=$buildFlag 25export TRACK_WIDGET_CREATION=${buildInfo?.trackWidgetCreation == true} 26export FLUTTER_TARGET=$target 27export PROJECT_DIR=${linuxProject.project.directory.path} 28'''); 29 if (artifacts is LocalEngineArtifacts) { 30 final LocalEngineArtifacts localEngineArtifacts = artifacts; 31 final String engineOutPath = localEngineArtifacts.engineOutPath; 32 buffer.writeln('export FLUTTER_ENGINE=${fs.path.dirname(fs.path.dirname(engineOutPath))}'); 33 buffer.writeln('export LOCAL_ENGINE=${fs.path.basename(engineOutPath)}'); 34 } 35 36 /// Cache flutter configuration files in the linux directory. 37 linuxProject.cacheDirectory.childFile('generated_config') 38 ..createSync(recursive: true) 39 ..writeAsStringSync(buffer.toString()); 40 41 // Invoke make. 42 final Stopwatch sw = Stopwatch()..start(); 43 final Process process = await processManager.start(<String>[ 44 'make', 45 '-C', 46 linuxProject.editableHostAppDirectory.path, 47 ], runInShell: true); 48 final Status status = logger.startProgress( 49 'Building Linux application...', 50 timeout: null, 51 ); 52 int result; 53 try { 54 process.stderr 55 .transform(utf8.decoder) 56 .transform(const LineSplitter()) 57 .listen(printError); 58 process.stdout 59 .transform(utf8.decoder) 60 .transform(const LineSplitter()) 61 .listen(printTrace); 62 result = await process.exitCode; 63 } finally { 64 status.cancel(); 65 } 66 if (result != 0) { 67 throwToolExit('Build process failed'); 68 } 69 flutterUsage.sendTiming('build', 'make-linux', Duration(milliseconds: sw.elapsedMilliseconds)); 70} 71