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() { ...@@ -392,6 +392,11 @@ String getWebBuildDirectory() {
return fs.path.join(getBuildDirectory(), 'web'); 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 /// Returns directory used by incremental compiler (IKG - incremental kernel
/// generator) to store cached intermediate state. /// generator) to store cached intermediate state.
String getIncrementalCompilerByteStoreDirectory() { String getIncrementalCompilerByteStoreDirectory() {
......
...@@ -5,12 +5,10 @@ ...@@ -5,12 +5,10 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart';
import '../base/process_manager.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../project.dart'; import '../project.dart';
import 'makefile.dart';
abstract class LinuxApp extends ApplicationPackage { abstract class LinuxApp extends ApplicationPackage {
LinuxApp({@required String projectBundleId}) : super(id: projectBundleId); LinuxApp({@required String projectBundleId}) : super(id: projectBundleId);
...@@ -59,14 +57,12 @@ class BuildableLinuxApp extends LinuxApp { ...@@ -59,14 +57,12 @@ class BuildableLinuxApp extends LinuxApp {
@override @override
String executable(BuildMode buildMode) { String executable(BuildMode buildMode) {
final ProcessResult result = processManager.runSync(<String>[ final String binaryName = makefileExecutableName(project);
project.nameScript.path, if (buildMode == BuildMode.debug) {
buildMode == BuildMode.debug ? 'debug' : 'release', return fs.path.join(getLinuxBuildDirectory(), 'debug', binaryName);
]); } else {
if (result.exitCode != 0) { return fs.path.join(getLinuxBuildDirectory(), 'release', binaryName);
throwToolExit('Failed to find Linux project name');
} }
return result.stdout.toString().trim();
} }
@override @override
......
...@@ -12,13 +12,22 @@ import '../convert.dart'; ...@@ -12,13 +12,22 @@ import '../convert.dart';
import '../globals.dart'; import '../globals.dart';
import '../project.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 { 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>[ final Process process = await processManager.start(<String>[
linuxProject.buildScript.path, 'make',
Cache.flutterRoot, '-C',
buildInfo?.isDebug == true ? 'debug' : 'release', linuxProject.editableHostAppDirectory.path,
buildInfo?.trackWidgetCreation == true ? 'track-widget-creation' : 'no-track-widget-creation', 'BUILD=$buildFlag',
'FLUTTER_ROOT=${Cache.flutterRoot}',
'FLUTTER_BUNDLE_FLAGS=$bundleFlags',
], runInShell: true); ], runInShell: true);
final Status status = logger.startProgress( final Status status = logger.startProgress(
'Building Linux application...', 'Building Linux application...',
......
...@@ -71,6 +71,7 @@ class LinuxDevice extends Device { ...@@ -71,6 +71,7 @@ class LinuxDevice extends Device {
bool usesTerminalUi = true, bool usesTerminalUi = true,
bool ipv6 = false, bool ipv6 = false,
}) async { }) async {
_lastBuiltMode = debuggingOptions.buildInfo.mode;
if (!prebuiltApplication) { if (!prebuiltApplication) {
await buildLinux((await FlutterProject.current()).linux, debuggingOptions.buildInfo); await buildLinux((await FlutterProject.current()).linux, debuggingOptions.buildInfo);
} }
...@@ -96,8 +97,7 @@ class LinuxDevice extends Device { ...@@ -96,8 +97,7 @@ class LinuxDevice extends Device {
@override @override
Future<bool> stopApp(covariant LinuxApp app) async { Future<bool> stopApp(covariant LinuxApp app) async {
// Assume debug for now. return killProcess(app.executable(_lastBuiltMode));
return killProcess(app.executable(BuildMode.debug));
} }
@override @override
...@@ -107,6 +107,9 @@ class LinuxDevice extends Device { ...@@ -107,6 +107,9 @@ class LinuxDevice extends Device {
// to uninstall the application. // to uninstall the application.
@override @override
Future<bool> uninstallApp(ApplicationPackage app) async => true; Future<bool> uninstallApp(ApplicationPackage app) async => true;
// Track the last built mode from startApp.
BuildMode _lastBuiltMode;
} }
class LinuxDevices extends PollingDeviceDiscovery { 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 { ...@@ -584,11 +584,10 @@ class LinuxProject {
final FlutterProject project; 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. bool existsSync() => editableHostAppDirectory.existsSync();
File get buildScript => project.directory.childDirectory('linux').childFile('build.sh');
// Note: The name script file exists as a temporary shim. /// The Linux project makefile.
File get nameScript => project.directory.childDirectory('linux').childFile('name_output.sh'); File get makeFile => editableHostAppDirectory.childFile('Makefile');
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ import 'package:flutter_tools/src/base/io.dart'; ...@@ -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/base/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.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:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -62,17 +64,19 @@ void main() { ...@@ -62,17 +64,19 @@ void main() {
FileSystem: () => memoryFilesystem, FileSystem: () => memoryFilesystem,
}); });
testUsingContext('Linux build invokes build script', () async { testUsingContext('Linux build invokes make', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
fs.file('linux/build.sh').createSync(recursive: true); fs.file('linux/build.sh').createSync(recursive: true);
fs.file('pubspec.yaml').createSync(); fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync(); fs.file('.packages').createSync();
when(mockProcessManager.start(<String>[ when(mockProcessManager.start(<String>[
'/linux/build.sh', 'make',
'/', '-C',
'release', '/linux',
'no-track-widget-creation', 'BUILD=release',
'FLUTTER_ROOT=/',
'FLUTTER_BUNDLE_FLAGS=',
], runInShell: true)).thenAnswer((Invocation invocation) async { ], runInShell: true)).thenAnswer((Invocation invocation) async {
return mockProcess; return mockProcess;
}); });
...@@ -85,6 +89,21 @@ void main() { ...@@ -85,6 +89,21 @@ void main() {
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Platform: () => linuxPlatform, 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 {} 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