Unverified Commit 37c73e77 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Remove need for build/name scripts on Linux desktop (#31567)

parent 0572f158
......@@ -392,6 +392,11 @@ String getWebBuildDirectory() {
return fs.path.join(getBuildDirectory(), 'web');
}
/// Returns the linux build output directory.
String getLinuxBuildDirectory() {
return fs.path.join(getBuildDirectory(), 'linux');
}
/// Returns directory used by incremental compiler (IKG - incremental kernel
/// generator) to store cached intermediate state.
String getIncrementalCompilerByteStoreDirectory() {
......
......@@ -5,12 +5,10 @@
import 'package:meta/meta.dart';
import '../application_package.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../project.dart';
import 'makefile.dart';
abstract class LinuxApp extends ApplicationPackage {
LinuxApp({@required String projectBundleId}) : super(id: projectBundleId);
......@@ -59,14 +57,12 @@ class BuildableLinuxApp extends LinuxApp {
@override
String executable(BuildMode buildMode) {
final ProcessResult result = processManager.runSync(<String>[
project.nameScript.path,
buildMode == BuildMode.debug ? 'debug' : 'release',
]);
if (result.exitCode != 0) {
throwToolExit('Failed to find Linux project name');
final String binaryName = makefileExecutableName(project);
if (buildMode == BuildMode.debug) {
return fs.path.join(getLinuxBuildDirectory(), 'debug', binaryName);
} else {
return fs.path.join(getLinuxBuildDirectory(), 'release', binaryName);
}
return result.stdout.toString().trim();
}
@override
......
......@@ -12,13 +12,22 @@ import '../convert.dart';
import '../globals.dart';
import '../project.dart';
/// Builds the Linux project through the project shell script.
/// Builds the Linux project through the Makefile.
Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo) async {
/// Cache flutter root in linux directory.
linuxProject.editableHostAppDirectory.childFile('.generated_flutter_root')
..createSync(recursive: true)
..writeAsStringSync(Cache.flutterRoot);
final String buildFlag = buildInfo?.isDebug == true ? 'debug' : 'release';
final String bundleFlags = buildInfo?.trackWidgetCreation == true ? '--track-widget-creation' : '';
final Process process = await processManager.start(<String>[
linuxProject.buildScript.path,
Cache.flutterRoot,
buildInfo?.isDebug == true ? 'debug' : 'release',
buildInfo?.trackWidgetCreation == true ? 'track-widget-creation' : 'no-track-widget-creation',
'make',
'-C',
linuxProject.editableHostAppDirectory.path,
'BUILD=$buildFlag',
'FLUTTER_ROOT=${Cache.flutterRoot}',
'FLUTTER_BUNDLE_FLAGS=$bundleFlags',
], runInShell: true);
final Status status = logger.startProgress(
'Building Linux application...',
......
......@@ -71,6 +71,7 @@ class LinuxDevice extends Device {
bool usesTerminalUi = true,
bool ipv6 = false,
}) async {
_lastBuiltMode = debuggingOptions.buildInfo.mode;
if (!prebuiltApplication) {
await buildLinux((await FlutterProject.current()).linux, debuggingOptions.buildInfo);
}
......@@ -96,8 +97,7 @@ class LinuxDevice extends Device {
@override
Future<bool> stopApp(covariant LinuxApp app) async {
// Assume debug for now.
return killProcess(app.executable(BuildMode.debug));
return killProcess(app.executable(_lastBuiltMode));
}
@override
......@@ -107,6 +107,9 @@ class LinuxDevice extends Device {
// to uninstall the application.
@override
Future<bool> uninstallApp(ApplicationPackage app) async => true;
// Track the last built mode from startApp.
BuildMode _lastBuiltMode;
}
class LinuxDevices extends PollingDeviceDiscovery {
......
// 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 '../project.dart';
// The setting that controls the executable name in the linux makefile.
const String _kBinaryNameVariable = 'BINARY_NAME=';
/// Extracts the `BINARY_NAME` from a linux project Makefile.
///
/// Returns `null` if it cannot be found.
String makefileExecutableName(LinuxProject project) {
for (String line in project.makeFile.readAsLinesSync()) {
if (line.startsWith(_kBinaryNameVariable)) {
return line.split(_kBinaryNameVariable).last.trim();
}
}
return null;
}
\ No newline at end of file
......@@ -584,11 +584,10 @@ class LinuxProject {
final FlutterProject project;
bool existsSync() => project.directory.childDirectory('linux').existsSync();
Directory get editableHostAppDirectory => project.directory.childDirectory('linux');
// Note: The build script file exists as a temporary shim.
File get buildScript => project.directory.childDirectory('linux').childFile('build.sh');
bool existsSync() => editableHostAppDirectory.existsSync();
// Note: The name script file exists as a temporary shim.
File get nameScript => project.directory.childDirectory('linux').childFile('name_output.sh');
/// The Linux project makefile.
File get makeFile => editableHostAppDirectory.childFile('Makefile');
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/linux/makefile.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
......@@ -62,17 +64,19 @@ void main() {
FileSystem: () => memoryFilesystem,
});
testUsingContext('Linux build invokes build script', () async {
testUsingContext('Linux build invokes make', () async {
final BuildCommand command = BuildCommand();
applyMocksToCommand(command);
fs.file('linux/build.sh').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
when(mockProcessManager.start(<String>[
'/linux/build.sh',
'/',
'release',
'no-track-widget-creation',
'make',
'-C',
'/linux',
'BUILD=release',
'FLUTTER_ROOT=/',
'FLUTTER_BUNDLE_FLAGS=',
], runInShell: true)).thenAnswer((Invocation invocation) async {
return mockProcess;
});
......@@ -85,6 +89,21 @@ void main() {
ProcessManager: () => mockProcessManager,
Platform: () => linuxPlatform,
});
testUsingContext('linux can extract binary name from Makefile', () async {
fs.file('linux/Makefile')
..createSync(recursive: true)
..writeAsStringSync(r'''
# Comment
SOMETHING_ELSE=FOO
BINARY_NAME=fizz_bar
''');
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final FlutterProject flutterProject = await FlutterProject.current();
expect(makefileExecutableName(flutterProject.linux), 'fizz_bar');
}, overrides: <Type, Generator>{FileSystem: () => MemoryFileSystem()});
}
class MockProcessManager extends Mock implements ProcessManager {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment