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

Add --target support for Windows and Linux (#34660)

- Adds desktop projects to ApplicationPackageStore
- Plumbs target overrides through the desktop builds
parent 2fefa8c7
......@@ -13,7 +13,7 @@ Future<void> main(List<String> arguments) async {
final String projectDirectory = Platform.environment['PROJECT_DIR'];
final bool verbose = Platform.environment['VERBOSE_SCRIPT_LOGGING'] != null;
final bool trackWidgetCreation = Platform.environment['TRACK_WIDGET_CREATION'] != null;
final String flutterTarget = Platform.environment['FLUTTER_TARGET'] ?? 'lib/main.dart';
final String flutterTarget = Platform.environment['FLUTTER_TARGET'] ?? path.join('lib', 'main.dart');
final String flutterEngine = Platform.environment['FLUTTER_ENGINE'];
final String localEngine = Platform.environment['LOCAL_ENGINE'];
final String flutterRoot = Platform.environment['FLUTTER_ROOT'];
......
......@@ -18,7 +18,7 @@ import 'devfs.dart';
import 'globals.dart';
import 'project.dart';
const String defaultMainPath = 'lib/main.dart';
String get defaultMainPath => fs.path.join('lib', 'main.dart');
const String defaultAssetBasePath = '.';
const String defaultManifestPath = 'pubspec.yaml';
String get defaultDepfilePath => fs.path.join(getBuildDirectory(), 'snapshot_blob.bin.d');
......@@ -55,7 +55,7 @@ class BundleBuilder {
Future<void> build({
TargetPlatform platform,
BuildMode buildMode,
String mainPath = defaultMainPath,
String mainPath,
String manifestPath = defaultManifestPath,
String applicationKernelFilePath,
String depfilePath,
......@@ -70,6 +70,7 @@ class BundleBuilder {
List<String> fileSystemRoots,
String fileSystemScheme,
}) async {
mainPath ??= defaultMainPath;
depfilePath ??= defaultDepfilePath;
assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath);
......
......@@ -16,6 +16,7 @@ import 'build.dart';
/// A command to build a linux desktop target through a build shell script.
class BuildLinuxCommand extends BuildSubCommand {
BuildLinuxCommand() {
usesTargetOption();
argParser.addFlag('debug',
negatable: false,
help: 'Build a debug version of your app.',
......@@ -59,7 +60,7 @@ class BuildLinuxCommand extends BuildSubCommand {
if (!flutterProject.linux.existsSync()) {
throwToolExit('No Linux desktop project configured.');
}
await buildLinux(flutterProject.linux, buildInfo);
await buildLinux(flutterProject.linux, buildInfo, target: targetFile);
return null;
}
}
......@@ -16,6 +16,7 @@ import 'build.dart';
/// A command to build a windows desktop target through a build shell script.
class BuildWindowsCommand extends BuildSubCommand {
BuildWindowsCommand() {
usesTargetOption();
argParser.addFlag('debug',
negatable: false,
help: 'Build a debug version of your app.',
......@@ -59,7 +60,7 @@ class BuildWindowsCommand extends BuildSubCommand {
if (!flutterProject.windows.existsSync()) {
throwToolExit('No Windows desktop project configured.');
}
await buildWindows(flutterProject.windows, buildInfo);
await buildWindows(flutterProject.windows, buildInfo, target: targetFile);
return null;
}
}
......@@ -81,7 +81,11 @@ class LinuxDevice extends Device {
}) async {
_lastBuiltMode = debuggingOptions.buildInfo.mode;
if (!prebuiltApplication) {
await buildLinux(FlutterProject.current().linux, debuggingOptions.buildInfo);
await buildLinux(
FlutterProject.current().linux,
debuggingOptions.buildInfo,
target: mainPath,
);
}
await stopApp(package);
final Process process = await processManager.start(<String>[
......
......@@ -18,13 +18,15 @@ import 'msbuild_utils.dart';
import 'visual_studio.dart';
/// Builds the Windows project using msbuild.
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {String target = 'lib/main.dart'}) async {
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {String target}) async {
final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': Cache.flutterRoot,
'FLUTTER_TARGET': target,
'PROJECT_DIR': windowsProject.project.directory.path,
'TRACK_WIDGET_CREATION': (buildInfo?.trackWidgetCreation == true).toString(),
};
if (target != null) {
environment['FLUTTER_TARGET'] = target;
}
if (artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = artifacts;
final String engineOutPath = localEngineArtifacts.engineOutPath;
......
......@@ -82,7 +82,11 @@ class WindowsDevice extends Device {
bool ipv6 = false,
}) async {
if (!prebuiltApplication) {
await buildWindows(FlutterProject.current().windows, debuggingOptions.buildInfo);
await buildWindows(
FlutterProject.current().windows,
debuggingOptions.buildInfo,
target: mainPath,
);
}
await stopApp(package);
final Process process = await processManager.start(<String>[
......
......@@ -34,7 +34,7 @@ void main() {
setUp(() {
Cache.disableLocking();
testFileSystem.directory('lib').createSync();
testFileSystem.file('lib/main.dart').createSync();
testFileSystem.file(testFileSystem.path.join('lib', 'main.dart')).createSync();
});
group('with one device and no specified target file', () {
......@@ -246,7 +246,7 @@ void main() {
..createSync();
// Delete the main.dart file to be sure that attach works without it.
fs.file('lib/main.dart').deleteSync();
fs.file(fs.path.join('lib', 'main.dart')).deleteSync();
final AttachCommand command = AttachCommand(hotRunnerFactory: mockHotRunnerFactory);
await createTestCommandRunner(command).run(<String>['attach', '-t', foo.path, '-v']);
......
......@@ -63,6 +63,7 @@ void main() {
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);
expect(createTestCommandRunner(command).run(
const <String>['build', 'linux']
......@@ -78,6 +79,7 @@ void main() {
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);
when(mockProcessManager.start(<String>[
'make',
......
......@@ -87,6 +87,7 @@ void main() {
when(mockVisualStudio.vcvarsPath).thenReturn(vcvarsPath);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
expect(createTestCommandRunner(command).run(
const <String>['build', 'windows']
......@@ -104,6 +105,7 @@ void main() {
when(mockVisualStudio.vcvarsPath).thenReturn(vcvarsPath);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
fs.file(fs.path.join('lib', 'main.dart')).createSync(recursive: true);
when(mockProcessManager.start(<String>[
r'C:\packages\flutter_tools\bin\vs_build.bat',
......
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