iphone sdk 4.3 running unit test from command line - command-line

i like to run test cases from the command line but there is a little problem… maybe someone can help me…
i' ve created a simple HelloWorld Project with XCode4! The build works fine.
xcodebuild -project HelloWorld.xcodeproj -target HelloWorld -sdk iphonesimulator4.3 -configuration "Debug"
But the test doesn't work (i use the default unit test which xcode4 creates)
xcodebuild -project HelloWorld.xcodeproj -target HelloWorldTests -sdk iphonesimulator4.3 -configuration "Debug"
Here are some interesting outputs:
=== BUILD NATIVE TARGET HelloWorld OF PROJECT HelloWorld WITH THE
DEFAULT CONFIGURATION (Release) ===
Check dependencies
And
/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/Tools/RunPlatformUnitTests:95:
warning: Skipping tests; the
iPhoneSimulator platform does not
currently support application-hosted
tests (TEST_HOST set).
I guess the last output is the problem but i haven't any idea to fix it :-(

It sounds as though you may have unit tests and application tests mixed up. Referring to the two following sources (especially the non-apple one) will help you out a lot:
Apple's Documentation
CocoaWithLove Article

Related

Build Failed Task failed with exit code 65

I am working on a project that uses Carthage, it’s been a couple of months since the last time the project was opened. Now I am trying to move dependencies to .xcframeworks because with the old .framework, it wasn’t working. I encountered various errors and fixed them but there’s one dependency that I can’t fix, 

SwinjectStoryboard
.

I tried using this workaround and setting command line tools
I have also tried creating an empty project with only Swinject and SwinjectStoryboard dependency
but still, my build is failing with the following message
Build Failed Task failed with exit code 65: /usr/bin/xcrun
xcodebuild -project
/Users/abu/Developer/xcframework_2/Carthage/Checkouts/SwinjectStoryboard/SwinjectStoryboard.xcodeproj
-scheme SwinjectStoryboard-iOS -configuration Release -derivedDataPath /Users/abu/Library/Caches/org.carthage.CarthageKit/DerivedData/12.5_12E262/SwinjectStoryboard/2.2.0
-sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive VALIDATE_WORKSPACE=NO
-archivePath /var/folders/g9/rjxzfx7d2s51_sr6stdkpc5c0000gn/T/SwinjectStoryboard
SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO
CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO
FRAMEWORK_SEARCH_PATHS=$(inherited)
/var/folders/g9/rjxzfx7d2s51_sr6stdkpc5c0000gn/T/carthage-xcframework-HTlC
(launched in
/Users/abu/Developer/xcframework_2/Carthage/Checkouts/SwinjectStoryboard)
This usually indicates that project itself failed to compile. Please
check the xcodebuild log for more details:
/var/folders/g9/rjxzfx7d2s51_sr6stdkpc5c0000gn/T/carthage-xcodebuild.Tafjce.log
I am running the following command to build the dependencies
carthage.sh update --use-xcframeworks --platform iOS
here's my contents of my Cartfile
github "Swinject/Swinject"
github "Swinject/SwinjectStoryboard"
I am stuck on this problem for a couple of days now and would appreciate any help

How can I build a Swift Package for iOS over command line?

In Xcode, I can select my destination as a "generic iOS device" or any iOS simulator, and my package will build platform-specific code for ios.
Via command line "swift build" only builds my target for macOS.
I want to build the target for iOS for CI purposes. The problem with building for macOS is that UIKit-specific code won't be built.
For example:
#if canImport(UIKit)
// some invalid code
#endif
The invalid code will not be noticed and will pass the build phase.
Ideally, I could say something like swift build -platform iOS. Is there a way to do something like this?
At time of writing (Feb 16, 2019), a working solution is:
swift build -v \
-Xswiftc "-sdk" \
-Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" \
-Xswiftc "-target" \
-Xswiftc "x86_64-apple-ios13.0-simulator"
This command uses -Xswiftc to workaround the issue by overriding the sdk from macOS to iphonesimulator.
Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.
Source
So I'm guessing there will be a more elegant solution in the future.
Starting with Xcode 11, xcodebuild supports SwiftPM packages out of the box.
An example invocation would look like this:
xcodebuild -scheme Foo \
-destination 'platform=iOS Simulator,OS=13.5,name=iPhone 11 Pro'
where Foo would be the name of the library product you're trying to build. You can
get the full list of available schemes for you SwiftPM package with xcodebuild -list.
You can get the list of available destinations for a given scheme with this invocation:
xcodebuild -showdestinations -scheme Foo

Swift fat framework w/Objective-C Cocoapod

I've built a framework in Swift. The framework uses Cocoapods, one of the pods is written in Objective C.
I also use a custom script to make the framework a fat framework so it supports 32/64 bit systems. (This runs in a separate target on the project and I'm wondering if that has something to do with it?)
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
// Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
//Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
// Step 3. Copy Swift modules (from iphonesimulator build) to the copied framework directory
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
// Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
// Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
// Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
fi
When I create this fat framework and put it into a project I'd like to use it on the compiler always fails b/c the project can't see the objective C cocoa pod module.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: framework not found Pusher for architecture x86_64
It is not found for any architecture when I change the build platform.
Any solution where I can produce a framework that I can use in a separate Xcode project (for all iOS or OS X) would be awesome.
You can't run xcodebuild with -target when using CocoaPods. When you use -target, Xcode will only consider the active project and fail to pull in the Pod dependencies, similar to if you just opened the project file in Xcode and tried building.
You should be running xcodebuild -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${PROJECT_NAME}" ..., assuming that CocoaPods generated the workspace and Xcode generated a scheme using the target name. You will also need to make sure your scheme is marked as shared if running this on another device.
Once your framework is built you will need to include it and the frameworks it depends on in apps that will be using it. For your framework, that means including it in General > Embedded Binaries and General > Linked Frameworks and Libraries. For frameworks you depend on, (e.g. AlamoFire), you could instruct users to include it in their Podfile, you could package it and ship it along with your framework, or you could do both and let the user do what works for them.
Apparently you are missing the 64bit architecture for Simulator.
When you build a target from Xcode, depending on what kind of simulator you have selected - the produced library will contains i386 or x86_64 respectively for selected 32bit or 64bit version of the simulator.
I guess that the cli build is producing only i386 version.
You can try to set the architectures in the script:
xcodebuild -target "${PROJECT_NAME}" ARCHS="i386 x86_64" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
As an alternative You can try to build by hand using 64bit simulator (iPhone 5S +), then extract the missing architecture and then put it into the final library using lipo command.

How do I catch OCUnit's test fail/success in command line?

My Expect: # Build Successed # and # Test Failed #
Actual Result: only # Build Succeeded #
How do I get fail/success in command line? [iphone, objective-c, xcode4, OCUnit]
I'm newbe of OCUnit and Xcode4. I create project:
https://github.com/sanemat/HogeHoge
This is scafold code by xcode4. I run test in xcode gui, #Test Failed# appear in successfully. In commandline (I want to use jenkins),I use following command.
xcodebuild -target HogeHogeTests -configuration Debug -sdk iphonesimulator4.3 clean build
I see # Build Succeeded # and then completed. I want run test and get it's result. How?
Edited:
I found BPOCUnitXMLReporter. This is for MacOS. I forked and adjusted iOS.
I found BPOCUnitXMLReporter. This is for MacOS. I forked and adjusted iOS.
Try the Text Finder Plugin It allows you to search a log for a string, and set pass or fail based on that.
You can integrate a custom test logger with OCUnit. See my answer here:
How do I trap OCUnit test pass/failure messages/events
what you're looking for is this undocumented argument (you do need sdk and target too) to run your OCUnit Tests from the terminal
xcodebuild -target MyTarget -sdk iphonesimulator TEST_AFTER_BUILD=YES

(iphone) build xcode4 project from command line

I've used to build my project with
xcodebuild -proj MyProject.xcodeproj -target MyTarget - configuration Debug -sdk iphonesimulator4.3
this works(it builds fine) but when I hit run in xcode, it recompiles.
(with xcode3, there was no need to rebuild once I build using command line)
I suspect xcode build use workspace/scheme rather than project/target.
How do I find out the workspace name that my current xcode project is using?
Thank you
edit
Chetan's links gave me directions what to look for.
xcode4 stores build output in ~/Library/...
whereas xcodebuild -project .. saves build output in project's build directory.
(if you want the workspace capability, you can't use the build directory for build output)
I created a workspace containing my project and ran
xcodebuild -workspace myWorkSpace -scheme myScheme
this saves build output in ~/Library/...../Debug-iphoneos
whereas xcode4 run button from the same workspace and same scheme saves output in
~/Library/..../Debug-iphonesimulator
any guess on why xcodebuild command uses Debug-iphoneos? :(
edit2
xcodebuild -workspace myWorkSpace -scheme myScheme -sdk iphonesimulator4.3
specifying sdk solved it
I know it isn't strictly the answer to your question, but you can configure the output directory of your build using the CONFIGURATION_BUILD_DIR environment variable.
Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40003931-CH1-SW1