How can I modify the OTHER_LDFLAGS field in the .xcconfig generated at pod install step?
End goal: Only weakly link certain Pods, so they can be loaded with dlopen at runtime.
I noticed in the Pod-Target.debug.xcconfig generated at pod install, it has this: OTHER_LDFLAGS = $(inherited) -framework "AFNetworking", if I change that to -weak_framework, it does what I want to do.
This Cocoapods issue talks about doing it through a post_install hook, however config.build_settings['OTHER_LDFLAGS'] doesn't write to that file.
PS: I know that the use of dlopen is not recommended, however I'm working with conflicting hardware libraries where I cannot have two loaded at the same time.
Add this code to your Podfile and run pod install again
post_install do |installer|
workDir = Dir.pwd
xcconfigFilename = "#{workDir}/Pods/Target Support Files/Pods-Target/Pod-Target.debug.xcconfig"
xcconfig = File.read(xcconfigFilename)
newXcconfig = xcconfig.gsub(/-framework "AFNetworking"/, "-weak_framework \"AFNetworking\"")
File.open(xcconfigFilename, "w") { |file| file << newXcconfig }
end
A little modification of answer by VoidLess which I think might be useful:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
xcconfig_mod = xcconfig.gsub(/-framework "YourFramework"/, "-weak_framework \"YourFramework\"")
File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
end
end
end
Related
I has created two configurations in Project > Project name > Info (tab) > Configurations Target.
Let's call em CustomDebug and CustomRelease. For each configuration, i has created xconfig files – CustomDebug.xconfig and CustomRelease.xconfig and set em as 'Base on Configuration File' field to corresponding configurations. After that i did run pod install. Pods has been installed with warnings – I should use config files generated by pods directly in my configs or by including em in my config files. So i choose 2nd option and add corresponding includes to my config files.
All works fine. But...
I tried to define custom macro in my config file:
GCC_PREPROCESSOR_DEFINITIONS='$(value) MACRO=1'
And it overrides same var from config file generated by pods.
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 $(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1 $(inherited) PB_FIELD_32BIT=1 PB_NO_PACKED_STRUCTS=1 PB_ENABLE_MALLOC=1
When i swap the import and custom macro lines, obviously, value defined in pods config for GCC_PREPROCESSOR_DEFINITIONS overrides my one.
Does any body know, how to "extend" value of GCC_PREPROCESSOR_DEFINITIONS defined in config file generated by CocoaPods?
You can't "extend" value of GCC_PREPROCESSOR_DEFINITIONS defined in config file generated by CocoaPods.
To fix nanopb framework in Pods, add to Podfile post-install script:
post_install do |installer|
installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == "nanopb"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PB_ENABLE_MALLOC=1'
end
end
end
end
Add $(inherited):
GCC_PREPROCESSOR_DEFINITIONS='$(inherited) $(value) MACRO=1'
Im trying to set a build configuration setting on my cocoapod im working on but I can only do it in a really inconvenient way, im trying to see if there is a better way doing it via the podspec file. Currently I have this in my example project pod file:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'MySDK'
target.build_configurations.each do |config|
if config.name == 'Test'
config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = 'TEST'
end
end
end
end
end
which gives me what I want, which looks like this:
I've tried going like this (after removing the previous solution above from the pod file) inside my podspec file, a lot of SO answers say this should work but it doesnt seem to
s.pod_target_xcconfig = {
'SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Test]' => 'TEST'
}
it lands up looking like this:
Can anyone help me achieve this in my podspec file as apposed to the 3rd parties pod file?
This should work:
s.pod_target_xcconfig = {
'SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Test][sdk=*][arch=*]' => 'TEST'
}
versions:
TesseractOCRiOS 4.0.0
CocoaPods 1.2.1
When i'm building on simulator - everything is fine, but when i'm trying to build on my iPhone xCode gives me next warning:
Warning: Multiple build commands for output file /Users/Username/Library/Developer/Xcode/DerivedData/ProjectName-hjheurpncvhpfbabezufoumrybad/Build/Products/Debug-iphoneos/TesseractOCRiOS/TesseractOCR.framework/PrivateHeaders/config_auto.h
Faced with the same problem recently, definitely not the best, but acceptable workaround - just delete one of the duplicate lines "config_auto.h" with path "./Pods/TesseractOCRiOS/TesseractOCR/include/leptonica/" in "Build Phases"-"Headers"-"Private" settings of TesseractOCRiOS target.
OCR recognition functionality does not affected by this change.
See screenshot for details.
If you're using cocoapods, you can add following script at the end of your pod file:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'TesseractOCRiOS'
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
header_phase = target.build_phases().select do |phase|
phase.is_a? Xcodeproj::Project::PBXHeadersBuildPhase
end.first
duplicated_header_files = header_phase.files.select do |file|
file.display_name == 'config_auto.h'
end
duplicated_header_files.each do |file|
header_phase.remove_build_file file
end
end
end
end
Just noticed that it's also disabling bitcode. Remove it if that's not what you need. The script removes the duplicate header files since they are under private section only.
I think you have a problem in your project directory. You have a duplicate file of config_auto.h
Go to your Target , Delete config_auto.h under the build phases.
Hope!! This helps you
Is there a way to exclude Pods from Code Coverage?
I would like to see Code Coverage only for the code I've written.
Not that it should matter, but I'm using Xcode 8.
These steps will help:
1. add these lines to Podfile
# Disable Code Coverage for Pods projects
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
end
end
end
2. run pod install
Now you won't see pods in test coverage.
Note: It only excludes Objective-c pods but not Swift
XCode 10 Update
In Xcode 10 you can set which targets you want to enable code coverage for in
Edit Schemes > Test > Options
Just select 'Gather coverage for some targets' and add your main project.
To disable coverage for swift code you can use a wrapper for SWIFT_EXEC (I verified this so far with Xcode 9.3). Hence the complete solution (incl. Swift) would be the following:
Append to your Podfile (and invoke pod install after that):
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |configuration|
configuration.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
configuration.build_settings['SWIFT_EXEC'] = '$(SRCROOT)/SWIFT_EXEC-no-coverage'
end
end
end
Place the following script (name it SWIFT_EXEC-no-coverage) at the root of your source tree (chmod +x as necessary):
#! /usr/bin/perl -w
use strict;
use Getopt::Long qw(:config pass_through);
my $profile_coverage_mapping;
GetOptions("profile-coverage-mapping" => \$profile_coverage_mapping);
exec(
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc",
#ARGV);
Here's a link to the corresponding gist: https://gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4
Click on your Pods project in the Project Navigator on the left
On the right hand side, open project and target list if it's not already open; then click on the Pods project name (NOT the targets).
Click Build Settings.
In the search bar, search for "CLANG_ENABLE_CODE_COVERAGE".
Change "Enable Code Coverage Support" to NO.
Re-run test.
If you are developing a pod and want to have code coverage just for yours:
# Disable Code Coverage for Pods projects except MyPod
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == 'MyPod'
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'YES'
end
else
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
end
end
end
end
Based on answer of #Tung Fam adding exclusion list for some pods
# Disable Code Coverage for projects listed in excluded_pods
excluded_pods = ['Pod1', 'Pod2', 'Pod3']
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
next if !excluded_pods.include?(target.name)
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
end
end
end
So, I am trying to add a folder reference in a target that was created by cocoapods.
I found this solution, but it is not working for me. https://github.com/CocoaPods/CocoaPods/issues/3521
I am on cocoapods 0.39. And I only changed the projects to pods_project since that was deprecated.
Also how do you enable logging when running pod update. I tried pod update --verbose, but my puts is not being displayed. :/
=========== UPDATED ===========
post_install do |installer|
puts "printing tests"
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == "TargetWhereToAddTheFolderOrFileReference"
source_files = target.source_build_phase.files
folderReference = installer.project.add_file_reference("/AbsolutePath/To/FileOrFolder", installer.project.pod_group("PodGroupWhereToAddTheFileOrFolder"), true)
target.source_build_phase.add_file_reference(btsdata, true)
end
end
end
end
post_install do |installer|
// another post install script is here.
end
I've attached the script that is failing plus there was another post_install script below it. That puts "printing tests" is not being called as well....
=========== UPDATED ENDS ===========
Oh, I think the script will only execute the last post_install and not
both. Can you put the code inside the first post_install into the last one?