How to use OCLint for the Cocoa Framework? - objective-c

Run the following command in the folder with the project:
$ xcodebuild -target MyCocoaFramework -configuration Debug -scheme MyCocoaFramework clean build | tee xcodebuild.log
$ oclint-xcodebuild
$ oclint-json-compilation-database
$
Nothing is displayed.
This approach works fine for Cocoa Application.
$ xcodebuild -target MyCocoaApplication -configuration Debug -scheme MyCocoaApplication clean build | tee xcodebuild.log
$ oclint-xcodebuild
$ oclint-json-compilation-database
/a/b/c/d.m:181:5: redundant local variable P3
/a/b/c/d/e.m:193:5: redundant local variable P3
/a/b/c/d.m:104:1: long line P3 Line with 112 characters exceeds limit of 100
What should be changed to work for the Cocoa Framework?

OCLint can't support the arm64 architecture: https://github.com/oclint/oclint/issues/190
If your code targets iOS 7, then OCLint may fail silently.

Related

Pod Install fails when installing MuPDF

I'm developing a pdf viewer app and I'm using MuPdf library cocoapods. I created a new project, added a pod file and ran pod install. Following error occurred. Any help is appreciated to fix this. I have set automatically manage signing in the project.
Analyzing dependencies
Downloading dependencies
Installing MuPDF (1.10)
[!] /bin/bash -c
set -e
cd platform/ios
# release armv7 + arm64
xcodebuild -scheme MuPDF -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
# debug 64bit sim
xcodebuild -scheme MuPDF -configuration Release -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
cd ../../build/
for i in mupdf mupdfthird; do
LIB=lib${i}.a
lipo -create -output $LIB release-ios-i386-x86_64/$LIB release-ios-armv7-arm64/$LIB
done
# rename to avoid any conflict with the libmupdf.a that the pod generates
mv libmupdf.a libmupdfcore.a
# copy iOS headers into the general include directory, as
# cocoapods 1.0 insists that all headers are under the
# header_mappings_dir location
cd ..
cp platform/ios/Classes/*.h platform/ios/common.h include/mupdf/
cd platform/ios
# now fix the imports/includes to be mupdf/foo.h instead of foo.h
find . -name '*.[mh]' -print0 | xargs -0 perl -pi -e 's,#import "Mu,#import "mupdf/Mu,'
find . -name '*.[mh]' -print0 | xargs -0 perl -pi -e 's,#include "common.h",#include "mupdf/common.h",'
find . -name '*.[mh]' -print0 | xargs -0 perl -pi -e 's,#import "common.h",#import "mupdf/common.h",'
# the reference to memory.h in memento.h upsets xcode when
# building a module (fixed upstream for version after 1.9)
cd ../..
find . -name 'memento.h' -print0 | xargs -0 perl -pi -e 's,#include <memory.h>,#include <stdlib.h>,'
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -scheme MuPDF -configuration Release CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
Build settings from command line:
CODE_SIGN_IDENTITY =
CODE_SIGNING_REQUIRED = NO
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
error: An empty identity is not valid when signing a binary for the product type 'Application'. (in target 'MuPDF' from project 'MuPDF')
** BUILD FAILED **

Fastlane Scan: How to add '--screenshots' (xcpretty flag)?

I need to add my screenshots to html-report after Fastlane Scan runs the tests, but here's the problem: --screenshots is xcpretty's flag, not xcodebuild's.
Scan has no such parameter, like xcpretty_args in Snapshot. So now I'm forced to run my tests without Scan but with next script:
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace ./MyProject.xcworkspace -scheme myScheme -destination 'platform=iOS Simulator,name=iPhone 7 Plus,OS=10.3.1' -derivedDataPath 'build'
-only-testing:myTarget/myTestSuite01 test-without-building| xcpretty -r html --screenshots -r junit
So, is it possible to do it any way with Scan?

Universal framework using Xcode 8.3?

I'm trying to build universal swift framework. When I completed developing framework following several tutorials such as
https://medium.com/swiftindia/build-a-custom-universal-framework-on-ios-swift-549c084de7c8
Creating a universal framework using Xcode 8?
Also by using Aggregate target as well but fail to run in Simulator.
Note: I developed using Swift 3, Xcode Version 8.3
I tried with tutorials scripts too but fail.
Also my framework Xcode extension is xcodeproj.
My question is How to develop universal swift framework which will be release to client where he can test through Simulator as well as with real device?
Thanks in advance.
Edit: I followed this answer instruction and successfully build swift framework.
https://stackoverflow.com/a/26691080/614154
You can also use the following script. Supporting Swift and Simulator as well.
just add the content under Project Settings -> Build Phase as new Run Script Phase
Build Project
Folder will open, showing your zipped framework
https://gist.github.com/PaulEhrhardt/6d2be145c5d1b51c216914e7f032013e
#!/bin/sh
# iOS universal library build script supporting swift modules inclusive simulator slices
# prevention from running xcodebuild in a recusive way
if [ "true" == ${ALREADYINVOKED:-false} ]; then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
# output directory for universal framework
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}/iOS"
# build both device and simulator versions for iOS
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "${PROJECT_NAME}" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8' ONLY_ACTIVE_ARCH=NO clean build
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -scheme "${PROJECT_NAME}" -sdk iphoneos ONLY_ACTIVE_ARCH=NO clean build
# copy the framework structure from iphoneos build to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/iOS"
# copy existing Swift modules from iphonesimulator build to the universal framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/"
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi
# create universal binary file using lipo and place the combined executable in the universal framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# intermediate step for copying the framework to the project's directory
mkdir -p "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"
cp -R "${UNIVERSAL_OUTPUTFOLDER}/iOS/${PROJECT_NAME}.framework" "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"
# create a zip file and move it to the project's directory
cd "${TMPDIR}/${PROJECT_NAME}/Frameworks/iOS"
zip -r "${PROJECT_NAME}.framework.zip" "${PROJECT_NAME}.framework"
mkdir -p "${PROJECT_DIR}/universal-framework"
mv "${PROJECT_NAME}.framework.zip" "${PROJECT_DIR}/universal-framework"
# optional: show the project's directory in Finder
open "${PROJECT_DIR}/universal-framework"
fi

xcodebuild far slower than Xcode?

Building from the command line with xcodebuild is orders of magnitude slower than building the same project, same scheme, same target from within Xcode. Does anyone know why this might be the case and how I might speed up my xcodebuild build?
I'm invoking xcodebuild as follows:
xcodebuild -scheme <SCHEME> -workspace <WORKSPACE> -configuration Debug -sdk iphonesimulator7.0 -jobs 12 build
for building on a 12-core Mac Pro. I guessed at the -jobs setting but it seems reasonable. Does anyone have any advice? Is there a way, by analyzing Xcode's build log, to tell what settings for xcodebuild most closely map to what Xcode itself is using? Thanks!
While this alone may not explain the slowness of xcodebuild compared to IDE, I've seen some improvements if I disable Spotlight indexing on ~/Library/Developer/Xcode/DerivedData directory.
When using xcodebuild test that will reboot the simulator each time. It is the main reason case the xcodebuild slowly. When you using xcode test directly, The simulator will not boot twice after booted.
You can try this:
xcodebuild -project Example.xcodeproj \
-scheme ExampleTests \
-disable-concurrent-destination-testing \
-destination 'platform=iOS Simulator,name=iPhone 13' \
-sdk iphonesimulator \
CODE_SIGNING_ALLOWED="NO" \
test
-disable-concurrent-destination-testing disable clone simulator in Xcode 14 and test in the same simulator
CODE_SIGNING_ALLOWED="NO" disable signing test target will faster

Let Xcode Project build static library

I have a Core Library for my ios projects. I use this library in several projects.
When building the library, I copied the .a -file and the header-files into several xcode projects. Everything worked fine.
Now I would like that each project, which uses the library, build the library on their own.
I tried to use this runscript:
# Build Core library first
CORE="${PWD}/../Core"
IDENT="PROJECTIDENT"
PROJ=$CORE/Core.xcodeproj
CORE_LIB="${PWD}/Classes/Core"
mkdir -p "${CORE_LIB}"
#rm -rf "${CORE_LIB}/"*
mkdir -p "/tmp/${IDENT}"
IS_EMPTY=`ls "${CORE_LIB}" | wc -l`
if [ "true" == ${ALREADYINVOKED:-false} ]; then
echo "ALREADY INVOKED"
else
# CRITICAL:
# Prevent infinite recursion (Xcode sucks)
export ALREADYINVOKED="true"
SDK_VERSION=$(echo ${SDK_NAME} | grep -o '.\{3\}$')
OUT_DIR="/tmp/${IDENT}"
EXEC_NAME="libCore.a"
UNIVERSAL_DIR="${OUT_DIR}/Universal"
rm -rf "${UNIVERSAL_DIR}"
mkdir -p "${UNIVERSAL_DIR}"
CONFIG="Debug"
if [ ${CONFIGURATION} != "Debug" ]; then
CONFIG="Release"
fi
echo "${CONFIG}"
# Create build
DID_COMPILE=`xcodebuild -project $PROJ -target Core -configuration "${CONFIG}" -sdk "${PLATFORM_NAME}${SDK_VERSION}" build RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${OUT_DIR}" BUILD_ROOT="${OUT_DIR}" EXECUTABLE_NAME="${EXEC_NAME}" | grep "CompileC"`
if [ ! -z "${DID_COMPILE}" ] || [ ${IS_EMPTY} -eq 0 ]; then
# Copy Headers
cp "${OUT_DIR}/${CONFIG}-${PLATFORM_NAME}/usr/local/include/"* "${UNIVERSAL_DIR}"
cp "${OUT_DIR}/${CONFIG}-${PLATFORM_NAME}/${EXEC_NAME}"* "${UNIVERSAL_DIR}"
# Finally we have a fat static library with .a and .h files
# now we copy them to the Project
rm -rf "${CORE_LIB}"
cp -Rf "${UNIVERSAL_DIR}" "${CORE_LIB}"
fi
fi
This script works but only every second time.
E.g. I make a change in a Library Class, and built, the main project is not compiled while the Library dependency get refreshed.
Then I make another change to the Library, build again, and all changes are usable in the main probject.
But always only each second build....
How can I fix this?