Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ad0dc2

Browse files
[flutter_tools] fix missing cmake (#103761)
1 parent 90a592b commit 0ad0dc2

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

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

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -124,34 +124,33 @@ Future<void> _runCmake(String buildModeName, Directory sourceDir, Directory buil
124124
final bool needCrossBuildOptionsForArm64 = needCrossBuild
125125
&& targetPlatform == TargetPlatform.linux_arm64;
126126
int result;
127-
try {
128-
result = await globals.processUtils.stream(
129-
<String>[
130-
'cmake',
131-
'-G',
132-
'Ninja',
133-
'-DCMAKE_BUILD_TYPE=$buildFlag',
134-
'-DFLUTTER_TARGET_PLATFORM=${getNameForTargetPlatform(targetPlatform)}',
135-
// Support cross-building for arm64 targets on x64 hosts.
136-
// (Cross-building for x64 on arm64 hosts isn't supported now.)
137-
if (needCrossBuild)
138-
'-DFLUTTER_TARGET_PLATFORM_SYSROOT=$targetSysroot',
139-
if (needCrossBuildOptionsForArm64)
140-
'-DCMAKE_C_COMPILER_TARGET=aarch64-linux-gnu',
141-
if (needCrossBuildOptionsForArm64)
142-
'-DCMAKE_CXX_COMPILER_TARGET=aarch64-linux-gnu',
143-
sourceDir.path,
144-
],
145-
workingDirectory: buildDir.path,
146-
environment: <String, String>{
147-
'CC': 'clang',
148-
'CXX': 'clang++',
149-
},
150-
trace: true,
151-
);
152-
} on ArgumentError {
153-
throwToolExit("cmake not found. Run 'flutter doctor' for more information.");
127+
if (!globals.processManager.canRun('cmake')) {
128+
throwToolExit(globals.userMessages.cmakeMissing);
154129
}
130+
result = await globals.processUtils.stream(
131+
<String>[
132+
'cmake',
133+
'-G',
134+
'Ninja',
135+
'-DCMAKE_BUILD_TYPE=$buildFlag',
136+
'-DFLUTTER_TARGET_PLATFORM=${getNameForTargetPlatform(targetPlatform)}',
137+
// Support cross-building for arm64 targets on x64 hosts.
138+
// (Cross-building for x64 on arm64 hosts isn't supported now.)
139+
if (needCrossBuild)
140+
'-DFLUTTER_TARGET_PLATFORM_SYSROOT=$targetSysroot',
141+
if (needCrossBuildOptionsForArm64)
142+
'-DCMAKE_C_COMPILER_TARGET=aarch64-linux-gnu',
143+
if (needCrossBuildOptionsForArm64)
144+
'-DCMAKE_CXX_COMPILER_TARGET=aarch64-linux-gnu',
145+
sourceDir.path,
146+
],
147+
workingDirectory: buildDir.path,
148+
environment: <String, String>{
149+
'CC': 'clang',
150+
'CXX': 'clang++',
151+
},
152+
trace: true,
153+
);
155154
if (result != 0) {
156155
throwToolExit('Unable to generate build files');
157156
}

packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,15 @@ void main() {
172172
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
173173
});
174174

175-
testUsingContext('Handles argument error from missing cmake', () async {
175+
testUsingContext('Handles missing cmake', () async {
176176
final BuildCommand command = BuildCommand();
177177
setUpMockProjectFilesForBuild();
178-
processManager = FakeProcessManager.list(<FakeCommand>[
179-
cmakeCommand('release', onRun: () {
180-
throw ArgumentError();
181-
}),
182-
]);
178+
processManager = FakeProcessManager.empty()
179+
..excludedExecutables.add('cmake');
183180

184181
expect(createTestCommandRunner(command).run(
185182
const <String>['build', 'linux', '--no-pub']
186-
), throwsToolExit(message: "cmake not found. Run 'flutter doctor' for more information."));
183+
), throwsToolExit(message: 'CMake is required for Linux development.'));
187184
}, overrides: <Type, Generator>{
188185
FileSystem: () => fileSystem,
189186
ProcessManager: () => processManager,

0 commit comments

Comments
 (0)