Class: Xcodeproj::Project::Object::AbstractTarget

Inherits:
Object
  • Object
show all
Includes:
CocoapodsCatalystSupport::TargetUtils
Defined in:
lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb

Instance Method Summary collapse

Methods included from CocoapodsCatalystSupport::TargetUtils

#module_name

Instance Method Details

#add_platform_filter_to_dependencies(platform) ⇒ Object

STEP 2 ###### In all targets (aggregates + native), filter dependencies



8
9
10
11
12
13
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 8

def add_platform_filter_to_dependencies platform
  loggs "\t\t- Filtering dependencies"
  dependencies.each do |dependency|
    dependency.platform_filter = platform.name.to_s
  end
end

#flag_libraries(libraries, platform) ⇒ Object

STEP 3 ###### If any unsupported library, then flag as platform-dependant for every build configuration



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 17

def flag_libraries libraries, platform
  loggs "\tTarget: #{name}"
  build_configurations.filter do |config| !config.base_configuration_reference.nil? 
  end.each do |config|
    loggs "\t\tScheme: #{config.name}"
    xcconfig_path = config.base_configuration_reference.real_path
    xcconfig = File.read(xcconfig_path)
  
    changed = false
    libraries.each do |framework|
      if xcconfig.include? framework
        xcconfig.gsub!(framework, '')
        unless xcconfig.include? "OTHER_LDFLAGS[sdk=#{platform.sdk}]"
          changed = true
          xcconfig += "\nOTHER_LDFLAGS[sdk=#{platform.sdk}] = $(inherited) -ObjC "
        end
        xcconfig += framework + ' '
      end
    end
  
    File.open(xcconfig_path, "w") { |file| file << xcconfig }
    loggs "\t\t\t#{changed ? "Succeded" : "Nothing to flag"}"
  end
end

#other_linker_flags_dependenciesObject

Dependencies contained in Other Linker Flags



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 48

def other_linker_flags_dependencies
  config = build_configurations.filter do |config| not config.base_configuration_reference.nil? end.first
  other_ldflags = config.resolve_build_setting 'OTHER_LDFLAGS'
  
  if other_ldflags.nil? 
    return [] 
  end
  
  if other_ldflags.class == String
    other_ldflags = other_ldflags.split ' '
  end
  
  libraries = other_ldflags.filter do |flag| flag.start_with? '-l' end.map do |flag| flag.gsub! /(["|\-l]*)/, '' end.map do |name| PodDependency.newLibrary name end
  mixed_frameworks = other_ldflags.filter do |flag| !flag.start_with? '-l' end
  
  weak_frameworks = mixed_frameworks.length.times.filter do |i| mixed_frameworks[i].include? 'weak_framework' end.map do |i| PodDependency.newWeakFramework(mixed_frameworks[i+1].gsub! '"', '') end
  frameworks = mixed_frameworks.length.times.select do |i| mixed_frameworks[i].match /^([^{weak_}]*)framework$/ end.map do |i| PodDependency.newFramework(mixed_frameworks[i+1].gsub! '"', '') end
  
  return libraries + frameworks + weak_frameworks
end

#to_dependencyObject



42
43
44
45
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 42

def to_dependency
  # We return both as we don't know if build as library or framework
  return [PodDependency.newFramework(module_name), PodDependency.newLibrary(name)]
end