2019-04-17 19:16:55 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-07-22 22:34:03 +00:00
|
|
|
import 'package:args/command_runner.dart';
|
2019-04-17 19:16:55 +00:00
|
|
|
import 'package:file/memory.dart';
|
|
|
|
import 'package:flutter_tools/src/base/common.dart';
|
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
|
|
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';
|
2019-07-22 22:34:03 +00:00
|
|
|
import 'package:flutter_tools/src/features.dart';
|
2019-04-24 20:34:56 +00:00
|
|
|
import 'package:flutter_tools/src/linux/makefile.dart';
|
|
|
|
import 'package:flutter_tools/src/project.dart';
|
2019-04-17 19:16:55 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import 'package:process/process.dart';
|
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../../src/common.dart';
|
|
|
|
import '../../src/context.dart';
|
|
|
|
import '../../src/mocks.dart';
|
2019-07-22 22:34:03 +00:00
|
|
|
import '../../src/testbed.dart';
|
2019-04-17 19:16:55 +00:00
|
|
|
|
|
|
|
void main() {
|
2019-06-10 22:37:23 +00:00
|
|
|
MockProcessManager mockProcessManager;
|
|
|
|
MockProcess mockProcess;
|
|
|
|
MockPlatform linuxPlatform;
|
|
|
|
MockPlatform notLinuxPlatform;
|
2019-04-17 19:16:55 +00:00
|
|
|
|
2019-06-10 22:37:23 +00:00
|
|
|
setUpAll(() {
|
|
|
|
Cache.disableLocking();
|
2019-04-17 19:16:55 +00:00
|
|
|
});
|
2019-06-10 22:37:23 +00:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockProcessManager = MockProcessManager();
|
|
|
|
mockProcess = MockProcess();
|
|
|
|
linuxPlatform = MockPlatform();
|
|
|
|
notLinuxPlatform = MockPlatform();
|
|
|
|
when(mockProcess.exitCode).thenAnswer((Invocation invocation) async {
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
when(mockProcess.stderr).thenAnswer((Invocation invocation) {
|
|
|
|
return const Stream<List<int>>.empty();
|
|
|
|
});
|
|
|
|
when(mockProcess.stdout).thenAnswer((Invocation invocation) {
|
|
|
|
return const Stream<List<int>>.empty();
|
|
|
|
});
|
|
|
|
when(linuxPlatform.isLinux).thenReturn(true);
|
|
|
|
when(notLinuxPlatform.isLinux).thenReturn(false);
|
2019-04-17 19:16:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testUsingContext('Linux build fails when there is no linux project', () async {
|
|
|
|
final BuildCommand command = BuildCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
expect(createTestCommandRunner(command).run(
|
|
|
|
const <String>['build', 'linux']
|
|
|
|
), throwsA(isInstanceOf<ToolExit>()));
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
Platform: () => linuxPlatform,
|
2019-05-11 07:08:29 +00:00
|
|
|
FileSystem: () => MemoryFileSystem(),
|
2019-07-22 22:34:03 +00:00
|
|
|
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
|
2019-04-17 19:16:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testUsingContext('Linux build fails on non-linux platform', () async {
|
|
|
|
final BuildCommand command = BuildCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
fs.file('linux/build.sh').createSync(recursive: true);
|
|
|
|
fs.file('pubspec.yaml').createSync();
|
|
|
|
fs.file('.packages').createSync();
|
2019-07-01 21:49:34 +00:00
|
|
|
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
|
2019-04-17 19:16:55 +00:00
|
|
|
|
|
|
|
expect(createTestCommandRunner(command).run(
|
|
|
|
const <String>['build', 'linux']
|
|
|
|
), throwsA(isInstanceOf<ToolExit>()));
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
Platform: () => notLinuxPlatform,
|
2019-05-11 07:08:29 +00:00
|
|
|
FileSystem: () => MemoryFileSystem(),
|
2019-07-22 22:34:03 +00:00
|
|
|
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
|
2019-04-17 19:16:55 +00:00
|
|
|
});
|
|
|
|
|
2019-05-11 07:08:29 +00:00
|
|
|
testUsingContext('Linux build invokes make and writes temporary files', () async {
|
2019-04-17 19:16:55 +00:00
|
|
|
final BuildCommand command = BuildCommand();
|
|
|
|
applyMocksToCommand(command);
|
|
|
|
fs.file('linux/build.sh').createSync(recursive: true);
|
|
|
|
fs.file('pubspec.yaml').createSync();
|
|
|
|
fs.file('.packages').createSync();
|
2019-07-01 21:49:34 +00:00
|
|
|
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
|
2019-05-11 07:08:29 +00:00
|
|
|
|
2019-04-17 19:16:55 +00:00
|
|
|
when(mockProcessManager.start(<String>[
|
2019-04-24 20:34:56 +00:00
|
|
|
'make',
|
|
|
|
'-C',
|
|
|
|
'/linux',
|
2019-04-17 19:16:55 +00:00
|
|
|
], runInShell: true)).thenAnswer((Invocation invocation) async {
|
|
|
|
return mockProcess;
|
|
|
|
});
|
|
|
|
|
|
|
|
await createTestCommandRunner(command).run(
|
|
|
|
const <String>['build', 'linux']
|
|
|
|
);
|
2019-05-11 07:08:29 +00:00
|
|
|
expect(fs.file('linux/flutter/generated_config').existsSync(), true);
|
2019-04-17 19:16:55 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
2019-05-11 07:08:29 +00:00
|
|
|
FileSystem: () => MemoryFileSystem(),
|
2019-04-17 19:16:55 +00:00
|
|
|
ProcessManager: () => mockProcessManager,
|
|
|
|
Platform: () => linuxPlatform,
|
2019-07-22 22:34:03 +00:00
|
|
|
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
|
2019-04-17 19:16:55 +00:00
|
|
|
});
|
2019-04-24 20:34:56 +00:00
|
|
|
|
|
|
|
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();
|
2019-04-29 15:21:32 +00:00
|
|
|
final FlutterProject flutterProject = FlutterProject.current();
|
2019-04-24 20:34:56 +00:00
|
|
|
|
|
|
|
expect(makefileExecutableName(flutterProject.linux), 'fizz_bar');
|
2019-07-22 22:34:03 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => MemoryFileSystem(),
|
|
|
|
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: true),
|
|
|
|
});
|
|
|
|
|
|
|
|
testUsingContext('Refuses to build for Linux when feature is disabled', () {
|
|
|
|
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand());
|
|
|
|
|
|
|
|
expect(() => runner.run(<String>['build', 'linux']),
|
|
|
|
throwsA(isInstanceOf<ToolExit>()));
|
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FeatureFlags: () => TestFeatureFlags(isLinuxEnabled: false),
|
|
|
|
});
|
2019-04-17 19:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MockProcessManager extends Mock implements ProcessManager {}
|
|
|
|
class MockProcess extends Mock implements Process {}
|
|
|
|
class MockPlatform extends Mock implements Platform {
|
|
|
|
@override
|
|
|
|
Map<String, String> environment = <String, String>{
|
|
|
|
'FLUTTER_ROOT': '/',
|
|
|
|
};
|
2019-04-29 23:02:42 +00:00
|
|
|
}
|