Class: Pod::Target::BuildSettings::AggregateTargetSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/link_filelist_optimize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ld_flags_for_any_archObject

Returns the value of attribute ld_flags_for_any_arch.



142
143
144
# File 'lib/link_filelist_optimize.rb', line 142

def ld_flags_for_any_arch
  @ld_flags_for_any_arch
end

#ld_flags_for_deviceObject

Returns the value of attribute ld_flags_for_device.



143
144
145
# File 'lib/link_filelist_optimize.rb', line 143

def ld_flags_for_device
  @ld_flags_for_device
end

#ld_flags_for_simulatorObject

Returns the value of attribute ld_flags_for_simulator.



144
145
146
# File 'lib/link_filelist_optimize.rb', line 144

def ld_flags_for_simulator
  @ld_flags_for_simulator
end

Instance Method Details

#_raw_other_ldflagsObject



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/link_filelist_optimize.rb', line 46

def _raw_other_ldflags
  # 每个 Pod 自带内部的 .a .framework
  vendored_paths = {}
  pod_targets.each do |pod_target|
    pod_target.file_accessors.each do |acc|
      (acc.vendored_dynamic_libraries + acc.vendored_static_libraries).each do |l|
        library_name = File.basename(l, l.extname).sub(/^lib/, '')
        vendored_paths[library_name] = l.to_s
      end

      (acc.vendored_dynamic_frameworks + acc.vendored_static_frameworks).each do |l|
        framework_name = File.basename(l, l.extname)
        vendored_paths[framework_name] = l.to_s
      end
    end
  end

  base_file_path = "#{target.name}.#{@configuration_name.to_s.downcase}"
  base_dir = File.expand_path("Target Support Files", self.target.sandbox.root.to_s)

  vendored_file_path = File.expand_path("#{base_file_path}.vendored.filelist", base_dir)
  vendored_files = []

  intermediates_file_path = File.expand_path("#{base_file_path}.intermediates.filelist", base_dir)
  intermediates_files = []

  system_file_path = File.expand_path("#{base_file_path}.system.filelist", base_dir)
  system_files = []

  ld_flags = []
  ld_flags << '-ObjC' if requires_objc_linker_flag?
  if requires_fobjc_arc?
    ld_flags << '-fobjc-arc'
  end

  libraries.each do |library_name|
    next if library_name == "stdc++" # libstdc++.dylib
    library_path = vendored_paths[library_name]
    if library_path
      vendored_files << library_path
    else
      library_path = find_path_of_lib(library_name)
      if library_path
        system_files << library_path
      else
        intermediates_files << "#{library_name}/lib#{library_name}.a"
      end
    end
  end

  frameworks.each do |framework_name|
    framework_path = nil
    framework_path = vendored_paths[framework_name] + "/" + framework_name unless vendored_paths[framework_name].nil?
    if framework_path
      vendored_files << framework_path
    else
      framework_path = find_path_of_framework(framework_name)
      if framework_path
        system_files << framework_path
      else
        raise "Can't find framework #{framework_name}"
      end
    end
  end

  extra_ld_info = "$(inherited) "
  if !intermediates_files.empty?
    File.open(intermediates_file_path, 'w') do |f|
      f.puts(intermediates_files)
    end
    extra_ld_info += "-filelist \"#{intermediates_file_path},${PODS_CONFIGURATION_BUILD_DIR}\" "
  end

  if !vendored_files.empty?
    File.open(vendored_file_path, 'w') do |f|
      f.puts(vendored_files)
    end
    extra_ld_info += "-filelist \"#{vendored_file_path}\""
  end

  if !intermediates_files.empty? || !vendored_files.empty?
    @ld_flags_for_any_arch = extra_ld_info.strip
  end

  if !system_files.empty?
    File.open(system_file_path, 'w') do |f|
      f.puts(system_files)
    end
    @ld_flags_for_device = "$(inherited) -filelist \"#{system_file_path},#{device_sdk_path}\""
    @ld_flags_for_simulator = "$(inherited) -filelist \"#{system_file_path},#{simulator_sdk_path}\""
  end

  weak_frameworks.each { |f| ld_flags << '-weak_framework' << %("#{f}") }
  ld_flags
end

#device_sdk_pathObject



7
8
9
# File 'lib/link_filelist_optimize.rb', line 7

def device_sdk_path
  @device_sdk_path ||= `xcrun --sdk iphoneos --show-sdk-path`.strip
end

#find_path_of_framework(framework_name) ⇒ Object



21
22
23
24
25
# File 'lib/link_filelist_optimize.rb', line 21

def find_path_of_framework(framework_name)
  storage_framework_path = framework_name + ".framework/" + framework_name + ".tbd"
  framework_path = File.expand_path(storage_framework_path, '/System/Library/Frameworks')
  return framework_path if File.exist?(device_sdk_path + framework_path)
end

#find_path_of_lib(lib_name) ⇒ Object



15
16
17
18
19
# File 'lib/link_filelist_optimize.rb', line 15

def find_path_of_lib(lib_name)
  storage_lib_name = "lib" + lib_name + ".tbd"
  library_path = File.expand_path(storage_lib_name, '/usr/lib')
  return library_path if File.exist?(device_sdk_path + library_path)
end

#simulator_sdk_pathObject



11
12
13
# File 'lib/link_filelist_optimize.rb', line 11

def simulator_sdk_path
  @simulator_sdk_path ||= `xcrun --sdk iphonesimulator --show-sdk-path`.strip
end

#to_hObject

xcconfig 总所有配置的 key => value



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/link_filelist_optimize.rb', line 28

def to_h
  hash = super()
  hash.delete('LIBRARY_SEARCH_PATHS')
  hash.delete('FRAMEWORK_SEARCH_PATHS')

  if defined?(@ld_flags_for_any_arch) && !@ld_flags_for_any_arch.blank?
    hash['OTHER_LDFLAGS[arch=*]'] = @ld_flags_for_any_arch
  end

  if defined?(@ld_flags_for_device) && !@ld_flags_for_device.blank?
    hash['OTHER_LDFLAGS[arch=armv7]']  = @ld_flags_for_device
    hash['OTHER_LDFLAGS[arch=arm64]']  = @ld_flags_for_device
    hash['OTHER_LDFLAGS[arch=i386]']   = @ld_flags_for_simulator
    hash['OTHER_LDFLAGS[arch=x86_64]'] = @ld_flags_for_simulator
  end
  hash
end