Does xcode use "xcodebuild" under the hood? - xcode

Does xcode use of the xcodebuild command behind the scenes to build?
If so, how can I find the exact xcodebuild command that is run?
I checked the report navigator but couldn't find it in there.
I would have thought that running xcodebuild -sdk iphonesimulator -configuration Debug -project <myproject>.xcodeproj -scheme <myscheme> would be identical to selecting product -> build in xcode (with a scheme/destination matching the command line), but they seem to have slightly different behavior.
For example, when running the command line above with the -showBuildSettings option, I noticed that BUILD_ACTIVE_RESOURCES_ONLY=NO even though it should be set to YES according to the target's build settings. When running product -> build from xcode, the build settings logs (generated by following #Slipp D. Thompson's answer here) show BUILD_ACTIVE_RESOURCES_ONLY=YES.
There are few other strange differences I noticed as well.

No. One could do an experiment: move all xcodebuild binaries in some local folder and check that Xcode still able to build some application.
Since Apple presents xcodebuild as a self contained command line tool for building Xcode projects, it is reasonable to suspect that use code sharing between both tools.

Related

How can I see log of commands Xcode executed when I press `build` on Xcode?

I want to see the commands Xcode executed when I press "Build" on Xcode.
Those commands should be like xcodebuild and such.
I tried to find it at Xcode > View > Navigators > Show Report Navigator (related post), but I can not find the keyword xcodebuild inside. I want to see the parameters Xcode used for xcodebuild.
Am I able to do that?
Apparently, Xcode doesn't use xcodebuild in the build process. (If you think about it, the xcodebuild command is user-facing and part of the Xcode command-line tools, but those aren't required to be present to build and/or run something in it.) Here's the entirety of this very short answer:
You can't. Xcode itself doesn't invoke xcodebuild during the build process. This post has more information on executing xcodebuild to build for the simulator.

xcodebuild gives signing error when it shouldn't

I execute the following xcodebuild command line:
xcodebuild CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
-workspace "MyThing.xcworkspace" -scheme "MyScheme"
-configuration 'Debug' -sdk iphoneos clean build
and get this error:
error: An empty identity is not valid when signing a binary
for the product type 'Application'. (in target 'MyTarget')
This used to work. How can I fix it?
This is using Xcode 10.2.1.
For whatever reason, this seems to be (yet another) strange side effect of using Xcode's new build system. You can fix this from the xcodebuild command line by forcing use of the legacy build system, using the following flag:
-UseModernBuildSystem=0
To set up your project/workspace to use the legacy build system for everything, see here.
NOTE: While one can apparently still use it for a bit longer (in June 2022), the legacy build system is marked deprecated in Xcode 13.4.1)

Xcode 9.2: Size Discrepancy between Release builds inside Xcode and using xcodebuild

It appears that when building with Xcode 9.2, binaries generated with xcodebuild are slightly larger than by using Xcode's regular 'Build for Profiling' command. Both are set to generate Release builds, the configuration for command-line builds is also set to 'Release' and this did not occur with previous versions of Xcode.
These are the frameworks with their respective sizes when building from within Xcode:
And these are generated by xcodebuild:
I suspect that some debug or code coverage data is left in some of the frameworks when using xcodebuild.
FYI: A previous build had way larger C binaries (e.g. sqlite3.framework was several megabytes in size). After discovering https://github.com/Carthage/Carthage/issues/2056, I disabled code coverage in the 'Test' action of my build scheme and disabled the "Undefined Behavior" sanitizer. Before that, the frameworks were even larger (again, note sqlite3.framework) and there was a dylib from the "Undefined Behavior" sanitizer which should not be present in Release builds:
Did anyone encounter something similar and/or was able to fix this issue? Happy to provide the output of e.g. nm or otool if that helps (and you tell me which options to pass to those tools to generate meaningful information).
P.S.:
I am using this command for xcodebuild:
xcodebuild -workspace Timing.xcworkspace -scheme 'Timing 2' -configuration 'Release' -derivedDataPath build clean build
I did enable parallel builds with
defaults write com.apple.dt.Xcode BuildSystemScheduleInherentlyParallelCommandsExclusively -bool NO
and am using the new Xcode build system, however the issue also appears with the "regular" build settings. Plus, there should not be a difference between the outputs of Xcode's build step and xcodebuild in either case. Also, sqlite3.framework is built via CocoaPods, but that should not matter, either.
Looks like the extra data was code coverage data injected due to xcodebuild adding the compiler options -profile-generate -profile-coverage-mapping. The "solution" was to uncheck the "Gather coverage data" option on the "Test" scheme action, even though xcodebuild was not building for testing.

'Cordova/CDVViewController.h' file not found when run in Xcode terminal

So when I am trying to build my code from xcode terminal it is failing and giving me an error of 'Cordova/CDVViewController.h' file not found but when I am building this from xcode then it is building just fine.
In my Xcode, I've done the whole Cordova sub directory thing Upgrade Cordova. Also when I ran list. This is what I see below:
xcodebuild -list
Information about project "myProject":
Targets:
myProject
Build Configurations:
Debug
Release
If no build configuration is specified and -scheme is not passed then "Release" is used.
Schemes:
myProject
CordovaLib
Environment: Xcode5, OS 10.8.5
Is there anything I am missing? The reason why I am doing this because I am trying to run this through jenkins. I thought it was a jenkins issue but then I got it down to the xcode terminal not seeing the CordovaLib.
I've spent too much time figuring out the solution for this so it is a shame not to share. There can be many possible reasons why this problem arise but if you feel like you've set up everything right in the CordovaLib (like me!) and still has the same problem. This can be one of the causes. What's happening is when I ran the
xcodebuild -scheme myProject -configuration "Release"
it is building successfully, but if you don't supply "-scheme" it it will fail by default it is using the "Release". The parameters of the scheme will control which targets are built and how they are built, myProject scheme contains the subfolder and reference to Cordovalib.
Now, moving to Jenkins, is you need to supply the scheme in the "Xcode Schema File" text box in the Advanced Xcode build options section of the XCode Plugin.
My set-up is Xcode as my slave but this may still apply to whatever Xcode and Jenkins combination you have - so when I ran the
xcodebuild -list
I receive the message the following message:
If no build configuration is specified and -scheme is not passed then "Release" is used.
This project contains no schemes.
The solution for this is, in your xcode project, go to Product|Scheme|Manage Scheme and checked "Shared" to both projects myProject and CordovaLib. Compile. Check-in (because I am grabbing this from TFS). Ran again the "-list" command and you will see the schemes that you just shared.
Hope this helps!
Thanks a lot !
Just adding "-scheme" and "-configuration" parameters fixed the problem for me.
If it can help someone else, here is the full command line i used :
xcodebuild -scheme MyProject -configuration "Release" -arch i386 -sdk iphonesimulator7.1
I used it to generate a ios simulator build in order to submit an Phonegap / Cordova application to the Facebook Review
In build settings
add this item to "Header Search Path"
$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include

Build and Analyze using xcodebuild

Is there a way to do a Build and Analyze like in Xcode using xcodebuild? I'm using Xcode 3.2.2
With Xcode 5, you can simply do $ xcodebuild [OTHER_OPTIONS] analyze.
I do not think so, however you can download the Clang Static Analyzer separately, and use it on the command line, for example before your build. The "Build and Analyze" option uses exactly this project to perform the analysis. The output of the Clang analyzer consists in HTML files, which you can automatically store for later review.
http://clang-analyzer.llvm.org/
Yes, you can do so now. You can use the "analyze" action.
Example:
xcodebuild analyze -workspace YourWorkspace.xcworkspace -scheme YourSchemeName -sdk iphoneos -configuration Release
(This is at least as of Xcode 10.0, Build version 10A255; however, without taking the time to research, I assume this has been available in previous versions too.)

Resources