Unverified Commit d1761f10 authored by stuartmorgan's avatar stuartmorgan Committed by GitHub

Pass Linux build mode on command line (#41551)

Currently Linux builds override the default BUILD mode by putting it in
the generated config. That makes it sticky for manual runs of make,
which is inconsistent with how other platforms work.

Instead, pass the build mode as a command-line override, the same way
someone would if building directly with make. This makes the flow of
controlling the mode less confusing.

Fixes #41528
parent 67ea92cb
...@@ -17,11 +17,9 @@ import '../reporting/reporting.dart'; ...@@ -17,11 +17,9 @@ import '../reporting/reporting.dart';
/// Builds the Linux project through the Makefile. /// Builds the Linux project through the Makefile.
Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async { Future<void> buildLinux(LinuxProject linuxProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async {
final String buildFlag = buildInfo?.isDebug == true ? 'debug' : 'release';
final StringBuffer buffer = StringBuffer(''' final StringBuffer buffer = StringBuffer('''
# Generated code do not commit. # Generated code do not commit.
export FLUTTER_ROOT=${Cache.flutterRoot} export FLUTTER_ROOT=${Cache.flutterRoot}
export BUILD=$buildFlag
export TRACK_WIDGET_CREATION=${buildInfo?.trackWidgetCreation == true} export TRACK_WIDGET_CREATION=${buildInfo?.trackWidgetCreation == true}
export FLUTTER_TARGET=$target export FLUTTER_TARGET=$target
export PROJECT_DIR=${linuxProject.project.directory.path} export PROJECT_DIR=${linuxProject.project.directory.path}
...@@ -48,12 +46,14 @@ export PROJECT_DIR=${linuxProject.project.directory.path} ...@@ -48,12 +46,14 @@ export PROJECT_DIR=${linuxProject.project.directory.path}
} }
// Invoke make. // Invoke make.
final String buildFlag = getNameForBuildMode(buildInfo.mode ?? BuildMode.release);
final Stopwatch sw = Stopwatch()..start(); final Stopwatch sw = Stopwatch()..start();
final Process process = await processManager.start(<String>[ final Process process = await processManager.start(<String>[
'make', 'make',
'-C', '-C',
linuxProject.makeFile.parent.path, linuxProject.makeFile.parent.path,
], runInShell: true); 'BUILD=$buildFlag'
]);
final Status status = logger.startProgress( final Status status = logger.startProgress(
'Building Linux application...', 'Building Linux application...',
timeout: null, timeout: null,
......
...@@ -54,6 +54,26 @@ void main() { ...@@ -54,6 +54,26 @@ void main() {
when(notLinuxPlatform.isWindows).thenReturn(false); when(notLinuxPlatform.isWindows).thenReturn(false);
}); });
// Creates the mock files necessary to run a build.
void setUpMockProjectFilesForBuild() {
fs.file('linux/build.sh').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
}
// Sets up mock expectation for running 'make'.
void expectMakeInvocationWithMode(String buildModeName) {
when(mockProcessManager.start(<String>[
'make',
'-C',
'/linux',
'BUILD=$buildModeName',
])).thenAnswer((Invocation invocation) async {
return mockProcess;
});
}
testUsingContext('Linux build fails when there is no linux project', () async { testUsingContext('Linux build fails when there is no linux project', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
...@@ -69,10 +89,7 @@ void main() { ...@@ -69,10 +89,7 @@ void main() {
testUsingContext('Linux build fails on non-linux platform', () async { testUsingContext('Linux build fails on non-linux platform', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
fs.file('linux/build.sh').createSync(recursive: true); setUpMockProjectFilesForBuild();
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
expect(createTestCommandRunner(command).run( expect(createTestCommandRunner(command).run(
const <String>['build', 'linux'] const <String>['build', 'linux']
...@@ -86,18 +103,8 @@ void main() { ...@@ -86,18 +103,8 @@ void main() {
testUsingContext('Linux build invokes make and writes temporary files', () async { testUsingContext('Linux build invokes make and writes temporary files', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
fs.file('linux/build.sh').createSync(recursive: true); setUpMockProjectFilesForBuild();
fs.file('pubspec.yaml').createSync(); expectMakeInvocationWithMode('release');
fs.file('.packages').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
when(mockProcessManager.start(<String>[
'make',
'-C',
'/linux',
], runInShell: true)).thenAnswer((Invocation invocation) async {
return mockProcess;
});
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
const <String>['build', 'linux'] const <String>['build', 'linux']
...@@ -110,6 +117,38 @@ void main() { ...@@ -110,6 +117,38 @@ void main() {
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true), FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
}); });
testUsingContext('Linux build --debug passes debug mode to make', () async {
final BuildCommand command = BuildCommand();
applyMocksToCommand(command);
setUpMockProjectFilesForBuild();
expectMakeInvocationWithMode('debug');
await createTestCommandRunner(command).run(
const <String>['build', 'linux', '--debug']
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => mockProcessManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
});
testUsingContext('Linux build --profile passes profile mode to make', () async {
final BuildCommand command = BuildCommand();
applyMocksToCommand(command);
setUpMockProjectFilesForBuild();
expectMakeInvocationWithMode('profile');
await createTestCommandRunner(command).run(
const <String>['build', 'linux', '--profile']
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
ProcessManager: () => mockProcessManager,
Platform: () => linuxPlatform,
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
});
testUsingContext('linux can extract binary name from Makefile', () async { testUsingContext('linux can extract binary name from Makefile', () async {
fs.file('linux/Makefile') fs.file('linux/Makefile')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -140,18 +179,8 @@ BINARY_NAME=fizz_bar ...@@ -140,18 +179,8 @@ BINARY_NAME=fizz_bar
testUsingContext('Release build prints an under-construction warning', () async { testUsingContext('Release build prints an under-construction warning', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
applyMocksToCommand(command); applyMocksToCommand(command);
fs.file('linux/build.sh').createSync(recursive: true); setUpMockProjectFilesForBuild();
fs.file('pubspec.yaml').createSync(); expectMakeInvocationWithMode('release');
fs.file('.packages').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
when(mockProcessManager.start(<String>[
'make',
'-C',
'/linux',
], runInShell: true)).thenAnswer((Invocation invocation) async {
return mockProcess;
});
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
const <String>['build', 'linux'] const <String>['build', 'linux']
......
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