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