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

Fix CMake invocation for 3.10 compat (#57415)

The -S/-B format of specifying source and build directories wasn't added
until 3.13. For 3.10 compatibility, use the older form of having the
working directory as the build directory, and the last argument as the
source directory.

Fixes #57409
parent b19b744b
...@@ -81,20 +81,20 @@ Future<void> buildLinux( ...@@ -81,20 +81,20 @@ Future<void> buildLinux(
Future<void> _runCmake(String buildModeName, Directory sourceDir, Directory buildDir) async { Future<void> _runCmake(String buildModeName, Directory sourceDir, Directory buildDir) async {
final Stopwatch sw = Stopwatch()..start(); final Stopwatch sw = Stopwatch()..start();
await buildDir.create(recursive: true);
final String buildFlag = toTitleCase(buildModeName); final String buildFlag = toTitleCase(buildModeName);
int result; int result;
try { try {
result = await processUtils.stream( result = await processUtils.stream(
<String>[ <String>[
'cmake', 'cmake',
'-S',
sourceDir.path,
'-B',
buildDir.path,
'-G', '-G',
'Ninja', 'Ninja',
'-DCMAKE_BUILD_TYPE=$buildFlag', '-DCMAKE_BUILD_TYPE=$buildFlag',
sourceDir.path,
], ],
workingDirectory: buildDir.path,
environment: <String, String>{ environment: <String, String>{
'CC': 'clang', 'CC': 'clang',
'CXX': 'clang++' 'CXX': 'clang++'
......
...@@ -82,28 +82,38 @@ void main() { ...@@ -82,28 +82,38 @@ void main() {
projectTemplateVersionFile.writeAsStringSync(templateVersion.toString()); projectTemplateVersionFile.writeAsStringSync(templateVersion.toString());
} }
// Returns the command list matching the build_linux call to cmake. // Returns the command matching the build_linux call to cmake.
List<String> cmakeCommand(String buildMode) { FakeCommand cmakeCommand(String buildMode, {void Function() onRun}) {
return <String>[ return FakeCommand(
'cmake', command: <String>[
'-S', 'cmake',
'/linux', '-G',
'-B', 'Ninja',
'build/linux/$buildMode', '-DCMAKE_BUILD_TYPE=${toTitleCase(buildMode)}',
'-G', '/linux',
'Ninja', ],
'-DCMAKE_BUILD_TYPE=${toTitleCase(buildMode)}', workingDirectory: 'build/linux/$buildMode',
]; onRun: onRun,
);
} }
// Returns the command list matching the build_linux call to ninja. // Returns the command matching the build_linux call to ninja.
List<String> ninjaCommand(String buildMode) { FakeCommand ninjaCommand(String buildMode, {
return <String>[ Map<String, String> environment,
'ninja', void Function() onRun,
'-C', String stdout = '',
'build/linux/$buildMode', }) {
'install', return FakeCommand(
]; command: <String>[
'ninja',
'-C',
'build/linux/$buildMode',
'install',
],
environment: environment,
onRun: onRun,
stdout: stdout,
);
} }
testUsingContext('Linux build fails when there is no linux project', () async { testUsingContext('Linux build fails when there is no linux project', () async {
...@@ -165,8 +175,8 @@ void main() { ...@@ -165,8 +175,8 @@ void main() {
testUsingContext('Linux build invokes CMake and ninja, and writes temporary files', () async { testUsingContext('Linux build invokes CMake and ninja, and writes temporary files', () async {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('release')), cmakeCommand('release'),
FakeCommand(command: ninjaCommand('release')), ninjaCommand('release'),
]); ]);
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
...@@ -186,7 +196,7 @@ void main() { ...@@ -186,7 +196,7 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('release'), onRun: () { cmakeCommand('release', onRun: () {
throw ArgumentError(); throw ArgumentError();
}), }),
]); ]);
...@@ -205,8 +215,8 @@ void main() { ...@@ -205,8 +215,8 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('release')), cmakeCommand('release'),
FakeCommand(command: ninjaCommand('release'), onRun: () { ninjaCommand('release', onRun: () {
throw ArgumentError(); throw ArgumentError();
}), }),
]); ]);
...@@ -225,10 +235,10 @@ void main() { ...@@ -225,10 +235,10 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('debug')), cmakeCommand('debug'),
FakeCommand( ninjaCommand('debug',
command: ninjaCommand('debug'), stdout: 'STDOUT STUFF',
stdout: 'STDOUT STUFF',), ),
]); ]);
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -247,9 +257,8 @@ void main() { ...@@ -247,9 +257,8 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('debug')), cmakeCommand('debug'),
FakeCommand( ninjaCommand('debug',
command: ninjaCommand('debug'),
environment: const <String, String>{ environment: const <String, String>{
'VERBOSE_SCRIPT_LOGGING': 'true' 'VERBOSE_SCRIPT_LOGGING': 'true'
}, },
...@@ -273,8 +282,8 @@ void main() { ...@@ -273,8 +282,8 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('debug')), cmakeCommand('debug'),
FakeCommand(command: ninjaCommand('debug')), ninjaCommand('debug'),
]); ]);
...@@ -292,8 +301,8 @@ void main() { ...@@ -292,8 +301,8 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('profile')), cmakeCommand('profile'),
FakeCommand(command: ninjaCommand('profile')), ninjaCommand('profile'),
]); ]);
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
...@@ -310,8 +319,8 @@ void main() { ...@@ -310,8 +319,8 @@ void main() {
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('release')), cmakeCommand('release'),
FakeCommand(command: ninjaCommand('release')), ninjaCommand('release'),
]); ]);
fileSystem.file('lib/other.dart') fileSystem.file('lib/other.dart')
.createSync(recursive: true); .createSync(recursive: true);
...@@ -396,8 +405,8 @@ set(BINARY_NAME "fizz_bar") ...@@ -396,8 +405,8 @@ set(BINARY_NAME "fizz_bar")
final BuildCommand command = BuildCommand(); final BuildCommand command = BuildCommand();
setUpMockProjectFilesForBuild(); setUpMockProjectFilesForBuild();
processManager = FakeProcessManager.list(<FakeCommand>[ processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(command: cmakeCommand('release')), cmakeCommand('release'),
FakeCommand(command: ninjaCommand('release')), ninjaCommand('release'),
]); ]);
await createTestCommandRunner(command).run( await createTestCommandRunner(command).run(
......
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