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(dependencies, 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 17

def flag_libraries dependencies, 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)

    other_ldflags = xcconfig.filter_lines do |line| line.include? 'OTHER_LDFLAGS = ' end.first || ''
    header_search_paths = xcconfig.filter_lines do |line| line.include? 'HEADER_SEARCH_PATHS = ' end.first  || ''
    framework_search_paths = xcconfig.filter_lines do |line| line.include? 'FRAMEWORK_SEARCH_PATHS = ' end.first  || ''
    other_swift_flags = xcconfig.filter_lines do |line| line.include? 'OTHER_SWIFT_FLAGS = ' end.first || ''
    
    new_other_ldflags = "OTHER_LDFLAGS[sdk=#{platform.sdk}] = $(inherited) -ObjC"
    new_header_search_paths = "HEADER_SEARCH_PATHS[sdk=#{platform.sdk}] = $(inherited)"
    new_framework_search_paths = "FRAMEWORK_SEARCH_PATHS[sdk=#{platform.sdk}] = $(inherited)"
    new_other_swift_flags = "OTHER_SWIFT_FLAGS[sdk=#{platform.sdk}] = $(inherited) -D COCOAPODS"
    new_xcconfig = xcconfig.gsub!(other_ldflags, '').gsub!(header_search_paths, '').gsub!(other_swift_flags, '').gsub!(framework_search_paths, '')

    changed = false
    dependencies.each do |dependency|
      if other_ldflags.include? dependency.link
        other_ldflags.gsub! dependency.link, ''
        changed = true
        new_other_ldflags += " #{dependency.link}"
      end
      
      regex = /(?<=[\s])([\"]*[\S]*#{Regexp.escape(dependency.name)}[\S]*[\"]*)(?=[\s]?)/
      if header_search_paths.match? regex
        to_replace = header_search_paths.scan(regex).flat_map do |m| m end.filter do |m| !m.nil? && !m.empty? end.each do |to_replace|
          header_search_paths.gsub! to_replace, ''
          new_header_search_paths += " #{to_replace}"
        end
        changed = true
      end

      regex = /(?<=[\s])([\"][\S]*#{Regexp.escape(dependency.name)}[\S]*\")(?=[\s]?)/
      if framework_search_paths.match? regex
        to_replace = framework_search_paths.scan(regex).flat_map do |m| m end.filter do |m| !m.nil? && !m.empty? end.each do |to_replace|
          framework_search_paths.gsub! to_replace, ''
          new_framework_search_paths += " #{to_replace}"
        end
        changed = true
      end

      regex = /(?<=[\s])(-Xcc -[\S]*#{Regexp.escape(dependency.name)}[\S]*\")(?=[\s]?)/
      if other_swift_flags.match? regex
        to_replace = other_swift_flags.scan(regex).flat_map do |m| m end.filter do |m| !m.nil? && !m.empty? end.each do |to_replace|
          other_swift_flags.gsub! to_replace, ''
          new_other_swift_flags += " #{to_replace}"
        end
        changed = true
      end
    end
  
    if changed
      new_xcconfig += "\n#{other_ldflags}\n#{framework_search_paths}\n#{header_search_paths}"
      new_xcconfig += "\n#{new_other_ldflags}\n#{new_framework_search_paths}\n#{new_header_search_paths}"
      if !other_swift_flags.empty?
        new_xcconfig += "\n#{other_swift_flags}\n#{new_other_swift_flags}"
      end
      new_xcconfig.gsub! /\n+/, "\n"
      new_xcconfig.gsub! /[ ]+/, " "
      File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
    end
    loggs "\t\t\t#{changed ? "Succeded" : "Nothing to flag"}"
  end
end

#other_linker_flags_dependenciesObject

Dependencies contained in Other Linker Flags


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 94

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


88
89
90
91
# File 'lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb', line 88

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