Class: Xcodeproj::Config
- Inherits:
-
Object
- Object
- Xcodeproj::Config
- Defined in:
- lib/xcodeproj/config.rb,
lib/xcodeproj/config/other_linker_flags_parser.rb
Overview
This class holds the data for a Xcode build settings file (xcconfig) and provides support for serialization.
Defined Under Namespace
Modules: OtherLinkerFlagsParser
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{String => String}
The attributes of the settings file excluding frameworks, weak_framework and libraries.
-
#includes ⇒ Array
The list of the configuration files included by this configuration file (‘#include “SomeConfig”`).
-
#other_linker_flags ⇒ Hash{Symbol => Set<String>}
The other linker flags by key.
Serialization collapse
-
#frameworks ⇒ Set<String>
The list of the frameworks required by this settings file.
-
#libraries ⇒ Set<String>
The list of the libraries required by this settings file.
-
#save_as(pathname, prefix = nil) ⇒ void
Writes the serialized representation of the internal data to the given path.
-
#to_hash(prefix = nil) ⇒ Hash
The hash representation of the xcconfig.
-
#to_s(prefix = nil) ⇒ String
Sorts the internal data by setting name and serializes it in the xcconfig format.
-
#weak_frameworks ⇒ Set<String>
The list of the weak frameworks required by this settings file.
Merging collapse
-
#dup ⇒ Config
A copy of the receiver.
-
#merge(config) ⇒ Config
Creates a new #Config with the data of the receiver merged with the given xcconfig representation.
-
#merge!(xcconfig) ⇒ void
(also: #<<)
Merges the given xcconfig representation in the receiver.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(xcconfig_hash_or_file = {}) ⇒ Config
constructor
A new instance of Config.
- #inspect ⇒ Object
Constructor Details
#initialize(xcconfig_hash_or_file = {}) ⇒ Config
Returns a new instance of Config.
57 58 59 60 61 62 63 64 65 |
# File 'lib/xcodeproj/config.rb', line 57 def initialize(xcconfig_hash_or_file = {}) @attributes = {} @includes = [] @other_linker_flags = {} [:simple, :frameworks, :weak_frameworks, :libraries, :force_load].each do |key| @other_linker_flags[key] = Set.new end merge!(extract_hash(xcconfig_hash_or_file)) end |
Instance Attribute Details
#attributes ⇒ Hash{String => String}
Returns The attributes of the settings file excluding frameworks, weak_framework and libraries.
41 42 43 |
# File 'lib/xcodeproj/config.rb', line 41 def attributes @attributes end |
#includes ⇒ Array
Returns The list of the configuration files included by this configuration file (‘#include “SomeConfig”`).
52 53 54 |
# File 'lib/xcodeproj/config.rb', line 52 def includes @includes end |
#other_linker_flags ⇒ Hash{Symbol => Set<String>}
Returns The other linker flags by key. Xcodeproj handles them in a dedicated way to prevent duplication of the libraries and of the frameworks.
47 48 49 |
# File 'lib/xcodeproj/config.rb', line 47 def other_linker_flags @other_linker_flags end |
Instance Method Details
#==(other) ⇒ Object
71 72 73 |
# File 'lib/xcodeproj/config.rb', line 71 def ==(other) other.attributes == attributes && other.other_linker_flags == other_linker_flags && other.includes == includes end |
#dup ⇒ Config
Returns A copy of the receiver.
237 238 239 |
# File 'lib/xcodeproj/config.rb', line 237 def dup Xcodeproj::Config.new(to_hash.dup) end |
#frameworks ⇒ Set<String>
Returns The list of the frameworks required by this settings file.
163 164 165 |
# File 'lib/xcodeproj/config.rb', line 163 def frameworks other_linker_flags[:frameworks] end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/xcodeproj/config.rb', line 67 def inspect to_hash.inspect end |
#libraries ⇒ Set<String>
Returns The list of the libraries required by this settings file.
177 178 179 |
# File 'lib/xcodeproj/config.rb', line 177 def libraries other_linker_flags[:libraries] end |
#merge(config) ⇒ Config
Creates a new #Xcodeproj::Config with the data of the receiver merged with the given xcconfig representation.
231 232 233 |
# File 'lib/xcodeproj/config.rb', line 231 def merge(config) dup.tap { |x| x.merge!(config) } end |
#merge!(xcconfig) ⇒ void Also known as: <<
The logic to normalize an hash should be extracted and the initializer should not call this method.
If a key in the given hash already exists in the internal data then its value is appended.
This method returns an undefined value.
Merges the given xcconfig representation in the receiver.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/xcodeproj/config.rb', line 205 def merge!(xcconfig) if xcconfig.is_a? Config merge_attributes!(xcconfig.attributes) other_linker_flags.keys.each do |key| other_linker_flags[key].merge(xcconfig.other_linker_flags[key]) end else merge_attributes!(xcconfig.to_hash) if flags = attributes.delete('OTHER_LDFLAGS') flags_by_key = OtherLinkerFlagsParser.parse(flags) other_linker_flags.keys.each do |key| other_linker_flags[key].merge(flags_by_key[key]) end end end end |
#save_as(pathname, prefix = nil) ⇒ void
This method returns an undefined value.
Writes the serialized representation of the internal data to the given path.
104 105 106 107 108 109 110 |
# File 'lib/xcodeproj/config.rb', line 104 def save_as(pathname, prefix = nil) if File.exist?(pathname) return if Config.new(pathname) == self end pathname.open('w') { |file| file << to_s(prefix) } end |
#to_hash(prefix = nil) ⇒ Hash
All the values are sorted to have a consistent output in Ruby 1.8.7.
The hash representation of the xcconfig. The hash includes the frameworks, the weak frameworks, the libraries and the simple other linker flags in the ‘Other Linker Flags` (`OTHER_LDFLAGS`).
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/xcodeproj/config.rb', line 121 def to_hash(prefix = nil) list = [] list += other_linker_flags[:simple].to_a.sort modifiers = { :frameworks => '-framework ', :weak_frameworks => '-weak_framework ', :libraries => '-l', :force_load => '-force_load', } [:libraries, :frameworks, :weak_frameworks, :force_load].each do |key| modifier = modifiers[key] sorted = other_linker_flags[key].to_a.sort if key == :force_load list += sorted.map { |l| %(#{modifier} #{l}) } else list += sorted.map { |l| %(#{modifier}"#{l}") } end end result = attributes.dup result['OTHER_LDFLAGS'] = list.join(' ') unless list.empty? result.reject! { |_, v| INHERITED.any? { |i| i == v.to_s.strip } } result = @includes.map do |incl| path = File.(incl, @filepath.dirname) if File.readable? path Xcodeproj::Config.new(path).to_hash else {} end end.inject(&:merge).merge(result) unless @filepath.nil? || @includes.empty? if prefix Hash[result.map { |k, v| [prefix + k, v] }] else result end end |
#to_s(prefix = nil) ⇒ String
Sorts the internal data by setting name and serializes it in the xcconfig format.
90 91 92 93 94 |
# File 'lib/xcodeproj/config.rb', line 90 def to_s(prefix = nil) include_lines = includes.map { |path| "#include \"#{normalized_xcconfig_path(path)}\"" } settings = to_hash(prefix).sort_by(&:first).map { |k, v| "#{k} = #{v}".strip } (include_lines + settings).join("\n") << "\n" end |
#weak_frameworks ⇒ Set<String>
Returns The list of the weak frameworks required by this settings file.
170 171 172 |
# File 'lib/xcodeproj/config.rb', line 170 def weak_frameworks other_linker_flags[:weak_frameworks] end |