Swift Package Manager - Resolve Package Versions terminal command - xcode

I want to replace cocoapods with SPM. I have decided to go at it one library at a time. I removed the swinject library from cocoapods and added it via File->Swift Packages->Add Package Dependency
This was successful and the project built and ran as expected.
I then asked other people in my team to check out the branch and see if they can build the project on their side without issues. We then ran into the error "Missing package product 'Swinject'". We resolved this error by performing File->Swift Packages->Resolve Package Versions in Xcode.
I need to get this working on the build server as well. I tried typing in swift package --help in the Terminal app to see what commands are available. The resolve command looked promising so I tried that to no avail. (error: root manifest not found)
So, my question then, is there a terminal command that does the same as File->Swift Packages->Resolve Package Versions?
Note: When I added the 3rd party library via SPM, it created one file for me: Proj.xcworkspace/xcshareddata/swiftpm/Package.resolved. It also made various changes to the Proj.xcodeproj/project.pbxproj file. No package.swift file was created.
Update:
The closest I have gotten to an answer was that I should try xcodebuild -resolvePackageDependencies, unfortunately the command does not do the same as File->Swift Packages->Resolve Package Versions.

I was struggling with the SPM in my project. It seems that you need to pass the -clonedSourcePackagesDirPath [directory]
xcodebuild -resolvePackageDependencies -workspace ck550.xcworkspace -scheme ck550-cli -clonedSourcePackagesDirPath .
xcodebuild -workspace ck550.xcworkspace -scheme ck550-cli -clonedSourcePackagesDirPath .
The first command resolves and downloads all Swift Packages into the ./checkouts and some other ./[dirs] are also created.
The second command initiates the build of your application, and those SPM packages are also built.
Here is output from the build server:
https://travis-ci.org/vookimedlo/ck550-macos/builds/626438212
Travis-CI configuration:
https://github.com/vookimedlo/ck550-macos/blob/master/.travis.yml

From what I have seen, there are 2 Package.resolved files. One on the workspace and one on the project. For some reason the workspace has old versions of the packages and running
xcodebuild -resolvePackageDependencies -workspace myworkspace.xcworkspace -scheme my scheme
does not work. However, resolving on the project (since the project's Package.resolved has the correct packages version info) does work
xcodebuild -resolvePackageDependencies -project myproject.xcodeproj -scheme my scheme

Related

Does xcode use "xcodebuild" under the hood?

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.

xcodebuild fails, but building from Xcode succeeds

I'm trying to automate my build using xcodebuild.
However, my xcodebuild fails while building static libraries, complaining that it can't find headers that are part of dependency frameworks.
No problem to build from Xcode.
Why is the result of xcodebuild different from the one of Xcode?
You might accidentally build the Xcode project instead of the Xcode Workspace from xcodebuild.
If this is the case, replace:
xcodebuild -project "<*yourProjectFile*>.xcodeproj"
with:
xcodebuild -workspace <*yourWorkspaceFile*>.xcworkspace
After fixing this I get the exact same results from Xcode and xcodebuild.

Xcodebuild no such module

I'm trying to build an Xcode project through the terminal. My project uses a submodule called SwiftRichString which I'm importing in one of my files.
On my terminal, I tried:
xcodebuild -project MyProject.xcodeproj
But this says that it cannot find the module called SwiftRichString, as expected.
So then I tried,
xcodebuild -scheme SwiftRichString
This worked and said "Build Succeeded", but then if I try to do
xcodebuild -project MyProject.xcodeproj
it fails just like before.
If I go to Xcode and go to Product>Scheme>SwiftRichString and build it, it succeeds building. Then if I build my project within Xcode, it works, but it doesn't build in terminal.

xcodebuild does not install into applications folder

I have an XCode project with two executable targets, which I use for my own work (that is, I don't sell or publish the applications, but they are still important to me), which depends on one external project. Until now, it has been unproblematic to build the Application(s) and install into the /Applications folder. What I did, was go into the command line and type:
sudo xcodebuild -scheme Trainer install
This would install the target Trainer into the Applications folder, and the application could be run from there. If I tried to specify the target using -target Trainer instead, it would not work, as it would not find dependencies in the external project. Anyway, since last time it worked, two things have happened:
I have upgraded to OS X 10.11
I have upgraded XCode to Version 7.1.1 (7B1005)
Whatever the reason, xcodebuild does no longer install the built product into the /Applications folder. The last lines from the build log, when building with xcodebuild now are:
Touch /var/root/Library/Developer/Xcode/DerivedData/SoundSample-bvsqlgnuhfmtjkgkhevztdzbjbie/Build/Intermediates/ArchiveIntermediates/Trainer/BuildProductsPath/Release/Trainer.app.dSYM
cd /Users/pbholmen/Projects/SoundSample
/usr/bin/touch -c /var/root/Library/Developer/Xcode/DerivedData/SoundSample-bvsqlgnuhfmtjkgkhevztdzbjbie/Build/Intermediates/ArchiveIntermediates/Trainer/BuildProductsPath/Release/Trainer.app.dSYM
RegisterWithLaunchServices /var/root/Library/Developer/Xcode/DerivedData/SoundSample-bvsqlgnuhfmtjkgkhevztdzbjbie/Build/Intermediates/ArchiveIntermediates/Trainer/InstallationBuildProductsLocation/Applications/Trainer.app
cd /Users/pbholmen/Projects/SoundSample
builtin-lsRegisterURL /var/root/Library/Developer/Xcode/DerivedData/SoundSample-bvsqlgnuhfmtjkgkhevztdzbjbie/Build/Intermediates/ArchiveIntermediates/Trainer/InstallationBuildProductsLocation/Applications/Trainer.app
** INSTALL SUCCEEDED **
I have tried to simply copy the Trainer.app that it builds into the /Applications folder, but if I double-click on it, it just won't run. Of course, the Application works when built and run from within XCode, both with the "Debug" and "Release" configuration.
Back when it did work, this would be the last lines of the build log (in Terminal):
Touch build/Release/Trainer.app.dSYM
cd /Users/pbholmen/Projects/SoundSample
/usr/bin/touch -c /Users/pbholmen/Projects/SoundSample/build/Release/SoundSample.app.dSYM
RegisterWithLaunchServices /Applications/Trainer.app
cd /Users/pbholmen/Projects/SoundSample
builtin-lsRegisterURL /Applications/Trainer.app
** INSTALL SUCCEEDED **
If I try to go into the build log from within XCode, find where it puts the builds, and maneuver into that location in Finder and start the application from outside of XCode, that doesn't work either.
Here you can see my Deployment build settings for the target:
Build settings
Under "Deployment location" I have tried both "YES" and "NO", and under "OS X Deployment target" I have tried both "OS X 10.10" and "OS X 10.11". And all four combinations of the two.
After hours of twiddling, I finally figured out the answer. First off, the command
sudo xcodebuild -scheme Trainer install
is wrong. It was a workaround, because I couldn't get XCode to manage my external dependencies from the command line, even though they were managed correctly within XCode. The correct invocation, for a target other than the project's main target is
sudo xcodebuild -target Trainer install
Previously, the first invocation would work, the product would be installed even though the scheme doesn't really include an "Install" action. This is clearly no longer so with XCode 7.1. The reason I couldn't use -target instead of -scheme previously, was because my target was dependent on a framework in another project, which was added to my main project (the external project was added, not just the framework). All dependencies were set up correctly in my main project, and from the command line it worked only when specifying the scheme, not when specifying the target. When running xcodebuild with -target specified, xcodebuild would not find the modules in the external project (a Swift framework).
I have now figured out the reason for this. The project which contained the external framework was not set up correctly. It was set up to install the framework into a bogus location (/tmp/ProjectName.dst/Library/Frameworks, which is the default). In addition, my main project needed to add /Library/Frameworks into the framework search paths. It seems that when the project is built inside XCode, or for archiving etc... libraries and executables are built into a "private" folder structure separate from the system itself. When running xcodebuild install, however, it tries to install the external frameworks into the proper system folders, and link it there. Therefore, setups that work inside XCode may not work when running 'xcodebuild'.
EDIT: It works now, but StackOverflow won't let me mark it as correct before two days.

'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

Resources