Selaa lähdekoodia

xcode: Restore ctest --build-and-test without --build-project

Previously, it used to be possible to execute ctest --build-and-test
without specifying --build-project. When used with the Xcode generator,
this would work as long as there was only one .xcodeproj file in the
directory, where xcodebuild would then default to using that project.
The recent changes to support .xcworkspace files broke that logic, placing
a malformed pair of options "-project .xcodeproj" on the command line
instead of omitting the "-project" option altogether.

Fixes: #27090
Stepanov Igor 3 kuukautta sitten
vanhempi
sitoutus
0b7d8e4ad6
1 muutettua tiedostoa jossa 10 lisäystä ja 1 poistoa
  1. 10 1
      Source/cmGlobalXCodeGenerator.cxx

+ 10 - 1
Source/cmGlobalXCodeGenerator.cxx

@@ -551,6 +551,15 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
   std::string const xcodebuild =
     this->SelectMakeProgram(makeProgram, this->GetXcodeBuildCommand());
 
+  // Note that projectName can be empty, such as from a command like this one:
+  //   ctest --build-and-test . build --build-generator Xcode
+  // If projectName is empty, then isWorkspace set further below will always
+  // be false because workspacePath will never point to a valid workspace file.
+  // And if projectName is empty, we don't add any -workspace or -project
+  // option to the xcodebuild command line because we don't know what to put
+  // after either option. For that scenario, we rely on xcodebuild finding
+  // exactly one .xcodeproj file in the working directory.
+
   std::string const workspacePath = cmStrCat(projectName, ".xcworkspace");
   std::string const projectPath = cmStrCat(projectName, ".xcodeproj");
 
@@ -563,7 +572,7 @@ cmGlobalXCodeGenerator::GenerateBuildCommand(
 
   if (isWorkspace) {
     requiredArgs.insert(requiredArgs.end(), { "-workspace", workspacePath });
-  } else {
+  } else if (!projectName.empty()) {
     requiredArgs.insert(requiredArgs.end(), { "-project", projectPath });
   }