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
-
#arg_files ⇒ Set<String>
The list of the arg files required by this settings file.
-
#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
(also: #to_h)
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.
58 59 60 61 62 63 64 65 66 |
# File 'lib/xcodeproj/config.rb', line 58 def initialize(xcconfig_hash_or_file = {}) @attributes = {} @includes = [] @other_linker_flags = {} [:simple, :frameworks, :weak_frameworks, :libraries, :arg_files, :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.
42 43 44 |
# File 'lib/xcodeproj/config.rb', line 42 def attributes @attributes end |
#includes ⇒ Array
Returns The list of the configuration files included by this configuration file (‘#include “SomeConfig”`).
53 54 55 |
# File 'lib/xcodeproj/config.rb', line 53 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.
48 49 50 |
# File 'lib/xcodeproj/config.rb', line 48 def other_linker_flags @other_linker_flags end |
Instance Method Details
#==(other) ⇒ Object
72 73 74 |
# File 'lib/xcodeproj/config.rb', line 72 def ==(other) other.attributes == attributes && other.other_linker_flags == other_linker_flags && other.includes == includes end |
#arg_files ⇒ Set<String>
Returns The list of the arg files required by this settings file.
188 189 190 |
# File 'lib/xcodeproj/config.rb', line 188 def arg_files other_linker_flags[:arg_files] end |
#dup ⇒ Config
Returns A copy of the receiver.
248 249 250 |
# File 'lib/xcodeproj/config.rb', line 248 def dup Xcodeproj::Config.new(to_hash.dup) end |
#frameworks ⇒ Set<String>
Returns The list of the frameworks required by this settings file.
167 168 169 |
# File 'lib/xcodeproj/config.rb', line 167 def frameworks other_linker_flags[:frameworks] end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/xcodeproj/config.rb', line 68 def inspect to_hash.inspect end |
#libraries ⇒ Set<String>
Returns The list of the libraries required by this settings file.
181 182 183 |
# File 'lib/xcodeproj/config.rb', line 181 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.
242 243 244 |
# File 'lib/xcodeproj/config.rb', line 242 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.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/xcodeproj/config.rb', line 216 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.
105 106 107 108 109 110 111 |
# File 'lib/xcodeproj/config.rb', line 105 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 Also known as: to_h
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`).
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 159 160 |
# File 'lib/xcodeproj/config.rb', line 122 def to_hash(prefix = nil) list = [] list += other_linker_flags[:simple].to_a.sort modifiers = { :frameworks => '-framework ', :weak_frameworks => '-weak_framework ', :libraries => '-l', :arg_files => '@', :force_load => '-force_load', } [:libraries, :frameworks, :weak_frameworks, :arg_files, :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.
91 92 93 94 95 |
# File 'lib/xcodeproj/config.rb', line 91 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.
174 175 176 |
# File 'lib/xcodeproj/config.rb', line 174 def weak_frameworks other_linker_flags[:weak_frameworks] end |