Skip to content

Commit 3c9b128

Browse files
Add --config-only build option for Linux and Windows (flutter#172239)
Adds a `--config-only` option for Linux and Windows, which generates the native build files (ninja and Visual Studio respectively) without actually doing the build. This brings them into alignment with Android, iOS, and macOS, which already have this flag, and will allow some workflow improvements when running native plugin tests in environments like the flutter/packages CI. Fixes flutter#93407 Fixes flutter#172029 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent b2cc192 commit 3c9b128

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed

packages/flutter_tools/lib/src/commands/build_linux.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class BuildLinuxCommand extends BuildSubCommand {
4040
'the app is compiled. This option is valid only '
4141
'if the current host and target architectures are different.',
4242
);
43+
argParser.addFlag(
44+
'config-only',
45+
help: 'Update the project configuration without performing a build.',
46+
);
4347
}
4448

4549
final OperatingSystemUtils _operatingSystemUtils;
@@ -58,6 +62,8 @@ class BuildLinuxCommand extends BuildSubCommand {
5862
@override
5963
String get description => 'Build a Linux desktop application.';
6064

65+
bool get configOnly => boolArg('config-only');
66+
6167
@override
6268
Future<FlutterCommandResult> runCommand() async {
6369
final BuildInfo buildInfo = await getBuildInfo();
@@ -95,6 +101,7 @@ class BuildLinuxCommand extends BuildSubCommand {
95101
targetPlatform: targetPlatform,
96102
targetSysroot: stringArg('target-sysroot')!,
97103
logger: logger,
104+
configOnly: configOnly,
98105
);
99106
return FlutterCommandResult.success();
100107
}

packages/flutter_tools/lib/src/commands/build_windows.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class BuildWindowsCommand extends BuildSubCommand {
2525
}) : _operatingSystemUtils = operatingSystemUtils,
2626
super(verboseHelp: verboseHelp) {
2727
addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
28+
argParser.addFlag(
29+
'config-only',
30+
help: 'Update the project configuration without performing a build.',
31+
);
2832
}
2933

3034
final OperatingSystemUtils _operatingSystemUtils;
@@ -46,6 +50,8 @@ class BuildWindowsCommand extends BuildSubCommand {
4650
@visibleForTesting
4751
VisualStudio? visualStudioOverride;
4852

53+
bool get configOnly => boolArg('config-only');
54+
4955
@override
5056
Future<FlutterCommandResult> runCommand() async {
5157
final BuildInfo buildInfo = await getBuildInfo();
@@ -75,6 +81,7 @@ class BuildWindowsCommand extends BuildSubCommand {
7581
appFilenamePattern: 'app.so',
7682
analytics: analytics,
7783
),
84+
configOnly: configOnly,
7885
);
7986
return FlutterCommandResult.success();
8087
}

packages/flutter_tools/lib/src/linux/build_linux.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Future<void> buildLinux(
4242
required TargetPlatform targetPlatform,
4343
String targetSysroot = '/',
4444
required Logger logger,
45+
bool configOnly = false,
4546
}) async {
4647
target ??= 'lib/main.dart';
4748
if (!linuxProject.cmakeFile.existsSync()) {
@@ -93,6 +94,9 @@ Future<void> buildLinux(
9394
targetPlatform,
9495
targetSysroot,
9596
);
97+
if (configOnly) {
98+
return;
99+
}
96100
await _runBuild(buildDirectory);
97101
} finally {
98102
status.cancel();

packages/flutter_tools/lib/src/windows/build_windows.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Future<void> buildWindows(
3737
String? target,
3838
VisualStudio? visualStudioOverride,
3939
SizeAnalyzer? sizeAnalyzer,
40+
bool configOnly = false,
4041
}) async {
4142
// MSBuild files generated by CMake do not properly escape some characters
4243
// In the directories. This check produces more meaningful error messages
@@ -111,6 +112,9 @@ Future<void> buildWindows(
111112
if (visualStudio.displayVersion == '17.1.0') {
112113
_fixBrokenCmakeGeneration(buildDirectory);
113114
}
115+
if (configOnly) {
116+
return;
117+
}
114118
await _runBuild(cmakePath, buildDirectory, buildModeName);
115119
} finally {
116120
status.stop();
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:ffi';
6+
7+
import 'package:file_testing/file_testing.dart';
8+
import 'package:flutter_tools/src/base/file_system.dart';
9+
10+
import '../src/common.dart';
11+
import 'test_utils.dart';
12+
13+
void main() {
14+
test(
15+
'flutter build linux --config-only updates generated build files without performing build',
16+
() async {
17+
final String workingDirectory = fileSystem.path.join(
18+
getFlutterRoot(),
19+
'dev',
20+
'integration_tests',
21+
'flutter_gallery',
22+
);
23+
24+
await processManager.run(<String>[
25+
flutterBin,
26+
...getLocalEngineArguments(),
27+
'clean',
28+
], workingDirectory: workingDirectory);
29+
final buildCommand = <String>[
30+
flutterBin,
31+
...getLocalEngineArguments(),
32+
'build',
33+
'linux',
34+
'--config-only',
35+
'-v',
36+
];
37+
await processManager.run(buildCommand, workingDirectory: workingDirectory);
38+
39+
final arch = Abi.current() == Abi.linuxArm64 ? 'arm64' : 'x64';
40+
41+
// Build file should be created.
42+
final File generatedConfig = fileSystem.file(
43+
fileSystem.path.join(workingDirectory, 'build', 'linux', arch, 'release', 'build.ninja'),
44+
);
45+
expect(generatedConfig, exists);
46+
47+
// No code should be compiled.
48+
final File appLibrary = fileSystem.file(
49+
fileSystem.path.join(workingDirectory, 'build', 'lib', 'libapp.so'),
50+
);
51+
final File exe = fileSystem.file(
52+
fileSystem.path.join(
53+
workingDirectory,
54+
'build',
55+
'linux',
56+
arch,
57+
'release',
58+
'intermediates_do_not_run',
59+
'flutter_gallery',
60+
),
61+
);
62+
final File bundleExe = fileSystem.file(
63+
fileSystem.path.join(
64+
workingDirectory,
65+
'build',
66+
'linux',
67+
arch,
68+
'release',
69+
'bundle',
70+
'flutter_gallery',
71+
),
72+
);
73+
expect(appLibrary, isNot(exists));
74+
expect(exe, isNot(exists));
75+
expect(bundleExe, isNot(exists));
76+
},
77+
skip: !platform.isLinux, // [intended] Linux builds only work on Linux.
78+
);
79+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:ffi';
6+
7+
import 'package:file_testing/file_testing.dart';
8+
import 'package:flutter_tools/src/base/file_system.dart';
9+
10+
import '../src/common.dart';
11+
import 'test_utils.dart';
12+
13+
void main() {
14+
test(
15+
'flutter build windows --config-only updates generated build files without performing build',
16+
() async {
17+
final String workingDirectory = fileSystem.path.join(
18+
getFlutterRoot(),
19+
'dev',
20+
'integration_tests',
21+
'flutter_gallery',
22+
);
23+
24+
await processManager.run(<String>[
25+
flutterBin,
26+
...getLocalEngineArguments(),
27+
'clean',
28+
], workingDirectory: workingDirectory);
29+
final buildCommand = <String>[
30+
flutterBin,
31+
...getLocalEngineArguments(),
32+
'build',
33+
'windows',
34+
'--config-only',
35+
'-v',
36+
];
37+
await processManager.run(buildCommand, workingDirectory: workingDirectory);
38+
39+
final arch = Abi.current() == Abi.windowsArm64 ? 'arm64' : 'x64';
40+
41+
// Solution file should be created.
42+
final File generatedConfig = fileSystem.file(
43+
fileSystem.path.join(workingDirectory, 'build', 'windows', arch, 'flutter_gallery.sln'),
44+
);
45+
expect(generatedConfig, exists);
46+
47+
// No code should be compiled.
48+
final File appLibrary = fileSystem.file(
49+
fileSystem.path.join(workingDirectory, 'build', 'windows', 'app.so'),
50+
);
51+
final File exe = fileSystem.file(
52+
fileSystem.path.join(
53+
workingDirectory,
54+
'build',
55+
'windows',
56+
arch,
57+
'runner',
58+
'Release',
59+
'flutter_gallery.exe',
60+
),
61+
);
62+
expect(appLibrary, isNot(exists));
63+
expect(exe, isNot(exists));
64+
},
65+
skip: !platform.isWindows, // [intended] Windows builds only work on Windows.
66+
);
67+
}

0 commit comments

Comments
 (0)